Skip to content

Commit

Permalink
Unit test updates for get_os_version_codename_swift removal
Browse files Browse the repository at this point in the history
(cherry picked from commit 62a356c)
  • Loading branch information
Corey Bryant committed Oct 30, 2023
1 parent eb09315 commit 2e6018e
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions tests/contrib/openstack/test_openstack_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,16 @@ def test_os_version_from_bad_codename(self, mocked_error):
expected_err = 'Could not derive OpenStack version for codename: foo'
mocked_error.assert_called_with(expected_err)

def test_os_version_swift_from_codename(self):
"""Test mapping a swift codename to numerical version"""
self.assertEquals(openstack.get_os_version_codename_swift('liberty'),
'2.5.0')
try:
openstack.get_os_version_codename('foo', raise_exception=True)
raise Exception("Failed call should have raised ValueError")
except ValueError as e:
self.assertEquals(e.args[0],
"Could not derive OpenStack version for codename: foo")

def test_get_swift_codename_single_version_kilo(self):
self.assertEquals(openstack.get_swift_codename('2.2.2'), 'kilo')

@patch('charmhelpers.contrib.openstack.utils.error_out')
def test_os_version_swift_from_bad_codename(self, mocked_error):
"""Test mapping a bad swift codename to numerical version"""
openstack.get_os_version_codename_swift('foo')
expected_err = 'Could not derive swift version for codename: foo'
mocked_error.assert_called_with(expected_err)

def test_get_swift_codename_multiple_versions_liberty(self):
with patch('subprocess.check_output') as _subp:
_subp.return_value = b"... trusty-updates/liberty/main ..."
Expand Down Expand Up @@ -730,10 +725,8 @@ def test_save_scriptrc(self, _open, _charm_dir, _exists, _mkdir):

@patch.object(openstack, 'lsb_release')
@patch.object(openstack, 'get_os_version_package')
@patch.object(openstack, 'get_os_version_codename_swift')
@patch.object(openstack, 'config')
def test_openstack_upgrade_detection_true(self, config, vers_swift,
vers_pkg, lsb):
def test_openstack_upgrade_detection_true(self, config, vers_pkg, lsb):
"""Test it detects when an openstack package has available upgrade"""
lsb.return_value = FAKE_RELEASE
config.return_value = 'cloud:precise-havana'
Expand All @@ -743,10 +736,8 @@ def test_openstack_upgrade_detection_true(self, config, vers_swift,
vers_pkg.return_value = '2013.2~b1'
self.assertTrue(openstack.openstack_upgrade_available('nova-common'))
vers_pkg.return_value = '1.9.0'
vers_swift.return_value = '2.5.0'
self.assertTrue(openstack.openstack_upgrade_available('swift-proxy'))
vers_pkg.return_value = '2.5.0'
vers_swift.return_value = '2.10.0'
self.assertTrue(openstack.openstack_upgrade_available('swift-proxy'))

@patch.object(openstack, 'lsb_release')
Expand All @@ -762,8 +753,8 @@ def test_openstack_upgrade_detection_false(self, config, vers_pkg, lsb):
vers_pkg.return_value = '2013.1~b1'
self.assertFalse(openstack.openstack_upgrade_available('nova-common'))
# ugly duckling testing
config.return_value = 'cloud:precise-havana'
vers_pkg.return_value = '1.10.0'
config.return_value = 'cloud:focal-wallaby'
vers_pkg.return_value = '2021.1'
self.assertFalse(openstack.openstack_upgrade_available('swift-proxy'))

@patch.object(openstack, 'is_block_device')
Expand Down

0 comments on commit 2e6018e

Please sign in to comment.