Resync helpers

This commit is contained in:
James Page 2014-07-02 09:22:25 +01:00
parent 58a9e396e8
commit 2792a4dc59
6 changed files with 81 additions and 15 deletions

2
.bzrignore Normal file
View File

@ -0,0 +1,2 @@
bin
.coverage

View File

@ -6,11 +6,15 @@ lint:
@charm proof @charm proof
test: test:
@echo Starting tests...
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests @$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
sync: bin/charm_helpers_sync.py:
@charm-helper-sync -c charm-helpers.yaml @mkdir -p bin
@bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
> bin/charm_helpers_sync.py
sync: bin/charm_helpers_sync.py
@$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers.yaml
publish: lint test publish: lint test
bzr push lp:charms/nova-cloud-controller bzr push lp:charms/nova-cloud-controller

View File

@ -67,3 +67,29 @@ def get_address_in_network(network, fallback=None, fatal=False):
not_found_error_out() not_found_error_out()
return None return None
def is_address_in_network(network, address):
"""
Determine whether the provided address is within a network range.
:param network (str): CIDR presentation format. For example,
'192.168.1.0/24'.
:param address: An individual IPv4 or IPv6 address without a net
mask or subnet prefix. For example, '192.168.1.1'.
:returns boolean: Flag indicating whether address is in network.
"""
try:
network = netaddr.IPNetwork(network)
except (netaddr.core.AddrFormatError, ValueError):
raise ValueError("Network (%s) is not in CIDR presentation format" %
network)
try:
address = netaddr.IPAddress(address)
except (netaddr.core.AddrFormatError, ValueError):
raise ValueError("Address (%s) is not in correct presentation format" %
address)
if address in network:
return True
else:
return False

View File

@ -7,19 +7,36 @@ class OpenStackAmuletDeployment(AmuletDeployment):
"""This class inherits from AmuletDeployment and has additional support """This class inherits from AmuletDeployment and has additional support
that is specifically for use by OpenStack charms.""" that is specifically for use by OpenStack charms."""
def __init__(self, series=None, openstack=None): def __init__(self, series=None, openstack=None, source=None):
"""Initialize the deployment environment.""" """Initialize the deployment environment."""
self.openstack = None
super(OpenStackAmuletDeployment, self).__init__(series) super(OpenStackAmuletDeployment, self).__init__(series)
if openstack:
self.openstack = openstack self.openstack = openstack
self.source = source
def _add_services(self, this_service, other_services):
"""Add services to the deployment and set openstack-origin."""
super(OpenStackAmuletDeployment, self)._add_services(this_service,
other_services)
name = 0
services = other_services
services.append(this_service)
use_source = ['mysql', 'mongodb', 'rabbitmq-server', 'ceph']
if self.openstack:
for svc in services:
if svc[name] not in use_source:
config = {'openstack-origin': self.openstack}
self.d.configure(svc[name], config)
if self.source:
for svc in services:
if svc[name] in use_source:
config = {'source': self.source}
self.d.configure(svc[name], config)
def _configure_services(self, configs): def _configure_services(self, configs):
"""Configure all of the services.""" """Configure all of the services."""
for service, config in configs.iteritems(): for service, config in configs.iteritems():
if service == self.this_service:
config['openstack-origin'] = self.openstack
self.d.configure(service, config) self.d.configure(service, config)
def _get_openstack_release(self): def _get_openstack_release(self):

View File

@ -74,7 +74,7 @@ class OpenStackAmuletUtils(AmuletUtils):
if ret: if ret:
return "unexpected tenant data - {}".format(ret) return "unexpected tenant data - {}".format(ret)
if not found: if not found:
return "tenant {} does not exist".format(e.name) return "tenant {} does not exist".format(e['name'])
return ret return ret
def validate_role_data(self, expected, actual): def validate_role_data(self, expected, actual):
@ -91,7 +91,7 @@ class OpenStackAmuletUtils(AmuletUtils):
if ret: if ret:
return "unexpected role data - {}".format(ret) return "unexpected role data - {}".format(ret)
if not found: if not found:
return "role {} does not exist".format(e.name) return "role {} does not exist".format(e['name'])
return ret return ret
def validate_user_data(self, expected, actual): def validate_user_data(self, expected, actual):
@ -110,7 +110,7 @@ class OpenStackAmuletUtils(AmuletUtils):
if ret: if ret:
return "unexpected user data - {}".format(ret) return "unexpected user data - {}".format(ret)
if not found: if not found:
return "user {} does not exist".format(e.name) return "user {} does not exist".format(e['name'])
return ret return ret
def validate_flavor_data(self, expected, actual): def validate_flavor_data(self, expected, actual):
@ -192,8 +192,8 @@ class OpenStackAmuletUtils(AmuletUtils):
count = 1 count = 1
status = instance.status status = instance.status
while status == 'BUILD' and count < 10: while status != 'ACTIVE' and count < 60:
time.sleep(5) time.sleep(3)
instance = nova.servers.get(instance.id) instance = nova.servers.get(instance.id)
status = instance.status status = instance.status
self.log.debug('instance status: {}'.format(status)) self.log.debug('instance status: {}'.format(status))

View File

@ -21,6 +21,7 @@ from charmhelpers.core.hookenv import (
relation_get, relation_get,
relation_ids, relation_ids,
related_units, related_units,
relation_set,
unit_get, unit_get,
unit_private_ip, unit_private_ip,
ERROR, ERROR,
@ -42,6 +43,8 @@ from charmhelpers.contrib.openstack.neutron import (
neutron_plugin_attribute, neutron_plugin_attribute,
) )
from charmhelpers.contrib.network.ip import get_address_in_network
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
@ -134,8 +137,22 @@ class SharedDBContext(OSContextGenerator):
'Missing required charm config options. ' 'Missing required charm config options. '
'(database name and user)') '(database name and user)')
raise OSContextError raise OSContextError
ctxt = {} ctxt = {}
# NOTE(jamespage) if mysql charm provides a network upon which
# access to the database should be made, reconfigure relation
# with the service units local address and defer execution
access_network = relation_get('access-network')
if access_network is not None:
access_hostname = get_address_in_network(access_network,
unit_get('private-address'))
set_hostname = relation_get(attribute='hostname',
unit=local_unit())
if set_hostname != access_hostname:
relation_set(hostname=access_hostname)
return ctxt # Defer any further hook execution for now....
password_setting = 'password' password_setting = 'password'
if self.relation_prefix: if self.relation_prefix:
password_setting = self.relation_prefix + '_password' password_setting = self.relation_prefix + '_password'