From c1aa2ba46d06fec0a650f4b03c6dece70a118f22 Mon Sep 17 00:00:00 2001 From: Roman Safronov Date: Thu, 18 Apr 2024 01:09:11 +0300 Subject: [PATCH] Fix vrrp test Patch [1] introduced 2 issues into vrrp test. Changing base class caused that during resource_setup the cls.image_ref was changed from advanced image to cirros. As a result, test fails to find keepalived service inside VM and skips the test. This patch ensures that the test uses an advanced image. The second issue was caused by the fact that running systemctl commands with globbing is not working as expected for services that are inactive initially. This patch restores the original code used for restarting keepalived service inside VMs. [1] https://review.opendev.org/c/x/whitebox-neutron-tempest-plugin/+/914116 Change-Id: I99bc1cac4c6ff814246f6d4d37027fbb491be629 --- .../tests/scenario/test_vrrp.py | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_vrrp.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_vrrp.py index cd7b339..5e50bc4 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_vrrp.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_vrrp.py @@ -15,6 +15,7 @@ from neutron_lib import constants 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 exceptions from oslo_log import log @@ -50,26 +51,9 @@ def get_keepalived_config(interface, vip_ip): return keepalived_config_template % (interface, vip_ip) -class VrrpTest(base.BaseTempestWhiteboxTestCase): +class VrrpTest(base.BaseTempestTestCaseAdvanced): credentials = ['primary', 'admin'] - @classmethod - def skip_checks(cls): - super(VrrpTest, cls).skip_checks() - if CONF.neutron_plugin_options.default_image_is_advanced: - cls.flavor_ref = CONF.compute.flavor_ref - cls.image_ref = CONF.compute.image_ref - cls.username = CONF.validation.image_ssh_user - else: - cls.flavor_ref = \ - CONF.neutron_plugin_options.advanced_image_flavor_ref - cls.image_ref = CONF.neutron_plugin_options.advanced_image_ref - cls.username = CONF.neutron_plugin_options.advanced_image_ssh_user - - if (not cls.flavor_ref) or (not cls.image_ref): - raise cls.skipException( - 'No advanced image/flavor available for these tests') - @classmethod @utils.requires_ext(extension="router", service="network") def resource_setup(cls): @@ -113,6 +97,11 @@ class VrrpTest(base.BaseTempestWhiteboxTestCase): raise self.skipException( "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): config_text = get_keepalived_config(interface, vip_ip) config_file = 'keepalived.conf' @@ -120,8 +109,12 @@ class VrrpTest(base.BaseTempestWhiteboxTestCase): 'echo "{0}" > /tmp/{1};' 'sudo mv -Z /tmp/{1} /etc/keepalived/'.format( config_text, config_file)) - # restart and make sure keepalived is active - self.reset_node_service('keepalived', ssh_client) + ssh_client.exec_command("sudo systemctl restart keepalived") + # make sure keepalived is active + common_utils.wait_until_true( + lambda: self._is_keepalived_service_active(ssh_client=ssh_client), + timeout=20, + exception=RuntimeError("Timed out waiting for keepalived active")) @staticmethod def _get_vm_id_by_name(name, vms):