Merge lp:~billy-olsen/charms/trusty/neutron-api/backport-lp1398182 into lp:~openstack-charmers-archive/charms/trusty/neutron-api/trunk

Proposed by Billy Olsen
Status: Merged
Merged at revision: 114
Proposed branch: lp:~billy-olsen/charms/trusty/neutron-api/backport-lp1398182
Merge into: lp:~openstack-charmers-archive/charms/trusty/neutron-api/trunk
Diff against target: 309 lines (+123/-51)
4 files modified
config.yaml (+12/-0)
hooks/charmhelpers/contrib/hahelpers/cluster.py (+25/-0)
hooks/charmhelpers/contrib/openstack/ip.py (+49/-44)
unit_tests/test_neutron_api_hooks.py (+37/-7)
To merge this branch: bzr merge lp:~billy-olsen/charms/trusty/neutron-api/backport-lp1398182
Reviewer Review Type Date Requested Status
Corey Bryant (community) Approve
charmers Pending
Review via email: mp+262005@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 #5408 neutron-api for billy-olsen mp262005
    LINT OK: passed

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

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

charm_unit_test #5040 neutron-api for billy-olsen mp262005
    UNIT OK: passed

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

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

charm_amulet_test #4651 neutron-api for billy-olsen mp262005
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/4651/

Revision history for this message
Corey Bryant (corey.bryant) :
review: Approve
115. By Billy Olsen

