Use network space binding for shared-db relation
To ensure that the charm presents the right IP address for accessing the MySQL database over the shared-db relation, ensure that any network space binding provided by the user is preferred over the default of 'private-address'. If network spaces is not supported (juju < 2.0), fallback to using 'private-address'. Change-Id: Ic49f16c8ccceeb5aa25a2197a92767dc5aacf703
This commit is contained in:
parent
52fd7b261c
commit
b6b0af9377
@ -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.
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user