Fix test: use unique service names for each test case
This commit is contained in:
parent
fb54666294
commit
f05cdf5f90
1 changed files with 24 additions and 32 deletions
|
|
@ -100,6 +100,23 @@ in
|
||||||
)
|
)
|
||||||
return cmd
|
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():
|
def agent_is_running():
|
||||||
"""Check if agent process is running."""
|
"""Check if agent process is running."""
|
||||||
result = client.execute("pgrep -f 'lightscale-client.*agent' || true")
|
result = client.execute("pgrep -f 'lightscale-client.*agent' || true")
|
||||||
|
|
@ -157,15 +174,8 @@ in
|
||||||
print("Starting lightscale-client agent...")
|
print("Starting lightscale-client agent...")
|
||||||
client.succeed("touch /tmp/agent.log")
|
client.succeed("touch /tmp/agent.log")
|
||||||
client.execute("sh -c 'tail -n +1 -f /tmp/agent.log >/dev/console 2>&1 &'")
|
client.execute("sh -c 'tail -n +1 -f /tmp/agent.log >/dev/console 2>&1 &'")
|
||||||
client.succeed(
|
client.succeed(start_agent_with_service("lightscale-agent-2", cleanup_before_start=True))
|
||||||
"systemd-run --no-block --unit=lightscale-agent --service-type=simple "
|
client.wait_for_unit("lightscale-agent-2.service")
|
||||||
"--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.wait_until_succeeds("ip link show ls-guard", timeout=60)
|
client.wait_until_succeeds("ip link show ls-guard", timeout=60)
|
||||||
print(" ✓ Agent started, ls-guard interface created")
|
print(" ✓ Agent started, ls-guard interface created")
|
||||||
|
|
||||||
|
|
@ -196,15 +206,8 @@ in
|
||||||
|
|
||||||
# Start agent again
|
# Start agent again
|
||||||
print("Starting agent for SIGKILL test...")
|
print("Starting agent for SIGKILL test...")
|
||||||
client.succeed(
|
client.succeed(start_agent_with_service("lightscale-agent-3", cleanup_before_start=True))
|
||||||
"systemd-run --no-block --unit=lightscale-agent --service-type=simple "
|
client.wait_for_unit("lightscale-agent-3.service")
|
||||||
"--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.wait_until_succeeds("ip link show ls-guard", timeout=60)
|
client.wait_until_succeeds("ip link show ls-guard", timeout=60)
|
||||||
print(" ✓ Agent started, ls-guard interface exists")
|
print(" ✓ Agent started, ls-guard interface exists")
|
||||||
|
|
||||||
|
|
@ -237,10 +240,6 @@ in
|
||||||
if interface_exists("ls-guard"):
|
if interface_exists("ls-guard"):
|
||||||
client.succeed("ip link del ls-guard 2>/dev/null || true")
|
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)
|
# TEST 4: Cleanup Before Start (--cleanup-before-start)
|
||||||
|
|
@ -268,15 +267,8 @@ in
|
||||||
|
|
||||||
# Start agent with --cleanup-before-start
|
# Start agent with --cleanup-before-start
|
||||||
print("Starting agent with --cleanup-before-start...")
|
print("Starting agent with --cleanup-before-start...")
|
||||||
client.succeed(
|
client.succeed(start_agent_with_service("lightscale-agent-4", cleanup_before_start=True))
|
||||||
"systemd-run --no-block --unit=lightscale-agent --service-type=simple "
|
client.wait_for_unit("lightscale-agent-4.service")
|
||||||
"--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")
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# The agent should have cleaned up old interfaces and created new one
|
# The agent should have cleaned up old interfaces and created new one
|
||||||
|
|
@ -288,7 +280,7 @@ in
|
||||||
print(" ✓ New ls-guard interface created")
|
print(" ✓ New ls-guard interface created")
|
||||||
|
|
||||||
# Stop agent
|
# Stop agent
|
||||||
client.succeed("systemctl stop lightscale-agent.service")
|
client.succeed("systemctl stop lightscale-agent-4.service")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# =======================================================================
|
# =======================================================================
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue