Merge lp:~hopem/charms/trusty/neutron-api/fix-network-vlan-ranges-parser into lp:~openstack-charmers-archive/charms/trusty/neutron-api/next

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 114
Proposed branch: lp:~hopem/charms/trusty/neutron-api/fix-network-vlan-ranges-parser
Merge into: lp:~openstack-charmers-archive/charms/trusty/neutron-api/next
Diff against target: 160 lines (+61/-13)
4 files modified
config.yaml (+4/-2)
hooks/charmhelpers/contrib/hahelpers/cluster.py (+25/-0)
hooks/charmhelpers/contrib/openstack/neutron.py (+10/-5)
hooks/charmhelpers/core/hookenv.py (+22/-6)
To merge this branch: bzr merge lp:~hopem/charms/trusty/neutron-api/fix-network-vlan-ranges-parser
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+258108@code.launchpad.net
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #4358 neutron-api-next for hopem mp258108
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/4358/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #4083 neutron-api-next for hopem mp258108
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/4083/

114. By Edward Hope-Morley

sync

Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-05-06 11:39:27 +0000
3+++ config.yaml 2015-05-20 19:43:04 +0000
4@@ -99,8 +99,10 @@
5 type: string
6 default: "physnet1:1000:2000"
7 description: |
8- Space-delimited list of Neutron network-provider & vlan-id-ranges using
9- the following format "<provider>:<start>:<end> ...".
10+ Space-delimited list of <physical_network>:<vlan_min>:<vlan_max> or
11+ <physical_network> specifying physical_network names usable for VLAN
12+ provider and tenant networks, as well as ranges of VLAN tags on each
13+ available for allocation to tenant networks.
14 # Quota configuration settings
15 quota-security-group:
16 default: 10
17
18=== modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py'
19--- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-03-16 14:16:02 +0000
20+++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-05-20 19:43:04 +0000
21@@ -52,6 +52,8 @@
22 bool_from_string,
23 )
24
25+DC_RESOURCE_NAME = 'DC'
26+
27
28 class HAIncompleteConfig(Exception):
29 pass
30@@ -95,6 +97,27 @@
31 return False
32
33
34+def is_crm_dc():
35+ """
36+ Determine leadership by querying the pacemaker Designated Controller
37+ """
38+ cmd = ['crm', 'status']
39+ try:
40+ status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
41+ if not isinstance(status, six.text_type):
42+ status = six.text_type(status, "utf-8")
43+ except subprocess.CalledProcessError:
44+ return False
45+ current_dc = ''
46+ for line in status.split('\n'):
47+ if line.startswith('Current DC'):
48+ # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum
49+ current_dc = line.split(':')[1].split()[0]
50+ if current_dc == get_unit_hostname():
51+ return True
52+ return False
53+
54+
55 @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound)
56 def is_crm_leader(resource, retry=False):
57 """
58@@ -104,6 +127,8 @@
59 We allow this operation to be retried to avoid the possibility of getting a
60 false negative. See LP #1396246 for more info.
61 """
62+ if resource == DC_RESOURCE_NAME:
63+ return is_crm_dc()
64 cmd = ['crm', 'resource', 'show', resource]
65 try:
66 status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
67
68=== modified file 'hooks/charmhelpers/contrib/openstack/neutron.py'
69--- hooks/charmhelpers/contrib/openstack/neutron.py 2015-04-16 19:58:18 +0000
70+++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-05-20 19:43:04 +0000
71@@ -256,11 +256,14 @@
72 def parse_mappings(mappings):
73 parsed = {}
74 if mappings:
75- mappings = mappings.split(' ')
76+ mappings = mappings.split()
77 for m in mappings:
78 p = m.partition(':')
79- if p[1] == ':':
80- parsed[p[0].strip()] = p[2].strip()
81+ key = p[0].strip()
82+ if p[1]:
83+ parsed[key] = p[2].strip()
84+ else:
85+ parsed[key] = ''
86
87 return parsed
88
89@@ -283,13 +286,13 @@
90 Returns dict of the form {bridge:port}.
91 """
92 _mappings = parse_mappings(mappings)
93- if not _mappings:
94+ if not _mappings or list(_mappings.values()) == ['']:
95 if not mappings:
96 return {}
97
98 # For backwards-compatibility we need to support port-only provided in
99 # config.
100- _mappings = {default_bridge: mappings.split(' ')[0]}
101+ _mappings = {default_bridge: mappings.split()[0]}
102
103 bridges = _mappings.keys()
104 ports = _mappings.values()
105@@ -309,6 +312,8 @@
106
107 Mappings must be a space-delimited list of provider:start:end mappings.
108
109+ The start:end range is optional and may be omitted.
110+
111 Returns dict of the form {provider: (start, end)}.
112 """
113 _mappings = parse_mappings(mappings)
114
115=== modified file 'hooks/charmhelpers/core/hookenv.py'
116--- hooks/charmhelpers/core/hookenv.py 2015-05-13 02:16:45 +0000
117+++ hooks/charmhelpers/core/hookenv.py 2015-05-20 19:43:04 +0000
118@@ -28,6 +28,7 @@
119 import subprocess
120 import sys
121 import errno
122+import tempfile
123 from subprocess import CalledProcessError
124
125 import six
126@@ -362,14 +363,29 @@
127 """Set relation information for the current unit"""
128 relation_settings = relation_settings if relation_settings else {}
129 relation_cmd_line = ['relation-set']
130+ accepts_file = "--file" in subprocess.check_output(
131+ relation_cmd_line + ["--help"])
132 if relation_id is not None:
133 relation_cmd_line.extend(('-r', relation_id))
134- for k, v in (list(relation_settings.items()) + list(kwargs.items())):
135- if v is None:
136- relation_cmd_line.append('{}='.format(k))
137- else:
138- relation_cmd_line.append('{}={}'.format(k, v))
139- subprocess.check_call(relation_cmd_line)
140+ settings = relation_settings.copy()
141+ settings.update(kwargs)
142+ if accepts_file:
143+ # --file was introduced in Juju 1.23.2. Use it by default if
144+ # available, since otherwise we'll break if the relation data is
145+ # too big. Ideally we should tell relation-set to read the data from
146+ # stdin, but that feature is broken in 1.23.2: Bug #1454678.
147+ with tempfile.NamedTemporaryFile(delete=False) as settings_file:
148+ settings_file.write(yaml.safe_dump(settings).encode("utf-8"))
149+ subprocess.check_call(
150+ relation_cmd_line + ["--file", settings_file.name])
151+ os.remove(settings_file.name)
152+ else:
153+ for key, value in settings.items():
154+ if value is None:
155+ relation_cmd_line.append('{}='.format(key))
156+ else:
157+ relation_cmd_line.append('{}={}'.format(key, value))
158+ subprocess.check_call(relation_cmd_line)
159 # Flush cache of any relation-gets for local unit
160 flush(local_unit())
161

Subscribers

People subscribed via source and target branches