138
143
quantum_url='http://nova-cc-host1:9696', quantum_plugin='nvp',
139
144
relation_id=None,
140
145
**FAKE_KS_AUTH_CFG)
147
def test_db_joined(self):
148
self.unit_get.return_value = 'nova.foohost.com'
149
self.is_relation_made.return_value = False
151
self.relation_set.assert_called_with(nova_database='nova',
152
nova_username='nova',
153
nova_hostname='nova.foohost.com')
154
self.unit_get.assert_called_with('private-address')
156
def test_postgresql_nova_db_joined(self):
157
self.is_relation_made.return_value = False
158
hooks.pgsql_nova_db_joined()
159
self.relation_set.assert_called_with(database='nova')
161
def test_postgresql_neutron_db_joined(self):
162
self.is_relation_made.return_value = False
163
hooks.pgsql_neutron_db_joined()
164
self.relation_set.assert_called_with(database='neutron')
166
def test_db_joined_with_postgresql(self):
167
self.is_relation_made.return_value = True
169
with self.assertRaises(Exception) as context:
171
self.assertEqual(context.exception.message,
172
'Attempting to associate a mysql database when there is already '
173
'associated a postgresql one')
175
def test_postgresql_nova_joined_with_db(self):
176
self.is_relation_made.return_value = True
178
with self.assertRaises(Exception) as context:
179
hooks.pgsql_nova_db_joined()
180
self.assertEqual(context.exception.message,
181
'Attempting to associate a postgresql database when there is already '
182
'associated a mysql one')
184
def test_postgresql_neutron_joined_with_db(self):
185
self.is_relation_made.return_value = True
187
with self.assertRaises(Exception) as context:
188
hooks.pgsql_neutron_db_joined()
189
self.assertEqual(context.exception.message,
190
'Attempting to associate a postgresql database when there is already '
191
'associated a mysql one')
193
@patch.object(hooks, 'CONFIGS')
194
def test_db_changed_missing_relation_data(self, configs):
195
configs.complete_contexts = MagicMock()
196
configs.complete_contexts.return_value = []
198
self.log.assert_called_with(
199
'shared-db relation incomplete. Peer not ready?'
202
@patch.object(hooks, 'CONFIGS')
203
def test_postgresql_nova_db_changed_missing_relation_data(self, configs):
204
configs.complete_contexts = MagicMock()
205
configs.complete_contexts.return_value = []
206
hooks.postgresql_nova_db_changed()
207
self.log.assert_called_with(
208
'pgsql-nova-db relation incomplete. Peer not ready?'
211
def _shared_db_test(self, configs):
212
configs.complete_contexts = MagicMock()
213
configs.complete_contexts.return_value = ['shared-db']
214
configs.write = MagicMock()
217
def _postgresql_db_test(self, configs):
218
configs.complete_contexts = MagicMock()
219
configs.complete_contexts.return_value = ['pgsql-nova-db']
220
configs.write = MagicMock()
221
hooks.postgresql_nova_db_changed()
223
@patch.object(hooks, 'CONFIGS')
224
def test_db_changed(self, configs):
225
self._shared_db_test(configs)
226
self.assertEquals([call('/etc/nova/nova.conf')],
227
configs.write.call_args_list)
228
self.migrate_database.assert_called_with()
230
@patch.object(hooks, 'CONFIGS')
231
def test_postgresql_db_changed(self, configs):
232
self._postgresql_db_test(configs)
233
self.assertEquals([call('/etc/nova/nova.conf')],
234
configs.write.call_args_list)
235
self.migrate_database.assert_called_with()