Add relation with memcached to use it to store nova-authconsole tokens
Fix bug #989337
This commit is contained in:
parent
97b3daa232
commit
4391e60be7
1
hooks/cache-relation-broken
Symbolic link
1
hooks/cache-relation-broken
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
nova_cc_hooks.py
|
1
hooks/cache-relation-changed
Symbolic link
1
hooks/cache-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
nova_cc_hooks.py
|
1
hooks/cache-relation-departed
Symbolic link
1
hooks/cache-relation-departed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
nova_cc_hooks.py
|
1
hooks/cache-relation-joined
Symbolic link
1
hooks/cache-relation-joined
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
nova_cc_hooks.py
|
@ -1,6 +1,6 @@
|
|||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
config, relation_ids, relation_set, log, ERROR,
|
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.fetch import apt_install, filter_installed_packages
|
||||||
from charmhelpers.contrib.openstack import context, neutron, utils
|
from charmhelpers.contrib.openstack import context, neutron, utils
|
||||||
@ -281,3 +281,22 @@ class NovaIPv6Context(context.BindHostContext):
|
|||||||
ctxt = super(NovaIPv6Context, self).__call__()
|
ctxt = super(NovaIPv6Context, self).__call__()
|
||||||
ctxt['use_ipv6'] = config('prefer-ipv6')
|
ctxt['use_ipv6'] = config('prefer-ipv6')
|
||||||
return ctxt
|
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
|
||||||
|
@ -852,6 +852,15 @@ def neutron_api_relation_broken():
|
|||||||
quantum_joined(rid=rid)
|
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():
|
def main():
|
||||||
try:
|
try:
|
||||||
hooks.execute(sys.argv)
|
hooks.execute(sys.argv)
|
||||||
|
@ -40,6 +40,8 @@ requires:
|
|||||||
nova-vmware:
|
nova-vmware:
|
||||||
interface: nova-vmware
|
interface: nova-vmware
|
||||||
scope: container
|
scope: container
|
||||||
|
cache:
|
||||||
|
interface: memcache
|
||||||
peers:
|
peers:
|
||||||
cluster:
|
cluster:
|
||||||
interface: nova-ha
|
interface: nova-ha
|
||||||
|
@ -21,6 +21,11 @@ volumes_path=/var/lib/nova/volumes
|
|||||||
enabled_apis=ec2,osapi_compute,metadata
|
enabled_apis=ec2,osapi_compute,metadata
|
||||||
auth_strategy=keystone
|
auth_strategy=keystone
|
||||||
compute_driver=libvirt.LibvirtDriver
|
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 -%}
|
{% if keystone_ec2_url -%}
|
||||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
@ -20,6 +20,11 @@ volumes_path=/var/lib/nova/volumes
|
|||||||
enabled_apis=ec2,osapi_compute,metadata
|
enabled_apis=ec2,osapi_compute,metadata
|
||||||
auth_strategy=keystone
|
auth_strategy=keystone
|
||||||
compute_driver=libvirt.LibvirtDriver
|
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 -%}
|
{% if keystone_ec2_url -%}
|
||||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
@ -26,6 +26,10 @@ scheduler_default_filters = RetryFilter,AvailabilityZoneFilter,CoreFilter,RamFil
|
|||||||
cpu_allocation_ratio = {{ cpu_allocation_ratio }}
|
cpu_allocation_ratio = {{ cpu_allocation_ratio }}
|
||||||
use_syslog={{ use_syslog }}
|
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 -%}
|
{% if keystone_ec2_url -%}
|
||||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
@ -38,6 +38,10 @@ ram_allocation_ratio = {{ ram_allocation_ratio }}
|
|||||||
|
|
||||||
use_syslog={{ use_syslog }}
|
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 -%}
|
{% if keystone_ec2_url -%}
|
||||||
keystone_ec2_url = {{ keystone_ec2_url }}
|
keystone_ec2_url = {{ keystone_ec2_url }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
58
unit_tests/test_nova_cc_contexts.py
Normal file
58
unit_tests/test_nova_cc_contexts.py
Normal 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())
|
Loading…
Reference in New Issue
Block a user