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])