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
This commit is contained in:
Roman Safronov 2024-08-04 17:41:38 +03:00
parent 2a3d2e7a51
commit 7f4b0f0895
2 changed files with 18 additions and 5 deletions

View File

@ -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

View File

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