Merge "Use network space binding for shared-db relation"

This commit is contained in:
Jenkins 2016-04-15 10:48:54 +00:00 committed by Gerrit Code Review
commit 6abd6f966c
3 changed files with 26 additions and 2 deletions

View File

@ -29,9 +29,11 @@ This charm supports the use of Juju Network Spaces, allowing the charm to be bou
API endpoints can be bound to distinct network spaces supporting the network separation of public, internal and admin endpoints.
Access to the underlying MySQL instance can also be bound to a specific space using the shared-db relation.
To use this feature, use the --bind option when deploying the charm:
juju deploy heat --bind "public=public-space internal=internal-space admin=admin-space"
juju deploy heat --bind "public=public-space internal=internal-space admin=admin-space shared-db=internal-space"
alternatively these can also be provided as part of a juju native bundle configuration:
@ -42,6 +44,7 @@ alternatively these can also be provided as part of a juju native bundle configu
public: public-space
admin: admin-space
internal: internal-space
shared-db: internal-space
NOTE: Spaces must be configured in the underlying provider prior to attempting to use them.

View File

@ -28,6 +28,7 @@ from charmhelpers.core.hookenv import (
leader_get,
leader_set,
is_leader,
network_get_primary_address,
)
from charmhelpers.core.host import (
@ -166,9 +167,17 @@ def db_joined():
config('database-user'),
relation_prefix='heat')
else:
host = None
try:
# NOTE: try to use network spaces
host = network_get_primary_address('shared-db')
except NotImplementedError:
# NOTE: fallback to private-address
host = unit_get('private-address')
relation_set(database=config('database'),
username=config('database-user'),
hostname=unit_get('private-address'))
hostname=host)
@hooks.hook('shared-db-relation-changed')

View File

@ -33,6 +33,7 @@ TO_PATCH = [
'open_port',
'relation_set',
'unit_get',
'network_get_primary_address',
# charmhelpers.core.host
'apt_install',
'apt_update',
@ -68,6 +69,7 @@ class HeatRelationTests(CharmTestCase):
super(HeatRelationTests, self).setUp(relations, TO_PATCH)
self.config.side_effect = self.test_config.get
self.charm_dir.return_value = '/var/lib/juju/charms/heat/charm'
self.network_get_primary_address.side_effect = NotImplementedError
def test_install_hook(self):
repo = 'cloud:precise-havana'
@ -106,6 +108,16 @@ class HeatRelationTests(CharmTestCase):
self.assertFalse(self.do_openstack_upgrade.called)
def test_db_joined_spaces(self):
self.network_get_primary_address.side_effect = None
self.network_get_primary_address.return_value = '192.168.20.1'
self.unit_get.return_value = 'heat.foohost.com'
relations.db_joined()
self.relation_set.assert_called_with(database='heat',
username='heat',
hostname='192.168.20.1')
self.assertFalse(self.unit_get.called)
def test_db_joined(self):
self.unit_get.return_value = 'heat.foohost.com'
relations.db_joined()