Merge "Make reset_node_service support inactive services"

This commit is contained in:
Zuul 2024-04-25 18:11:15 +00:00 committed by Gerrit Code Review
commit 04bb1ca93b
2 changed files with 17 additions and 26 deletions

View File

@ -433,35 +433,35 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase):
return False return False
@classmethod @classmethod
def reset_node_service(cls, service_name, ssh_client, def reset_node_service(cls, service_alias, ssh_client,
wait_until_active=True, timeout=30): wait_until_active=True, timeout=30):
# NOTE(mblue): Globbing works on podified/devstack/tripleo
service_glob = re.sub(r'[^a-zA-Z]', '?', service_name)
host_ip = ssh_client.host host_ip = ssh_client.host
service_name = ssh_client.exec_command(
"systemctl list-unit-files --type service | grep {} | "
"cut -d' ' -f1".format(
service_alias.replace(" ", ".*"))).strip()
LOG.debug("Restarting service '%s' on host '%s'.", LOG.debug("Restarting service '%s' on host '%s'.",
service_glob, host_ip) service_name, host_ip)
ssh_client.exec_command( ssh_client.exec_command(
'sudo systemctl restart *{}.service'.format(service_glob)) 'sudo systemctl restart {}'.format(service_name))
if not wait_until_active: if not wait_until_active:
return return
def _is_service_active(): def _is_service_active():
return 'active' in ssh_client.exec_command( return 'active' in ssh_client.exec_command(
'sudo systemctl is-active *{}.service; true'.format( 'sudo systemctl is-active {}; true'.format(service_name))
service_glob))
LOG.debug("Waiting for service '%s' to become active on host '%s'.", LOG.debug("Waiting for service '%s' to become active on host '%s'.",
service_glob, host_ip) service_name, host_ip)
common_utils.wait_until_true( common_utils.wait_until_true(
_is_service_active, timeout=timeout, sleep=5, _is_service_active, timeout=timeout, sleep=5,
exception=RuntimeError( exception=RuntimeError(
"Timed out {} seconds, service {} (globbing '*{}.service') " "Timed out {} seconds, service {} "
"didn't become active after restart.\n\n'''\n{}\n'''".format( "didn't become active after restart.\n\n'''\n{}\n'''".format(
timeout, service_name, service_glob, timeout, service_name, ssh_client.exec_command(
ssh_client.exec_command( 'sudo systemctl status {}; true'.format(
'sudo systemctl status *{}.service; true'.format( service_name)))))
service_glob)))))
LOG.debug("Service '%s' active on host '%s'.", LOG.debug("Service '%s' active on host '%s'.",
service_glob, host_ip) service_name, host_ip)
def _create_server( def _create_server(
self, create_floating_ip=True, exclude_hosts=None, self, create_floating_ip=True, exclude_hosts=None,

View File

@ -15,7 +15,6 @@
from neutron_lib import constants from neutron_lib import constants
from neutron_tempest_plugin.common import ssh from neutron_tempest_plugin.common import ssh
from neutron_tempest_plugin.common import utils as common_utils
from neutron_tempest_plugin import config from neutron_tempest_plugin import config
from neutron_tempest_plugin import exceptions from neutron_tempest_plugin import exceptions
from oslo_log import log from oslo_log import log
@ -97,11 +96,6 @@ class VrrpTest(base.BaseTempestTestCaseAdvanced):
raise self.skipException( raise self.skipException(
"keepalived is not available on server %s" % (server_id)) "keepalived is not available on server %s" % (server_id))
@staticmethod
def _is_keepalived_service_active(ssh_client):
output = ssh_client.exec_command("sudo systemctl is-active keepalived")
return 'active' == output.splitlines()[0]
def _prepare_server(self, ssh_client, interface, vip_ip): def _prepare_server(self, ssh_client, interface, vip_ip):
config_text = get_keepalived_config(interface, vip_ip) config_text = get_keepalived_config(interface, vip_ip)
config_file = 'keepalived.conf' config_file = 'keepalived.conf'
@ -110,16 +104,13 @@ class VrrpTest(base.BaseTempestTestCaseAdvanced):
'sudo mv -Z /tmp/{1} /etc/keepalived/'.format( 'sudo mv -Z /tmp/{1} /etc/keepalived/'.format(
config_text, config_file)) config_text, config_file))
ssh_client.exec_command("sudo systemctl restart keepalived") ssh_client.exec_command("sudo systemctl restart keepalived")
# make sure keepalived is active # restart and make sure keepalived is active
common_utils.wait_until_true( self.reset_node_service('keepalived', ssh_client)
lambda: self._is_keepalived_service_active(ssh_client=ssh_client),
timeout=20,
exception=RuntimeError("Timed out waiting for keepalived active"))
@staticmethod @staticmethod
def _get_vm_id_by_name(name, vms): def _get_vm_id_by_name(name, vms):
for vm in vms: for vm in vms:
if vm['server']['name'] == name: if vm['server']['name'] in name:
return vm['server']['id'] return vm['server']['id']
return None return None