Some checks are pending
linux-lab / core-fast (push) Waiting to run
linux-lab / core-nat (push) Waiting to run
linux-lab / core-netem (push) Waiting to run
linux-lab / extended-auth-url (push) Waiting to run
linux-lab / extended-nat-churn (push) Waiting to run
linux-lab / extended-relay-switch (push) Waiting to run
linux-lab / extended-soak (push) Waiting to run
linux-lab / extended-standalone (push) Waiting to run
142 lines
5.2 KiB
Nix
142 lines
5.2 KiB
Nix
{ pkgs, serverPkg, clientPkg }:
|
|
{
|
|
name = "lightscale-lab-auth-url";
|
|
nodes = {
|
|
node1 = { ... }: {
|
|
networking.hostName = "node1";
|
|
networking.usePredictableInterfaceNames = false;
|
|
virtualisation.vlans = [ 1 ];
|
|
networking.interfaces.eth1.useDHCP = false;
|
|
networking.interfaces.eth1.ipv4.addresses = [
|
|
{ address = "10.0.0.1"; prefixLength = 24; }
|
|
];
|
|
networking.firewall.enable = false;
|
|
boot.kernelModules = [ "wireguard" ];
|
|
environment.systemPackages = [
|
|
serverPkg
|
|
clientPkg
|
|
pkgs.wireguard-tools
|
|
pkgs.iproute2
|
|
pkgs.iputils
|
|
pkgs.netcat-openbsd
|
|
pkgs.curl
|
|
];
|
|
};
|
|
node2 = { ... }: {
|
|
networking.hostName = "node2";
|
|
networking.usePredictableInterfaceNames = false;
|
|
virtualisation.vlans = [ 1 ];
|
|
networking.interfaces.eth1.useDHCP = false;
|
|
networking.interfaces.eth1.ipv4.addresses = [
|
|
{ address = "10.0.0.2"; prefixLength = 24; }
|
|
];
|
|
networking.firewall.enable = false;
|
|
boot.kernelModules = [ "wireguard" ];
|
|
environment.systemPackages = [
|
|
clientPkg
|
|
pkgs.wireguard-tools
|
|
pkgs.iproute2
|
|
pkgs.iputils
|
|
pkgs.curl
|
|
];
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
start_all()
|
|
node1.wait_for_unit("multi-user.target")
|
|
node2.wait_for_unit("multi-user.target")
|
|
node1.wait_until_succeeds("ip -4 addr show dev eth1 | grep -q '10.0.0.1/24'")
|
|
node2.wait_until_succeeds("ip -4 addr show dev eth1 | grep -q '10.0.0.2/24'")
|
|
|
|
node1.succeed("touch /tmp/lightscale-server.log")
|
|
node1.execute("sh -c 'tail -n +1 -f /tmp/lightscale-server.log >/dev/console 2>&1 &'")
|
|
node1.succeed(
|
|
"systemd-run --no-block --unit=lightscale-server --service-type=simple "
|
|
"--property=Restart=on-failure --property=RestartSec=1 "
|
|
"--property=TimeoutStartSec=30 "
|
|
"--property=StandardOutput=append:/tmp/lightscale-server.log "
|
|
"--property=StandardError=append:/tmp/lightscale-server.log "
|
|
"--setenv=RUST_LOG=info --setenv=LIGHTSCALE_ADMIN_TOKEN=test-admin -- "
|
|
"lightscale-server --listen 10.0.0.1:8080 --state /tmp/lightscale-state.json"
|
|
)
|
|
node1.wait_for_unit("lightscale-server.service")
|
|
node1.wait_for_open_port(8080, addr="10.0.0.1", timeout=120)
|
|
|
|
import json
|
|
|
|
net = json.loads(node1.succeed(
|
|
"curl -sSf -X POST http://10.0.0.1:8080/v1/networks "
|
|
"-H 'authorization: Bearer test-admin' "
|
|
"-H 'content-type: application/json' "
|
|
"-d '{\"name\":\"auth-url\",\"bootstrap_token_ttl_seconds\":600,"
|
|
"\"bootstrap_token_uses\":10,\"bootstrap_token_tags\":[\"auth-url\"]}'"
|
|
))
|
|
token = net["bootstrap_token"]["token"]
|
|
network_id = net["network"]["id"]
|
|
|
|
node1.succeed(
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"init http://10.0.0.1:8080"
|
|
)
|
|
node1.succeed(
|
|
f"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
f"--state-dir /tmp/ls-state register --node-name node1 -- {token}"
|
|
)
|
|
|
|
node2.succeed(
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"init http://10.0.0.1:8080"
|
|
)
|
|
node2.succeed(
|
|
"sh -c 'lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state register-url "
|
|
+ network_id +
|
|
" --node-name node2 --approve | tee /tmp/register-url.out'"
|
|
)
|
|
node2.succeed("grep -q 'approved=true' /tmp/register-url.out")
|
|
node2.succeed(
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state status | grep -q 'approved: true'"
|
|
)
|
|
|
|
node1.succeed(
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state heartbeat --endpoint 10.0.0.1:51820"
|
|
)
|
|
node2.succeed(
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state heartbeat --endpoint 10.0.0.2:51820"
|
|
)
|
|
|
|
def start_agent(node, endpoint):
|
|
node.succeed("touch /tmp/lightscale-agent.log")
|
|
cmd = (
|
|
"lightscale-client --profile auth --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state agent --listen-port 51820 "
|
|
"--heartbeat-interval 5 --longpoll-timeout 5 "
|
|
f"--endpoint {endpoint}"
|
|
)
|
|
node.succeed(
|
|
"systemd-run --no-block --unit=lightscale-agent --service-type=simple "
|
|
"--property=Restart=on-failure --property=RestartSec=1 "
|
|
"--property=TimeoutStartSec=30 "
|
|
"--property=StandardOutput=append:/tmp/lightscale-agent.log "
|
|
"--property=StandardError=append:/tmp/lightscale-agent.log -- "
|
|
+ cmd
|
|
)
|
|
node.wait_for_unit("lightscale-agent.service")
|
|
node.wait_until_succeeds("ip link show ls-auth", timeout=60)
|
|
|
|
start_agent(node1, "10.0.0.1:51820")
|
|
start_agent(node2, "10.0.0.2:51820")
|
|
|
|
data1 = json.loads(node1.succeed("cat /tmp/ls-state/state.json"))
|
|
data2 = json.loads(node2.succeed("cat /tmp/ls-state/state.json"))
|
|
ip1 = data1["ipv4"]
|
|
ip2 = data2["ipv4"]
|
|
|
|
node1.wait_until_succeeds(f"ping -c 3 {ip2}", timeout=180)
|
|
node2.wait_until_succeeds(f"ping -c 3 {ip1}", timeout=180)
|
|
'';
|
|
}
|