Merge lp:~hopem/charms/precise/nova-cloud-controller/lp1246796 into lp:~charmers/charms/precise/nova-cloud-controller/trunk

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 62
Proposed branch: lp:~hopem/charms/precise/nova-cloud-controller/lp1246796
Merge into: lp:~charmers/charms/precise/nova-cloud-controller/trunk
Diff against target: 81 lines (+46/-16)
2 files modified
hooks/charmhelpers/contrib/openstack/context.py (+45/-15)
revision (+1/-1)
To merge this branch: bzr merge lp:~hopem/charms/precise/nova-cloud-controller/lp1246796
Reviewer Review Type Date Requested Status
James Page Approve
Marco Ceppi (community) Abstain
OpenStack Charmers Pending
Review via email: mp+199474@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

Deferring to ~openstack-charmers

review: Abstain
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 'hooks/charmhelpers/contrib/openstack/context.py'
2--- hooks/charmhelpers/contrib/openstack/context.py 2013-10-28 19:03:14 +0000
3+++ hooks/charmhelpers/contrib/openstack/context.py 2013-12-18 14:58:51 +0000
4@@ -433,25 +433,55 @@
5
6
7 class OSConfigFlagContext(OSContextGenerator):
8- '''
9- Responsible adding user-defined config-flags in charm config to a
10- to a template context.
11- '''
12+ """
13+ Responsible for adding user-defined config-flags in charm config to a
14+ template context.
15+
16+ NOTE: the value of config-flags may be a comma-separated list of
17+ key=value pairs and some Openstack config files support
18+ comma-separated lists as values.
19+ """
20 def __call__(self):
21 config_flags = config('config-flags')
22- if not config_flags or config_flags in ['None', '']:
23+ if not config_flags:
24 return {}
25- config_flags = config_flags.split(',')
26+
27+ if config_flags.find('==') >= 0:
28+ log("config_flags is not in expected format (key=value)",
29+ level=ERROR)
30+ raise OSContextError
31+
32+ # strip the following from each value.
33+ post_strippers = ' ,'
34+ # we strip any leading/trailing '=' or ' ' from the string then
35+ # split on '='.
36+ split = config_flags.strip(' =').split('=')
37+ limit = len(split)
38 flags = {}
39- for flag in config_flags:
40- if '=' not in flag:
41- log('Improperly formatted config-flag, expected k=v '
42- 'got %s' % flag, level=WARNING)
43- continue
44- k, v = flag.split('=')
45- flags[k.strip()] = v
46- ctxt = {'user_config_flags': flags}
47- return ctxt
48+ for i in xrange(0, limit - 1):
49+ current = split[i]
50+ next = split[i + 1]
51+ vindex = next.rfind(',')
52+ if (i == limit - 2) or (vindex < 0):
53+ value = next
54+ else:
55+ value = next[:vindex]
56+
57+ if i == 0:
58+ key = current
59+ else:
60+ # if this not the first entry, expect an embedded key.
61+ index = current.rfind(',')
62+ if index < 0:
63+ log("invalid config value(s) at index %s" % (i),
64+ level=ERROR)
65+ raise OSContextError
66+ key = current[index + 1:]
67+
68+ # Add to collection.
69+ flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
70+
71+ return {'user_config_flags': flags}
72
73
74 class SubordinateConfigContext(OSContextGenerator):
75
76=== modified file 'revision'
77--- revision 2013-11-08 05:41:39 +0000
78+++ revision 2013-12-18 14:58:51 +0000
79@@ -1,1 +1,1 @@
80-311
81+312

Subscribers

People subscribed via source and target branches