Merge lp:~hopem/charms/trusty/nova-cloud-controller/lp1519035 into lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 209
Proposed branch: lp:~hopem/charms/trusty/nova-cloud-controller/lp1519035
Merge into: lp:~openstack-charmers-archive/charms/trusty/nova-cloud-controller/next
Diff against target: 249 lines (+90/-33)
3 files modified
hooks/nova_cc_hooks.py (+55/-27)
hooks/nova_cc_utils.py (+18/-1)
unit_tests/test_nova_cc_hooks.py (+17/-5)
To merge this branch: bzr merge lp:~hopem/charms/trusty/nova-cloud-controller/lp1519035
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+281991@code.launchpad.net
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #16833 nova-cloud-controller-next for hopem mp281991
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/16833/

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

charm_unit_test #15719 nova-cloud-controller-next for hopem mp281991
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/15719/

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

charm_amulet_test #8602 nova-cloud-controller-next for hopem mp281991
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/14440717/
Build: http://10.245.162.77:8080/job/charm_amulet_test/8602/

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

charm_amulet_test #8616 nova-cloud-controller-next for hopem mp281991
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8616/

Revision history for this message
Liam Young (gnuoy) wrote :

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 2015-10-27 14:51:11 +0000
3+++ hooks/nova_cc_hooks.py 2016-01-08 13:47:03 +0000
4@@ -19,6 +19,7 @@
5 is_relation_made,
6 log,
7 local_unit,
8+ DEBUG,
9 ERROR,
10 relation_get,
11 relation_ids,
12@@ -105,6 +106,7 @@
13 setup_ipv6,
14 REQUIRED_INTERFACES,
15 check_optional_relations,
16+ is_db_initialised,
17 )
18
19 from charmhelpers.contrib.hahelpers.cluster import (
20@@ -148,6 +150,43 @@
21 NOVA_CONSOLEAUTH_OVERRIDE = '/etc/init/nova-consoleauth.override'
22
23
24+def leader_init_db_if_ready(skip_acl_check=False, skip_cells_restarts=False,
25+ db_rid=None, unit=None):
26+ """Initialise db if leader and db not yet intialised.
27+
28+ NOTE: must be called from database context.
29+ """
30+ if not is_elected_leader(CLUSTER_RES):
31+ log("Not leader - skipping db init", level=DEBUG)
32+ return
33+
34+ if is_db_initialised():
35+ log("Database already initialised - skipping db init", level=DEBUG)
36+ return
37+
38+ # Bugs 1353135 & 1187508. Dbs can appear to be ready before the units
39+ # acl entry has been added. So, if the db supports passing a list of
40+ # permitted units then check if we're in the list.
41+ allowed_units = relation_get('nova_allowed_units', rid=db_rid, unit=unit)
42+ if skip_acl_check or (allowed_units and local_unit() in
43+ allowed_units.split()):
44+ status_set('maintenance', 'Running nova db migration')
45+ migrate_nova_database()
46+ log('Triggering remote cloud-compute restarts.')
47+ [compute_joined(rid=rid, remote_restart=True)
48+ for rid in relation_ids('cloud-compute')]
49+
50+ if not skip_cells_restarts:
51+ log('Triggering remote cell restarts.')
52+ [nova_cell_relation_joined(rid=rid, remote_restart=True)
53+ for rid in relation_ids('cell')]
54+
55+ conditional_neutron_migration()
56+ else:
57+ log('allowed_units either not presented, or local unit '
58+ 'not in acl list: %s' % repr(allowed_units))
59+
60+
61 @hooks.hook('install.real')
62 def install():
63 status_set('maintenance', 'Executing pre-install')
64@@ -340,26 +379,9 @@
65 if 'shared-db' not in CONFIGS.complete_contexts():
66 log('shared-db relation incomplete. Peer not ready?')
67 return
68+
69 CONFIGS.write_all()
70-
71- if is_elected_leader(CLUSTER_RES):
72- # Bugs 1353135 & 1187508. Dbs can appear to be ready before the units
73- # acl entry has been added. So, if the db supports passing a list of
74- # permitted units then check if we're in the list.
75- allowed_units = relation_get('nova_allowed_units')
76- if allowed_units and local_unit() in allowed_units.split():
77- status_set('maintenance', 'Running nova db migration')
78- migrate_nova_database()
79- log('Triggering remote cloud-compute restarts.')
80- [compute_joined(rid=rid, remote_restart=True)
81- for rid in relation_ids('cloud-compute')]
82- log('Triggering remote cell restarts.')
83- [nova_cell_relation_joined(rid=rid, remote_restart=True)
84- for rid in relation_ids('cell')]
85- conditional_neutron_migration()
86- else:
87- log('allowed_units either not presented, or local unit '
88- 'not in acl list: %s' % repr(allowed_units))
89+ leader_init_db_if_ready()
90
91
92 @hooks.hook('pgsql-nova-db-relation-changed')
93@@ -370,15 +392,9 @@
94 if 'pgsql-nova-db' not in CONFIGS.complete_contexts():
95 log('pgsql-nova-db relation incomplete. Peer not ready?')
96 return
97+
98 CONFIGS.write_all()
99-
100- if is_elected_leader(CLUSTER_RES):
101- status_set('maintenance', 'Running nova db migration')
102- migrate_nova_database()
103- log('Triggering remote cloud-compute restarts.')
104- [compute_joined(rid=rid, remote_restart=True)
105- for rid in relation_ids('cloud-compute')]
106- conditional_neutron_migration()
107+ leader_init_db_if_ready(skip_acl_check=True, skip_cells_restarts=True)
108
109
110 @hooks.hook('pgsql-neutron-db-relation-changed')
111@@ -880,6 +896,18 @@
112 for r_id in relation_ids('cloud-compute'):
113 for unit in related_units(r_id):
114 compute_changed(r_id, unit)
115+
116+ rels = ['shared-db', 'pgsql-nova-db']
117+ for rname in rels:
118+ for rid in relation_ids(rname):
119+ for unit in related_units(rid):
120+ if rname == 'pgsql-nova-db':
121+ leader_init_db_if_ready(skip_acl_check=True,
122+ skip_cells_restarts=True,
123+ db_rid=rid, unit=unit)
124+ else:
125+ leader_init_db_if_ready(db_rid=rid, unit=unit)
126+
127 update_nrpe_config()
128 update_nova_consoleauth_config()
129
130
131=== modified file 'hooks/nova_cc_utils.py'
132--- hooks/nova_cc_utils.py 2015-10-09 00:19:14 +0000
133+++ hooks/nova_cc_utils.py 2016-01-08 13:47:03 +0000
134@@ -16,7 +16,10 @@
135 get_hacluster_config,
136 )
137
138-from charmhelpers.contrib.peerstorage import peer_store
139+from charmhelpers.contrib.peerstorage import (
140+ peer_retrieve,
141+ peer_store,
142+)
143
144 from charmhelpers.contrib.python.packages import (
145 pip_install,
146@@ -53,9 +56,11 @@
147 relation_ids,
148 remote_unit,
149 is_relation_made,
150+ DEBUG,
151 INFO,
152 ERROR,
153 status_get,
154+ status_set,
155 )
156
157 from charmhelpers.core.host import (
158@@ -591,6 +596,17 @@
159 subprocess.check_call(cmd)
160
161
162+def is_db_initialised():
163+ if relation_ids('cluster'):
164+ dbsync_state = peer_retrieve('dbsync_state')
165+ if dbsync_state == 'complete':
166+ log("Database is initialised", level=DEBUG)
167+ return True
168+
169+ log("Database is NOT initialised", level=DEBUG)
170+ return False
171+
172+
173 def _do_openstack_upgrade(new_src):
174 enable_policy_rcd()
175 cur_os_rel = os_release('nova-common')
176@@ -634,6 +650,7 @@
177 ml2_migration()
178
179 if is_elected_leader(CLUSTER_RES):
180+ status_set('maintenance', 'Running nova db migration')
181 migrate_nova_database()
182 [service_start(s) for s in services()]
183
184
185=== modified file 'unit_tests/test_nova_cc_hooks.py'
186--- unit_tests/test_nova_cc_hooks.py 2015-10-07 09:32:28 +0000
187+++ unit_tests/test_nova_cc_hooks.py 2016-01-08 13:47:03 +0000
188@@ -441,17 +441,22 @@
189 configs.write = MagicMock()
190 hooks.postgresql_nova_db_changed()
191
192+ @patch.object(hooks, 'is_db_initialised')
193 @patch.object(hooks, 'conditional_neutron_migration')
194 @patch.object(hooks, 'CONFIGS')
195- def test_db_changed(self, configs, cond_neutron_mig):
196+ def test_db_changed(self, configs, cond_neutron_mig,
197+ mock_is_db_initialised):
198+ mock_is_db_initialised.return_value = False
199 'No database migration is attempted when ACL list is not present'
200 self._shared_db_test(configs)
201 self.assertTrue(configs.write_all.called)
202 self.assertFalse(self.migrate_nova_database.called)
203 self.assertFalse(cond_neutron_mig.called)
204
205+ @patch.object(hooks, 'is_db_initialised')
206 @patch.object(hooks, 'CONFIGS')
207- def test_db_changed_allowed(self, configs):
208+ def test_db_changed_allowed(self, configs, mock_is_db_initialised):
209+ mock_is_db_initialised.return_value = False
210 allowed_units = 'nova-cloud-controller/0 nova-cloud-controller/3'
211 self.test_relation.set({
212 'nova_allowed_units': allowed_units,
213@@ -461,8 +466,10 @@
214 self.assertTrue(configs.write_all.called)
215 self.migrate_nova_database.assert_called_with()
216
217+ @patch.object(hooks, 'is_db_initialised')
218 @patch.object(hooks, 'CONFIGS')
219- def test_db_changed_not_allowed(self, configs):
220+ def test_db_changed_not_allowed(self, configs, mock_is_db_initialised):
221+ mock_is_db_initialised.return_value = False
222 allowed_units = 'nova-cloud-controller/0 nova-cloud-controller/3'
223 self.test_relation.set({
224 'nova_allowed_units': allowed_units,
225@@ -472,17 +479,22 @@
226 self.assertTrue(configs.write_all.called)
227 self.assertFalse(self.migrate_nova_database.called)
228
229+ @patch.object(hooks, 'is_db_initialised')
230 @patch.object(hooks, 'CONFIGS')
231- def test_postgresql_db_changed(self, configs):
232+ def test_postgresql_db_changed(self, configs, mock_is_db_initialised):
233+ mock_is_db_initialised.return_value = False
234 self._postgresql_db_test(configs)
235 self.assertTrue(configs.write_all.called)
236 self.migrate_nova_database.assert_called_with()
237
238+ @patch.object(hooks, 'is_db_initialised')
239 @patch.object(hooks, 'nova_cell_relation_joined')
240 @patch.object(hooks, 'compute_joined')
241 @patch.object(hooks, 'CONFIGS')
242 def test_db_changed_remote_restarts(self, configs, comp_joined,
243- cell_joined):
244+ cell_joined, mock_is_db_initialised):
245+ mock_is_db_initialised.return_value = False
246+
247 def _relation_ids(rel):
248 relid = {
249 'cloud-compute': ['nova-compute/0'],

Subscribers

People subscribed via source and target branches