Merge lp:~astara-drivers/charms/trusty/nova-cloud-controller/api-ready-rebase into lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/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
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+284962@code.launchpad.net
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 :

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/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #133 nova-cloud-controller-next for gandelman-a mp284962
    LINT OK: passed

Build: http://10.245.162.36:8080/job/charm_lint_check/133/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #14 nova-cloud-controller-next for gandelman-a mp284962
    AMULET OK: passed

Build: http://10.245.162.36:8080/job/charm_amulet_test/14/

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
=== modified file 'hooks/nova_cc_hooks.py'
--- hooks/nova_cc_hooks.py 2016-01-08 13:46:56 +0000
+++ hooks/nova_cc_hooks.py 2016-02-04 18:24:21 +0000
@@ -81,6 +81,7 @@
81 do_openstack_upgrade,81 do_openstack_upgrade,
82 enable_services,82 enable_services,
83 git_install,83 git_install,
84 is_api_ready,
84 keystone_ca_cert_b64,85 keystone_ca_cert_b64,
85 migrate_neutron_database,86 migrate_neutron_database,
86 migrate_nova_database,87 migrate_nova_database,
@@ -286,6 +287,9 @@
286 [nova_cell_relation_joined(rid=rid)287 [nova_cell_relation_joined(rid=rid)
287 for rid in relation_ids('cell')]288 for rid in relation_ids('cell')]
288289
290 for r_id in relation_ids('nova-api'):
291 nova_api_relation_joined(rid=r_id)
292
289293
290def conditional_neutron_migration():294def conditional_neutron_migration():
291 if os_release('nova-common') <= 'icehouse':295 if os_release('nova-common') <= 'icehouse':
@@ -396,6 +400,9 @@
396 CONFIGS.write_all()400 CONFIGS.write_all()
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)
398402
403 for r_id in relation_ids('nova-api'):
404 nova_api_relation_joined(rid=r_id)
405
399406
400@hooks.hook('pgsql-neutron-db-relation-changed')407@hooks.hook('pgsql-neutron-db-relation-changed')
401@service_guard(guard_map(), CONFIGS,408@service_guard(guard_map(), CONFIGS,
@@ -419,6 +426,9 @@
419 CONFIGS.write(NOVA_CONF)426 CONFIGS.write(NOVA_CONF)
420 # TODO: special case config flag for essex (strip protocol)427 # TODO: special case config flag for essex (strip protocol)
421428
429 for r_id in relation_ids('nova-api'):
430 nova_api_relation_joined(rid=r_id)
431
422432
423@hooks.hook('identity-service-relation-joined')433@hooks.hook('identity-service-relation-joined')
424def identity_joined(rid=None):434def identity_joined(rid=None):
@@ -453,6 +463,9 @@
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')]
454 configure_https()464 configure_https()
455465
466 for r_id in relation_ids('nova-api'):
467 nova_api_relation_joined(rid=r_id)
468
456469
457@hooks.hook('nova-volume-service-relation-joined',470@hooks.hook('nova-volume-service-relation-joined',
458 'cinder-volume-service-relation-joined')471 'cinder-volume-service-relation-joined')
@@ -610,6 +623,9 @@
610623
611@hooks.hook('cloud-compute-relation-changed')624@hooks.hook('cloud-compute-relation-changed')
612def compute_changed(rid=None, unit=None):625def compute_changed(rid=None, unit=None):
626 for r_id in relation_ids('nova-api'):
627 nova_api_relation_joined(rid=r_id)
628
613 rel_settings = relation_get(rid=rid, unit=unit)629 rel_settings = relation_get(rid=rid, unit=unit)
614 if 'migration_auth_type' not in rel_settings:630 if 'migration_auth_type' not in rel_settings:
615 return631 return
@@ -1083,6 +1099,13 @@
1083 log(str(e), level='DEBUG')1099 log(str(e), level='DEBUG')
10841100
10851101
1102def nova_api_relation_joined(rid=None):
1103 rel_data = {
1104 'nova-api-ready': 'yes' if is_api_ready(CONFIGS) else 'no'
1105 }
1106 relation_set(rid, **rel_data)
1107
1108
1086def main():1109def main():
1087 try:1110 try:
1088 hooks.execute(sys.argv)1111 hooks.execute(sys.argv)
10891112
=== modified file 'hooks/nova_cc_utils.py'
--- hooks/nova_cc_utils.py 2016-01-08 12:30:31 +0000
+++ hooks/nova_cc_utils.py 2016-02-04 18:24:21 +0000
@@ -35,6 +35,7 @@
35 git_src_dir,35 git_src_dir,
36 git_pip_venv_dir,36 git_pip_venv_dir,
37 git_yaml_value,37 git_yaml_value,
38 incomplete_relation_data,
38 is_ip,39 is_ip,
39 os_release,40 os_release,
40 save_script_rc as _save_script_rc,41 save_script_rc as _save_script_rc,
@@ -1385,3 +1386,7 @@
1385 return status_get()1386 return status_get()
1386 else:1387 else:
1387 return 'unknown', 'No optional relations'1388 return 'unknown', 'No optional relations'
1389
1390
1391def is_api_ready(configs):
1392 return (not incomplete_relation_data(configs, REQUIRED_INTERFACES))
13881393
=== modified file 'unit_tests/test_nova_cc_hooks.py'
--- unit_tests/test_nova_cc_hooks.py 2016-01-08 12:30:31 +0000
+++ unit_tests/test_nova_cc_hooks.py 2016-02-04 18:24:21 +0000
@@ -202,6 +202,12 @@
202 self.assertTrue(self.save_script_rc.called)202 self.assertTrue(self.save_script_rc.called)
203 mock_filter_packages.assert_called_with([])203 mock_filter_packages.assert_called_with([])
204204
205 @patch.object(hooks, 'nova_api_relation_joined')
206 def test_compute_changed_nova_api_trigger(self, api_joined):
207 self.relation_ids.return_value = ['nova-api/0']
208 hooks.compute_changed()
209 api_joined.assert_called_with(rid='nova-api/0')
210
205 def test_compute_changed_ssh_migration(self):211 def test_compute_changed_ssh_migration(self):
206 self.test_relation.set({212 self.test_relation.set({
207 'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey',213 'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey',
@@ -441,17 +447,20 @@
441 configs.write = MagicMock()447 configs.write = MagicMock()
442 hooks.postgresql_nova_db_changed()448 hooks.postgresql_nova_db_changed()
443449
450 @patch.object(hooks, 'nova_api_relation_joined')
444 @patch.object(hooks, 'is_db_initialised')451 @patch.object(hooks, 'is_db_initialised')
445 @patch.object(hooks, 'conditional_neutron_migration')452 @patch.object(hooks, 'conditional_neutron_migration')
446 @patch.object(hooks, 'CONFIGS')453 @patch.object(hooks, 'CONFIGS')
447 def test_db_changed(self, configs, cond_neutron_mig,454 def test_db_changed(self, configs, cond_neutron_mig,
448 mock_is_db_initialised):455 mock_is_db_initialised, api_joined):
456 self.relation_ids.return_value = ['nova-api/0']
449 mock_is_db_initialised.return_value = False457 mock_is_db_initialised.return_value = False
450 'No database migration is attempted when ACL list is not present'458 'No database migration is attempted when ACL list is not present'
451 self._shared_db_test(configs)459 self._shared_db_test(configs)
452 self.assertTrue(configs.write_all.called)460 self.assertTrue(configs.write_all.called)
453 self.assertFalse(self.migrate_nova_database.called)461 self.assertFalse(self.migrate_nova_database.called)
454 self.assertFalse(cond_neutron_mig.called)462 self.assertFalse(cond_neutron_mig.called)
463 api_joined.asert_called_with(rid='nova-api/0')
455464
456 @patch.object(hooks, 'is_db_initialised')465 @patch.object(hooks, 'is_db_initialised')
457 @patch.object(hooks, 'CONFIGS')466 @patch.object(hooks, 'CONFIGS')
@@ -479,13 +488,19 @@
479 self.assertTrue(configs.write_all.called)488 self.assertTrue(configs.write_all.called)
480 self.assertFalse(self.migrate_nova_database.called)489 self.assertFalse(self.migrate_nova_database.called)
481490
491 @patch.object(hooks, 'nova_api_relation_joined')
482 @patch.object(hooks, 'is_db_initialised')492 @patch.object(hooks, 'is_db_initialised')
483 @patch.object(hooks, 'CONFIGS')493 @patch.object(hooks, 'CONFIGS')
484 def test_postgresql_db_changed(self, configs, mock_is_db_initialised):494 def test_postgresql_db_changed(self, configs, mock_is_db_initialised,
495 api_joined):
496 self.relation_ids.side_effect = [
497 [],
498 ['nova-api/0']]
485 mock_is_db_initialised.return_value = False499 mock_is_db_initialised.return_value = False
486 self._postgresql_db_test(configs)500 self._postgresql_db_test(configs)
487 self.assertTrue(configs.write_all.called)501 self.assertTrue(configs.write_all.called)
488 self.migrate_nova_database.assert_called_with()502 self.migrate_nova_database.assert_called_with()
503 api_joined.assert_called_with(rid='nova-api/0')
489504
490 @patch.object(hooks, 'is_db_initialised')505 @patch.object(hooks, 'is_db_initialised')
491 @patch.object(hooks, 'nova_cell_relation_joined')506 @patch.object(hooks, 'nova_cell_relation_joined')
@@ -524,9 +539,11 @@
524 self.assertTrue(configs.write_all.called)539 self.assertTrue(configs.write_all.called)
525 cell_joined.assert_called_with(rid='nova-cell-api/0')540 cell_joined.assert_called_with(rid='nova-cell-api/0')
526541
542 @patch.object(hooks, 'nova_api_relation_joined')
527 @patch.object(hooks, 'nova_cell_relation_joined')543 @patch.object(hooks, 'nova_cell_relation_joined')
528 @patch.object(hooks, 'CONFIGS')544 @patch.object(hooks, 'CONFIGS')
529 def test_amqp_changed_api_rel(self, configs, cell_joined):545 def test_amqp_changed_api_rel(self, configs, cell_joined, api_joined):
546 self.relation_ids.return_value = ['nova-api/0']
530 configs.complete_contexts = MagicMock()547 configs.complete_contexts = MagicMock()
531 configs.complete_contexts.return_value = ['amqp']548 configs.complete_contexts.return_value = ['amqp']
532 configs.write = MagicMock()549 configs.write = MagicMock()
@@ -534,14 +551,19 @@
534 hooks.amqp_changed()551 hooks.amqp_changed()
535 self.assertEquals(configs.write.call_args_list,552 self.assertEquals(configs.write.call_args_list,
536 [call('/etc/nova/nova.conf')])553 [call('/etc/nova/nova.conf')])
554 api_joined.assert_called_with(rid='nova-api/0')
537555
556 @patch.object(hooks, 'nova_api_relation_joined')
538 @patch.object(hooks, 'nova_cell_relation_joined')557 @patch.object(hooks, 'nova_cell_relation_joined')
539 @patch.object(hooks, 'CONFIGS')558 @patch.object(hooks, 'CONFIGS')
540 def test_amqp_changed_noapi_rel(self, configs, cell_joined):559 def test_amqp_changed_noapi_rel(self, configs, cell_joined, api_joined):
541 configs.complete_contexts = MagicMock()560 configs.complete_contexts = MagicMock()
542 configs.complete_contexts.return_value = ['amqp']561 configs.complete_contexts.return_value = ['amqp']
543 configs.write = MagicMock()562 configs.write = MagicMock()
544 self.relation_ids.return_value = ['nova-cell-api/0']563 self.relation_ids.side_effect = [
564 ['nova-cell-api/0'],
565 ['nova-api/0'],
566 ]
545 self.is_relation_made.return_value = False567 self.is_relation_made.return_value = False
546 self.network_manager.return_value = 'neutron'568 self.network_manager.return_value = 'neutron'
547 hooks.amqp_changed()569 hooks.amqp_changed()
@@ -549,6 +571,7 @@
549 [call('/etc/nova/nova.conf'),571 [call('/etc/nova/nova.conf'),
550 call('/etc/neutron/neutron.conf')])572 call('/etc/neutron/neutron.conf')])
551 cell_joined.assert_called_with(rid='nova-cell-api/0')573 cell_joined.assert_called_with(rid='nova-cell-api/0')
574 api_joined.assert_called_with(rid='nova-api/0')
552575
553 @patch.object(hooks, 'canonical_url')576 @patch.object(hooks, 'canonical_url')
554 def test_nova_cell_relation_joined(self, _canonical_url):577 def test_nova_cell_relation_joined(self, _canonical_url):
@@ -886,3 +909,17 @@
886 ])909 ])
887910
888 mock_filter_packages.assert_called_with([])911 mock_filter_packages.assert_called_with([])
912
913 @patch.object(hooks, 'is_api_ready')
914 def _test_nova_api_relation_joined(self, tgt, is_api_ready):
915 is_api_ready.return_value = tgt
916 exp = 'yes' if tgt else 'no'
917 hooks.nova_api_relation_joined(rid='foo')
918 self.relation_set.assert_called_with(
919 'foo', **{'nova-api-ready': exp})
920
921 def test_nova_api_relation_joined_ready(self):
922 self._test_nova_api_relation_joined(True)
923
924 def test_nova_api_relation_joined_not_ready(self):
925 self._test_nova_api_relation_joined(False)
889926
=== modified file 'unit_tests/test_nova_cc_utils.py'
--- unit_tests/test_nova_cc_utils.py 2015-10-06 08:37:21 +0000
+++ unit_tests/test_nova_cc_utils.py 2016-02-04 18:24:21 +0000
@@ -1140,3 +1140,17 @@
1140 self.assertTrue(self.apt_update.called)1140 self.assertTrue(self.apt_update.called)
1141 self.apt_install.assert_called_with(['novnc', 'spice-html5',1141 self.apt_install.assert_called_with(['novnc', 'spice-html5',
1142 'websockify'], fatal=True)1142 'websockify'], fatal=True)
1143
1144 def _test_is_api_ready(self, tgt):
1145 fake_config = MagicMock()
1146 with patch.object(utils, 'incomplete_relation_data') as ird:
1147 ird.return_value = (not tgt)
1148 self.assertEqual(utils.is_api_ready(fake_config), tgt)
1149 ird.assert_called_with(
1150 fake_config, utils.REQUIRED_INTERFACES)
1151
1152 def test_is_api_ready_true(self):
1153 self._test_is_api_ready(True)
1154
1155 def test_is_api_ready_false(self):
1156 self._test_is_api_ready(False)

Subscribers

People subscribed via source and target branches