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
This commit is contained in:
Felipe Reyes
2023-02-27 15:36:04 -03:00
parent e6940c6cce
commit a81376183f
3 changed files with 77 additions and 1 deletions

View File

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

View File

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

View File

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