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: I8e70be47250c650e4b0135b0f2707f7eb1d46d1e
This commit is contained in:
James Page 2016-04-12 14:50:54 +01:00
parent e1d5e7ef68
commit c59e76217b
3 changed files with 27 additions and 2 deletions

View File

@ -124,9 +124,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 neutron-api --bind "public=public-space internal=internal-space admin=admin-space"
juju deploy neutron-api --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:
@ -137,6 +139,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

@ -22,6 +22,7 @@ from charmhelpers.core.hookenv import (
status_set,
open_port,
unit_get,
network_get_primary_address,
)
from charmhelpers.core.host import (
@ -330,7 +331,14 @@ def db_joined():
sync_db_with_multi_ipv6_addresses(config('database'),
config('database-user'))
else:
host = unit_get('private-address')
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=host)

View File

@ -74,6 +74,7 @@ TO_PATCH = [
'IdentityServiceContext',
'force_etcd_restart',
'status_set',
'network_get_primary_address',
]
NEUTRON_CONF_DIR = "/etc/neutron"
@ -117,6 +118,7 @@ class NeutronAPIHooksTests(CharmTestCase):
self.test_config.set('openstack-origin', 'distro')
self.test_config.set('neutron-plugin', 'ovs')
self.neutron_plugin_attribute.side_effect = _mock_nuage_npa
self.network_get_primary_address.side_effect = NotImplementedError
def _fake_relids(self, rel_name):
return [randrange(100) for _count in range(2)]
@ -341,6 +343,18 @@ class NeutronAPIHooksTests(CharmTestCase):
hostname='myhostname',
)
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.is_relation_made.return_value = False
self.unit_get.return_value = 'myhostname'
self._call_hook('shared-db-relation-joined')
self.relation_set.assert_called_with(
username='neutron',
database='neutron',
hostname='192.168.20.1',
)
def test_db_joined_with_postgresql(self):
self.is_relation_made.return_value = True