Merge lp:~billy-olsen/charms/trusty/neutron-api/public-endpoint-host into lp:~openstack-charmers-archive/charms/trusty/neutron-api/next
- Trusty Tahr (14.04)
- public-endpoint-host
- Merge into next
Proposed by
Billy Olsen
Status: | Merged |
---|---|
Merged at revision: | 118 |
Proposed branch: | lp:~billy-olsen/charms/trusty/neutron-api/public-endpoint-host |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/neutron-api/next |
Diff against target: |
259 lines (+98/-51) 3 files modified
config.yaml (+12/-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/public-endpoint-host |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant (community) | Approve | ||
Review via email: mp+261007@code.launchpad.net |
Commit message
Description of the change
Provides a config option which allows the user to specify the public hostname used to advertise to keystone when creating endpoints.
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4725 neutron-api-next for billy-olsen mp261007
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4451 neutron-api-next for billy-olsen mp261007
AMULET OK: passed
Build: http://
- 117. By Billy Olsen
-
merge with /next
- 118. By Billy Olsen
-
c-h sync
- 119. By Billy Olsen
-
Fix unit test error from c-h sync
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5069 neutron-api-next for billy-olsen mp261007
LINT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4748 neutron-api-next for billy-olsen mp261007
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4476 neutron-api-next for billy-olsen mp261007
AMULET OK: passed
Build: http://
Revision history for this message
Corey Bryant (corey.bryant) : | # |
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-21 15:02:07 +0000 | |||
3 | +++ config.yaml 2015-06-04 23:28:32 +0000 | |||
4 | @@ -235,6 +235,18 @@ | |||
5 | 235 | 192.168.0.0/24) | 235 | 192.168.0.0/24) |
6 | 236 | . | 236 | . |
7 | 237 | This network will be used for public endpoints. | 237 | This network will be used for public endpoints. |
8 | 238 | os-public-hostname: | ||
9 | 239 | type: string | ||
10 | 240 | default: | ||
11 | 241 | description: | | ||
12 | 242 | The hostname or address of the public endpoints created for neutron-api | ||
13 | 243 | in the keystone identity provider. | ||
14 | 244 | . | ||
15 | 245 | This value will be used for public endpoints. For example, an | ||
16 | 246 | os-public-hostname set to 'neutron-api.example.com' with ssl enabled | ||
17 | 247 | will create the following endpoint for neutron-api: | ||
18 | 248 | . | ||
19 | 249 | https://neutron-api.example.com:9696/ | ||
20 | 238 | ssl_cert: | 250 | ssl_cert: |
21 | 239 | type: string | 251 | type: string |
22 | 240 | default: | 252 | default: |
23 | 241 | 253 | ||
24 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
25 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-16 14:16:02 +0000 | |||
26 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-04 23:28:32 +0000 | |||
27 | @@ -17,6 +17,7 @@ | |||
28 | 17 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
29 | 18 | config, | 18 | config, |
30 | 19 | unit_get, | 19 | unit_get, |
31 | 20 | service_name, | ||
32 | 20 | ) | 21 | ) |
33 | 21 | from charmhelpers.contrib.network.ip import ( | 22 | from charmhelpers.contrib.network.ip import ( |
34 | 22 | get_address_in_network, | 23 | get_address_in_network, |
35 | @@ -26,8 +27,6 @@ | |||
36 | 26 | ) | 27 | ) |
37 | 27 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 28 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
38 | 28 | 29 | ||
39 | 29 | from functools import partial | ||
40 | 30 | |||
41 | 31 | PUBLIC = 'public' | 30 | PUBLIC = 'public' |
42 | 32 | INTERNAL = 'int' | 31 | INTERNAL = 'int' |
43 | 33 | ADMIN = 'admin' | 32 | ADMIN = 'admin' |
44 | @@ -35,15 +34,18 @@ | |||
45 | 35 | ADDRESS_MAP = { | 34 | ADDRESS_MAP = { |
46 | 36 | PUBLIC: { | 35 | PUBLIC: { |
47 | 37 | 'config': 'os-public-network', | 36 | 'config': 'os-public-network', |
49 | 38 | 'fallback': 'public-address' | 37 | 'fallback': 'public-address', |
50 | 38 | 'override': 'os-public-hostname', | ||
51 | 39 | }, | 39 | }, |
52 | 40 | INTERNAL: { | 40 | INTERNAL: { |
53 | 41 | 'config': 'os-internal-network', | 41 | 'config': 'os-internal-network', |
55 | 42 | 'fallback': 'private-address' | 42 | 'fallback': 'private-address', |
56 | 43 | 'override': 'os-internal-hostname', | ||
57 | 43 | }, | 44 | }, |
58 | 44 | ADMIN: { | 45 | ADMIN: { |
59 | 45 | 'config': 'os-admin-network', | 46 | 'config': 'os-admin-network', |
61 | 46 | 'fallback': 'private-address' | 47 | 'fallback': 'private-address', |
62 | 48 | 'override': 'os-admin-hostname', | ||
63 | 47 | } | 49 | } |
64 | 48 | } | 50 | } |
65 | 49 | 51 | ||
66 | @@ -57,15 +59,50 @@ | |||
67 | 57 | :param endpoint_type: str endpoint type to resolve. | 59 | :param endpoint_type: str endpoint type to resolve. |
68 | 58 | :param returns: str base URL for services on the current service unit. | 60 | :param returns: str base URL for services on the current service unit. |
69 | 59 | """ | 61 | """ |
73 | 60 | scheme = 'http' | 62 | scheme = _get_scheme(configs) |
74 | 61 | if 'https' in configs.complete_contexts(): | 63 | |
72 | 62 | scheme = 'https' | ||
75 | 63 | address = resolve_address(endpoint_type) | 64 | address = resolve_address(endpoint_type) |
76 | 64 | if is_ipv6(address): | 65 | if is_ipv6(address): |
77 | 65 | address = "[{}]".format(address) | 66 | address = "[{}]".format(address) |
78 | 67 | |||
79 | 66 | return '%s://%s' % (scheme, address) | 68 | return '%s://%s' % (scheme, address) |
80 | 67 | 69 | ||
81 | 68 | 70 | ||
82 | 71 | def _get_scheme(configs): | ||
83 | 72 | """Returns the scheme to use for the url (either http or https) | ||
84 | 73 | depending upon whether https is in the configs value. | ||
85 | 74 | |||
86 | 75 | :param configs: OSTemplateRenderer config templating object to inspect | ||
87 | 76 | for a complete https context. | ||
88 | 77 | :returns: either 'http' or 'https' depending on whether https is | ||
89 | 78 | configured within the configs context. | ||
90 | 79 | """ | ||
91 | 80 | scheme = 'http' | ||
92 | 81 | if configs and 'https' in configs.complete_contexts(): | ||
93 | 82 | scheme = 'https' | ||
94 | 83 | return scheme | ||
95 | 84 | |||
96 | 85 | |||
97 | 86 | def _get_address_override(endpoint_type=PUBLIC): | ||
98 | 87 | """Returns any address overrides that the user has defined based on the | ||
99 | 88 | endpoint type. | ||
100 | 89 | |||
101 | 90 | Note: this function allows for the service name to be inserted into the | ||
102 | 91 | address if the user specifies {service_name}.somehost.org. | ||
103 | 92 | |||
104 | 93 | :param endpoint_type: the type of endpoint to retrieve the override | ||
105 | 94 | value for. | ||
106 | 95 | :returns: any endpoint address or hostname that the user has overridden | ||
107 | 96 | or None if an override is not present. | ||
108 | 97 | """ | ||
109 | 98 | override_key = ADDRESS_MAP[endpoint_type]['override'] | ||
110 | 99 | addr_override = config(override_key) | ||
111 | 100 | if not addr_override: | ||
112 | 101 | return None | ||
113 | 102 | else: | ||
114 | 103 | return addr_override.format(service_name=service_name()) | ||
115 | 104 | |||
116 | 105 | |||
117 | 69 | def resolve_address(endpoint_type=PUBLIC): | 106 | def resolve_address(endpoint_type=PUBLIC): |
118 | 70 | """Return unit address depending on net config. | 107 | """Return unit address depending on net config. |
119 | 71 | 108 | ||
120 | @@ -77,7 +114,10 @@ | |||
121 | 77 | 114 | ||
122 | 78 | :param endpoint_type: Network endpoing type | 115 | :param endpoint_type: Network endpoing type |
123 | 79 | """ | 116 | """ |
125 | 80 | resolved_address = None | 117 | resolved_address = _get_address_override(endpoint_type) |
126 | 118 | if resolved_address: | ||
127 | 119 | return resolved_address | ||
128 | 120 | |||
129 | 81 | vips = config('vip') | 121 | vips = config('vip') |
130 | 82 | if vips: | 122 | if vips: |
131 | 83 | vips = vips.split() | 123 | vips = vips.split() |
132 | @@ -109,38 +149,3 @@ | |||
133 | 109 | "clustered=%s)" % (net_type, clustered)) | 149 | "clustered=%s)" % (net_type, clustered)) |
134 | 110 | 150 | ||
135 | 111 | return resolved_address | 151 | return resolved_address |
136 | 112 | |||
137 | 113 | |||
138 | 114 | def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, | ||
139 | 115 | override=None): | ||
140 | 116 | """Returns the correct endpoint URL to advertise to Keystone. | ||
141 | 117 | |||
142 | 118 | This method provides the correct endpoint URL which should be advertised to | ||
143 | 119 | the keystone charm for endpoint creation. This method allows for the url to | ||
144 | 120 | be overridden to force a keystone endpoint to have specific URL for any of | ||
145 | 121 | the defined scopes (admin, internal, public). | ||
146 | 122 | |||
147 | 123 | :param configs: OSTemplateRenderer config templating object to inspect | ||
148 | 124 | for a complete https context. | ||
149 | 125 | :param url_template: str format string for creating the url template. Only | ||
150 | 126 | two values will be passed - the scheme+hostname | ||
151 | 127 | returned by the canonical_url and the port. | ||
152 | 128 | :param endpoint_type: str endpoint type to resolve. | ||
153 | 129 | :param override: str the name of the config option which overrides the | ||
154 | 130 | endpoint URL defined by the charm itself. None will | ||
155 | 131 | disable any overrides (default). | ||
156 | 132 | """ | ||
157 | 133 | if override: | ||
158 | 134 | # Return any user-defined overrides for the keystone endpoint URL. | ||
159 | 135 | user_value = config(override) | ||
160 | 136 | if user_value: | ||
161 | 137 | return user_value.strip() | ||
162 | 138 | |||
163 | 139 | return url_template % (canonical_url(configs, endpoint_type), port) | ||
164 | 140 | |||
165 | 141 | |||
166 | 142 | public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) | ||
167 | 143 | |||
168 | 144 | internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) | ||
169 | 145 | |||
170 | 146 | admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) | ||
171 | 147 | 152 | ||
172 | === modified file 'unit_tests/test_neutron_api_hooks.py' | |||
173 | --- unit_tests/test_neutron_api_hooks.py 2015-04-23 08:49:03 +0000 | |||
174 | +++ unit_tests/test_neutron_api_hooks.py 2015-06-04 23:28:32 +0000 | |||
175 | @@ -25,7 +25,6 @@ | |||
176 | 25 | 'api_port', | 25 | 'api_port', |
177 | 26 | 'apt_update', | 26 | 'apt_update', |
178 | 27 | 'apt_install', | 27 | 'apt_install', |
179 | 28 | 'canonical_url', | ||
180 | 29 | 'config', | 28 | 'config', |
181 | 30 | 'CONFIGS', | 29 | 'CONFIGS', |
182 | 31 | 'check_call', | 30 | 'check_call', |
183 | @@ -319,8 +318,9 @@ | |||
184 | 319 | self._call_hook('amqp-relation-broken') | 318 | self._call_hook('amqp-relation-broken') |
185 | 320 | self.assertTrue(self.CONFIGS.write_all.called) | 319 | self.assertTrue(self.CONFIGS.write_all.called) |
186 | 321 | 320 | ||
189 | 322 | def test_identity_joined(self): | 321 | @patch.object(hooks, 'canonical_url') |
190 | 323 | self.canonical_url.return_value = 'http://127.0.0.1' | 322 | def test_identity_joined(self, _canonical_url): |
191 | 323 | _canonical_url.return_value = 'http://127.0.0.1' | ||
192 | 324 | self.api_port.return_value = '9696' | 324 | self.api_port.return_value = '9696' |
193 | 325 | self.test_config.set('region', 'region1') | 325 | self.test_config.set('region', 'region1') |
194 | 326 | _neutron_url = 'http://127.0.0.1:9696' | 326 | _neutron_url = 'http://127.0.0.1:9696' |
195 | @@ -337,6 +337,34 @@ | |||
196 | 337 | relation_settings=_endpoints | 337 | relation_settings=_endpoints |
197 | 338 | ) | 338 | ) |
198 | 339 | 339 | ||
199 | 340 | @patch('charmhelpers.contrib.openstack.ip.service_name', | ||
200 | 341 | lambda *args: 'neutron-api') | ||
201 | 342 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
202 | 343 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
203 | 344 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
204 | 345 | def test_identity_changed_public_name(self, _config, _is_clustered, | ||
205 | 346 | _unit_get): | ||
206 | 347 | _unit_get.return_value = '127.0.0.1' | ||
207 | 348 | _is_clustered.return_value = False | ||
208 | 349 | _config.side_effect = self.test_config.get | ||
209 | 350 | self.api_port.return_value = '9696' | ||
210 | 351 | self.test_config.set('region', 'region1') | ||
211 | 352 | self.test_config.set('os-public-hostname', | ||
212 | 353 | 'neutron-api.example.com') | ||
213 | 354 | self._call_hook('identity-service-relation-joined') | ||
214 | 355 | _neutron_url = 'http://127.0.0.1:9696' | ||
215 | 356 | _endpoints = { | ||
216 | 357 | 'quantum_service': 'quantum', | ||
217 | 358 | 'quantum_region': 'region1', | ||
218 | 359 | 'quantum_public_url': 'http://neutron-api.example.com:9696', | ||
219 | 360 | 'quantum_admin_url': _neutron_url, | ||
220 | 361 | 'quantum_internal_url': _neutron_url, | ||
221 | 362 | } | ||
222 | 363 | self.relation_set.assert_called_with( | ||
223 | 364 | relation_id=None, | ||
224 | 365 | relation_settings=_endpoints | ||
225 | 366 | ) | ||
226 | 367 | |||
227 | 340 | def test_identity_changed_partial_ctxt(self): | 368 | def test_identity_changed_partial_ctxt(self): |
228 | 341 | self.CONFIGS.complete_contexts.return_value = [] | 369 | self.CONFIGS.complete_contexts.return_value = [] |
229 | 342 | _api_rel_joined = self.patch('neutron_api_relation_joined') | 370 | _api_rel_joined = self.patch('neutron_api_relation_joined') |
230 | @@ -353,12 +381,13 @@ | |||
231 | 353 | self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF)) | 381 | self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF)) |
232 | 354 | self.assertTrue(_api_rel_joined.called) | 382 | self.assertTrue(_api_rel_joined.called) |
233 | 355 | 383 | ||
235 | 356 | def test_neutron_api_relation_no_id_joined(self): | 384 | @patch.object(hooks, 'canonical_url') |
236 | 385 | def test_neutron_api_relation_no_id_joined(self, _canonical_url): | ||
237 | 357 | host = 'http://127.0.0.1' | 386 | host = 'http://127.0.0.1' |
238 | 358 | port = 1234 | 387 | port = 1234 |
239 | 359 | _id_rel_joined = self.patch('identity_joined') | 388 | _id_rel_joined = self.patch('identity_joined') |
240 | 360 | self.relation_ids.side_effect = self._fake_relids | 389 | self.relation_ids.side_effect = self._fake_relids |
242 | 361 | self.canonical_url.return_value = host | 390 | _canonical_url.return_value = host |
243 | 362 | self.api_port.return_value = port | 391 | self.api_port.return_value = port |
244 | 363 | self.is_relation_made = False | 392 | self.is_relation_made = False |
245 | 364 | neutron_url = '%s:%s' % (host, port) | 393 | neutron_url = '%s:%s' % (host, port) |
246 | @@ -381,10 +410,11 @@ | |||
247 | 381 | **_relation_data | 410 | **_relation_data |
248 | 382 | ) | 411 | ) |
249 | 383 | 412 | ||
251 | 384 | def test_neutron_api_relation_joined(self): | 413 | @patch.object(hooks, 'canonical_url') |
252 | 414 | def test_neutron_api_relation_joined(self, _canonical_url): | ||
253 | 385 | host = 'http://127.0.0.1' | 415 | host = 'http://127.0.0.1' |
254 | 386 | port = 1234 | 416 | port = 1234 |
256 | 387 | self.canonical_url.return_value = host | 417 | _canonical_url.return_value = host |
257 | 388 | self.api_port.return_value = port | 418 | self.api_port.return_value = port |
258 | 389 | self.is_relation_made = True | 419 | self.is_relation_made = True |
259 | 390 | neutron_url = '%s:%s' % (host, port) | 420 | neutron_url = '%s:%s' % (host, port) |
charm_lint_check #5045 neutron-api-next for billy-olsen mp261007
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5045/