From 7f4b0f0895832ae73ff86a77b4aa2b1c8ae28f5a Mon Sep 17 00:00:00 2001 From: Roman Safronov Date: Sun, 4 Aug 2024 17:41:38 +0300 Subject: [PATCH] Wait for target status in remote_service_action A new target_state parameter was introduced into remote_service_action() function in order to make sure that a service reached the expected state. Change-Id: I6fe09ffa86c7cbc703db56a7b72d0cf90b42f9f4 --- whitebox_neutron_tempest_plugin/common/utils.py | 15 +++++++++++++-- .../tests/scenario/test_l3ha_ovn.py | 8 +++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/common/utils.py b/whitebox_neutron_tempest_plugin/common/utils.py index 0c003ed..c9d974e 100644 --- a/whitebox_neutron_tempest_plugin/common/utils.py +++ b/whitebox_neutron_tempest_plugin/common/utils.py @@ -223,12 +223,23 @@ def interface_state_set(client, interface, state): path=shell_path, interface=interface, state=state)) -def remote_service_action(client, service, action): +def remote_service_action(client, service, action, target_state): cmd = "sudo systemctl {action} {service}".format( action=action, service=service) LOG.debug("Running '{}' on {}".format(cmd, client.host)) client.exec_command(cmd) - time.sleep(5) + common_utils.wait_until_true( + lambda: remote_service_check_state(client, service, target_state), + timeout=30, sleep=5, + exception=RuntimeError("Service failed to reach the required " + "state '{}'".format(target_state))) + + +def remote_service_check_state(client, service, state): + cmd = ("sudo systemctl is-active {service} " + "| grep -w {state} || true".format(service=service, state=state)) + output = client.exec_command(cmd).strip() + return (state in output) # NOTE(mblue): Please use specific regex to avoid dismissing various issues diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_l3ha_ovn.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_l3ha_ovn.py index 27ecc82..122e4b9 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_l3ha_ovn.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_l3ha_ovn.py @@ -300,10 +300,12 @@ class L3haOvnTest(L3haOvnCommon): remote_service = 'ovs-vswitchd.service' self.addCleanup( utils.remote_service_action, node_client, - remote_service, constants.ACTION_START) + remote_service, constants.ACTION_START, 'active') utils.remote_service_action( - node_client, remote_service, constants.ACTION_STOP) + node_client, remote_service, constants.ACTION_STOP, + target_state='inactive') self.verify_routing_via_chassis(self.chassis_list[1]) utils.remote_service_action( - node_client, remote_service, constants.ACTION_START) + node_client, remote_service, constants.ACTION_START, + target_state='active') self.verify_routing_via_chassis(self.chassis_list[0])