Enable network spaces for the memcache relation

This enables network spaces for the memcache relation.  Essentially,
the charm tries to use the binding for the memcache, and if that doesn't
work falls back to the private address.

Change-Id: I831c4df22a698709fc0fa42ccea74f10b64a469b
This commit is contained in:
Alex Kavanagh 2017-04-21 10:22:11 +01:00
parent 62a85e47bc
commit 3ffd566f55
5 changed files with 79 additions and 31 deletions

View File

@ -547,7 +547,7 @@ class OpenStackAmuletUtils(AmuletUtils):
"""Create the specified instance."""
self.log.debug('Creating instance '
'({}|{}|{})'.format(instance_name, image_name, flavor))
image = nova.images.find(name=image_name)
image = nova.glance.find_image(image_name)
flavor = nova.flavors.find(name=flavor)
instance = nova.servers.create(name=instance_name, image=image,
flavor=flavor)

View File

@ -537,6 +537,8 @@ class HAProxyContext(OSContextGenerator):
"""Provides half a context for the haproxy template, which describes
all peers to be included in the cluster. Each charm needs to include
its own context generator that describes the port mapping.
:side effect: mkdir is called on HAPROXY_RUN_DIR
"""
interfaces = ['cluster']
@ -1230,31 +1232,50 @@ MAX_DEFAULT_WORKERS = 4
DEFAULT_MULTIPLIER = 2
def _calculate_workers():
'''
Determine the number of worker processes based on the CPU
count of the unit containing the application.
Workers will be limited to MAX_DEFAULT_WORKERS in
container environments where no worker-multipler configuration
option been set.
@returns int: number of worker processes to use
'''
multiplier = config('worker-multiplier') or DEFAULT_MULTIPLIER
count = int(_num_cpus() * multiplier)
if multiplier > 0 and count == 0:
count = 1
if config('worker-multiplier') is None and is_container():
# NOTE(jamespage): Limit unconfigured worker-multiplier
# to MAX_DEFAULT_WORKERS to avoid insane
# worker configuration in LXD containers
# on large servers
# Reference: https://pad.lv/1665270
count = min(count, MAX_DEFAULT_WORKERS)
return count
def _num_cpus():
'''
Compatibility wrapper for calculating the number of CPU's
a unit has.
@returns: int: number of CPU cores detected
'''
try:
return psutil.cpu_count()
except AttributeError:
return psutil.NUM_CPUS
class WorkerConfigContext(OSContextGenerator):
@property
def num_cpus(self):
# NOTE: use cpu_count if present (16.04 support)
if hasattr(psutil, 'cpu_count'):
return psutil.cpu_count()
else:
return psutil.NUM_CPUS
def __call__(self):
multiplier = config('worker-multiplier') or DEFAULT_MULTIPLIER
count = int(self.num_cpus * multiplier)
if multiplier > 0 and count == 0:
count = 1
if config('worker-multiplier') is None and is_container():
# NOTE(jamespage): Limit unconfigured worker-multiplier
# to MAX_DEFAULT_WORKERS to avoid insane
# worker configuration in LXD containers
# on large servers
# Reference: https://pad.lv/1665270
count = min(count, MAX_DEFAULT_WORKERS)
ctxt = {"workers": count}
ctxt = {"workers": _calculate_workers()}
return ctxt
@ -1262,7 +1283,7 @@ class WSGIWorkerConfigContext(WorkerConfigContext):
def __init__(self, name=None, script=None, admin_script=None,
public_script=None, process_weight=1.00,
admin_process_weight=0.75, public_process_weight=0.25):
admin_process_weight=0.25, public_process_weight=0.75):
self.service_name = name
self.user = name
self.group = name
@ -1274,8 +1295,7 @@ class WSGIWorkerConfigContext(WorkerConfigContext):
self.public_process_weight = public_process_weight
def __call__(self):
multiplier = config('worker-multiplier') or 1
total_processes = self.num_cpus * multiplier
total_processes = _calculate_workers()
ctxt = {
"service_name": self.service_name,
"user": self.user,

View File

@ -1090,12 +1090,27 @@ def update_nrpe_config():
nrpe_setup.write()
@hooks.hook('memcache-relation-joined',
'memcache-relation-departed',
@hooks.hook('memcache-relation-joined')
def memcached_joined():
"""When memcache relation joins we want to set our private address as the
spaces address rather than leaving it as the unit address. This is to
support network spaces in the memcached charm.
"""
relation_set(
relation_id=None,
relation_settings={'private-address': get_relation_ip('memcache')})
memcached_common()
@hooks.hook('memcache-relation-departed',
'memcache-relation-changed',
'memcache-relation-broken')
def memcached_other_hooks():
memcached_common()
@restart_on_change(restart_map())
def memcached_joined():
def memcached_common():
CONFIGS.write(NOVA_CONF)

View File

@ -679,7 +679,7 @@ class NovaCCBasicDeployment(OpenStackAmuletDeployment):
# Kilo and later
expected['database'] = {
'connection': db_uri,
'max_pool_size': '4',
'max_pool_size': u.not_null,
}
expected['glance'] = {
'api_servers': gl_ncc_rel['glance-api-server'],
@ -695,8 +695,11 @@ class NovaCCBasicDeployment(OpenStackAmuletDeployment):
expected['osapi_v3'] = {
'enabled': 'True',
}
# due to worker multiplier changes and the way the unit changes
# depending on whether it is LXC or KVM, we can't actually guess
# the workers reliable.
expected['conductor'] = {
'workers': '4',
'workers': u.not_null,
}
expected['oslo_messaging_rabbit'] = {
'rabbit_userid': 'nova',

View File

@ -1066,3 +1066,13 @@ class NovaCCHooksTests(CharmTestCase):
def test_nova_api_relation_joined_not_ready(self):
self._test_nova_api_relation_joined(False)
@patch.object(hooks, 'memcached_common')
def test_memcache_joined(self, _memcached_common):
self.get_relation_ip.return_value = 'foo'
hooks.memcached_joined()
self.get_relation_ip.assert_called_once_with('memcache')
self.relation_set.assert_called_once_with(
relation_id=None,
relation_settings={'private-address': 'foo'})
hooks.memcached_joined()