Merge lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next
- Trusty Tahr (14.04)
- public-endpoint-host
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 98 |
Proposed branch: | lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next |
Diff against target: |
291 lines (+155/-48) 3 files modified
config.yaml (+12/-0) hooks/charmhelpers/contrib/openstack/ip.py (+49/-44) unit_tests/test_swift_hooks.py (+94/-4) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant (community) | Approve | ||
Review via email: mp+261005@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.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4723 swift-proxy-next for billy-olsen mp261005
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4449 swift-proxy-next for billy-olsen mp261005
AMULET OK: passed
Build: http://
- 99. By Billy Olsen
-
c-h sync
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5074 swift-proxy-next for billy-olsen mp261005
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4753 swift-proxy-next for billy-olsen mp261005
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4481 swift-proxy-next for billy-olsen mp261005
AMULET OK: passed
Build: http://
Corey Bryant (corey.bryant) wrote : | # |
Looks good! Mind adding a unit test?
- 100. By Billy Olsen
-
Add unit test for public hostname.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5344 swift-proxy-next for billy-olsen mp261005
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4976 swift-proxy-next for billy-olsen mp261005
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4585 swift-proxy-next for billy-olsen mp261005
AMULET OK: passed
Build: http://
Corey Bryant (corey.bryant) : | # |
Preview Diff
1 | === modified file 'config.yaml' | |||
2 | --- config.yaml 2015-04-20 11:19:04 +0000 | |||
3 | +++ config.yaml 2015-06-11 23:23:30 +0000 | |||
4 | @@ -207,6 +207,18 @@ | |||
5 | 207 | 192.168.0.0/24) | 207 | 192.168.0.0/24) |
6 | 208 | . | 208 | . |
7 | 209 | This network will be used for public endpoints. | 209 | This network will be used for public endpoints. |
8 | 210 | os-public-hostname: | ||
9 | 211 | type: string | ||
10 | 212 | default: | ||
11 | 213 | description: | | ||
12 | 214 | The hostname or address of the public endpoints created for swift-proxy | ||
13 | 215 | in the keystone identity provider. | ||
14 | 216 | . | ||
15 | 217 | This value will be used for public endpoints. For example, an | ||
16 | 218 | os-public-hostname set to 'files.example.com' with will create | ||
17 | 219 | the following public endpoint for the swift-proxy: | ||
18 | 220 | . | ||
19 | 221 | https://files.example.com:80/swift/v1 | ||
20 | 210 | prefer-ipv6: | 222 | prefer-ipv6: |
21 | 211 | type: boolean | 223 | type: boolean |
22 | 212 | default: False | 224 | default: False |
23 | 213 | 225 | ||
24 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
25 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
26 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-13 13:02:08 +0000 | |||
27 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-11 23:23:30 +0000 | |||
28 | @@ -17,6 +17,7 @@ | |||
29 | 17 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
30 | 18 | config, | 18 | config, |
31 | 19 | unit_get, | 19 | unit_get, |
32 | 20 | service_name, | ||
33 | 20 | ) | 21 | ) |
34 | 21 | from charmhelpers.contrib.network.ip import ( | 22 | from charmhelpers.contrib.network.ip import ( |
35 | 22 | get_address_in_network, | 23 | get_address_in_network, |
36 | @@ -26,8 +27,6 @@ | |||
37 | 26 | ) | 27 | ) |
38 | 27 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 28 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
39 | 28 | 29 | ||
40 | 29 | from functools import partial | ||
41 | 30 | |||
42 | 31 | PUBLIC = 'public' | 30 | PUBLIC = 'public' |
43 | 32 | INTERNAL = 'int' | 31 | INTERNAL = 'int' |
44 | 33 | ADMIN = 'admin' | 32 | ADMIN = 'admin' |
45 | @@ -35,15 +34,18 @@ | |||
46 | 35 | ADDRESS_MAP = { | 34 | ADDRESS_MAP = { |
47 | 36 | PUBLIC: { | 35 | PUBLIC: { |
48 | 37 | 'config': 'os-public-network', | 36 | 'config': 'os-public-network', |
50 | 38 | 'fallback': 'public-address' | 37 | 'fallback': 'public-address', |
51 | 38 | 'override': 'os-public-hostname', | ||
52 | 39 | }, | 39 | }, |
53 | 40 | INTERNAL: { | 40 | INTERNAL: { |
54 | 41 | 'config': 'os-internal-network', | 41 | 'config': 'os-internal-network', |
56 | 42 | 'fallback': 'private-address' | 42 | 'fallback': 'private-address', |
57 | 43 | 'override': 'os-internal-hostname', | ||
58 | 43 | }, | 44 | }, |
59 | 44 | ADMIN: { | 45 | ADMIN: { |
60 | 45 | 'config': 'os-admin-network', | 46 | 'config': 'os-admin-network', |
62 | 46 | 'fallback': 'private-address' | 47 | 'fallback': 'private-address', |
63 | 48 | 'override': 'os-admin-hostname', | ||
64 | 47 | } | 49 | } |
65 | 48 | } | 50 | } |
66 | 49 | 51 | ||
67 | @@ -57,15 +59,50 @@ | |||
68 | 57 | :param endpoint_type: str endpoint type to resolve. | 59 | :param endpoint_type: str endpoint type to resolve. |
69 | 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. |
70 | 59 | """ | 61 | """ |
74 | 60 | scheme = 'http' | 62 | scheme = _get_scheme(configs) |
75 | 61 | if 'https' in configs.complete_contexts(): | 63 | |
73 | 62 | scheme = 'https' | ||
76 | 63 | address = resolve_address(endpoint_type) | 64 | address = resolve_address(endpoint_type) |
77 | 64 | if is_ipv6(address): | 65 | if is_ipv6(address): |
78 | 65 | address = "[{}]".format(address) | 66 | address = "[{}]".format(address) |
79 | 67 | |||
80 | 66 | return '%s://%s' % (scheme, address) | 68 | return '%s://%s' % (scheme, address) |
81 | 67 | 69 | ||
82 | 68 | 70 | ||
83 | 71 | def _get_scheme(configs): | ||
84 | 72 | """Returns the scheme to use for the url (either http or https) | ||
85 | 73 | depending upon whether https is in the configs value. | ||
86 | 74 | |||
87 | 75 | :param configs: OSTemplateRenderer config templating object to inspect | ||
88 | 76 | for a complete https context. | ||
89 | 77 | :returns: either 'http' or 'https' depending on whether https is | ||
90 | 78 | configured within the configs context. | ||
91 | 79 | """ | ||
92 | 80 | scheme = 'http' | ||
93 | 81 | if configs and 'https' in configs.complete_contexts(): | ||
94 | 82 | scheme = 'https' | ||
95 | 83 | return scheme | ||
96 | 84 | |||
97 | 85 | |||
98 | 86 | def _get_address_override(endpoint_type=PUBLIC): | ||
99 | 87 | """Returns any address overrides that the user has defined based on the | ||
100 | 88 | endpoint type. | ||
101 | 89 | |||
102 | 90 | Note: this function allows for the service name to be inserted into the | ||
103 | 91 | address if the user specifies {service_name}.somehost.org. | ||
104 | 92 | |||
105 | 93 | :param endpoint_type: the type of endpoint to retrieve the override | ||
106 | 94 | value for. | ||
107 | 95 | :returns: any endpoint address or hostname that the user has overridden | ||
108 | 96 | or None if an override is not present. | ||
109 | 97 | """ | ||
110 | 98 | override_key = ADDRESS_MAP[endpoint_type]['override'] | ||
111 | 99 | addr_override = config(override_key) | ||
112 | 100 | if not addr_override: | ||
113 | 101 | return None | ||
114 | 102 | else: | ||
115 | 103 | return addr_override.format(service_name=service_name()) | ||
116 | 104 | |||
117 | 105 | |||
118 | 69 | def resolve_address(endpoint_type=PUBLIC): | 106 | def resolve_address(endpoint_type=PUBLIC): |
119 | 70 | """Return unit address depending on net config. | 107 | """Return unit address depending on net config. |
120 | 71 | 108 | ||
121 | @@ -77,7 +114,10 @@ | |||
122 | 77 | 114 | ||
123 | 78 | :param endpoint_type: Network endpoing type | 115 | :param endpoint_type: Network endpoing type |
124 | 79 | """ | 116 | """ |
126 | 80 | resolved_address = None | 117 | resolved_address = _get_address_override(endpoint_type) |
127 | 118 | if resolved_address: | ||
128 | 119 | return resolved_address | ||
129 | 120 | |||
130 | 81 | vips = config('vip') | 121 | vips = config('vip') |
131 | 82 | if vips: | 122 | if vips: |
132 | 83 | vips = vips.split() | 123 | vips = vips.split() |
133 | @@ -109,38 +149,3 @@ | |||
134 | 109 | "clustered=%s)" % (net_type, clustered)) | 149 | "clustered=%s)" % (net_type, clustered)) |
135 | 110 | 150 | ||
136 | 111 | return resolved_address | 151 | return resolved_address |
137 | 112 | |||
138 | 113 | |||
139 | 114 | def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, | ||
140 | 115 | override=None): | ||
141 | 116 | """Returns the correct endpoint URL to advertise to Keystone. | ||
142 | 117 | |||
143 | 118 | This method provides the correct endpoint URL which should be advertised to | ||
144 | 119 | the keystone charm for endpoint creation. This method allows for the url to | ||
145 | 120 | be overridden to force a keystone endpoint to have specific URL for any of | ||
146 | 121 | the defined scopes (admin, internal, public). | ||
147 | 122 | |||
148 | 123 | :param configs: OSTemplateRenderer config templating object to inspect | ||
149 | 124 | for a complete https context. | ||
150 | 125 | :param url_template: str format string for creating the url template. Only | ||
151 | 126 | two values will be passed - the scheme+hostname | ||
152 | 127 | returned by the canonical_url and the port. | ||
153 | 128 | :param endpoint_type: str endpoint type to resolve. | ||
154 | 129 | :param override: str the name of the config option which overrides the | ||
155 | 130 | endpoint URL defined by the charm itself. None will | ||
156 | 131 | disable any overrides (default). | ||
157 | 132 | """ | ||
158 | 133 | if override: | ||
159 | 134 | # Return any user-defined overrides for the keystone endpoint URL. | ||
160 | 135 | user_value = config(override) | ||
161 | 136 | if user_value: | ||
162 | 137 | return user_value.strip() | ||
163 | 138 | |||
164 | 139 | return url_template % (canonical_url(configs, endpoint_type), port) | ||
165 | 140 | |||
166 | 141 | |||
167 | 142 | public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) | ||
168 | 143 | |||
169 | 144 | internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) | ||
170 | 145 | |||
171 | 146 | admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) | ||
172 | 147 | 152 | ||
173 | === modified file 'hooks/charmhelpers/contrib/peerstorage/__init__.py' | |||
174 | === modified file 'unit_tests/test_swift_hooks.py' | |||
175 | --- unit_tests/test_swift_hooks.py 2014-12-05 13:21:52 +0000 | |||
176 | +++ unit_tests/test_swift_hooks.py 2015-06-11 23:23:30 +0000 | |||
177 | @@ -1,16 +1,16 @@ | |||
179 | 1 | import mock | 1 | from mock import patch |
180 | 2 | import unittest | 2 | import unittest |
181 | 3 | import uuid | 3 | import uuid |
182 | 4 | 4 | ||
183 | 5 | 5 | ||
185 | 6 | with mock.patch('charmhelpers.core.hookenv.log'): | 6 | with patch('charmhelpers.core.hookenv.log'): |
186 | 7 | import swift_hooks | 7 | import swift_hooks |
187 | 8 | 8 | ||
188 | 9 | 9 | ||
189 | 10 | class SwiftHooksTestCase(unittest.TestCase): | 10 | class SwiftHooksTestCase(unittest.TestCase): |
190 | 11 | 11 | ||
193 | 12 | @mock.patch("swift_hooks.relation_get") | 12 | @patch("swift_hooks.relation_get") |
194 | 13 | @mock.patch("swift_hooks.local_unit") | 13 | @patch("swift_hooks.local_unit") |
195 | 14 | def test_all_peers_stopped(self, mock_local_unit, mock_relation_get): | 14 | def test_all_peers_stopped(self, mock_local_unit, mock_relation_get): |
196 | 15 | token1 = str(uuid.uuid4()) | 15 | token1 = str(uuid.uuid4()) |
197 | 16 | token2 = str(uuid.uuid4()) | 16 | token2 = str(uuid.uuid4()) |
198 | @@ -37,3 +37,93 @@ | |||
199 | 37 | responses = [{'stop-proxy-service-ack': token1}, | 37 | responses = [{'stop-proxy-service-ack': token1}, |
200 | 38 | {'stop-proxy-service-ack': token1}] | 38 | {'stop-proxy-service-ack': token1}] |
201 | 39 | self.assertFalse(swift_hooks.all_peers_stopped(responses)) | 39 | self.assertFalse(swift_hooks.all_peers_stopped(responses)) |
202 | 40 | |||
203 | 41 | @patch.object(swift_hooks, 'config') | ||
204 | 42 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
205 | 43 | @patch.object(swift_hooks, 'CONFIGS') | ||
206 | 44 | @patch('charmhelpers.core.hookenv.local_unit') | ||
207 | 45 | @patch('charmhelpers.core.hookenv.service_name') | ||
208 | 46 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
209 | 47 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
210 | 48 | @patch.object(swift_hooks, 'relation_set') | ||
211 | 49 | def test_keystone_joined(self, _relation_set, _is_clustered, _unit_get, | ||
212 | 50 | _service_name, _local_unit, _CONFIGS, _ip_config, | ||
213 | 51 | _config): | ||
214 | 52 | config_dict = { | ||
215 | 53 | 'bind-port': '1234', | ||
216 | 54 | 'region': 'RegionOne', | ||
217 | 55 | 'operator-roles': 'Operator,Monitor' | ||
218 | 56 | } | ||
219 | 57 | |||
220 | 58 | def foo(key=None): | ||
221 | 59 | if key is None: | ||
222 | 60 | return config_dict | ||
223 | 61 | else: | ||
224 | 62 | return config_dict.get(key) | ||
225 | 63 | |||
226 | 64 | _config.side_effect = foo | ||
227 | 65 | _ip_config.side_effect = foo | ||
228 | 66 | _unit_get.return_value = 'swift-proxy' | ||
229 | 67 | _local_unit.return_value = 'swift-proxy/0' | ||
230 | 68 | _service_name.return_value = 'swift-proxy' | ||
231 | 69 | _is_clustered.return_value = False | ||
232 | 70 | |||
233 | 71 | swift_hooks.keystone_joined() | ||
234 | 72 | |||
235 | 73 | _relation_set.assert_called_with( | ||
236 | 74 | service='swift', | ||
237 | 75 | region='RegionOne', | ||
238 | 76 | public_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
239 | 77 | internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
240 | 78 | admin_url='http://swift-proxy:1234', | ||
241 | 79 | requested_roles='Operator,Monitor', | ||
242 | 80 | relation_id=None | ||
243 | 81 | ) | ||
244 | 82 | |||
245 | 83 | @patch.object(swift_hooks, 'config') | ||
246 | 84 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
247 | 85 | @patch.object(swift_hooks, 'CONFIGS') | ||
248 | 86 | @patch('charmhelpers.core.hookenv.local_unit') | ||
249 | 87 | @patch('charmhelpers.core.hookenv.service_name') | ||
250 | 88 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
251 | 89 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
252 | 90 | @patch.object(swift_hooks, 'relation_set') | ||
253 | 91 | def test_keystone_joined_public_hostname(self, | ||
254 | 92 | _relation_set, | ||
255 | 93 | _is_clustered, | ||
256 | 94 | _unit_get, | ||
257 | 95 | _service_name, | ||
258 | 96 | _local_unit, | ||
259 | 97 | _CONFIGS, | ||
260 | 98 | _ip_config, | ||
261 | 99 | _config): | ||
262 | 100 | config_dict = { | ||
263 | 101 | 'bind-port': '1234', | ||
264 | 102 | 'region': 'RegionOne', | ||
265 | 103 | 'operator-roles': 'Operator,Monitor', | ||
266 | 104 | 'os-public-hostname': 'public.example.com' | ||
267 | 105 | } | ||
268 | 106 | |||
269 | 107 | def foo(key=None): | ||
270 | 108 | if key is None: | ||
271 | 109 | return config_dict | ||
272 | 110 | else: | ||
273 | 111 | return config_dict.get(key) | ||
274 | 112 | |||
275 | 113 | _config.side_effect = _ip_config.side_effect = foo | ||
276 | 114 | _unit_get.return_value = _service_name.return_value = 'swift-proxy' | ||
277 | 115 | _local_unit.return_value = 'swift-proxy/0' | ||
278 | 116 | _is_clustered.return_value = False | ||
279 | 117 | |||
280 | 118 | swift_hooks.keystone_joined() | ||
281 | 119 | |||
282 | 120 | _relation_set.assert_called_with( | ||
283 | 121 | service='swift', | ||
284 | 122 | region='RegionOne', | ||
285 | 123 | public_url=('http://public.example.com:1234/' | ||
286 | 124 | 'v1/AUTH_$(tenant_id)s'), | ||
287 | 125 | internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
288 | 126 | admin_url='http://swift-proxy:1234', | ||
289 | 127 | requested_roles='Operator,Monitor', | ||
290 | 128 | relation_id=None | ||
291 | 129 | ) |
charm_lint_check #5043 swift-proxy-next for billy-olsen mp261005
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5043/