Merge lp:~gnuoy/charm-helpers/bug1478061 into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 414
Proposed branch: lp:~gnuoy/charm-helpers/bug1478061
Merge into: lp:charm-helpers
Diff against target: 135 lines (+73/-6)
2 files modified
charmhelpers/contrib/openstack/context.py (+13/-5)
tests/contrib/openstack/test_os_contexts.py (+60/-1)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/bug1478061
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+265944@code.launchpad.net
To post a comment you must log in.

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 2015-07-15 08:24:09 +0000
3+++ charmhelpers/contrib/openstack/context.py 2015-07-27 10:16:04 +0000
4@@ -1053,11 +1053,17 @@
5 """
6 self.service = service
7 self.config_file = config_file
8- self.interface = interface
9+ if isinstance(interface, list):
10+ self.interfaces = interface
11+ else:
12+ self.interfaces = [interface]
13
14 def __call__(self):
15 ctxt = {'sections': {}}
16- for rid in relation_ids(self.interface):
17+ rids = []
18+ for interface in self.interfaces:
19+ rids.extend(relation_ids(interface))
20+ for rid in rids:
21 for unit in related_units(rid):
22 sub_config = relation_get('subordinate_configuration',
23 rid=rid, unit=unit)
24@@ -1085,13 +1091,15 @@
25 sub_config = sub_config[self.config_file]
26 for k, v in six.iteritems(sub_config):
27 if k == 'sections':
28- for section, config_dict in six.iteritems(v):
29+ for section, config_list in six.iteritems(v):
30 log("adding section '%s'" % (section),
31 level=DEBUG)
32- ctxt[k][section] = config_dict
33+ if ctxt[k].get(section):
34+ ctxt[k][section].extend(config_list)
35+ else:
36+ ctxt[k][section] = config_list
37 else:
38 ctxt[k] = v
39-
40 log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG)
41 return ctxt
42
43
44=== modified file 'tests/contrib/openstack/test_os_contexts.py'
45--- tests/contrib/openstack/test_os_contexts.py 2015-04-29 12:52:18 +0000
46+++ tests/contrib/openstack/test_os_contexts.py 2015-07-27 10:16:04 +0000
47@@ -73,7 +73,11 @@
48 return None
49
50 def relation_ids(self, relation):
51- return self.relation_data.keys()
52+ rids = []
53+ for rid in self.relation_data.keys():
54+ if relation + ':' in rid:
55+ rids.append(rid)
56+ return rids
57
58 def relation_units(self, relation_id):
59 if relation_id not in self.relation_data:
60@@ -325,6 +329,25 @@
61 - [glance-key2, value2]
62 """
63
64+NOVA_SUB_CONFIG1 = """
65+nova:
66+ /etc/nova/nova.conf:
67+ sections:
68+ DEFAULT:
69+ - [nova-key1, value1]
70+ - [nova-key2, value2]
71+"""
72+
73+
74+NOVA_SUB_CONFIG2 = """
75+nova:
76+ /etc/nova/nova.conf:
77+ sections:
78+ DEFAULT:
79+ - [nova-key3, value3]
80+ - [nova-key4, value4]
81+"""
82+
83 CINDER_SUB_CONFIG1 = """
84 cinder:
85 /etc/cinder/cinder.conf:
86@@ -376,6 +399,21 @@
87 },
88 }
89
90+SUB_CONFIG_RELATION2 = {
91+ 'nova-ceilometer:6': {
92+ 'ceilometer-agent/0': {
93+ 'private-address': 'nova_node1',
94+ 'subordinate_configuration': json.dumps(yaml.load(NOVA_SUB_CONFIG1)),
95+ },
96+ },
97+ 'neutron-plugin:3': {
98+ 'neutron-ovs-plugin/0': {
99+ 'private-address': 'nova_node1',
100+ 'subordinate_configuration': json.dumps(yaml.load(NOVA_SUB_CONFIG2)),
101+ },
102+ }
103+}
104+
105 NONET_CONFIG = {
106 'vip': 'cinderhost1vip',
107 'os-internal-network': None,
108@@ -2053,6 +2091,27 @@
109 # subordinate supplies bad input
110 self.assertEquals(foo_sub_ctxt(), {'sections': {}})
111
112+ def test_os_subordinate_config_context_multiple(self):
113+ relation = FakeRelation(relation_data=SUB_CONFIG_RELATION2)
114+ self.relation_get.side_effect = relation.get
115+ self.relation_ids.side_effect = relation.relation_ids
116+ self.related_units.side_effect = relation.relation_units
117+ nova_sub_ctxt = context.SubordinateConfigContext(
118+ service='nova',
119+ config_file='/etc/nova/nova.conf',
120+ interface=['nova-ceilometer', 'neutron-plugin'],
121+ )
122+ self.assertEquals(
123+ nova_sub_ctxt(),
124+ {'sections': {
125+ 'DEFAULT': [
126+ ['nova-key1', 'value1'],
127+ ['nova-key2', 'value2'],
128+ ['nova-key3', 'value3'],
129+ ['nova-key4', 'value4']]
130+ }}
131+ )
132+
133 def test_syslog_context(self):
134 self.config.side_effect = fake_config({'use-syslog': 'foo'})
135 syslog = context.SyslogContext()

Subscribers

People subscribed via source and target branches