From a81376183f60d38af2a1cb2cea919714545d715d Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Mon, 27 Feb 2023 15:36:04 -0300 Subject: [PATCH] Skip test_930_scaleback on crmsh-4.4.0-1ubuntu1 The crmsh package available in kinetic fails to put a cluster node in maintenance mode, this is part of the scaleback process, more details on the failure available at the related bug. This change introduces a new decorator skipVersion() that allows to provide a list of package versions with an operation flag on how dpkg should compare the version(s). The test HaclusterTest.test_930_scaleback() is disabled when running crmsh-4.4.0-1ubuntu1, at the moment this would be kinetic, although if any new package gets released this test will be re-enabled automatically allowing us catch early if the test got fixed or not. Related-Bug: http://pad.lv/1972730 --- unit_tests/charm_tests/test_utils.py | 19 +++++++ zaza/openstack/charm_tests/hacluster/tests.py | 5 ++ zaza/openstack/charm_tests/test_utils.py | 54 ++++++++++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/unit_tests/charm_tests/test_utils.py b/unit_tests/charm_tests/test_utils.py index f810a17..d2564a2 100644 --- a/unit_tests/charm_tests/test_utils.py +++ b/unit_tests/charm_tests/test_utils.py @@ -185,6 +185,25 @@ class TestBaseCharmTest(ut_utils.BaseTestCase): self.config_current.assert_called_once_with(None, None) + @mock.patch('zaza.openstack.utilities.generic.get_pkg_version') + def test_skipVersion(self, get_pkg_version): + releases = ['4.3.0', '4.0.0'] + + @test_utils.skipVersion('hacluster', 'crmsh', + releases=releases, + op='eq', + reason='should not run') + def _check_should_not_run(): + raise Exception('should not run') + + for release in releases: + get_pkg_version.return_value = release + _check_should_not_run() + get_pkg_version.reset_mock() + + get_pkg_version.return_value = '4.4.1' + self.assertRaises(Exception, _check_should_not_run) + class TestOpenStackBaseTest(ut_utils.BaseTestCase): diff --git a/zaza/openstack/charm_tests/hacluster/tests.py b/zaza/openstack/charm_tests/hacluster/tests.py index 9414145..62ba042 100644 --- a/zaza/openstack/charm_tests/hacluster/tests.py +++ b/zaza/openstack/charm_tests/hacluster/tests.py @@ -87,6 +87,11 @@ class HaclusterScaleBackAndForthTest(HaclusterBaseTest): cls._principle_app_name = test_config['principle-app-name'] cls._hacluster_charm_name = test_config['hacluster-charm-name'] + @test_utils.skipVersion(application='hacluster', + package='crmsh', + releases=['4.4.0-1ubuntu1'], + op='eq', + reason='http://pad.lv/1972730') def test_930_scaleback(self): """Remove one unit, recalculate quorum and re-add one unit. diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index ff96da1..37dc8ff 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -48,7 +48,12 @@ def skipIfNotHA(service_name): def skipUntilVersion(service, package, release): - """Run decorator to skip this test if application version is too low.""" + """Run decorator to skip this test if application version is too low. + + :param service: the name of the application to check the package's version + :param package: the name of the package to check + :param releases: package version to compare with. + """ def _skipUntilVersion_inner_1(f): def _skipUntilVersion_inner_2(*args, **kwargs): package_version = generic_utils.get_pkg_version(service, package) @@ -66,6 +71,53 @@ def skipUntilVersion(service, package, release): return _skipUntilVersion_inner_1 +def skipVersion(application, package, releases, op, reason): + """Skip the test if the application is running a versions that matches. + + The version comparison is delegated to `dpkg --compare-versions`, if the + command returns 0, means the release matches, then the test is skipped. + + Usage examples: + + * Skip the test if hacluster units have crmsh-4.4.0-1ubuntu1 installed + + @skipVersion('hacluster', 'crmsh', ['4.4.0-1ubuntu1'], 'eq', + 'LP:# 1234') + def test_hacluster(): + ... + + :param application: the name of the application to check the package's + versions. + :param package: the name of the package to check + :param versions: list of versions to compare with + :param op: operation to do the comparison (e.g. lt le eq ne ge gt, see for + more details dpkg(1)) + :param reason: The reason logged to skip the test + + """ + def _skipVersion_inner_1(f): + def _skipVersion_inner_2(*args, **kwargs): + package_version = generic_utils.get_pkg_version(application, + package) + matches = [] + for release in releases: + p = subprocess.run(['dpkg', '--compare-versions', + package_version, op, release], + stderr=subprocess.STDOUT, + universal_newlines=True) + # match succeeded, the test should be skipped. + matches.append(p.returncode == 0) + if any(matches): + logging.warning("Skipping test on (%s)" + "application %s, reason: %s", + package_version, application, reason) + else: + return f(*args, **kwargs) + + return _skipVersion_inner_2 + return _skipVersion_inner_1 + + def audit_assertions(action, expected_passes, expected_failures=None,