Merge lp:~gnuoy/charms/trusty/neutron-api/kilo-neutron-dbmig into lp:~openstack-charmers-archive/charms/trusty/neutron-api/next
- Trusty Tahr (14.04)
- kilo-neutron-dbmig
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 108 |
Proposed branch: | lp:~gnuoy/charms/trusty/neutron-api/kilo-neutron-dbmig |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/neutron-api/next |
Diff against target: |
372 lines (+181/-5) 4 files modified
hooks/neutron_api_hooks.py (+27/-0) hooks/neutron_api_utils.py (+34/-0) unit_tests/test_neutron_api_hooks.py (+54/-2) unit_tests/test_neutron_api_utils.py (+66/-3) |
To merge this branch: | bzr merge lp:~gnuoy/charms/trusty/neutron-api/kilo-neutron-dbmig |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+257225@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #3642 neutron-api-next for gnuoy mp257225
UNIT OK: passed
- 112. By Liam Young
-
Merge next
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #3856 neutron-api-next for gnuoy mp257225
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #3643 neutron-api-next for gnuoy mp257225
UNIT OK: passed
- 113. By Liam Young
-
Only run migration if allowed units is present
- 114. By Liam Young
-
Remove erronious print
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #3858 neutron-api-next for gnuoy mp257225
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #3645 neutron-api-next for gnuoy mp257225
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #3643 neutron-api-next for gnuoy mp257225
AMULET OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #3644 neutron-api-next for gnuoy mp257225
AMULET OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #3646 neutron-api-next for gnuoy mp257225
AMULET OK: passed
Build: http://
Preview Diff
1 | === modified file 'hooks/neutron_api_hooks.py' |
2 | --- hooks/neutron_api_hooks.py 2015-04-21 08:46:00 +0000 |
3 | +++ hooks/neutron_api_hooks.py 2015-04-23 08:51:18 +0000 |
4 | @@ -11,6 +11,7 @@ |
5 | UnregisteredHookError, |
6 | config, |
7 | is_relation_made, |
8 | + local_unit, |
9 | log, |
10 | ERROR, |
11 | relation_get, |
12 | @@ -23,6 +24,7 @@ |
13 | from charmhelpers.core.host import ( |
14 | restart_on_change, |
15 | service_reload, |
16 | + service_restart, |
17 | ) |
18 | |
19 | from charmhelpers.fetch import ( |
20 | @@ -37,10 +39,12 @@ |
21 | git_install_requested, |
22 | openstack_upgrade_available, |
23 | os_requires_version, |
24 | + os_release, |
25 | sync_db_with_multi_ipv6_addresses |
26 | ) |
27 | |
28 | from neutron_api_utils import ( |
29 | + CLUSTER_RES, |
30 | NEUTRON_CONF, |
31 | api_port, |
32 | determine_packages, |
33 | @@ -49,6 +53,7 @@ |
34 | git_install, |
35 | dvr_router_present, |
36 | l3ha_router_present, |
37 | + migrate_neutron_database, |
38 | neutron_ready, |
39 | register_configs, |
40 | restart_map, |
41 | @@ -66,6 +71,7 @@ |
42 | |
43 | from charmhelpers.contrib.hahelpers.cluster import ( |
44 | get_hacluster_config, |
45 | + is_elected_leader, |
46 | ) |
47 | |
48 | from charmhelpers.payload.execd import execd_preinstall |
49 | @@ -91,6 +97,25 @@ |
50 | CONFIGS = register_configs() |
51 | |
52 | |
53 | +def conditional_neutron_migration(): |
54 | + if os_release('neutron-server') < 'kilo': |
55 | + log('Not running neutron database migration as migrations are handled ' |
56 | + 'by the neutron-server process or nova-cloud-controller charm.') |
57 | + return |
58 | + |
59 | + if is_elected_leader(CLUSTER_RES): |
60 | + allowed_units = relation_get('allowed_units') |
61 | + if allowed_units and local_unit() in allowed_units.split(): |
62 | + migrate_neutron_database() |
63 | + service_restart('neutron-server') |
64 | + else: |
65 | + log('Not running neutron database migration, either no' |
66 | + ' allowed_units or this unit is not present') |
67 | + return |
68 | + else: |
69 | + log('Not running neutron database migration, not leader') |
70 | + |
71 | + |
72 | def configure_https(): |
73 | ''' |
74 | Enables SSL API Apache config if appropriate and kicks identity-service |
75 | @@ -231,12 +256,14 @@ |
76 | log('shared-db relation incomplete. Peer not ready?') |
77 | return |
78 | CONFIGS.write_all() |
79 | + conditional_neutron_migration() |
80 | |
81 | |
82 | @hooks.hook('pgsql-db-relation-changed') |
83 | @restart_on_change(restart_map()) |
84 | def postgresql_neutron_db_changed(): |
85 | CONFIGS.write(NEUTRON_CONF) |
86 | + conditional_neutron_migration() |
87 | |
88 | |
89 | @hooks.hook('amqp-relation-broken', |
90 | |
91 | === modified file 'hooks/neutron_api_utils.py' |
92 | --- hooks/neutron_api_utils.py 2015-04-21 08:46:00 +0000 |
93 | +++ hooks/neutron_api_utils.py 2015-04-23 08:51:18 +0000 |
94 | @@ -3,6 +3,7 @@ |
95 | from functools import partial |
96 | import os |
97 | import shutil |
98 | +import subprocess |
99 | from base64 import b64encode |
100 | from charmhelpers.contrib.openstack import context, templating |
101 | from charmhelpers.contrib.openstack.neutron import ( |
102 | @@ -258,6 +259,7 @@ |
103 | |
104 | :param configs: The charms main OSConfigRenderer object. |
105 | """ |
106 | + cur_os_rel = os_release('neutron-server') |
107 | new_src = config('openstack-origin') |
108 | new_os_rel = get_os_codename_install_source(new_src) |
109 | |
110 | @@ -279,6 +281,38 @@ |
111 | |
112 | # set CONFIGS to load templates from new release |
113 | configs.set_release(openstack_release=new_os_rel) |
114 | + # Before kilo it's nova-cloud-controllers job |
115 | + if new_os_rel >= 'kilo': |
116 | + stamp_neutron_database(cur_os_rel) |
117 | + migrate_neutron_database() |
118 | + |
119 | + |
120 | +def stamp_neutron_database(release): |
121 | + '''Stamp the database with the current release before upgrade.''' |
122 | + log('Stamping the neutron database with release %s.' % release) |
123 | + plugin = config('neutron-plugin') |
124 | + cmd = ['neutron-db-manage', |
125 | + '--config-file', NEUTRON_CONF, |
126 | + '--config-file', neutron_plugin_attribute(plugin, |
127 | + 'config', |
128 | + 'neutron'), |
129 | + 'stamp', |
130 | + release] |
131 | + subprocess.check_output(cmd) |
132 | + |
133 | + |
134 | +def migrate_neutron_database(): |
135 | + '''Initializes a new database or upgrades an existing database.''' |
136 | + log('Migrating the neutron database.') |
137 | + plugin = config('neutron-plugin') |
138 | + cmd = ['neutron-db-manage', |
139 | + '--config-file', NEUTRON_CONF, |
140 | + '--config-file', neutron_plugin_attribute(plugin, |
141 | + 'config', |
142 | + 'neutron'), |
143 | + 'upgrade', |
144 | + 'head'] |
145 | + subprocess.check_output(cmd) |
146 | |
147 | |
148 | def get_topics(): |
149 | |
150 | === modified file 'unit_tests/test_neutron_api_hooks.py' |
151 | --- unit_tests/test_neutron_api_hooks.py 2015-04-21 08:46:00 +0000 |
152 | +++ unit_tests/test_neutron_api_hooks.py 2015-04-23 08:51:18 +0000 |
153 | @@ -34,6 +34,7 @@ |
154 | 'determine_ports', |
155 | 'do_openstack_upgrade', |
156 | 'dvr_router_present', |
157 | + 'local_unit', |
158 | 'l3ha_router_present', |
159 | 'execd_preinstall', |
160 | 'filter_installed_packages', |
161 | @@ -42,15 +43,19 @@ |
162 | 'get_l2population', |
163 | 'get_overlay_network_type', |
164 | 'git_install', |
165 | + 'is_elected_leader', |
166 | 'is_relation_made', |
167 | 'log', |
168 | + 'migrate_neutron_database', |
169 | 'neutron_ready', |
170 | 'open_port', |
171 | 'openstack_upgrade_available', |
172 | + 'os_release', |
173 | 'os_requires_version', |
174 | 'relation_get', |
175 | 'relation_ids', |
176 | 'relation_set', |
177 | + 'service_restart', |
178 | 'unit_get', |
179 | 'get_iface_for_address', |
180 | 'get_netmask_for_address', |
181 | @@ -292,19 +297,23 @@ |
182 | 'Attempting to associate a postgresql database when' |
183 | ' there is already associated a mysql one') |
184 | |
185 | - def test_shared_db_changed(self): |
186 | + @patch.object(hooks, 'conditional_neutron_migration') |
187 | + def test_shared_db_changed(self, cond_neutron_mig): |
188 | self.CONFIGS.complete_contexts.return_value = ['shared-db'] |
189 | self._call_hook('shared-db-relation-changed') |
190 | self.assertTrue(self.CONFIGS.write_all.called) |
191 | + cond_neutron_mig.assert_called_with() |
192 | |
193 | def test_shared_db_changed_partial_ctxt(self): |
194 | self.CONFIGS.complete_contexts.return_value = [] |
195 | self._call_hook('shared-db-relation-changed') |
196 | self.assertFalse(self.CONFIGS.write_all.called) |
197 | |
198 | - def test_pgsql_db_changed(self): |
199 | + @patch.object(hooks, 'conditional_neutron_migration') |
200 | + def test_pgsql_db_changed(self, cond_neutron_mig): |
201 | self._call_hook('pgsql-db-relation-changed') |
202 | self.assertTrue(self.CONFIGS.write.called) |
203 | + cond_neutron_mig.assert_called_with() |
204 | |
205 | def test_amqp_broken(self): |
206 | self._call_hook('amqp-relation-broken') |
207 | @@ -668,3 +677,46 @@ |
208 | call('service', 'apache2', 'reload')] |
209 | self.check_call.assert_called_has_calls(calls) |
210 | self.assertTrue(_id_rel_joined.called) |
211 | + |
212 | + def test_conditional_neutron_migration_icehouse(self): |
213 | + self.os_release.return_value = 'icehouse' |
214 | + hooks.conditional_neutron_migration() |
215 | + self.log.assert_called_with( |
216 | + 'Not running neutron database migration as migrations are handled ' |
217 | + 'by the neutron-server process or nova-cloud-controller charm.' |
218 | + ) |
219 | + |
220 | + def test_conditional_neutron_migration_ncc_rel_leader_juno(self): |
221 | + self.test_relation.set({ |
222 | + 'allowed_units': 'neutron-api/0 neutron-api/1 neutron-api/4', |
223 | + }) |
224 | + self.local_unit.return_value = 'neutron-api/1' |
225 | + self.is_elected_leader.return_value = True |
226 | + self.os_release.return_value = 'juno' |
227 | + hooks.conditional_neutron_migration() |
228 | + self.log.assert_called_with( |
229 | + 'Not running neutron database migration as migrations are handled' |
230 | + ' by the neutron-server process or nova-cloud-controller charm.' |
231 | + ) |
232 | + |
233 | + def test_conditional_neutron_migration_ncc_rel_leader_kilo(self): |
234 | + self.test_relation.set({ |
235 | + 'allowed_units': 'neutron-api/0 neutron-api/1 neutron-api/4', |
236 | + }) |
237 | + self.local_unit.return_value = 'neutron-api/1' |
238 | + self.is_elected_leader.return_value = True |
239 | + self.os_release.return_value = 'kilo' |
240 | + hooks.conditional_neutron_migration() |
241 | + self.migrate_neutron_database.assert_called_with() |
242 | + self.service_restart.assert_called_with('neutron-server') |
243 | + |
244 | + def test_conditional_neutron_migration_ncc_rel_notleader(self): |
245 | + self.is_elected_leader.return_value = False |
246 | + self.os_release.return_value = 'juno' |
247 | + hooks.conditional_neutron_migration() |
248 | + self.assertFalse(self.migrate_neutron_database.called) |
249 | + self.assertFalse(self.service_restart.called) |
250 | + self.log.assert_called_with( |
251 | + 'Not running neutron database migration as migrations are handled ' |
252 | + 'by the neutron-server process or nova-cloud-controller charm.' |
253 | + ) |
254 | |
255 | === modified file 'unit_tests/test_neutron_api_utils.py' |
256 | --- unit_tests/test_neutron_api_utils.py 2015-04-21 08:46:00 +0000 |
257 | +++ unit_tests/test_neutron_api_utils.py 2015-04-23 08:51:18 +0000 |
258 | @@ -3,6 +3,7 @@ |
259 | from collections import OrderedDict |
260 | from copy import deepcopy |
261 | import charmhelpers.contrib.openstack.templating as templating |
262 | +import charmhelpers.contrib.openstack.utils |
263 | import neutron_api_context as ncontext |
264 | |
265 | templating.OSConfigRenderer = MagicMock() |
266 | @@ -30,6 +31,7 @@ |
267 | 'log', |
268 | 'neutron_plugin_attribute', |
269 | 'os_release', |
270 | + 'subprocess', |
271 | ] |
272 | |
273 | openstack_origin_git = \ |
274 | @@ -73,7 +75,6 @@ |
275 | self.config.side_effect = self.test_config.get |
276 | self.test_config.set('region', 'region101') |
277 | self.neutron_plugin_attribute.side_effect = _mock_npa |
278 | - self.os_release.side_effect = 'trusty' |
279 | |
280 | def tearDown(self): |
281 | # Reset cached cache |
282 | @@ -182,15 +183,19 @@ |
283 | nutils.keystone_ca_cert_b64() |
284 | self.assertTrue(self.b64encode.called) |
285 | |
286 | + @patch.object(nutils, 'migrate_neutron_database') |
287 | + @patch.object(nutils, 'stamp_neutron_database') |
288 | @patch.object(nutils, 'git_install_requested') |
289 | - def test_do_openstack_upgrade(self, git_requested): |
290 | + def test_do_openstack_upgrade_juno(self, git_requested, |
291 | + stamp_neutron_db, migrate_neutron_db): |
292 | git_requested.return_value = False |
293 | self.config.side_effect = self.test_config.get |
294 | self.test_config.set('openstack-origin', 'cloud:trusty-juno') |
295 | - self.os_release.side_effect = 'icehouse' |
296 | + self.os_release.return_value = 'icehouse' |
297 | self.get_os_codename_install_source.return_value = 'juno' |
298 | configs = MagicMock() |
299 | nutils.do_openstack_upgrade(configs) |
300 | + self.os_release.assert_called_with('neutron-server') |
301 | self.log.assert_called() |
302 | self.configure_installation_source.assert_called_with( |
303 | 'cloud:trusty-juno' |
304 | @@ -209,6 +214,46 @@ |
305 | options=dpkg_opts, |
306 | fatal=True) |
307 | configs.set_release.assert_called_with(openstack_release='juno') |
308 | + self.assertItemsEqual(stamp_neutron_db.call_args_list, []) |
309 | + self.assertItemsEqual(migrate_neutron_db.call_args_list, []) |
310 | + |
311 | + @patch.object(charmhelpers.contrib.openstack.utils, |
312 | + 'get_os_codename_install_source') |
313 | + @patch.object(nutils, 'migrate_neutron_database') |
314 | + @patch.object(nutils, 'stamp_neutron_database') |
315 | + @patch.object(nutils, 'git_install_requested') |
316 | + def test_do_openstack_upgrade_kilo(self, git_requested, |
317 | + stamp_neutron_db, migrate_neutron_db, |
318 | + gsrc): |
319 | + git_requested.return_value = False |
320 | + self.os_release.return_value = 'juno' |
321 | + self.config.side_effect = self.test_config.get |
322 | + self.test_config.set('openstack-origin', 'cloud:trusty-kilo') |
323 | + gsrc.return_value = 'kilo' |
324 | + self.get_os_codename_install_source.return_value = 'kilo' |
325 | + configs = MagicMock() |
326 | + nutils.do_openstack_upgrade(configs) |
327 | + self.os_release.assert_called_with('neutron-server') |
328 | + self.log.assert_called() |
329 | + self.configure_installation_source.assert_called_with( |
330 | + 'cloud:trusty-kilo' |
331 | + ) |
332 | + self.apt_update.assert_called_with(fatal=True) |
333 | + dpkg_opts = [ |
334 | + '--option', 'Dpkg::Options::=--force-confnew', |
335 | + '--option', 'Dpkg::Options::=--force-confdef', |
336 | + ] |
337 | + self.apt_upgrade.assert_called_with(options=dpkg_opts, |
338 | + fatal=True, |
339 | + dist=True) |
340 | + pkgs = nutils.determine_packages() |
341 | + pkgs.sort() |
342 | + self.apt_install.assert_called_with(packages=pkgs, |
343 | + options=dpkg_opts, |
344 | + fatal=True) |
345 | + configs.set_release.assert_called_with(openstack_release='kilo') |
346 | + stamp_neutron_db.assert_called_with('juno') |
347 | + migrate_neutron_db.assert_called_with() |
348 | |
349 | @patch.object(ncontext, 'IdentityServiceContext') |
350 | @patch('neutronclient.v2_0.client.Client') |
351 | @@ -402,3 +447,21 @@ |
352 | call('neutron-server'), |
353 | ] |
354 | self.assertEquals(service_restart.call_args_list, expected) |
355 | + |
356 | + def test_stamp_neutron_database(self): |
357 | + nutils.stamp_neutron_database('icehouse') |
358 | + cmd = ['neutron-db-manage', |
359 | + '--config-file', '/etc/neutron/neutron.conf', |
360 | + '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini', |
361 | + 'stamp', |
362 | + 'icehouse'] |
363 | + self.subprocess.check_output.assert_called_with(cmd) |
364 | + |
365 | + def test_migrate_neutron_database(self): |
366 | + nutils.migrate_neutron_database() |
367 | + cmd = ['neutron-db-manage', |
368 | + '--config-file', '/etc/neutron/neutron.conf', |
369 | + '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini', |
370 | + 'upgrade', |
371 | + 'head'] |
372 | + self.subprocess.check_output.assert_called_with(cmd) |
charm_lint_check #3855 neutron-api-next for gnuoy mp257225
LINT FAIL: lint-test failed
LINT Results (max last 2 lines):
make: *** [lint] Error 1
ERROR:root:Make target returned non-zero.
Full lint test output: http:// paste.ubuntu. com/10870003/ 10.245. 162.77: 8080/job/ charm_lint_ check/3855/
Build: http://