From f05cdf5f90f8b24493abaa6098cc6c119c30dfb8 Mon Sep 17 00:00:00 2001 From: centra Date: Tue, 17 Feb 2026 17:48:12 +0900 Subject: [PATCH] Fix test: use unique service names for each test case --- lab/test-resource-guard.nix | 56 ++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/lab/test-resource-guard.nix b/lab/test-resource-guard.nix index d50d0a2..2453c7d 100644 --- a/lab/test-resource-guard.nix +++ b/lab/test-resource-guard.nix @@ -100,6 +100,23 @@ in ) return cmd + def start_agent_with_service(service_name="lightscale-agent", cleanup_before_start=True): + """Start lightscale-client agent using systemd-run with unique service name.""" + cleanup_arg = "--cleanup-before-start" if cleanup_before_start else "" + cmd = ( + f"systemd-run --no-block --unit={service_name} --service-type=simple " + "--property=Restart=no " + "--property=TimeoutStartSec=30 " + "--property=StandardOutput=append:/tmp/agent.log " + "--property=StandardError=append:/tmp/agent.log -- " + "lightscale-client --profile guard " + "--state-dir /var/lib/lightscale-client/guard " + "--control-url http://10.0.0.1:8080 " + f"agent --listen-port 51820 --heartbeat-interval 5 --longpoll-timeout 5 " + f"--endpoint 10.0.0.2:51820 {cleanup_arg}" + ) + return cmd + def agent_is_running(): """Check if agent process is running.""" result = client.execute("pgrep -f 'lightscale-client.*agent' || true") @@ -157,15 +174,8 @@ in print("Starting lightscale-client agent...") client.succeed("touch /tmp/agent.log") client.execute("sh -c 'tail -n +1 -f /tmp/agent.log >/dev/console 2>&1 &'") - client.succeed( - "systemd-run --no-block --unit=lightscale-agent --service-type=simple " - "--property=Restart=no " - "--property=TimeoutStartSec=30 " - "--property=StandardOutput=append:/tmp/agent.log " - "--property=StandardError=append:/tmp/agent.log -- " - + start_agent_with_pidfile(cleanup_before_start=True) - ) - client.wait_for_unit("lightscale-agent.service") + client.succeed(start_agent_with_service("lightscale-agent-2", cleanup_before_start=True)) + client.wait_for_unit("lightscale-agent-2.service") client.wait_until_succeeds("ip link show ls-guard", timeout=60) print(" ✓ Agent started, ls-guard interface created") @@ -196,15 +206,8 @@ in # Start agent again print("Starting agent for SIGKILL test...") - client.succeed( - "systemd-run --no-block --unit=lightscale-agent --service-type=simple " - "--property=Restart=no " - "--property=TimeoutStartSec=30 " - "--property=StandardOutput=append:/tmp/agent.log " - "--property=StandardError=append:/tmp/agent.log -- " - + start_agent_with_pidfile(cleanup_before_start=True) - ) - client.wait_for_unit("lightscale-agent.service") + client.succeed(start_agent_with_service("lightscale-agent-3", cleanup_before_start=True)) + client.wait_for_unit("lightscale-agent-3.service") client.wait_until_succeeds("ip link show ls-guard", timeout=60) print(" ✓ Agent started, ls-guard interface exists") @@ -237,10 +240,6 @@ in if interface_exists("ls-guard"): client.succeed("ip link del ls-guard 2>/dev/null || true") - # Clean up systemd service from previous test - client.execute("systemctl stop lightscale-agent.service 2>/dev/null || true") - client.execute("systemctl reset-failed lightscale-agent.service 2>/dev/null || true") - time.sleep(1) # ======================================================================= # TEST 4: Cleanup Before Start (--cleanup-before-start) @@ -268,15 +267,8 @@ in # Start agent with --cleanup-before-start print("Starting agent with --cleanup-before-start...") - client.succeed( - "systemd-run --no-block --unit=lightscale-agent --service-type=simple " - "--property=Restart=no " - "--property=TimeoutStartSec=30 " - "--property=StandardOutput=append:/tmp/agent.log " - "--property=StandardError=append:/tmp/agent.log -- " - + start_agent_with_pidfile(cleanup_before_start=True) - ) - client.wait_for_unit("lightscale-agent.service") + client.succeed(start_agent_with_service("lightscale-agent-4", cleanup_before_start=True)) + client.wait_for_unit("lightscale-agent-4.service") time.sleep(2) # The agent should have cleaned up old interfaces and created new one @@ -288,7 +280,7 @@ in print(" ✓ New ls-guard interface created") # Stop agent - client.succeed("systemctl stop lightscale-agent.service") + client.succeed("systemctl stop lightscale-agent-4.service") time.sleep(2) # =======================================================================