Files
davidandClaude Opus 5.5 dfb43c866c Find storage and AI servers on the tailnet, not only over mDNS
Ports CoreDesktop's 16e5a9c.

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>.

Smoketest: 45-tailnet, with a stand-in tailscale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 18:58:18 -07:00

83 lines
3.9 KiB
Bash

# shellcheck shell=bash
# Scenarios set what the runner and items read
# shellcheck disable=SC2034
DESCRIPTION="Storage and AI servers found on the Core's tailnet as well as over mDNS"
TIER=quick
# 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)
TAILNET_JSON='{
"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}
}
}'
scenario() {
local bin="$HOME/.local/bin" status_json="$HOME/tailscale.json" probes="$HOME/probes"
mkdir -p "$bin"
# A stand-in tailscale that prints $status_json for `status --json`
printf '#!/bin/bash\ncat %q\n' "$status_json" > "$bin/tailscale"
chmod +x "$bin/tailscale"
echo '{"BackendState": "Stopped", "Peer": {}}' > "$status_json"
source "$CONNECTOR/configure.d/lib/tailnet.sh"
step "lib/tailnet.sh"
check_eq "nothing while Tailscale is stopped" "" "$(tailnet_hosts)"
check_not "not joined while it's stopped" tailnet_joined
echo "$TAILNET_JSON" > "$status_json"
check_eq "the other online computers, without phones or the trailing dot" \
"$(printf 'llm.tail.example\nnas.tail.example')" "$(tailnet_hosts)"
check "joined while it runs" tailnet_joined
check_eq "nothing without Tailscale" "" "$(PATH=/usr/bin:/bin tailnet_hosts)"
check_eq "short_host shortens a tailnet name" box "$(short_host box.tail.example)"
check_eq "and a .local one" box "$(short_host box.local)"
check_eq "not an address" 192.168.0.5 "$(short_host 192.168.0.5)"
check "box.tail.example is a tailnet name" is_tailnet_host box.tail.example
check_not "box.local isn't" is_tailnet_host box.local
check_not "nor 100.64.0.3" is_tailnet_host 100.64.0.3
check_eq "a machine found both ways is listed once, by its tailnet name" \
"$(printf 'llm.tail.example\nnas.tail.example\nlab.local\npi-star.local')" \
"$(with_tailnet_hosts "$(printf 'lab.local\nllm.local\npi-star.local')")"
step "configure ai-servers"
source "$CONNECTOR/configure.d/50-ai-servers.sh"
mdns_hosts() { printf 'llm.local\npi-star.local\n'; }
curl() {
echo "$*" >> "$probes"
case "$*" in
*http://llm.tail.example:11434/v1/models*) echo '{"data": [{"id": "gemma4:12b"}]}' ;;
*) return 7 ;;
esac
}
: > "$probes"
check_eq "find_servers finds the server on the tailnet" "llm.tail.example:11434|1" "$(find_servers)"
check "it asks the machine only on the tailnet" grep -qF http://nas.tail.example:11434/v1/models "$probes"
check "and the one only on mDNS" grep -qF http://pi-star.local:11434/v1/models "$probes"
check_not "not a machine twice" grep -qF llm.local "$probes"
unset -f curl
step "configure storage"
source "$CONNECTOR/configure.d/60-storage.sh"
mdns_own_host() { echo basement.local; }
mdns_services() {
printf '%s\n' 'PI-STAR|_smb._tcp|pi-star.local|192.168.0.9|445|' \
'llm|_sftp-ssh._tcp|llm.local|192.168.0.7|22|' \
'basement|_smb._tcp|basement.local|192.168.0.2|445|'
}
port_open() { [ "$1:$2" = nas.tail.example:22 ] || [ "$1:$2" = llm.tail.example:445 ]; }
check_eq "find_storage lists each machine once, tailnet ones by their tailnet name" \
"$(printf 'sftp|nas.tail.example|nas\nsmb|llm.tail.example|llm\nsmb|pi-star.local|PI-STAR')" \
"$(find_storage)"
STORAGE_CONF="$HOME/storage"
check_eq "a tailnet server mounts at /mnt/<short name>" /mnt/nas-data "$(mount_point nas.tail.example data)"
rm -f "$bin/tailscale" "$status_json" "$probes"
}