Find storage and AI servers on the tailnet, not only over mDNS
shellcheck / shellcheck (push) Failing after 18s

configure storage and configure ai-servers now also ask the other online
computers on the Core's tailnet, so a laptop away from home still finds the
MiniServer and the LLM box. A machine found both ways is listed once, by its
tailnet name, and tailnet servers mount at /mnt/<short name>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 14:30:38 -07:00
co-authored by Claude Opus 5.5
parent 7e80d37986
commit 16e5a9c79d
5 changed files with 220 additions and 26 deletions
+106 -2
View File
@@ -2,8 +2,9 @@
load test_helper
# The mDNS helper and the configure items built on it (ai-servers, storage),
# with fake avahi-browse, curl and smbclient. Nothing here touches the network.
# The mDNS and tailnet helpers and the configure items built on them
# (ai-servers, storage), with fake avahi-browse, tailscale, curl and smbclient.
# Nothing here touches the network.
setup() {
common_setup
@@ -23,6 +24,11 @@ EOF
export AVAHI
stub avahi-browse 'cat "$AVAHI"'
stub hostnamectl 'echo basement'
# Tailscale is stopped unless a test calls on_tailnet
TAILSCALE_JSON="$BATS_TEST_TMPDIR/tailscale.json"
echo '{"BackendState": "Stopped", "Peer": {}}' > "$TAILSCALE_JSON"
export TAILSCALE_JSON
stub tailscale 'cat "$TAILSCALE_JSON"'
confirm_yes() { return 0; }
confirm() { return 0; }
@@ -55,6 +61,73 @@ EOF
[ "$output" = "$(printf 'lab.local\nllm.local\npi-star.local')" ]
}
# --- lib/tailnet.sh ------------------------------------------------------------------
# What tailscale status --json prints on a tailnet with: llm (also on mDNS as
# llm.local), nas (only on the tailnet), an offline machine, a phone, and this
# machine (Self, which isn't a Peer)
on_tailnet() {
cat > "$TAILSCALE_JSON" << 'EOF'
{
"BackendState": "Running",
"Self": {"HostName": "basement", "DNSName": "basement.tail.example.", "OS": "linux", "Online": true},
"Peer": {
"nodekey:1": {"HostName": "LLM", "DNSName": "llm.tail.example.", "OS": "macOS", "Online": true},
"nodekey:2": {"HostName": "nas", "DNSName": "nas.tail.example.", "OS": "linux", "Online": true},
"nodekey:3": {"HostName": "old", "DNSName": "old.tail.example.", "OS": "linux", "Online": false},
"nodekey:4": {"HostName": "phone", "DNSName": "phone.tail.example.", "OS": "iOS", "Online": true}
}
}
EOF
}
@test "tailnet_hosts lists the other online computers, without the trailing dot" {
source "$REPO/configure.d/lib/tailnet.sh"
on_tailnet
run tailnet_hosts
[ "$status" -eq 0 ]
[ "$output" = "$(printf 'llm.tail.example\nnas.tail.example')" ]
tailnet_joined
}
@test "tailnet_hosts lists nothing when Tailscale isn't running" {
source "$REPO/configure.d/lib/tailnet.sh"
run tailnet_hosts
[ "$status" -eq 0 ]
[ -z "$output" ]
refute tailnet_joined
}
@test "tailnet_hosts lists nothing without Tailscale" {
source "$REPO/configure.d/lib/tailnet.sh"
on_tailnet
# A PATH with what tailnet_hosts needs, but no tailscale
mkdir "$BATS_TEST_TMPDIR/path"
for tool in jq sort timeout; do ln -s "$(command -v "$tool")" "$BATS_TEST_TMPDIR/path/"; done
PATH="$BATS_TEST_TMPDIR/path" run tailnet_hosts
[ "$status" -eq 0 ]
[ -z "$output" ]
PATH="$BATS_TEST_TMPDIR/path" refute tailnet_joined
}
@test "short_host shortens tailnet and .local names, not addresses" {
source "$REPO/configure.d/lib/tailnet.sh"
[ "$(short_host box.tail.example)" = box ]
[ "$(short_host box.local)" = box ]
[ "$(short_host box)" = box ]
[ "$(short_host 192.168.0.5)" = 192.168.0.5 ]
is_tailnet_host box.tail.example
refute is_tailnet_host box.local
refute is_tailnet_host 100.64.0.3
}
@test "with_tailnet_hosts lists a machine found both ways once, by its tailnet name" {
source "$REPO/configure.d/lib/tailnet.sh"
on_tailnet
run with_tailnet_hosts "$(printf 'lab.local\nllm.local\npi-star.local')"
[ "$output" = "$(printf 'llm.tail.example\nnas.tail.example\nlab.local\npi-star.local')" ]
}
# --- configure ai-servers --------------------------------------------------------------
setup_ai() {
@@ -169,6 +242,21 @@ setup_ai() {
[ ! -e "$SANDBOX_CONF" ]
}
@test "find_servers asks the machines on the tailnet too, and a machine found both ways once" {
setup_ai
on_tailnet
stub curl 'case "$*" in
*http://llm.tail.example:11434/v1/models*) echo "{\"data\": [{\"id\": \"gemma4:12b\"}]}" ;;
*) exit 7 ;;
esac'
run find_servers
[ "$status" -eq 0 ]
[ "$output" = "llm.tail.example:11434|1" ]
called curl -sf -m 3 http://nas.tail.example:11434/v1/models
called curl -sf -m 3 http://pi-star.local:11434/v1/models
refute grep -qF llm.local "$STUB_LOG"
}
# --- configure storage -------------------------------------------------------------------
@test "find_storage lists SMB and SFTP servers, not this machine" {
@@ -178,6 +266,21 @@ setup_ai() {
[ "$output" = "$(printf 'sftp|llm.local|llm\nsmb|pi-star.local|PI-STAR')" ]
}
@test "find_storage asks the machines on the tailnet, and lists one found both ways by its tailnet name" {
source "$REPO/configure.d/60-storage.sh"
on_tailnet
# nas answers on SSH, llm (also llm.local over mDNS) on SSH and SMB
port_open() {
case "$1:$2" in
nas.tail.example:22 | llm.tail.example:22 | llm.tail.example:445) return 0 ;;
*) return 1 ;;
esac
}
run find_storage
[ "$status" -eq 0 ]
[ "$output" = "$(printf 'sftp|llm.tail.example|llm\nsftp|nas.tail.example|nas\nsmb|llm.tail.example|llm\nsmb|pi-star.local|PI-STAR')" ]
}
@test "smb_shares lists disk shares, without admin shares, and passes the password outside the arguments" {
source "$REPO/configure.d/60-storage.sh"
stub smbclient 'echo "PASSWD=$PASSWD" >> "$STUB_LOG"
@@ -204,6 +307,7 @@ printf "Disk|files|Shared files\nDisk|C\$|Default share\nIPC|IPC\$|IPC Service\n
mkdir -p "$(dirname "$STORAGE_CONF")"
echo "sftp|me@bats-test-host.local:|/mnt/bats-test-host" > "$STORAGE_CONF"
[ "$(mount_point bats-test-host.local '')" = /mnt/bats-test-host-2 ]
[ "$(mount_point bats-test-nas.tail.example '')" = /mnt/bats-test-nas ]
}
@test "sftp_unit runs sftp-mount as a user service" {