Merge lp:~corey.bryant/charm-helpers/swift-mitaka into lp:charm-helpers

Proposed by Corey Bryant on 2016-01-12
Status: Merged
Merged at revision: 517
Proposed branch: lp:~corey.bryant/charm-helpers/swift-mitaka
Merge into: lp:charm-helpers
Diff against target: 195 lines (+95/-31)
2 files modified
charmhelpers/contrib/openstack/utils.py (+63/-30)
tests/contrib/openstack/test_openstack_utils.py (+32/-1)
To merge this branch: bzr merge lp:~corey.bryant/charm-helpers/swift-mitaka
Reviewer Review Type Date Requested Status
charmers 2016-01-12 Pending
Review via email: mp+282337@code.launchpad.net
To post a comment you must log in.
Corey Bryant (corey.bryant) wrote :

The code changes in this mp only target the swift paths so it should have no impact on non-swift charms.

I've tested this code with swift-proxy and swift-storage deploys on icehouse and mitaka-proposed, in addition to upgrades from icehouse->juno->kilo->liberty. Note that an attempt to upgrade from liberty->mitaka remains at the liberty version of swift. I think this makes sense since liberty and mitaka both have 2.5.0 at the moment.

518. By Corey Bryant on 2016-01-13

Fix lint errors and add unit test updates

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2016-01-08 13:27:39 +0000
+++ charmhelpers/contrib/openstack/utils.py 2016-01-13 21:14:08 +0000
@@ -103,29 +103,28 @@
103 ('2016.1', 'mitaka'),103 ('2016.1', 'mitaka'),
104])104])
105105
106# The ugly duckling106# The ugly duckling - must list releases oldest to newest
107SWIFT_CODENAMES = OrderedDict([107SWIFT_CODENAMES = OrderedDict([
108 ('1.4.3', 'diablo'),108 ('diablo',
109 ('1.4.8', 'essex'),109 ['1.4.3']),
110 ('1.7.4', 'folsom'),110 ('essex',
111 ('1.8.0', 'grizzly'),111 ['1.4.8']),
112 ('1.7.7', 'grizzly'),112 ('folsom',
113 ('1.7.6', 'grizzly'),113 ['1.7.4']),
114 ('1.10.0', 'havana'),114 ('grizzly',
115 ('1.9.1', 'havana'),115 ['1.7.6', '1.7.7', '1.8.0']),
116 ('1.9.0', 'havana'),116 ('havana',
117 ('1.13.1', 'icehouse'),117 ['1.9.0', '1.9.1', '1.10.0']),
118 ('1.13.0', 'icehouse'),118 ('icehouse',
119 ('1.12.0', 'icehouse'),119 ['1.11.0', '1.12.0', '1.13.0', '1.13.1']),
120 ('1.11.0', 'icehouse'),120 ('juno',
121 ('2.0.0', 'juno'),121 ['2.0.0', '2.1.0', '2.2.0']),
122 ('2.1.0', 'juno'),122 ('kilo',
123 ('2.2.0', 'juno'),123 ['2.2.1', '2.2.2']),
124 ('2.2.1', 'kilo'),124 ('liberty',
125 ('2.2.2', 'kilo'),125 ['2.3.0', '2.4.0', '2.5.0']),
126 ('2.3.0', 'liberty'),126 ('mitaka',
127 ('2.4.0', 'liberty'),127 ['2.5.0']),
128 ('2.5.0', 'liberty'),
129])128])
130129
131# >= Liberty version->codename mapping130# >= Liberty version->codename mapping
@@ -227,6 +226,33 @@
227 error_out(e)226 error_out(e)
228227
229228
229def get_os_version_codename_swift(codename):
230 '''Determine OpenStack version number of swift from codename.'''
231 for k, v in six.iteritems(SWIFT_CODENAMES):
232 if k == codename:
233 return v[-1]
234 e = 'Could not derive swift version for '\
235 'codename: %s' % codename
236 error_out(e)
237
238
239def get_swift_codename(version):
240 '''Determine OpenStack codename that corresponds to swift version.'''
241 codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v]
242 if len(codenames) > 1:
243 # If more than one release codename contains this version we determine
244 # the actual codename based on the highest available install source.
245 for codename in reversed(codenames):
246 releases = UBUNTU_OPENSTACK_RELEASE
247 release = [k for k, v in six.iteritems(releases) if codename in v]
248 ret = subprocess.check_output(['apt-cache', 'policy', 'swift'])
249 if codename in ret or release[0] in ret:
250 return codename
251 elif len(codenames) == 1:
252 return codenames[0]
253 return None
254
255
230def get_os_codename_package(package, fatal=True):256def get_os_codename_package(package, fatal=True):
231 '''Derive OpenStack release codename from an installed package.'''257 '''Derive OpenStack release codename from an installed package.'''
232 import apt_pkg as apt258 import apt_pkg as apt
@@ -270,7 +296,7 @@
270 # < Liberty co-ordinated project versions296 # < Liberty co-ordinated project versions
271 try:297 try:
272 if 'swift' in pkg.name:298 if 'swift' in pkg.name:
273 return SWIFT_CODENAMES[vers]299 return get_swift_codename(vers)
274 else:300 else:
275 return OPENSTACK_CODENAMES[vers]301 return OPENSTACK_CODENAMES[vers]
276 except KeyError:302 except KeyError:
@@ -289,12 +315,14 @@
289315
290 if 'swift' in pkg:316 if 'swift' in pkg:
291 vers_map = SWIFT_CODENAMES317 vers_map = SWIFT_CODENAMES
318 for cname, version in six.iteritems(vers_map):
319 if cname == codename:
320 return version[-1]
292 else:321 else:
293 vers_map = OPENSTACK_CODENAMES322 vers_map = OPENSTACK_CODENAMES
294323 for version, cname in six.iteritems(vers_map):
295 for version, cname in six.iteritems(vers_map):324 if cname == codename:
296 if cname == codename:325 return version
297 return version
298 # e = "Could not determine OpenStack version for package: %s" % pkg326 # e = "Could not determine OpenStack version for package: %s" % pkg
299 # error_out(e)327 # error_out(e)
300328
@@ -460,11 +488,16 @@
460 cur_vers = get_os_version_package(package)488 cur_vers = get_os_version_package(package)
461 if "swift" in package:489 if "swift" in package:
462 codename = get_os_codename_install_source(src)490 codename = get_os_codename_install_source(src)
463 available_vers = get_os_version_codename(codename, SWIFT_CODENAMES)491 avail_vers = get_os_version_codename_swift(codename)
464 else:492 else:
465 available_vers = get_os_version_install_source(src)493 avail_vers = get_os_version_install_source(src)
466 apt.init()494 apt.init()
467 return apt.version_compare(available_vers, cur_vers) == 1495 if "swift" in package:
496 major_cur_vers = cur_vers.split('.', 1)[0]
497 major_avail_vers = avail_vers.split('.', 1)[0]
498 major_diff = apt.version_compare(major_avail_vers, major_cur_vers)
499 return avail_vers > cur_vers and (major_diff == 1 or major_diff == 0)
500 return apt.version_compare(avail_vers, cur_vers) == 1
468501
469502
470def ensure_block_device(block_device):503def ensure_block_device(block_device):
471504
=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
--- tests/contrib/openstack/test_openstack_utils.py 2016-01-08 13:27:39 +0000
+++ tests/contrib/openstack/test_openstack_utils.py 2016-01-13 21:14:08 +0000
@@ -248,6 +248,34 @@
248 expected_err = 'Could not derive OpenStack version for codename: foo'248 expected_err = 'Could not derive OpenStack version for codename: foo'
249 mocked_error.assert_called_with(expected_err)249 mocked_error.assert_called_with(expected_err)
250250
251 def test_os_version_swift_from_codename(self):
252 '''Test mapping a swift codename to numerical version'''
253 self.assertEquals(openstack.get_os_version_codename_swift('liberty'),
254 '2.5.0')
255
256 def test_get_swift_codename_single_version_kilo(self):
257 self.assertEquals(openstack.get_swift_codename('2.2.2'), 'kilo')
258
259 @patch('charmhelpers.contrib.openstack.utils.error_out')
260 def test_os_version_swift_from_bad_codename(self, mocked_error):
261 '''Test mapping a bad swift codename to numerical version'''
262 openstack.get_os_version_codename_swift('foo')
263 expected_err = 'Could not derive swift version for codename: foo'
264 mocked_error.assert_called_with(expected_err)
265
266 def test_get_swift_codename_multiple_versions_liberty(self):
267 with patch('subprocess.check_output') as _subp:
268 _subp.return_value = "... trusty-updates/liberty/main ..."
269 self.assertEquals(openstack.get_swift_codename('2.5.0'), 'liberty')
270
271 def test_get_swift_codename_multiple_versions_mitaka(self):
272 with patch('subprocess.check_output') as _subp:
273 _subp.return_value = "... trusty-updates/mitaka/main ..."
274 self.assertEquals(openstack.get_swift_codename('2.5.0'), 'mitaka')
275
276 def test_get_swift_codename_none(self):
277 self.assertEquals(openstack.get_swift_codename('1.2.3'), None)
278
251 def test_os_codename_from_package(self):279 def test_os_codename_from_package(self):
252 '''Test deriving OpenStack codename from an installed package'''280 '''Test deriving OpenStack codename from an installed package'''
253 with patch('apt_pkg.Cache') as cache:281 with patch('apt_pkg.Cache') as cache:
@@ -507,8 +535,10 @@
507535
508 @patch.object(openstack, 'lsb_release')536 @patch.object(openstack, 'lsb_release')
509 @patch.object(openstack, 'get_os_version_package')537 @patch.object(openstack, 'get_os_version_package')
538 @patch.object(openstack, 'get_os_version_codename_swift')
510 @patch.object(openstack, 'config')539 @patch.object(openstack, 'config')
511 def test_openstack_upgrade_detection_true(self, config, vers_pkg, lsb):540 def test_openstack_upgrade_detection_true(self, config, vers_swift,
541 vers_pkg, lsb):
512 """Test it detects when an openstack package has available upgrade"""542 """Test it detects when an openstack package has available upgrade"""
513 lsb.return_value = FAKE_RELEASE543 lsb.return_value = FAKE_RELEASE
514 config.return_value = 'cloud:precise-havana'544 config.return_value = 'cloud:precise-havana'
@@ -518,6 +548,7 @@
518 vers_pkg.return_value = '2013.2~b1'548 vers_pkg.return_value = '2013.2~b1'
519 self.assertTrue(openstack.openstack_upgrade_available('nova-common'))549 self.assertTrue(openstack.openstack_upgrade_available('nova-common'))
520 vers_pkg.return_value = '1.9.0'550 vers_pkg.return_value = '1.9.0'
551 vers_swift.return_value = '2.5.0'
521 self.assertTrue(openstack.openstack_upgrade_available('swift-proxy'))552 self.assertTrue(openstack.openstack_upgrade_available('swift-proxy'))
522553
523 @patch.object(openstack, 'lsb_release')554 @patch.object(openstack, 'lsb_release')

Subscribers

People subscribed via source and target branches