Merge lp:~astara-drivers/charms/trusty/nova-cloud-controller/api-ready-rebase into lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next
- Trusty Tahr (14.04)
- api-ready-rebase
- Merge into next
Proposed by
Adam Gandelman
Status: | Merged |
---|---|
Merged at revision: | 221 |
Proposed branch: | lp:~astara-drivers/charms/trusty/nova-cloud-controller/api-ready-rebase |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next |
Diff against target: |
238 lines (+84/-5) 4 files modified
hooks/nova_cc_hooks.py (+23/-0) hooks/nova_cc_utils.py (+5/-0) unit_tests/test_nova_cc_hooks.py (+42/-5) unit_tests/test_nova_cc_utils.py (+14/-0) |
To merge this branch: | bzr merge lp:~astara-drivers/charms/trusty/nova-cloud-controller/api-ready-rebase |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Liam Young (community) | Approve | ||
Review via email: mp+284962@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 216. By Adam Gandelman
-
Remove duplicate hook trigger
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #133 nova-cloud-
LINT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #14 nova-cloud-
AMULET OK: passed
Revision history for this message
Liam Young (gnuoy) wrote : | # |
Thank you for this contribution, it is very much appreciated. Approved.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hooks/nova_cc_hooks.py' | |||
2 | --- hooks/nova_cc_hooks.py 2016-01-08 13:46:56 +0000 | |||
3 | +++ hooks/nova_cc_hooks.py 2016-02-04 18:24:21 +0000 | |||
4 | @@ -81,6 +81,7 @@ | |||
5 | 81 | do_openstack_upgrade, | 81 | do_openstack_upgrade, |
6 | 82 | enable_services, | 82 | enable_services, |
7 | 83 | git_install, | 83 | git_install, |
8 | 84 | is_api_ready, | ||
9 | 84 | keystone_ca_cert_b64, | 85 | keystone_ca_cert_b64, |
10 | 85 | migrate_neutron_database, | 86 | migrate_neutron_database, |
11 | 86 | migrate_nova_database, | 87 | migrate_nova_database, |
12 | @@ -286,6 +287,9 @@ | |||
13 | 286 | [nova_cell_relation_joined(rid=rid) | 287 | [nova_cell_relation_joined(rid=rid) |
14 | 287 | for rid in relation_ids('cell')] | 288 | for rid in relation_ids('cell')] |
15 | 288 | 289 | ||
16 | 290 | for r_id in relation_ids('nova-api'): | ||
17 | 291 | nova_api_relation_joined(rid=r_id) | ||
18 | 292 | |||
19 | 289 | 293 | ||
20 | 290 | def conditional_neutron_migration(): | 294 | def conditional_neutron_migration(): |
21 | 291 | if os_release('nova-common') <= 'icehouse': | 295 | if os_release('nova-common') <= 'icehouse': |
22 | @@ -396,6 +400,9 @@ | |||
23 | 396 | CONFIGS.write_all() | 400 | CONFIGS.write_all() |
24 | 397 | leader_init_db_if_ready(skip_acl_check=True, skip_cells_restarts=True) | 401 | leader_init_db_if_ready(skip_acl_check=True, skip_cells_restarts=True) |
25 | 398 | 402 | ||
26 | 403 | for r_id in relation_ids('nova-api'): | ||
27 | 404 | nova_api_relation_joined(rid=r_id) | ||
28 | 405 | |||
29 | 399 | 406 | ||
30 | 400 | @hooks.hook('pgsql-neutron-db-relation-changed') | 407 | @hooks.hook('pgsql-neutron-db-relation-changed') |
31 | 401 | @service_guard(guard_map(), CONFIGS, | 408 | @service_guard(guard_map(), CONFIGS, |
32 | @@ -419,6 +426,9 @@ | |||
33 | 419 | CONFIGS.write(NOVA_CONF) | 426 | CONFIGS.write(NOVA_CONF) |
34 | 420 | # TODO: special case config flag for essex (strip protocol) | 427 | # TODO: special case config flag for essex (strip protocol) |
35 | 421 | 428 | ||
36 | 429 | for r_id in relation_ids('nova-api'): | ||
37 | 430 | nova_api_relation_joined(rid=r_id) | ||
38 | 431 | |||
39 | 422 | 432 | ||
40 | 423 | @hooks.hook('identity-service-relation-joined') | 433 | @hooks.hook('identity-service-relation-joined') |
41 | 424 | def identity_joined(rid=None): | 434 | def identity_joined(rid=None): |
42 | @@ -453,6 +463,9 @@ | |||
43 | 453 | [neutron_api_relation_joined(rid) for rid in relation_ids('neutron-api')] | 463 | [neutron_api_relation_joined(rid) for rid in relation_ids('neutron-api')] |
44 | 454 | configure_https() | 464 | configure_https() |
45 | 455 | 465 | ||
46 | 466 | for r_id in relation_ids('nova-api'): | ||
47 | 467 | nova_api_relation_joined(rid=r_id) | ||
48 | 468 | |||
49 | 456 | 469 | ||
50 | 457 | @hooks.hook('nova-volume-service-relation-joined', | 470 | @hooks.hook('nova-volume-service-relation-joined', |
51 | 458 | 'cinder-volume-service-relation-joined') | 471 | 'cinder-volume-service-relation-joined') |
52 | @@ -610,6 +623,9 @@ | |||
53 | 610 | 623 | ||
54 | 611 | @hooks.hook('cloud-compute-relation-changed') | 624 | @hooks.hook('cloud-compute-relation-changed') |
55 | 612 | def compute_changed(rid=None, unit=None): | 625 | def compute_changed(rid=None, unit=None): |
56 | 626 | for r_id in relation_ids('nova-api'): | ||
57 | 627 | nova_api_relation_joined(rid=r_id) | ||
58 | 628 | |||
59 | 613 | rel_settings = relation_get(rid=rid, unit=unit) | 629 | rel_settings = relation_get(rid=rid, unit=unit) |
60 | 614 | if 'migration_auth_type' not in rel_settings: | 630 | if 'migration_auth_type' not in rel_settings: |
61 | 615 | return | 631 | return |
62 | @@ -1083,6 +1099,13 @@ | |||
63 | 1083 | log(str(e), level='DEBUG') | 1099 | log(str(e), level='DEBUG') |
64 | 1084 | 1100 | ||
65 | 1085 | 1101 | ||
66 | 1102 | def nova_api_relation_joined(rid=None): | ||
67 | 1103 | rel_data = { | ||
68 | 1104 | 'nova-api-ready': 'yes' if is_api_ready(CONFIGS) else 'no' | ||
69 | 1105 | } | ||
70 | 1106 | relation_set(rid, **rel_data) | ||
71 | 1107 | |||
72 | 1108 | |||
73 | 1086 | def main(): | 1109 | def main(): |
74 | 1087 | try: | 1110 | try: |
75 | 1088 | hooks.execute(sys.argv) | 1111 | hooks.execute(sys.argv) |
76 | 1089 | 1112 | ||
77 | === modified file 'hooks/nova_cc_utils.py' | |||
78 | --- hooks/nova_cc_utils.py 2016-01-08 12:30:31 +0000 | |||
79 | +++ hooks/nova_cc_utils.py 2016-02-04 18:24:21 +0000 | |||
80 | @@ -35,6 +35,7 @@ | |||
81 | 35 | git_src_dir, | 35 | git_src_dir, |
82 | 36 | git_pip_venv_dir, | 36 | git_pip_venv_dir, |
83 | 37 | git_yaml_value, | 37 | git_yaml_value, |
84 | 38 | incomplete_relation_data, | ||
85 | 38 | is_ip, | 39 | is_ip, |
86 | 39 | os_release, | 40 | os_release, |
87 | 40 | save_script_rc as _save_script_rc, | 41 | save_script_rc as _save_script_rc, |
88 | @@ -1385,3 +1386,7 @@ | |||
89 | 1385 | return status_get() | 1386 | return status_get() |
90 | 1386 | else: | 1387 | else: |
91 | 1387 | return 'unknown', 'No optional relations' | 1388 | return 'unknown', 'No optional relations' |
92 | 1389 | |||
93 | 1390 | |||
94 | 1391 | def is_api_ready(configs): | ||
95 | 1392 | return (not incomplete_relation_data(configs, REQUIRED_INTERFACES)) | ||
96 | 1388 | 1393 | ||
97 | === modified file 'unit_tests/test_nova_cc_hooks.py' | |||
98 | --- unit_tests/test_nova_cc_hooks.py 2016-01-08 12:30:31 +0000 | |||
99 | +++ unit_tests/test_nova_cc_hooks.py 2016-02-04 18:24:21 +0000 | |||
100 | @@ -202,6 +202,12 @@ | |||
101 | 202 | self.assertTrue(self.save_script_rc.called) | 202 | self.assertTrue(self.save_script_rc.called) |
102 | 203 | mock_filter_packages.assert_called_with([]) | 203 | mock_filter_packages.assert_called_with([]) |
103 | 204 | 204 | ||
104 | 205 | @patch.object(hooks, 'nova_api_relation_joined') | ||
105 | 206 | def test_compute_changed_nova_api_trigger(self, api_joined): | ||
106 | 207 | self.relation_ids.return_value = ['nova-api/0'] | ||
107 | 208 | hooks.compute_changed() | ||
108 | 209 | api_joined.assert_called_with(rid='nova-api/0') | ||
109 | 210 | |||
110 | 205 | def test_compute_changed_ssh_migration(self): | 211 | def test_compute_changed_ssh_migration(self): |
111 | 206 | self.test_relation.set({ | 212 | self.test_relation.set({ |
112 | 207 | 'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey', | 213 | 'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey', |
113 | @@ -441,17 +447,20 @@ | |||
114 | 441 | configs.write = MagicMock() | 447 | configs.write = MagicMock() |
115 | 442 | hooks.postgresql_nova_db_changed() | 448 | hooks.postgresql_nova_db_changed() |
116 | 443 | 449 | ||
117 | 450 | @patch.object(hooks, 'nova_api_relation_joined') | ||
118 | 444 | @patch.object(hooks, 'is_db_initialised') | 451 | @patch.object(hooks, 'is_db_initialised') |
119 | 445 | @patch.object(hooks, 'conditional_neutron_migration') | 452 | @patch.object(hooks, 'conditional_neutron_migration') |
120 | 446 | @patch.object(hooks, 'CONFIGS') | 453 | @patch.object(hooks, 'CONFIGS') |
121 | 447 | def test_db_changed(self, configs, cond_neutron_mig, | 454 | def test_db_changed(self, configs, cond_neutron_mig, |
123 | 448 | mock_is_db_initialised): | 455 | mock_is_db_initialised, api_joined): |
124 | 456 | self.relation_ids.return_value = ['nova-api/0'] | ||
125 | 449 | mock_is_db_initialised.return_value = False | 457 | mock_is_db_initialised.return_value = False |
126 | 450 | 'No database migration is attempted when ACL list is not present' | 458 | 'No database migration is attempted when ACL list is not present' |
127 | 451 | self._shared_db_test(configs) | 459 | self._shared_db_test(configs) |
128 | 452 | self.assertTrue(configs.write_all.called) | 460 | self.assertTrue(configs.write_all.called) |
129 | 453 | self.assertFalse(self.migrate_nova_database.called) | 461 | self.assertFalse(self.migrate_nova_database.called) |
130 | 454 | self.assertFalse(cond_neutron_mig.called) | 462 | self.assertFalse(cond_neutron_mig.called) |
131 | 463 | api_joined.asert_called_with(rid='nova-api/0') | ||
132 | 455 | 464 | ||
133 | 456 | @patch.object(hooks, 'is_db_initialised') | 465 | @patch.object(hooks, 'is_db_initialised') |
134 | 457 | @patch.object(hooks, 'CONFIGS') | 466 | @patch.object(hooks, 'CONFIGS') |
135 | @@ -479,13 +488,19 @@ | |||
136 | 479 | self.assertTrue(configs.write_all.called) | 488 | self.assertTrue(configs.write_all.called) |
137 | 480 | self.assertFalse(self.migrate_nova_database.called) | 489 | self.assertFalse(self.migrate_nova_database.called) |
138 | 481 | 490 | ||
139 | 491 | @patch.object(hooks, 'nova_api_relation_joined') | ||
140 | 482 | @patch.object(hooks, 'is_db_initialised') | 492 | @patch.object(hooks, 'is_db_initialised') |
141 | 483 | @patch.object(hooks, 'CONFIGS') | 493 | @patch.object(hooks, 'CONFIGS') |
143 | 484 | def test_postgresql_db_changed(self, configs, mock_is_db_initialised): | 494 | def test_postgresql_db_changed(self, configs, mock_is_db_initialised, |
144 | 495 | api_joined): | ||
145 | 496 | self.relation_ids.side_effect = [ | ||
146 | 497 | [], | ||
147 | 498 | ['nova-api/0']] | ||
148 | 485 | mock_is_db_initialised.return_value = False | 499 | mock_is_db_initialised.return_value = False |
149 | 486 | self._postgresql_db_test(configs) | 500 | self._postgresql_db_test(configs) |
150 | 487 | self.assertTrue(configs.write_all.called) | 501 | self.assertTrue(configs.write_all.called) |
151 | 488 | self.migrate_nova_database.assert_called_with() | 502 | self.migrate_nova_database.assert_called_with() |
152 | 503 | api_joined.assert_called_with(rid='nova-api/0') | ||
153 | 489 | 504 | ||
154 | 490 | @patch.object(hooks, 'is_db_initialised') | 505 | @patch.object(hooks, 'is_db_initialised') |
155 | 491 | @patch.object(hooks, 'nova_cell_relation_joined') | 506 | @patch.object(hooks, 'nova_cell_relation_joined') |
156 | @@ -524,9 +539,11 @@ | |||
157 | 524 | self.assertTrue(configs.write_all.called) | 539 | self.assertTrue(configs.write_all.called) |
158 | 525 | cell_joined.assert_called_with(rid='nova-cell-api/0') | 540 | cell_joined.assert_called_with(rid='nova-cell-api/0') |
159 | 526 | 541 | ||
160 | 542 | @patch.object(hooks, 'nova_api_relation_joined') | ||
161 | 527 | @patch.object(hooks, 'nova_cell_relation_joined') | 543 | @patch.object(hooks, 'nova_cell_relation_joined') |
162 | 528 | @patch.object(hooks, 'CONFIGS') | 544 | @patch.object(hooks, 'CONFIGS') |
164 | 529 | def test_amqp_changed_api_rel(self, configs, cell_joined): | 545 | def test_amqp_changed_api_rel(self, configs, cell_joined, api_joined): |
165 | 546 | self.relation_ids.return_value = ['nova-api/0'] | ||
166 | 530 | configs.complete_contexts = MagicMock() | 547 | configs.complete_contexts = MagicMock() |
167 | 531 | configs.complete_contexts.return_value = ['amqp'] | 548 | configs.complete_contexts.return_value = ['amqp'] |
168 | 532 | configs.write = MagicMock() | 549 | configs.write = MagicMock() |
169 | @@ -534,14 +551,19 @@ | |||
170 | 534 | hooks.amqp_changed() | 551 | hooks.amqp_changed() |
171 | 535 | self.assertEquals(configs.write.call_args_list, | 552 | self.assertEquals(configs.write.call_args_list, |
172 | 536 | [call('/etc/nova/nova.conf')]) | 553 | [call('/etc/nova/nova.conf')]) |
173 | 554 | api_joined.assert_called_with(rid='nova-api/0') | ||
174 | 537 | 555 | ||
175 | 556 | @patch.object(hooks, 'nova_api_relation_joined') | ||
176 | 538 | @patch.object(hooks, 'nova_cell_relation_joined') | 557 | @patch.object(hooks, 'nova_cell_relation_joined') |
177 | 539 | @patch.object(hooks, 'CONFIGS') | 558 | @patch.object(hooks, 'CONFIGS') |
179 | 540 | def test_amqp_changed_noapi_rel(self, configs, cell_joined): | 559 | def test_amqp_changed_noapi_rel(self, configs, cell_joined, api_joined): |
180 | 541 | configs.complete_contexts = MagicMock() | 560 | configs.complete_contexts = MagicMock() |
181 | 542 | configs.complete_contexts.return_value = ['amqp'] | 561 | configs.complete_contexts.return_value = ['amqp'] |
182 | 543 | configs.write = MagicMock() | 562 | configs.write = MagicMock() |
184 | 544 | self.relation_ids.return_value = ['nova-cell-api/0'] | 563 | self.relation_ids.side_effect = [ |
185 | 564 | ['nova-cell-api/0'], | ||
186 | 565 | ['nova-api/0'], | ||
187 | 566 | ] | ||
188 | 545 | self.is_relation_made.return_value = False | 567 | self.is_relation_made.return_value = False |
189 | 546 | self.network_manager.return_value = 'neutron' | 568 | self.network_manager.return_value = 'neutron' |
190 | 547 | hooks.amqp_changed() | 569 | hooks.amqp_changed() |
191 | @@ -549,6 +571,7 @@ | |||
192 | 549 | [call('/etc/nova/nova.conf'), | 571 | [call('/etc/nova/nova.conf'), |
193 | 550 | call('/etc/neutron/neutron.conf')]) | 572 | call('/etc/neutron/neutron.conf')]) |
194 | 551 | cell_joined.assert_called_with(rid='nova-cell-api/0') | 573 | cell_joined.assert_called_with(rid='nova-cell-api/0') |
195 | 574 | api_joined.assert_called_with(rid='nova-api/0') | ||
196 | 552 | 575 | ||
197 | 553 | @patch.object(hooks, 'canonical_url') | 576 | @patch.object(hooks, 'canonical_url') |
198 | 554 | def test_nova_cell_relation_joined(self, _canonical_url): | 577 | def test_nova_cell_relation_joined(self, _canonical_url): |
199 | @@ -886,3 +909,17 @@ | |||
200 | 886 | ]) | 909 | ]) |
201 | 887 | 910 | ||
202 | 888 | mock_filter_packages.assert_called_with([]) | 911 | mock_filter_packages.assert_called_with([]) |
203 | 912 | |||
204 | 913 | @patch.object(hooks, 'is_api_ready') | ||
205 | 914 | def _test_nova_api_relation_joined(self, tgt, is_api_ready): | ||
206 | 915 | is_api_ready.return_value = tgt | ||
207 | 916 | exp = 'yes' if tgt else 'no' | ||
208 | 917 | hooks.nova_api_relation_joined(rid='foo') | ||
209 | 918 | self.relation_set.assert_called_with( | ||
210 | 919 | 'foo', **{'nova-api-ready': exp}) | ||
211 | 920 | |||
212 | 921 | def test_nova_api_relation_joined_ready(self): | ||
213 | 922 | self._test_nova_api_relation_joined(True) | ||
214 | 923 | |||
215 | 924 | def test_nova_api_relation_joined_not_ready(self): | ||
216 | 925 | self._test_nova_api_relation_joined(False) | ||
217 | 889 | 926 | ||
218 | === modified file 'unit_tests/test_nova_cc_utils.py' | |||
219 | --- unit_tests/test_nova_cc_utils.py 2015-10-06 08:37:21 +0000 | |||
220 | +++ unit_tests/test_nova_cc_utils.py 2016-02-04 18:24:21 +0000 | |||
221 | @@ -1140,3 +1140,17 @@ | |||
222 | 1140 | self.assertTrue(self.apt_update.called) | 1140 | self.assertTrue(self.apt_update.called) |
223 | 1141 | self.apt_install.assert_called_with(['novnc', 'spice-html5', | 1141 | self.apt_install.assert_called_with(['novnc', 'spice-html5', |
224 | 1142 | 'websockify'], fatal=True) | 1142 | 'websockify'], fatal=True) |
225 | 1143 | |||
226 | 1144 | def _test_is_api_ready(self, tgt): | ||
227 | 1145 | fake_config = MagicMock() | ||
228 | 1146 | with patch.object(utils, 'incomplete_relation_data') as ird: | ||
229 | 1147 | ird.return_value = (not tgt) | ||
230 | 1148 | self.assertEqual(utils.is_api_ready(fake_config), tgt) | ||
231 | 1149 | ird.assert_called_with( | ||
232 | 1150 | fake_config, utils.REQUIRED_INTERFACES) | ||
233 | 1151 | |||
234 | 1152 | def test_is_api_ready_true(self): | ||
235 | 1153 | self._test_is_api_ready(True) | ||
236 | 1154 | |||
237 | 1155 | def test_is_api_ready_false(self): | ||
238 | 1156 | self._test_is_api_ready(False) |
charm_unit_test #119 nova-cloud- controller- next for gandelman-a mp284962
UNIT OK: passed
Build: http:// 10.245. 162.36: 8080/job/ charm_unit_ test/119/