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
1=== modified file 'charmhelpers/contrib/openstack/utils.py'
2--- charmhelpers/contrib/openstack/utils.py 2016-01-08 13:27:39 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2016-01-13 21:14:08 +0000
4@@ -103,29 +103,28 @@
5 ('2016.1', 'mitaka'),
6 ])
7
8-# The ugly duckling
9+# The ugly duckling - must list releases oldest to newest
10 SWIFT_CODENAMES = OrderedDict([
11- ('1.4.3', 'diablo'),
12- ('1.4.8', 'essex'),
13- ('1.7.4', 'folsom'),
14- ('1.8.0', 'grizzly'),
15- ('1.7.7', 'grizzly'),
16- ('1.7.6', 'grizzly'),
17- ('1.10.0', 'havana'),
18- ('1.9.1', 'havana'),
19- ('1.9.0', 'havana'),
20- ('1.13.1', 'icehouse'),
21- ('1.13.0', 'icehouse'),
22- ('1.12.0', 'icehouse'),
23- ('1.11.0', 'icehouse'),
24- ('2.0.0', 'juno'),
25- ('2.1.0', 'juno'),
26- ('2.2.0', 'juno'),
27- ('2.2.1', 'kilo'),
28- ('2.2.2', 'kilo'),
29- ('2.3.0', 'liberty'),
30- ('2.4.0', 'liberty'),
31- ('2.5.0', 'liberty'),
32+ ('diablo',
33+ ['1.4.3']),
34+ ('essex',
35+ ['1.4.8']),
36+ ('folsom',
37+ ['1.7.4']),
38+ ('grizzly',
39+ ['1.7.6', '1.7.7', '1.8.0']),
40+ ('havana',
41+ ['1.9.0', '1.9.1', '1.10.0']),
42+ ('icehouse',
43+ ['1.11.0', '1.12.0', '1.13.0', '1.13.1']),
44+ ('juno',
45+ ['2.0.0', '2.1.0', '2.2.0']),
46+ ('kilo',
47+ ['2.2.1', '2.2.2']),
48+ ('liberty',
49+ ['2.3.0', '2.4.0', '2.5.0']),
50+ ('mitaka',
51+ ['2.5.0']),
52 ])
53
54 # >= Liberty version->codename mapping
55@@ -227,6 +226,33 @@
56 error_out(e)
57
58
59+def get_os_version_codename_swift(codename):
60+ '''Determine OpenStack version number of swift from codename.'''
61+ for k, v in six.iteritems(SWIFT_CODENAMES):
62+ if k == codename:
63+ return v[-1]
64+ e = 'Could not derive swift version for '\
65+ 'codename: %s' % codename
66+ error_out(e)
67+
68+
69+def get_swift_codename(version):
70+ '''Determine OpenStack codename that corresponds to swift version.'''
71+ codenames = [k for k, v in six.iteritems(SWIFT_CODENAMES) if version in v]
72+ if len(codenames) > 1:
73+ # If more than one release codename contains this version we determine
74+ # the actual codename based on the highest available install source.
75+ for codename in reversed(codenames):
76+ releases = UBUNTU_OPENSTACK_RELEASE
77+ release = [k for k, v in six.iteritems(releases) if codename in v]
78+ ret = subprocess.check_output(['apt-cache', 'policy', 'swift'])
79+ if codename in ret or release[0] in ret:
80+ return codename
81+ elif len(codenames) == 1:
82+ return codenames[0]
83+ return None
84+
85+
86 def get_os_codename_package(package, fatal=True):
87 '''Derive OpenStack release codename from an installed package.'''
88 import apt_pkg as apt
89@@ -270,7 +296,7 @@
90 # < Liberty co-ordinated project versions
91 try:
92 if 'swift' in pkg.name:
93- return SWIFT_CODENAMES[vers]
94+ return get_swift_codename(vers)
95 else:
96 return OPENSTACK_CODENAMES[vers]
97 except KeyError:
98@@ -289,12 +315,14 @@
99
100 if 'swift' in pkg:
101 vers_map = SWIFT_CODENAMES
102+ for cname, version in six.iteritems(vers_map):
103+ if cname == codename:
104+ return version[-1]
105 else:
106 vers_map = OPENSTACK_CODENAMES
107-
108- for version, cname in six.iteritems(vers_map):
109- if cname == codename:
110- return version
111+ for version, cname in six.iteritems(vers_map):
112+ if cname == codename:
113+ return version
114 # e = "Could not determine OpenStack version for package: %s" % pkg
115 # error_out(e)
116
117@@ -460,11 +488,16 @@
118 cur_vers = get_os_version_package(package)
119 if "swift" in package:
120 codename = get_os_codename_install_source(src)
121- available_vers = get_os_version_codename(codename, SWIFT_CODENAMES)
122+ avail_vers = get_os_version_codename_swift(codename)
123 else:
124- available_vers = get_os_version_install_source(src)
125+ avail_vers = get_os_version_install_source(src)
126 apt.init()
127- return apt.version_compare(available_vers, cur_vers) == 1
128+ if "swift" in package:
129+ major_cur_vers = cur_vers.split('.', 1)[0]
130+ major_avail_vers = avail_vers.split('.', 1)[0]
131+ major_diff = apt.version_compare(major_avail_vers, major_cur_vers)
132+ return avail_vers > cur_vers and (major_diff == 1 or major_diff == 0)
133+ return apt.version_compare(avail_vers, cur_vers) == 1
134
135
136 def ensure_block_device(block_device):
137
138=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
139--- tests/contrib/openstack/test_openstack_utils.py 2016-01-08 13:27:39 +0000
140+++ tests/contrib/openstack/test_openstack_utils.py 2016-01-13 21:14:08 +0000
141@@ -248,6 +248,34 @@
142 expected_err = 'Could not derive OpenStack version for codename: foo'
143 mocked_error.assert_called_with(expected_err)
144
145+ def test_os_version_swift_from_codename(self):
146+ '''Test mapping a swift codename to numerical version'''
147+ self.assertEquals(openstack.get_os_version_codename_swift('liberty'),
148+ '2.5.0')
149+
150+ def test_get_swift_codename_single_version_kilo(self):
151+ self.assertEquals(openstack.get_swift_codename('2.2.2'), 'kilo')
152+
153+ @patch('charmhelpers.contrib.openstack.utils.error_out')
154+ def test_os_version_swift_from_bad_codename(self, mocked_error):
155+ '''Test mapping a bad swift codename to numerical version'''
156+ openstack.get_os_version_codename_swift('foo')
157+ expected_err = 'Could not derive swift version for codename: foo'
158+ mocked_error.assert_called_with(expected_err)
159+
160+ def test_get_swift_codename_multiple_versions_liberty(self):
161+ with patch('subprocess.check_output') as _subp:
162+ _subp.return_value = "... trusty-updates/liberty/main ..."
163+ self.assertEquals(openstack.get_swift_codename('2.5.0'), 'liberty')
164+
165+ def test_get_swift_codename_multiple_versions_mitaka(self):
166+ with patch('subprocess.check_output') as _subp:
167+ _subp.return_value = "... trusty-updates/mitaka/main ..."
168+ self.assertEquals(openstack.get_swift_codename('2.5.0'), 'mitaka')
169+
170+ def test_get_swift_codename_none(self):
171+ self.assertEquals(openstack.get_swift_codename('1.2.3'), None)
172+
173 def test_os_codename_from_package(self):
174 '''Test deriving OpenStack codename from an installed package'''
175 with patch('apt_pkg.Cache') as cache:
176@@ -507,8 +535,10 @@
177
178 @patch.object(openstack, 'lsb_release')
179 @patch.object(openstack, 'get_os_version_package')
180+ @patch.object(openstack, 'get_os_version_codename_swift')
181 @patch.object(openstack, 'config')
182- def test_openstack_upgrade_detection_true(self, config, vers_pkg, lsb):
183+ def test_openstack_upgrade_detection_true(self, config, vers_swift,
184+ vers_pkg, lsb):
185 """Test it detects when an openstack package has available upgrade"""
186 lsb.return_value = FAKE_RELEASE
187 config.return_value = 'cloud:precise-havana'
188@@ -518,6 +548,7 @@
189 vers_pkg.return_value = '2013.2~b1'
190 self.assertTrue(openstack.openstack_upgrade_available('nova-common'))
191 vers_pkg.return_value = '1.9.0'
192+ vers_swift.return_value = '2.5.0'
193 self.assertTrue(openstack.openstack_upgrade_available('swift-proxy'))
194
195 @patch.object(openstack, 'lsb_release')

Subscribers

People subscribed via source and target branches