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
157 lines
6.3 KiB
Nix
157 lines
6.3 KiB
Nix
{ pkgs, serverPkg, clientPkg }:
|
|
{
|
|
name = "lightscale-lab-soak";
|
|
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
|
|
pkgs.iptables
|
|
];
|
|
};
|
|
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
|
|
pkgs.iptables
|
|
];
|
|
};
|
|
};
|
|
|
|
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 "
|
|
"--stream-relay 10.0.0.1:8443 --stream-relay-listen 10.0.0.1:8443"
|
|
)
|
|
node1.wait_for_unit("lightscale-server.service")
|
|
node1.wait_for_open_port(8080, addr="10.0.0.1", timeout=120)
|
|
node1.wait_for_open_port(8443, 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\":\"soak\",\"bootstrap_token_ttl_seconds\":600,"
|
|
"\"bootstrap_token_uses\":10,\"bootstrap_token_tags\":[\"soak\"]}'"
|
|
))
|
|
token = net["bootstrap_token"]["token"]
|
|
|
|
def enroll(node, name, endpoint):
|
|
node.succeed(
|
|
"lightscale-client --profile soak --config /tmp/ls-config.json "
|
|
"init http://10.0.0.1:8080"
|
|
)
|
|
node.succeed(
|
|
f"lightscale-client --profile soak --config /tmp/ls-config.json "
|
|
f"--state-dir /tmp/ls-state register --node-name {name} -- {token}"
|
|
)
|
|
node.succeed(
|
|
f"lightscale-client --profile soak --config /tmp/ls-config.json "
|
|
f"--state-dir /tmp/ls-state heartbeat --endpoint {endpoint}"
|
|
)
|
|
|
|
enroll(node1, "node1", "10.0.0.1:51820")
|
|
enroll(node2, "node2", "10.0.0.2:51820")
|
|
|
|
def start_agent(node, endpoint):
|
|
node.succeed("touch /tmp/lightscale-agent.log")
|
|
cmd = (
|
|
"lightscale-client --profile soak --config /tmp/ls-config.json "
|
|
"--state-dir /tmp/ls-state agent --listen-port 51820 "
|
|
"--heartbeat-interval 5 --longpoll-timeout 5 "
|
|
"--endpoint-stale-after 5 --endpoint-max-rotations 1 "
|
|
"--relay-reprobe-after 8 --stream-relay "
|
|
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-soak", 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"]
|
|
|
|
def mesh_ping(timeout=180):
|
|
node1.wait_until_succeeds(f"ping -c 2 {ip2}", timeout=timeout)
|
|
node2.wait_until_succeeds(f"ping -c 2 {ip1}", timeout=timeout)
|
|
|
|
for cycle in range(1, 7):
|
|
print(f"=== soak cycle {cycle} ===")
|
|
mesh_ping()
|
|
|
|
if cycle % 2 == 1:
|
|
node1.succeed("iptables -I OUTPUT -p udp --dport 51820 -d 10.0.0.2 -j DROP")
|
|
node1.succeed("iptables -I INPUT -p udp --sport 51820 -s 10.0.0.2 -j DROP")
|
|
node2.succeed("iptables -I OUTPUT -p udp --dport 51820 -d 10.0.0.1 -j DROP")
|
|
node2.succeed("iptables -I INPUT -p udp --sport 51820 -s 10.0.0.1 -j DROP")
|
|
mesh_ping(timeout=240)
|
|
node1.succeed("iptables -D OUTPUT -p udp --dport 51820 -d 10.0.0.2 -j DROP")
|
|
node1.succeed("iptables -D INPUT -p udp --sport 51820 -s 10.0.0.2 -j DROP")
|
|
node2.succeed("iptables -D OUTPUT -p udp --dport 51820 -d 10.0.0.1 -j DROP")
|
|
node2.succeed("iptables -D INPUT -p udp --sport 51820 -s 10.0.0.1 -j DROP")
|
|
node1.wait_until_succeeds("wg show ls-soak endpoints | grep -q '10.0.0.2:51820'", timeout=240)
|
|
node2.wait_until_succeeds("wg show ls-soak endpoints | grep -q '10.0.0.1:51820'", timeout=240)
|
|
mesh_ping(timeout=240)
|
|
|
|
if cycle % 3 == 0:
|
|
node2.succeed("systemctl stop lightscale-agent.service")
|
|
start_agent(node2, "10.0.0.2:51820")
|
|
mesh_ping(timeout=240)
|
|
|
|
node1.succeed("! grep -qi panic /tmp/lightscale-agent.log")
|
|
node2.succeed("! grep -qi panic /tmp/lightscale-agent.log")
|
|
'';
|
|
}
|