Added some cells and amqp unit tests

This commit is contained in:
Liam Young
2014-09-29 09:03:49 +00:00
parent cd6855eaf5
commit 5bc9e8b4a6
3 changed files with 52 additions and 7 deletions

View File

@@ -238,10 +238,10 @@ def db_changed():
migrate_database()
log('Triggering remote cloud-compute restarts.')
[compute_joined(rid=rid, remote_restart=True)
for rid in relation_ids('cloud-compute')]
for rid in relation_ids('cloud-compute')]
log('Triggering remote cell restarts.')
[nova_cell_relation_joined(rid=rid, remote_restart=True)
for rid in relation_ids('cell')]
for rid in relation_ids('cell')]
@hooks.hook('pgsql-nova-db-relation-changed')

View File

@@ -279,11 +279,6 @@ def resource_map():
if s not in resource_map[NOVA_CONF]['services']:
resource_map[NOVA_CONF]['services'].append(s)
novacell_ctxt = context.SubordinateConfigContext(interface='cell',
service='nova',
config_file=NOVA_CONF)
novacell_ctxt = novacell_ctxt()
return resource_map

View File

@@ -356,6 +356,56 @@ class NovaCCHooksTests(CharmTestCase):
self.assertTrue(configs.write_all.called)
self.migrate_database.assert_called_with()
@patch.object(hooks, 'nova_cell_relation_joined')
@patch.object(hooks, 'compute_joined')
@patch.object(hooks, 'CONFIGS')
def test_db_changed_remote_restarts(self, configs, comp_joined,
cell_joined):
def _relation_ids(rel):
relid = {
'cloud-compute': ['nova-compute/0'],
'cell': ['nova-cell-api/0'],
}
return relid[rel]
self.relation_ids.side_effect = _relation_ids
allowed_units = 'nova-cloud-controller/0'
self.test_relation.set({
'nova_allowed_units': allowed_units,
})
self.local_unit.return_value = 'nova-cloud-controller/0'
self._shared_db_test(configs)
comp_joined.assert_called_with(remote_restart=True,
rid='nova-compute/0')
cell_joined.assert_called_with(remote_restart=True,
rid='nova-cell-api/0')
self.migrate_database.assert_called_with()
@patch.object(hooks, 'nova_cell_relation_joined')
@patch.object(hooks, 'CONFIGS')
def test_amqp_changed_api_rel(self, configs, cell_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['amqp']
configs.write = MagicMock()
self.is_relation_made.return_value = True
hooks.amqp_changed()
self.assertEquals(configs.write.call_args_list,
[call('/etc/nova/nova.conf')])
@patch.object(hooks, 'nova_cell_relation_joined')
@patch.object(hooks, 'CONFIGS')
def test_amqp_changed_noapi_rel(self, configs, cell_joined):
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = ['amqp']
configs.write = MagicMock()
self.relation_ids.return_value = ['nova-cell-api/0']
self.is_relation_made.return_value = False
self.network_manager.return_value = 'neutron'
hooks.amqp_changed()
self.assertEquals(configs.write.call_args_list,
[call('/etc/nova/nova.conf'),
call('/etc/neutron/neutron.conf')])
cell_joined.assert_called_with(rid='nova-cell-api/0')
@patch.object(os, 'rename')
@patch.object(os.path, 'isfile')
@patch.object(hooks, 'CONFIGS')