Ensure access to neutron db on a late joining cloud-compute relation.

This commit is contained in:
Adam Gandelman 2013-08-15 12:43:43 -07:00
parent 10793bc187
commit c473d2f282
3 changed files with 33 additions and 7 deletions

View File

@ -92,12 +92,15 @@ def amqp_changed():
@hooks.hook('shared-db-relation-joined')
def db_joined():
relation_set(database=config('database'), username=config('database-user'),
hostname=unit_get('private-address'))
def db_joined(rid=None):
relation_set(relation_id=rid,
nova_database=config('database'),
nova_username=config('database-user'),
nova_hostname=unit_get('private-address'))
if network_manager() in ['quantum', 'neutron']:
# XXX: Renaming relations from quantum_* to neutron_* here.
relation_set(neutron_database=config('neutron-database'),
relation_set(relation_id=rid,
neutron_database=config('neutron-database'),
neutron_username=config('neutron-database-user'),
neutron_hostname=unit_get('private-address'))
@ -145,6 +148,10 @@ def compute_changed():
CONFIGS.write_all()
import_authorized_keys()
import_keystone_ca_cert()
if network_manager() in ['quantum', 'neutron']:
# in case we already have a database relation, need to request
# access to the additional neutron database.
[db_joined(rid) for rid in relation_ids('shared-db')]
@hooks.hook('ceph-relation-joined')

View File

@ -50,7 +50,7 @@ BASE_RESOURCE_MAP = {
'/etc/nova/nova.conf': {
'services': ['nova-compute'],
'contexts': [context.AMQPContext(),
context.SharedDBContext(),
context.SharedDBContext(relation_prefix='nova'),
context.ImageServiceContext(),
context.OSConfigFlagContext(),
CloudComputeContext(),

View File

@ -136,8 +136,27 @@ class NovaComputeRelationsTests(CharmTestCase):
def test_db_joined(self):
self.unit_get.return_value = 'nova.foohost.com'
hooks.db_joined()
self.relation_set.assert_called_with(database='nova', username='nova',
hostname='nova.foohost.com')
self.relation_set.assert_called_with(relation_id=None,
nova_database='nova',
nova_username='nova',
nova_hostname='nova.foohost.com')
self.unit_get.assert_called_with('private-address')
def test_db_joined_quantum(self):
self.unit_get.return_value = 'nova.foohost.com'
self.network_manager.return_value = 'quantum'
hooks.db_joined(rid='shared-db:0')
calls = [call(nova_database='nova',
nova_username='nova',
nova_hostname='nova.foohost.com',
relation_id='shared-db:0'),
call(neutron_database='neutron',
neutron_username='neutron',
neutron_hostname='nova.foohost.com',
relation_id='shared-db:0'),
]
[self.assertIn(c, self.relation_set.call_args_list)
for c in calls]
self.unit_get.assert_called_with('private-address')
@patch.object(hooks, 'CONFIGS')