Merge lp:~gnuoy/charm-helpers/subconfs-multi-sections into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 415
Proposed branch: lp:~gnuoy/charm-helpers/subconfs-multi-sections
Merge into: lp:charm-helpers
Diff against target: 96 lines (+32/-28)
2 files modified
charmhelpers/contrib/openstack/context.py (+30/-26)
tests/contrib/openstack/test_os_contexts.py (+2/-2)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/subconfs-multi-sections
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+266237@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Approve

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-27 10:15:04 +0000
3+++ charmhelpers/contrib/openstack/context.py 2015-07-29 14:22:46 +0000
4@@ -1051,8 +1051,11 @@
5 :param config_file : Service's config file to query sections
6 :param interface : Subordinate interface to inspect
7 """
8- self.service = service
9 self.config_file = config_file
10+ if isinstance(service, list):
11+ self.services = service
12+ else:
13+ self.services = [service]
14 if isinstance(interface, list):
15 self.interfaces = interface
16 else:
17@@ -1075,31 +1078,32 @@
18 'setting from %s' % rid, level=ERROR)
19 continue
20
21- if self.service not in sub_config:
22- log('Found subordinate_config on %s but it contained'
23- 'nothing for %s service' % (rid, self.service),
24- level=INFO)
25- continue
26-
27- sub_config = sub_config[self.service]
28- if self.config_file not in sub_config:
29- log('Found subordinate_config on %s but it contained'
30- 'nothing for %s' % (rid, self.config_file),
31- level=INFO)
32- continue
33-
34- sub_config = sub_config[self.config_file]
35- for k, v in six.iteritems(sub_config):
36- if k == 'sections':
37- for section, config_list in six.iteritems(v):
38- log("adding section '%s'" % (section),
39- level=DEBUG)
40- if ctxt[k].get(section):
41- ctxt[k][section].extend(config_list)
42- else:
43- ctxt[k][section] = config_list
44- else:
45- ctxt[k] = v
46+ for service in self.services:
47+ if service not in sub_config:
48+ log('Found subordinate_config on %s but it contained'
49+ 'nothing for %s service' % (rid, service),
50+ level=INFO)
51+ continue
52+
53+ sub_config = sub_config[service]
54+ if self.config_file not in sub_config:
55+ log('Found subordinate_config on %s but it contained'
56+ 'nothing for %s' % (rid, self.config_file),
57+ level=INFO)
58+ continue
59+
60+ sub_config = sub_config[self.config_file]
61+ for k, v in six.iteritems(sub_config):
62+ if k == 'sections':
63+ for section, config_list in six.iteritems(v):
64+ log("adding section '%s'" % (section),
65+ level=DEBUG)
66+ if ctxt[k].get(section):
67+ ctxt[k][section].extend(config_list)
68+ else:
69+ ctxt[k][section] = config_list
70+ else:
71+ ctxt[k] = v
72 log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG)
73 return ctxt
74
75
76=== modified file 'tests/contrib/openstack/test_os_contexts.py'
77--- tests/contrib/openstack/test_os_contexts.py 2015-07-27 10:15:04 +0000
78+++ tests/contrib/openstack/test_os_contexts.py 2015-07-29 14:22:46 +0000
79@@ -340,7 +340,7 @@
80
81
82 NOVA_SUB_CONFIG2 = """
83-nova:
84+nova-compute:
85 /etc/nova/nova.conf:
86 sections:
87 DEFAULT:
88@@ -2097,7 +2097,7 @@
89 self.relation_ids.side_effect = relation.relation_ids
90 self.related_units.side_effect = relation.relation_units
91 nova_sub_ctxt = context.SubordinateConfigContext(
92- service='nova',
93+ service=['nova', 'nova-compute'],
94 config_file='/etc/nova/nova.conf',
95 interface=['nova-ceilometer', 'neutron-plugin'],
96 )

Subscribers

People subscribed via source and target branches