Merge lp:~gnuoy/charm-helpers/neutron-refactor-again into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 170
Proposed branch: lp:~gnuoy/charm-helpers/neutron-refactor-again
Merge into: lp:charm-helpers
Diff against target: 104 lines (+37/-5)
4 files modified
charmhelpers/contrib/openstack/context.py (+13/-5)
charmhelpers/contrib/openstack/utils.py (+2/-0)
tests/contrib/openstack/test_openstack_utils.py (+2/-0)
tests/contrib/openstack/test_os_contexts.py (+20/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/neutron-refactor-again
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+224267@code.launchpad.net
To post a comment you must log in.
172. By Liam Young

Add unit tests for changes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2014-06-23 13:50:12 +0000
3+++ charmhelpers/contrib/openstack/context.py 2014-06-24 12:58:41 +0000
4@@ -243,23 +243,31 @@
5
6
7 class AMQPContext(OSContextGenerator):
8- interfaces = ['amqp']
9
10- def __init__(self, ssl_dir=None):
11+ def __init__(self, rel_name='amqp', relation_prefix=None, ssl_dir=None):
12 self.ssl_dir = ssl_dir
13+ self.rel_name = rel_name
14+ self.relation_prefix = relation_prefix
15+ self.interfaces = [rel_name]
16
17 def __call__(self):
18 log('Generating template context for amqp')
19 conf = config()
20+ user_setting = 'rabbit-user'
21+ vhost_setting = 'rabbit-vhost'
22+ if self.relation_prefix:
23+ user_setting = self.relation_prefix + '-rabbit-user'
24+ vhost_setting = self.relation_prefix + '-rabbit-vhost'
25+
26 try:
27- username = conf['rabbit-user']
28- vhost = conf['rabbit-vhost']
29+ username = conf[user_setting]
30+ vhost = conf[vhost_setting]
31 except KeyError as e:
32 log('Could not generate shared_db context. '
33 'Missing required charm config options: %s.' % e)
34 raise OSContextError
35 ctxt = {}
36- for rid in relation_ids('amqp'):
37+ for rid in relation_ids(self.rel_name):
38 ha_vip_only = False
39 for unit in related_units(rid):
40 if relation_get('clustered', rid=rid, unit=unit):
41
42=== modified file 'charmhelpers/contrib/openstack/utils.py'
43--- charmhelpers/contrib/openstack/utils.py 2014-06-23 13:50:12 +0000
44+++ charmhelpers/contrib/openstack/utils.py 2014-06-24 12:58:41 +0000
45@@ -84,6 +84,8 @@
46 '''Derive OpenStack release codename from a given installation source.'''
47 ubuntu_rel = lsb_release()['DISTRIB_CODENAME']
48 rel = ''
49+ if src is None:
50+ return rel
51 if src in ['distro', 'distro-proposed']:
52 try:
53 rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel]
54
55=== modified file 'tests/contrib/openstack/test_openstack_utils.py'
56--- tests/contrib/openstack/test_openstack_utils.py 2014-04-22 17:19:02 +0000
57+++ tests/contrib/openstack/test_openstack_utils.py 2014-06-24 12:58:41 +0000
58@@ -169,6 +169,8 @@
59 'precise-havana main')
60 self.assertEquals(openstack.get_os_codename_install_source(src),
61 'havana')
62+ self.assertEquals(openstack.get_os_codename_install_source(None),
63+ '')
64
65 @patch.object(openstack, 'get_os_version_codename')
66 @patch.object(openstack, 'get_os_codename_install_source')
67
68=== modified file 'tests/contrib/openstack/test_os_contexts.py'
69--- tests/contrib/openstack/test_os_contexts.py 2014-06-23 09:58:48 +0000
70+++ tests/contrib/openstack/test_os_contexts.py 2014-06-24 12:58:41 +0000
71@@ -176,6 +176,11 @@
72 'rabbit-vhost': 'foo',
73 }
74
75+AMQP_NOVA_CONFIG = {
76+ 'nova-rabbit-user': 'adam',
77+ 'nova-rabbit-vhost': 'foo',
78+}
79+
80 CEPH_RELATION = {
81 'ceph:0': {
82 'ceph/0': {
83@@ -495,6 +500,21 @@
84 }
85 self.assertEquals(result, expected)
86
87+ def test_amqp_context_with_data_altname(self):
88+ '''Test amqp context with alternative relation name'''
89+ relation = FakeRelation(relation_data=AMQP_RELATION)
90+ self.relation_get.side_effect = relation.get
91+ self.config.return_value = AMQP_NOVA_CONFIG
92+ amqp = context.AMQPContext(rel_name='amqp-nova', relation_prefix='nova')
93+ result = amqp()
94+ expected = {
95+ 'rabbitmq_host': 'rabbithost',
96+ 'rabbitmq_password': 'foobar',
97+ 'rabbitmq_user': 'adam',
98+ 'rabbitmq_virtual_host': 'foo'
99+ }
100+ self.assertEquals(result, expected)
101+
102 @patch('__builtin__.open')
103 def test_amqp_context_with_data_ssl(self, _open):
104 '''Test amqp context with all required data and ssl'''

Subscribers

People subscribed via source and target branches