Merge lp:~billy-olsen/charms/trusty/swift-proxy/backport-lp1398182 into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk
- Trusty Tahr (14.04)
- backport-lp1398182
- Merge into trunk
Proposed by
Billy Olsen
Status: | Merged |
---|---|
Merged at revision: | 98 |
Proposed branch: | lp:~billy-olsen/charms/trusty/swift-proxy/backport-lp1398182 |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/swift-proxy/trunk |
Diff against target: |
339 lines (+180/-48) 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_swift_hooks.py (+94/-4) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/swift-proxy/backport-lp1398182 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant (community) | Approve | ||
Review via email: mp+262007@code.launchpad.net |
Commit message
Description of the change
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 #5042 swift-proxy for billy-olsen mp262007
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4653 swift-proxy for billy-olsen mp262007
AMULET OK: passed
Build: http://
Revision history for this message
Corey Bryant (corey.bryant) : | # |
review:
Approve
- 99. 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-20 11:19:04 +0000 | |||
3 | +++ config.yaml 2015-06-18 23:44:32 +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 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-03-13 13:02:08 +0000 | |||
26 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-18 23:44:32 +0000 | |||
27 | @@ -52,6 +52,8 @@ | |||
28 | 52 | bool_from_string, | 52 | bool_from_string, |
29 | 53 | ) | 53 | ) |
30 | 54 | 54 | ||
31 | 55 | DC_RESOURCE_NAME = 'DC' | ||
32 | 56 | |||
33 | 55 | 57 | ||
34 | 56 | class HAIncompleteConfig(Exception): | 58 | class HAIncompleteConfig(Exception): |
35 | 57 | pass | 59 | pass |
36 | @@ -95,6 +97,27 @@ | |||
37 | 95 | return False | 97 | return False |
38 | 96 | 98 | ||
39 | 97 | 99 | ||
40 | 100 | def is_crm_dc(): | ||
41 | 101 | """ | ||
42 | 102 | Determine leadership by querying the pacemaker Designated Controller | ||
43 | 103 | """ | ||
44 | 104 | cmd = ['crm', 'status'] | ||
45 | 105 | try: | ||
46 | 106 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
47 | 107 | if not isinstance(status, six.text_type): | ||
48 | 108 | status = six.text_type(status, "utf-8") | ||
49 | 109 | except subprocess.CalledProcessError: | ||
50 | 110 | return False | ||
51 | 111 | current_dc = '' | ||
52 | 112 | for line in status.split('\n'): | ||
53 | 113 | if line.startswith('Current DC'): | ||
54 | 114 | # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum | ||
55 | 115 | current_dc = line.split(':')[1].split()[0] | ||
56 | 116 | if current_dc == get_unit_hostname(): | ||
57 | 117 | return True | ||
58 | 118 | return False | ||
59 | 119 | |||
60 | 120 | |||
61 | 98 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) | 121 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) |
62 | 99 | def is_crm_leader(resource, retry=False): | 122 | def is_crm_leader(resource, retry=False): |
63 | 100 | """ | 123 | """ |
64 | @@ -104,6 +127,8 @@ | |||
65 | 104 | We allow this operation to be retried to avoid the possibility of getting a | 127 | We allow this operation to be retried to avoid the possibility of getting a |
66 | 105 | false negative. See LP #1396246 for more info. | 128 | false negative. See LP #1396246 for more info. |
67 | 106 | """ | 129 | """ |
68 | 130 | if resource == DC_RESOURCE_NAME: | ||
69 | 131 | return is_crm_dc() | ||
70 | 107 | cmd = ['crm', 'resource', 'show', resource] | 132 | cmd = ['crm', 'resource', 'show', resource] |
71 | 108 | try: | 133 | try: |
72 | 109 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | 134 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
73 | 110 | 135 | ||
74 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
75 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-13 13:02:08 +0000 | |||
76 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-18 23:44:32 +0000 | |||
77 | @@ -17,6 +17,7 @@ | |||
78 | 17 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
79 | 18 | config, | 18 | config, |
80 | 19 | unit_get, | 19 | unit_get, |
81 | 20 | service_name, | ||
82 | 20 | ) | 21 | ) |
83 | 21 | from charmhelpers.contrib.network.ip import ( | 22 | from charmhelpers.contrib.network.ip import ( |
84 | 22 | get_address_in_network, | 23 | get_address_in_network, |
85 | @@ -26,8 +27,6 @@ | |||
86 | 26 | ) | 27 | ) |
87 | 27 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 28 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
88 | 28 | 29 | ||
89 | 29 | from functools import partial | ||
90 | 30 | |||
91 | 31 | PUBLIC = 'public' | 30 | PUBLIC = 'public' |
92 | 32 | INTERNAL = 'int' | 31 | INTERNAL = 'int' |
93 | 33 | ADMIN = 'admin' | 32 | ADMIN = 'admin' |
94 | @@ -35,15 +34,18 @@ | |||
95 | 35 | ADDRESS_MAP = { | 34 | ADDRESS_MAP = { |
96 | 36 | PUBLIC: { | 35 | PUBLIC: { |
97 | 37 | 'config': 'os-public-network', | 36 | 'config': 'os-public-network', |
99 | 38 | 'fallback': 'public-address' | 37 | 'fallback': 'public-address', |
100 | 38 | 'override': 'os-public-hostname', | ||
101 | 39 | }, | 39 | }, |
102 | 40 | INTERNAL: { | 40 | INTERNAL: { |
103 | 41 | 'config': 'os-internal-network', | 41 | 'config': 'os-internal-network', |
105 | 42 | 'fallback': 'private-address' | 42 | 'fallback': 'private-address', |
106 | 43 | 'override': 'os-internal-hostname', | ||
107 | 43 | }, | 44 | }, |
108 | 44 | ADMIN: { | 45 | ADMIN: { |
109 | 45 | 'config': 'os-admin-network', | 46 | 'config': 'os-admin-network', |
111 | 46 | 'fallback': 'private-address' | 47 | 'fallback': 'private-address', |
112 | 48 | 'override': 'os-admin-hostname', | ||
113 | 47 | } | 49 | } |
114 | 48 | } | 50 | } |
115 | 49 | 51 | ||
116 | @@ -57,15 +59,50 @@ | |||
117 | 57 | :param endpoint_type: str endpoint type to resolve. | 59 | :param endpoint_type: str endpoint type to resolve. |
118 | 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. |
119 | 59 | """ | 61 | """ |
123 | 60 | scheme = 'http' | 62 | scheme = _get_scheme(configs) |
124 | 61 | if 'https' in configs.complete_contexts(): | 63 | |
122 | 62 | scheme = 'https' | ||
125 | 63 | address = resolve_address(endpoint_type) | 64 | address = resolve_address(endpoint_type) |
126 | 64 | if is_ipv6(address): | 65 | if is_ipv6(address): |
127 | 65 | address = "[{}]".format(address) | 66 | address = "[{}]".format(address) |
128 | 67 | |||
129 | 66 | return '%s://%s' % (scheme, address) | 68 | return '%s://%s' % (scheme, address) |
130 | 67 | 69 | ||
131 | 68 | 70 | ||
132 | 71 | def _get_scheme(configs): | ||
133 | 72 | """Returns the scheme to use for the url (either http or https) | ||
134 | 73 | depending upon whether https is in the configs value. | ||
135 | 74 | |||
136 | 75 | :param configs: OSTemplateRenderer config templating object to inspect | ||
137 | 76 | for a complete https context. | ||
138 | 77 | :returns: either 'http' or 'https' depending on whether https is | ||
139 | 78 | configured within the configs context. | ||
140 | 79 | """ | ||
141 | 80 | scheme = 'http' | ||
142 | 81 | if configs and 'https' in configs.complete_contexts(): | ||
143 | 82 | scheme = 'https' | ||
144 | 83 | return scheme | ||
145 | 84 | |||
146 | 85 | |||
147 | 86 | def _get_address_override(endpoint_type=PUBLIC): | ||
148 | 87 | """Returns any address overrides that the user has defined based on the | ||
149 | 88 | endpoint type. | ||
150 | 89 | |||
151 | 90 | Note: this function allows for the service name to be inserted into the | ||
152 | 91 | address if the user specifies {service_name}.somehost.org. | ||
153 | 92 | |||
154 | 93 | :param endpoint_type: the type of endpoint to retrieve the override | ||
155 | 94 | value for. | ||
156 | 95 | :returns: any endpoint address or hostname that the user has overridden | ||
157 | 96 | or None if an override is not present. | ||
158 | 97 | """ | ||
159 | 98 | override_key = ADDRESS_MAP[endpoint_type]['override'] | ||
160 | 99 | addr_override = config(override_key) | ||
161 | 100 | if not addr_override: | ||
162 | 101 | return None | ||
163 | 102 | else: | ||
164 | 103 | return addr_override.format(service_name=service_name()) | ||
165 | 104 | |||
166 | 105 | |||
167 | 69 | def resolve_address(endpoint_type=PUBLIC): | 106 | def resolve_address(endpoint_type=PUBLIC): |
168 | 70 | """Return unit address depending on net config. | 107 | """Return unit address depending on net config. |
169 | 71 | 108 | ||
170 | @@ -77,7 +114,10 @@ | |||
171 | 77 | 114 | ||
172 | 78 | :param endpoint_type: Network endpoing type | 115 | :param endpoint_type: Network endpoing type |
173 | 79 | """ | 116 | """ |
175 | 80 | resolved_address = None | 117 | resolved_address = _get_address_override(endpoint_type) |
176 | 118 | if resolved_address: | ||
177 | 119 | return resolved_address | ||
178 | 120 | |||
179 | 81 | vips = config('vip') | 121 | vips = config('vip') |
180 | 82 | if vips: | 122 | if vips: |
181 | 83 | vips = vips.split() | 123 | vips = vips.split() |
182 | @@ -109,38 +149,3 @@ | |||
183 | 109 | "clustered=%s)" % (net_type, clustered)) | 149 | "clustered=%s)" % (net_type, clustered)) |
184 | 110 | 150 | ||
185 | 111 | return resolved_address | 151 | return resolved_address |
186 | 112 | |||
187 | 113 | |||
188 | 114 | def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, | ||
189 | 115 | override=None): | ||
190 | 116 | """Returns the correct endpoint URL to advertise to Keystone. | ||
191 | 117 | |||
192 | 118 | This method provides the correct endpoint URL which should be advertised to | ||
193 | 119 | the keystone charm for endpoint creation. This method allows for the url to | ||
194 | 120 | be overridden to force a keystone endpoint to have specific URL for any of | ||
195 | 121 | the defined scopes (admin, internal, public). | ||
196 | 122 | |||
197 | 123 | :param configs: OSTemplateRenderer config templating object to inspect | ||
198 | 124 | for a complete https context. | ||
199 | 125 | :param url_template: str format string for creating the url template. Only | ||
200 | 126 | two values will be passed - the scheme+hostname | ||
201 | 127 | returned by the canonical_url and the port. | ||
202 | 128 | :param endpoint_type: str endpoint type to resolve. | ||
203 | 129 | :param override: str the name of the config option which overrides the | ||
204 | 130 | endpoint URL defined by the charm itself. None will | ||
205 | 131 | disable any overrides (default). | ||
206 | 132 | """ | ||
207 | 133 | if override: | ||
208 | 134 | # Return any user-defined overrides for the keystone endpoint URL. | ||
209 | 135 | user_value = config(override) | ||
210 | 136 | if user_value: | ||
211 | 137 | return user_value.strip() | ||
212 | 138 | |||
213 | 139 | return url_template % (canonical_url(configs, endpoint_type), port) | ||
214 | 140 | |||
215 | 141 | |||
216 | 142 | public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) | ||
217 | 143 | |||
218 | 144 | internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) | ||
219 | 145 | |||
220 | 146 | admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) | ||
221 | 147 | 152 | ||
222 | === modified file 'unit_tests/test_swift_hooks.py' | |||
223 | --- unit_tests/test_swift_hooks.py 2014-12-05 13:21:52 +0000 | |||
224 | +++ unit_tests/test_swift_hooks.py 2015-06-18 23:44:32 +0000 | |||
225 | @@ -1,16 +1,16 @@ | |||
227 | 1 | import mock | 1 | from mock import patch |
228 | 2 | import unittest | 2 | import unittest |
229 | 3 | import uuid | 3 | import uuid |
230 | 4 | 4 | ||
231 | 5 | 5 | ||
233 | 6 | with mock.patch('charmhelpers.core.hookenv.log'): | 6 | with patch('charmhelpers.core.hookenv.log'): |
234 | 7 | import swift_hooks | 7 | import swift_hooks |
235 | 8 | 8 | ||
236 | 9 | 9 | ||
237 | 10 | class SwiftHooksTestCase(unittest.TestCase): | 10 | class SwiftHooksTestCase(unittest.TestCase): |
238 | 11 | 11 | ||
241 | 12 | @mock.patch("swift_hooks.relation_get") | 12 | @patch("swift_hooks.relation_get") |
242 | 13 | @mock.patch("swift_hooks.local_unit") | 13 | @patch("swift_hooks.local_unit") |
243 | 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): |
244 | 15 | token1 = str(uuid.uuid4()) | 15 | token1 = str(uuid.uuid4()) |
245 | 16 | token2 = str(uuid.uuid4()) | 16 | token2 = str(uuid.uuid4()) |
246 | @@ -37,3 +37,93 @@ | |||
247 | 37 | responses = [{'stop-proxy-service-ack': token1}, | 37 | responses = [{'stop-proxy-service-ack': token1}, |
248 | 38 | {'stop-proxy-service-ack': token1}] | 38 | {'stop-proxy-service-ack': token1}] |
249 | 39 | self.assertFalse(swift_hooks.all_peers_stopped(responses)) | 39 | self.assertFalse(swift_hooks.all_peers_stopped(responses)) |
250 | 40 | |||
251 | 41 | @patch.object(swift_hooks, 'config') | ||
252 | 42 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
253 | 43 | @patch.object(swift_hooks, 'CONFIGS') | ||
254 | 44 | @patch('charmhelpers.core.hookenv.local_unit') | ||
255 | 45 | @patch('charmhelpers.core.hookenv.service_name') | ||
256 | 46 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
257 | 47 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
258 | 48 | @patch.object(swift_hooks, 'relation_set') | ||
259 | 49 | def test_keystone_joined(self, _relation_set, _is_clustered, _unit_get, | ||
260 | 50 | _service_name, _local_unit, _CONFIGS, _ip_config, | ||
261 | 51 | _config): | ||
262 | 52 | config_dict = { | ||
263 | 53 | 'bind-port': '1234', | ||
264 | 54 | 'region': 'RegionOne', | ||
265 | 55 | 'operator-roles': 'Operator,Monitor' | ||
266 | 56 | } | ||
267 | 57 | |||
268 | 58 | def foo(key=None): | ||
269 | 59 | if key is None: | ||
270 | 60 | return config_dict | ||
271 | 61 | else: | ||
272 | 62 | return config_dict.get(key) | ||
273 | 63 | |||
274 | 64 | _config.side_effect = foo | ||
275 | 65 | _ip_config.side_effect = foo | ||
276 | 66 | _unit_get.return_value = 'swift-proxy' | ||
277 | 67 | _local_unit.return_value = 'swift-proxy/0' | ||
278 | 68 | _service_name.return_value = 'swift-proxy' | ||
279 | 69 | _is_clustered.return_value = False | ||
280 | 70 | |||
281 | 71 | swift_hooks.keystone_joined() | ||
282 | 72 | |||
283 | 73 | _relation_set.assert_called_with( | ||
284 | 74 | service='swift', | ||
285 | 75 | region='RegionOne', | ||
286 | 76 | public_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
287 | 77 | internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
288 | 78 | admin_url='http://swift-proxy:1234', | ||
289 | 79 | requested_roles='Operator,Monitor', | ||
290 | 80 | relation_id=None | ||
291 | 81 | ) | ||
292 | 82 | |||
293 | 83 | @patch.object(swift_hooks, 'config') | ||
294 | 84 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
295 | 85 | @patch.object(swift_hooks, 'CONFIGS') | ||
296 | 86 | @patch('charmhelpers.core.hookenv.local_unit') | ||
297 | 87 | @patch('charmhelpers.core.hookenv.service_name') | ||
298 | 88 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
299 | 89 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
300 | 90 | @patch.object(swift_hooks, 'relation_set') | ||
301 | 91 | def test_keystone_joined_public_hostname(self, | ||
302 | 92 | _relation_set, | ||
303 | 93 | _is_clustered, | ||
304 | 94 | _unit_get, | ||
305 | 95 | _service_name, | ||
306 | 96 | _local_unit, | ||
307 | 97 | _CONFIGS, | ||
308 | 98 | _ip_config, | ||
309 | 99 | _config): | ||
310 | 100 | config_dict = { | ||
311 | 101 | 'bind-port': '1234', | ||
312 | 102 | 'region': 'RegionOne', | ||
313 | 103 | 'operator-roles': 'Operator,Monitor', | ||
314 | 104 | 'os-public-hostname': 'public.example.com' | ||
315 | 105 | } | ||
316 | 106 | |||
317 | 107 | def foo(key=None): | ||
318 | 108 | if key is None: | ||
319 | 109 | return config_dict | ||
320 | 110 | else: | ||
321 | 111 | return config_dict.get(key) | ||
322 | 112 | |||
323 | 113 | _config.side_effect = _ip_config.side_effect = foo | ||
324 | 114 | _unit_get.return_value = _service_name.return_value = 'swift-proxy' | ||
325 | 115 | _local_unit.return_value = 'swift-proxy/0' | ||
326 | 116 | _is_clustered.return_value = False | ||
327 | 117 | |||
328 | 118 | swift_hooks.keystone_joined() | ||
329 | 119 | |||
330 | 120 | _relation_set.assert_called_with( | ||
331 | 121 | service='swift', | ||
332 | 122 | region='RegionOne', | ||
333 | 123 | public_url=('http://public.example.com:1234/' | ||
334 | 124 | 'v1/AUTH_$(tenant_id)s'), | ||
335 | 125 | internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', | ||
336 | 126 | admin_url='http://swift-proxy:1234', | ||
337 | 127 | requested_roles='Operator,Monitor', | ||
338 | 128 | relation_id=None | ||
339 | 129 | ) |
charm_lint_check #5410 swift-proxy for billy-olsen mp262007
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5410/