Add relation with memcached to use it to store nova-authconsole tokens

Fix bug #989337
This commit is contained in:
Felipe Reyes 2014-10-24 10:20:36 -03:00
parent 97b3daa232
commit 4391e60be7
12 changed files with 111 additions and 1 deletions

1
hooks/cache-relation-broken Symbolic link
View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

1
hooks/cache-relation-joined Symbolic link
View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -1,6 +1,6 @@
from charmhelpers.core.hookenv import (
config, relation_ids, relation_set, log, ERROR,
unit_get, related_units, relation_get)
unit_get, related_units, relation_get, relations_for_id)
from charmhelpers.fetch import apt_install, filter_installed_packages
from charmhelpers.contrib.openstack import context, neutron, utils
@ -281,3 +281,22 @@ class NovaIPv6Context(context.BindHostContext):
ctxt = super(NovaIPv6Context, self).__call__()
ctxt['use_ipv6'] = config('prefer-ipv6')
return ctxt
class InstanceConsoleContext(context.OSContextGenerator):
interfaces = []
def __call__(self):
ctxt = {}
servers = []
try:
for rid in relation_ids('cache'):
for rel in relations_for_id(rid):
servers.append({'private-address': rel['private-address'],
'port': rel['port']})
except Exception as ex:
log(str(ex))
servers = []
ctxt['memcached_servers'] = servers
return ctxt

View File

@ -852,6 +852,15 @@ def neutron_api_relation_broken():
quantum_joined(rid=rid)
@hooks.hook('cache-relation-joined',
'cache-relation-departed',
'cache-relation-changed',
'cache-relation-broken')
@restart_on_change(restart_map())
def memcached_joined():
CONFIGS.write(NOVA_CONF)
def main():
try:
hooks.execute(sys.argv)

View File

@ -40,6 +40,8 @@ requires:
nova-vmware:
interface: nova-vmware
scope: container
cache:
interface: memcache
peers:
cluster:
interface: nova-ha

View File

@ -21,6 +21,11 @@ volumes_path=/var/lib/nova/volumes
enabled_apis=ec2,osapi_compute,metadata
auth_strategy=keystone
compute_driver=libvirt.LibvirtDriver
{% if memcached_servers %}
memcached_servers = {%for s in memcached_servers %}{% if loop.index0 != 0 %},{% endif %}{{s['private-address']}}:{{s['port']}}{% endfor %}
{% endif %}
{% if keystone_ec2_url -%}
keystone_ec2_url = {{ keystone_ec2_url }}
{% endif -%}

View File

@ -20,6 +20,11 @@ volumes_path=/var/lib/nova/volumes
enabled_apis=ec2,osapi_compute,metadata
auth_strategy=keystone
compute_driver=libvirt.LibvirtDriver
{% if memcached_servers %}
memcached_servers = {%for s in memcached_servers %}{% if loop.index0 != 0 %},{% endif %}{{s['private-address']}}:{{s['port']}}{% endfor %}
{% endif %}
{% if keystone_ec2_url -%}
keystone_ec2_url = {{ keystone_ec2_url }}
{% endif -%}

View File

@ -26,6 +26,10 @@ scheduler_default_filters = RetryFilter,AvailabilityZoneFilter,CoreFilter,RamFil
cpu_allocation_ratio = {{ cpu_allocation_ratio }}
use_syslog={{ use_syslog }}
{% if memcached_servers %}
memcached_servers = {%for s in memcached_servers %}{% if loop.index0 != 0 %},{% endif %}{{s['private-address']}}:{{s['port']}}{% endfor %}
{% endif %}
{% if keystone_ec2_url -%}
keystone_ec2_url = {{ keystone_ec2_url }}
{% endif -%}

View File

@ -38,6 +38,10 @@ ram_allocation_ratio = {{ ram_allocation_ratio }}
use_syslog={{ use_syslog }}
{% if memcached_servers %}
memcached_servers = {%for s in memcached_servers %}{% if loop.index0 != 0 %},{% endif %}{{s['private-address']}}:{{s['port']}}{% endfor %}
{% endif %}
{% if keystone_ec2_url -%}
keystone_ec2_url = {{ keystone_ec2_url }}
{% endif -%}

View File

@ -0,0 +1,58 @@
from __future__ import print_function
import mock
import nova_cc_context as context
from charmhelpers.contrib.openstack import utils
from test_utils import CharmTestCase
TO_PATCH = [
'apt_install',
'filter_installed_packages',
'relation_ids',
'relation_get',
'related_units',
'config',
'log',
'unit_get',
'relations_for_id',
]
def fake_log(msg, level=None):
level = level or 'INFO'
print('[juju test log (%s)] %s' % (level, msg))
class NovaComputeContextTests(CharmTestCase):
def setUp(self):
super(NovaComputeContextTests, self).setUp(context, TO_PATCH)
self.relation_get.side_effect = self.test_relation.get
self.config.side_effect = self.test_config.get
self.log.side_effect = fake_log
@mock.patch.object(utils, 'os_release')
def test_instance_console_context_without_memcache(self, os_release):
self.unit_get.return_value = '127.0.0.1'
self.relation_ids.return_value = 'cache:0'
self.related_units.return_value = 'memcached/0'
instance_console = context.InstanceConsoleContext()
os_release.return_value = 'icehouse'
self.assertEqual({'memcached_servers': []},
instance_console())
@mock.patch.object(utils, 'os_release')
def test_instance_console_context_with_memcache(self, os_release):
memcached_servers = [{'private-address': '127.0.1.1',
'port': '11211'}]
self.unit_get.return_value = '127.0.0.1'
self.relation_ids.return_value = ['cache:0']
self.relations_for_id.return_value = memcached_servers
self.related_units.return_value = 'memcached/0'
instance_console = context.InstanceConsoleContext()
os_release.return_value = 'icehouse'
self.maxDiff = None
self.assertEqual({'memcached_servers': memcached_servers},
instance_console())