From 090b56e33113c90c2a18341d9c3bd21697b73ae7 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 12 Dec 2024 09:09:29 +0100 Subject: [PATCH] nixos/tests/phoebus-alarm: use IPv4 when querying Kafka In the current config Kafka only listens to IPv4, but when we use `kcat server:9092 ...`, sometimes `server` gets resolved to the IPv6 of the VM, which makes the test fail. --- nixos/tests/phoebus/alarm.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nixos/tests/phoebus/alarm.py b/nixos/tests/phoebus/alarm.py index 20a624f3..6a322d7d 100644 --- a/nixos/tests/phoebus/alarm.py +++ b/nixos/tests/phoebus/alarm.py @@ -28,17 +28,19 @@ def wait_for_boot(): alarm_config = f"config:{alarm_path}" alarm_state = f"state:{alarm_path}" +server_ip = "192.168.1.3" + def send_kafka(key: str, value: dict[str, Any]): value_s = json.dumps(value) client.succeed( - f"echo '{key}={value_s}' | kcat -P -b server:9092 -t Accelerator -K=" + f"echo '{key}={value_s}' | kcat -P -b {server_ip}:9092 -t Accelerator -K=" ) def get_alarm() -> dict[str, Any]: result_s = client.wait_until_succeeds( - f"kcat -b server:9092 -C -t Accelerator -e -qJ | grep -F '{alarm_state}' | tail -1" + f"kcat -b {server_ip}:9092 -C -t Accelerator -e -qJ | grep -F '{alarm_state}' | tail -1" ) result = json.loads(result_s) @@ -61,7 +63,7 @@ def get_logger(uri: str): client.wait_until_succeeds("caput ALARM_TEST 2") with subtest("Topics are created"): - client.wait_until_succeeds("kcat -b server:9092 -L | grep Accelerator") + client.wait_until_succeeds(f"kcat -b {server_ip}:9092 -L | grep Accelerator") with subtest("Can monitor a PV"): send_kafka( @@ -127,7 +129,7 @@ def logger_has_config(_): with subtest("We can see that the previous alarm was acknowledged"): result_s = client.wait_until_succeeds( - f"kcat -b server:9092 -C -t Accelerator -e -qJ | grep -F '{alarm_state}' | tail -1" + f"kcat -b {server_ip}:9092 -C -t Accelerator -e -qJ | grep -F '{alarm_state}' | tail -1" ) result = json.loads(result_s) @@ -192,6 +194,8 @@ def logger_has_latest_state(_): assert alarm_states[2]["value"] == "4.0" with subtest("Can export alarm configuration"): - server.succeed("phoebus-alarm-server -settings /etc/phoebus/alarm-server.properties -export export.xml") + server.succeed( + "phoebus-alarm-server -settings /etc/phoebus/alarm-server.properties -export export.xml" + ) server.succeed("grep ALARM_TEST export.xml") server.copy_from_vm("export.xml")