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 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
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 do_openstack_upgrade,
6 enable_services,
7 git_install,
8+ is_api_ready,
9 keystone_ca_cert_b64,
10 migrate_neutron_database,
11 migrate_nova_database,
12@@ -286,6 +287,9 @@
13 [nova_cell_relation_joined(rid=rid)
14 for rid in relation_ids('cell')]
15
16+ for r_id in relation_ids('nova-api'):
17+ nova_api_relation_joined(rid=r_id)
18+
19
20 def conditional_neutron_migration():
21 if os_release('nova-common') <= 'icehouse':
22@@ -396,6 +400,9 @@
23 CONFIGS.write_all()
24 leader_init_db_if_ready(skip_acl_check=True, skip_cells_restarts=True)
25
26+ for r_id in relation_ids('nova-api'):
27+ nova_api_relation_joined(rid=r_id)
28+
29
30 @hooks.hook('pgsql-neutron-db-relation-changed')
31 @service_guard(guard_map(), CONFIGS,
32@@ -419,6 +426,9 @@
33 CONFIGS.write(NOVA_CONF)
34 # TODO: special case config flag for essex (strip protocol)
35
36+ for r_id in relation_ids('nova-api'):
37+ nova_api_relation_joined(rid=r_id)
38+
39
40 @hooks.hook('identity-service-relation-joined')
41 def identity_joined(rid=None):
42@@ -453,6 +463,9 @@
43 [neutron_api_relation_joined(rid) for rid in relation_ids('neutron-api')]
44 configure_https()
45
46+ for r_id in relation_ids('nova-api'):
47+ nova_api_relation_joined(rid=r_id)
48+
49
50 @hooks.hook('nova-volume-service-relation-joined',
51 'cinder-volume-service-relation-joined')
52@@ -610,6 +623,9 @@
53
54 @hooks.hook('cloud-compute-relation-changed')
55 def compute_changed(rid=None, unit=None):
56+ for r_id in relation_ids('nova-api'):
57+ nova_api_relation_joined(rid=r_id)
58+
59 rel_settings = relation_get(rid=rid, unit=unit)
60 if 'migration_auth_type' not in rel_settings:
61 return
62@@ -1083,6 +1099,13 @@
63 log(str(e), level='DEBUG')
64
65
66+def nova_api_relation_joined(rid=None):
67+ rel_data = {
68+ 'nova-api-ready': 'yes' if is_api_ready(CONFIGS) else 'no'
69+ }
70+ relation_set(rid, **rel_data)
71+
72+
73 def main():
74 try:
75 hooks.execute(sys.argv)
76
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 git_src_dir,
82 git_pip_venv_dir,
83 git_yaml_value,
84+ incomplete_relation_data,
85 is_ip,
86 os_release,
87 save_script_rc as _save_script_rc,
88@@ -1385,3 +1386,7 @@
89 return status_get()
90 else:
91 return 'unknown', 'No optional relations'
92+
93+
94+def is_api_ready(configs):
95+ return (not incomplete_relation_data(configs, REQUIRED_INTERFACES))
96
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 self.assertTrue(self.save_script_rc.called)
102 mock_filter_packages.assert_called_with([])
103
104+ @patch.object(hooks, 'nova_api_relation_joined')
105+ def test_compute_changed_nova_api_trigger(self, api_joined):
106+ self.relation_ids.return_value = ['nova-api/0']
107+ hooks.compute_changed()
108+ api_joined.assert_called_with(rid='nova-api/0')
109+
110 def test_compute_changed_ssh_migration(self):
111 self.test_relation.set({
112 'migration_auth_type': 'ssh', 'ssh_public_key': 'fookey',
113@@ -441,17 +447,20 @@
114 configs.write = MagicMock()
115 hooks.postgresql_nova_db_changed()
116
117+ @patch.object(hooks, 'nova_api_relation_joined')
118 @patch.object(hooks, 'is_db_initialised')
119 @patch.object(hooks, 'conditional_neutron_migration')
120 @patch.object(hooks, 'CONFIGS')
121 def test_db_changed(self, configs, cond_neutron_mig,
122- mock_is_db_initialised):
123+ mock_is_db_initialised, api_joined):
124+ self.relation_ids.return_value = ['nova-api/0']
125 mock_is_db_initialised.return_value = False
126 'No database migration is attempted when ACL list is not present'
127 self._shared_db_test(configs)
128 self.assertTrue(configs.write_all.called)
129 self.assertFalse(self.migrate_nova_database.called)
130 self.assertFalse(cond_neutron_mig.called)
131+ api_joined.asert_called_with(rid='nova-api/0')
132
133 @patch.object(hooks, 'is_db_initialised')
134 @patch.object(hooks, 'CONFIGS')
135@@ -479,13 +488,19 @@
136 self.assertTrue(configs.write_all.called)
137 self.assertFalse(self.migrate_nova_database.called)
138
139+ @patch.object(hooks, 'nova_api_relation_joined')
140 @patch.object(hooks, 'is_db_initialised')
141 @patch.object(hooks, 'CONFIGS')
142- def test_postgresql_db_changed(self, configs, mock_is_db_initialised):
143+ def test_postgresql_db_changed(self, configs, mock_is_db_initialised,
144+ api_joined):
145+ self.relation_ids.side_effect = [
146+ [],
147+ ['nova-api/0']]
148 mock_is_db_initialised.return_value = False
149 self._postgresql_db_test(configs)
150 self.assertTrue(configs.write_all.called)
151 self.migrate_nova_database.assert_called_with()
152+ api_joined.assert_called_with(rid='nova-api/0')
153
154 @patch.object(hooks, 'is_db_initialised')
155 @patch.object(hooks, 'nova_cell_relation_joined')
156@@ -524,9 +539,11 @@
157 self.assertTrue(configs.write_all.called)
158 cell_joined.assert_called_with(rid='nova-cell-api/0')
159
160+ @patch.object(hooks, 'nova_api_relation_joined')
161 @patch.object(hooks, 'nova_cell_relation_joined')
162 @patch.object(hooks, 'CONFIGS')
163- def test_amqp_changed_api_rel(self, configs, cell_joined):
164+ def test_amqp_changed_api_rel(self, configs, cell_joined, api_joined):
165+ self.relation_ids.return_value = ['nova-api/0']
166 configs.complete_contexts = MagicMock()
167 configs.complete_contexts.return_value = ['amqp']
168 configs.write = MagicMock()
169@@ -534,14 +551,19 @@
170 hooks.amqp_changed()
171 self.assertEquals(configs.write.call_args_list,
172 [call('/etc/nova/nova.conf')])
173+ api_joined.assert_called_with(rid='nova-api/0')
174
175+ @patch.object(hooks, 'nova_api_relation_joined')
176 @patch.object(hooks, 'nova_cell_relation_joined')
177 @patch.object(hooks, 'CONFIGS')
178- def test_amqp_changed_noapi_rel(self, configs, cell_joined):
179+ def test_amqp_changed_noapi_rel(self, configs, cell_joined, api_joined):
180 configs.complete_contexts = MagicMock()
181 configs.complete_contexts.return_value = ['amqp']
182 configs.write = MagicMock()
183- self.relation_ids.return_value = ['nova-cell-api/0']
184+ self.relation_ids.side_effect = [
185+ ['nova-cell-api/0'],
186+ ['nova-api/0'],
187+ ]
188 self.is_relation_made.return_value = False
189 self.network_manager.return_value = 'neutron'
190 hooks.amqp_changed()
191@@ -549,6 +571,7 @@
192 [call('/etc/nova/nova.conf'),
193 call('/etc/neutron/neutron.conf')])
194 cell_joined.assert_called_with(rid='nova-cell-api/0')
195+ api_joined.assert_called_with(rid='nova-api/0')
196
197 @patch.object(hooks, 'canonical_url')
198 def test_nova_cell_relation_joined(self, _canonical_url):
199@@ -886,3 +909,17 @@
200 ])
201
202 mock_filter_packages.assert_called_with([])
203+
204+ @patch.object(hooks, 'is_api_ready')
205+ def _test_nova_api_relation_joined(self, tgt, is_api_ready):
206+ is_api_ready.return_value = tgt
207+ exp = 'yes' if tgt else 'no'
208+ hooks.nova_api_relation_joined(rid='foo')
209+ self.relation_set.assert_called_with(
210+ 'foo', **{'nova-api-ready': exp})
211+
212+ def test_nova_api_relation_joined_ready(self):
213+ self._test_nova_api_relation_joined(True)
214+
215+ def test_nova_api_relation_joined_not_ready(self):
216+ self._test_nova_api_relation_joined(False)
217
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 self.assertTrue(self.apt_update.called)
223 self.apt_install.assert_called_with(['novnc', 'spice-html5',
224 'websockify'], fatal=True)
225+
226+ def _test_is_api_ready(self, tgt):
227+ fake_config = MagicMock()
228+ with patch.object(utils, 'incomplete_relation_data') as ird:
229+ ird.return_value = (not tgt)
230+ self.assertEqual(utils.is_api_ready(fake_config), tgt)
231+ ird.assert_called_with(
232+ fake_config, utils.REQUIRED_INTERFACES)
233+
234+ def test_is_api_ready_true(self):
235+ self._test_is_api_ready(True)
236+
237+ def test_is_api_ready_false(self):
238+ self._test_is_api_ready(False)

Subscribers

People subscribed via source and target branches