Official c-h stable sync

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-04-16 19:58:18 +0000
3+++ config.yaml 2015-06-18 23:36:57 +0000
4@@ -232,6 +232,18 @@
5 192.168.0.0/24)
6 .
7 This network will be used for public endpoints.
8+ os-public-hostname:
9+ type: string
10+ default:
11+ description: |
12+ The hostname or address of the public endpoints created for neutron-api
13+ in the keystone identity provider.
14+ .
15+ This value will be used for public endpoints. For example, an
16+ os-public-hostname set to 'neutron-api.example.com' with ssl enabled
17+ will create the following endpoint for neutron-api:
18+ .
19+ https://neutron-api.example.com:9696/
20 ssl_cert:
21 type: string
22 default:
23
24=== modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py'
25--- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-03-16 14:16:02 +0000
26+++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-18 23:36:57 +0000
27@@ -52,6 +52,8 @@
28 bool_from_string,
29 )
30
31+DC_RESOURCE_NAME = 'DC'
32+
33
34 class HAIncompleteConfig(Exception):
35 pass
36@@ -95,6 +97,27 @@
37 return False
38
39
40+def is_crm_dc():
41+ """
42+ Determine leadership by querying the pacemaker Designated Controller
43+ """
44+ cmd = ['crm', 'status']
45+ try:
46+ status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
47+ if not isinstance(status, six.text_type):
48+ status = six.text_type(status, "utf-8")
49+ except subprocess.CalledProcessError:
50+ return False
51+ current_dc = ''
52+ for line in status.split('\n'):
53+ if line.startswith('Current DC'):
54+ # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum
55+ current_dc = line.split(':')[1].split()[0]
56+ if current_dc == get_unit_hostname():
57+ return True
58+ return False
59+
60+
61 @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound)
62 def is_crm_leader(resource, retry=False):
63 """
64@@ -104,6 +127,8 @@
65 We allow this operation to be retried to avoid the possibility of getting a
66 false negative. See LP #1396246 for more info.
67 """
68+ if resource == DC_RESOURCE_NAME:
69+ return is_crm_dc()
70 cmd = ['crm', 'resource', 'show', resource]
71 try:
72 status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
73
74=== modified file 'hooks/charmhelpers/contrib/openstack/ip.py'
75--- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-16 14:16:02 +0000
76+++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-18 23:36:57 +0000
77@@ -17,6 +17,7 @@
78 from charmhelpers.core.hookenv import (
79 config,
80 unit_get,
81+ service_name,
82 )
83 from charmhelpers.contrib.network.ip import (
84 get_address_in_network,
85@@ -26,8 +27,6 @@
86 )
87 from charmhelpers.contrib.hahelpers.cluster import is_clustered
88
89-from functools import partial
90-
91 PUBLIC = 'public'
92 INTERNAL = 'int'
93 ADMIN = 'admin'
94@@ -35,15 +34,18 @@
95 ADDRESS_MAP = {
96 PUBLIC: {
97 'config': 'os-public-network',
98- 'fallback': 'public-address'
99+ 'fallback': 'public-address',
100+ 'override': 'os-public-hostname',
101 },
102 INTERNAL: {
103 'config': 'os-internal-network',
104- 'fallback': 'private-address'
105+ 'fallback': 'private-address',
106+ 'override': 'os-internal-hostname',
107 },
108 ADMIN: {
109 'config': 'os-admin-network',
110- 'fallback': 'private-address'
111+ 'fallback': 'private-address',
112+ 'override': 'os-admin-hostname',
113 }
114 }
115
116@@ -57,15 +59,50 @@
117 :param endpoint_type: str endpoint type to resolve.
118 :param returns: str base URL for services on the current service unit.
119 """
120- scheme = 'http'
121- if 'https' in configs.complete_contexts():
122- scheme = 'https'
123+ scheme = _get_scheme(configs)
124+
125 address = resolve_address(endpoint_type)
126 if is_ipv6(address):
127 address = "[{}]".format(address)
128+
129 return '%s://%s' % (scheme, address)
130
131
132+def _get_scheme(configs):
133+ """Returns the scheme to use for the url (either http or https)
134+ depending upon whether https is in the configs value.
135+
136+ :param configs: OSTemplateRenderer config templating object to inspect
137+ for a complete https context.
138+ :returns: either 'http' or 'https' depending on whether https is
139+ configured within the configs context.
140+ """
141+ scheme = 'http'
142+ if configs and 'https' in configs.complete_contexts():
143+ scheme = 'https'
144+ return scheme
145+
146+
147+def _get_address_override(endpoint_type=PUBLIC):
148+ """Returns any address overrides that the user has defined based on the
149+ endpoint type.
150+
151+ Note: this function allows for the service name to be inserted into the
152+ address if the user specifies {service_name}.somehost.org.
153+
154+ :param endpoint_type: the type of endpoint to retrieve the override
155+ value for.
156+ :returns: any endpoint address or hostname that the user has overridden
157+ or None if an override is not present.
158+ """
159+ override_key = ADDRESS_MAP[endpoint_type]['override']
160+ addr_override = config(override_key)
161+ if not addr_override:
162+ return None
163+ else:
164+ return addr_override.format(service_name=service_name())
165+
166+
167 def resolve_address(endpoint_type=PUBLIC):
168 """Return unit address depending on net config.
169
170@@ -77,7 +114,10 @@
171
172 :param endpoint_type: Network endpoing type
173 """
174- resolved_address = None
175+ resolved_address = _get_address_override(endpoint_type)
176+ if resolved_address:
177+ return resolved_address
178+
179 vips = config('vip')
180 if vips:
181 vips = vips.split()
182@@ -109,38 +149,3 @@
183 "clustered=%s)" % (net_type, clustered))
184
185 return resolved_address
186-
187-
188-def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC,
189- override=None):
190- """Returns the correct endpoint URL to advertise to Keystone.
191-
192- This method provides the correct endpoint URL which should be advertised to
193- the keystone charm for endpoint creation. This method allows for the url to
194- be overridden to force a keystone endpoint to have specific URL for any of
195- the defined scopes (admin, internal, public).
196-
197- :param configs: OSTemplateRenderer config templating object to inspect
198- for a complete https context.
199- :param url_template: str format string for creating the url template. Only
200- two values will be passed - the scheme+hostname
201- returned by the canonical_url and the port.
202- :param endpoint_type: str endpoint type to resolve.
203- :param override: str the name of the config option which overrides the
204- endpoint URL defined by the charm itself. None will
205- disable any overrides (default).
206- """
207- if override:
208- # Return any user-defined overrides for the keystone endpoint URL.
209- user_value = config(override)
210- if user_value:
211- return user_value.strip()
212-
213- return url_template % (canonical_url(configs, endpoint_type), port)
214-
215-
216-public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC)
217-
218-internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL)
219-
220-admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN)
221
222=== modified file 'unit_tests/test_neutron_api_hooks.py'
223--- unit_tests/test_neutron_api_hooks.py 2015-04-23 08:49:03 +0000
224+++ unit_tests/test_neutron_api_hooks.py 2015-06-18 23:36:57 +0000
225@@ -25,7 +25,6 @@
226 'api_port',
227 'apt_update',
228 'apt_install',
229- 'canonical_url',
230 'config',
231 'CONFIGS',
232 'check_call',
233@@ -319,8 +318,9 @@
234 self._call_hook('amqp-relation-broken')
235 self.assertTrue(self.CONFIGS.write_all.called)
236
237- def test_identity_joined(self):
238- self.canonical_url.return_value = 'http://127.0.0.1'
239+ @patch.object(hooks, 'canonical_url')
240+ def test_identity_joined(self, _canonical_url):
241+ _canonical_url.return_value = 'http://127.0.0.1'
242 self.api_port.return_value = '9696'
243 self.test_config.set('region', 'region1')
244 _neutron_url = 'http://127.0.0.1:9696'
245@@ -337,6 +337,34 @@
246 relation_settings=_endpoints
247 )
248
249+ @patch('charmhelpers.contrib.openstack.ip.service_name',
250+ lambda *args: 'neutron-api')
251+ @patch('charmhelpers.contrib.openstack.ip.unit_get')
252+ @patch('charmhelpers.contrib.openstack.ip.is_clustered')
253+ @patch('charmhelpers.contrib.openstack.ip.config')
254+ def test_identity_changed_public_name(self, _config, _is_clustered,
255+ _unit_get):
256+ _unit_get.return_value = '127.0.0.1'
257+ _is_clustered.return_value = False
258+ _config.side_effect = self.test_config.get
259+ self.api_port.return_value = '9696'
260+ self.test_config.set('region', 'region1')
261+ self.test_config.set('os-public-hostname',
262+ 'neutron-api.example.com')
263+ self._call_hook('identity-service-relation-joined')
264+ _neutron_url = 'http://127.0.0.1:9696'
265+ _endpoints = {
266+ 'quantum_service': 'quantum',
267+ 'quantum_region': 'region1',
268+ 'quantum_public_url': 'http://neutron-api.example.com:9696',
269+ 'quantum_admin_url': _neutron_url,
270+ 'quantum_internal_url': _neutron_url,
271+ }
272+ self.relation_set.assert_called_with(
273+ relation_id=None,
274+ relation_settings=_endpoints
275+ )
276+
277 def test_identity_changed_partial_ctxt(self):
278 self.CONFIGS.complete_contexts.return_value = []
279 _api_rel_joined = self.patch('neutron_api_relation_joined')
280@@ -353,12 +381,13 @@
281 self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF))
282 self.assertTrue(_api_rel_joined.called)
283
284- def test_neutron_api_relation_no_id_joined(self):
285+ @patch.object(hooks, 'canonical_url')
286+ def test_neutron_api_relation_no_id_joined(self, _canonical_url):
287 host = 'http://127.0.0.1'
288 port = 1234
289 _id_rel_joined = self.patch('identity_joined')
290 self.relation_ids.side_effect = self._fake_relids
291- self.canonical_url.return_value = host
292+ _canonical_url.return_value = host
293 self.api_port.return_value = port
294 self.is_relation_made = False
295 neutron_url = '%s:%s' % (host, port)
296@@ -381,10 +410,11 @@
297 **_relation_data
298 )
299
300- def test_neutron_api_relation_joined(self):
301+ @patch.object(hooks, 'canonical_url')
302+ def test_neutron_api_relation_joined(self, _canonical_url):
303 host = 'http://127.0.0.1'
304 port = 1234
305- self.canonical_url.return_value = host
306+ _canonical_url.return_value = host
307 self.api_port.return_value = port
308 self.is_relation_made = True
309 neutron_url = '%s:%s' % (host, port)

Subscribers

People subscribed via source and target branches