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 | 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 swift-proxy |
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 'files.example.com' with will create |
17 | + the following public endpoint for the swift-proxy: |
18 | + . |
19 | + https://files.example.com:80/swift/v1 |
20 | prefer-ipv6: |
21 | type: boolean |
22 | default: False |
23 | |
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 | 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-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 | 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_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 @@ |
226 | -import mock |
227 | +from mock import patch |
228 | import unittest |
229 | import uuid |
230 | |
231 | |
232 | -with mock.patch('charmhelpers.core.hookenv.log'): |
233 | +with patch('charmhelpers.core.hookenv.log'): |
234 | import swift_hooks |
235 | |
236 | |
237 | class SwiftHooksTestCase(unittest.TestCase): |
238 | |
239 | - @mock.patch("swift_hooks.relation_get") |
240 | - @mock.patch("swift_hooks.local_unit") |
241 | + @patch("swift_hooks.relation_get") |
242 | + @patch("swift_hooks.local_unit") |
243 | def test_all_peers_stopped(self, mock_local_unit, mock_relation_get): |
244 | token1 = str(uuid.uuid4()) |
245 | token2 = str(uuid.uuid4()) |
246 | @@ -37,3 +37,93 @@ |
247 | responses = [{'stop-proxy-service-ack': token1}, |
248 | {'stop-proxy-service-ack': token1}] |
249 | self.assertFalse(swift_hooks.all_peers_stopped(responses)) |
250 | + |
251 | + @patch.object(swift_hooks, 'config') |
252 | + @patch('charmhelpers.contrib.openstack.ip.config') |
253 | + @patch.object(swift_hooks, 'CONFIGS') |
254 | + @patch('charmhelpers.core.hookenv.local_unit') |
255 | + @patch('charmhelpers.core.hookenv.service_name') |
256 | + @patch('charmhelpers.contrib.openstack.ip.unit_get') |
257 | + @patch('charmhelpers.contrib.openstack.ip.is_clustered') |
258 | + @patch.object(swift_hooks, 'relation_set') |
259 | + def test_keystone_joined(self, _relation_set, _is_clustered, _unit_get, |
260 | + _service_name, _local_unit, _CONFIGS, _ip_config, |
261 | + _config): |
262 | + config_dict = { |
263 | + 'bind-port': '1234', |
264 | + 'region': 'RegionOne', |
265 | + 'operator-roles': 'Operator,Monitor' |
266 | + } |
267 | + |
268 | + def foo(key=None): |
269 | + if key is None: |
270 | + return config_dict |
271 | + else: |
272 | + return config_dict.get(key) |
273 | + |
274 | + _config.side_effect = foo |
275 | + _ip_config.side_effect = foo |
276 | + _unit_get.return_value = 'swift-proxy' |
277 | + _local_unit.return_value = 'swift-proxy/0' |
278 | + _service_name.return_value = 'swift-proxy' |
279 | + _is_clustered.return_value = False |
280 | + |
281 | + swift_hooks.keystone_joined() |
282 | + |
283 | + _relation_set.assert_called_with( |
284 | + service='swift', |
285 | + region='RegionOne', |
286 | + public_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', |
287 | + internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', |
288 | + admin_url='http://swift-proxy:1234', |
289 | + requested_roles='Operator,Monitor', |
290 | + relation_id=None |
291 | + ) |
292 | + |
293 | + @patch.object(swift_hooks, 'config') |
294 | + @patch('charmhelpers.contrib.openstack.ip.config') |
295 | + @patch.object(swift_hooks, 'CONFIGS') |
296 | + @patch('charmhelpers.core.hookenv.local_unit') |
297 | + @patch('charmhelpers.core.hookenv.service_name') |
298 | + @patch('charmhelpers.contrib.openstack.ip.unit_get') |
299 | + @patch('charmhelpers.contrib.openstack.ip.is_clustered') |
300 | + @patch.object(swift_hooks, 'relation_set') |
301 | + def test_keystone_joined_public_hostname(self, |
302 | + _relation_set, |
303 | + _is_clustered, |
304 | + _unit_get, |
305 | + _service_name, |
306 | + _local_unit, |
307 | + _CONFIGS, |
308 | + _ip_config, |
309 | + _config): |
310 | + config_dict = { |
311 | + 'bind-port': '1234', |
312 | + 'region': 'RegionOne', |
313 | + 'operator-roles': 'Operator,Monitor', |
314 | + 'os-public-hostname': 'public.example.com' |
315 | + } |
316 | + |
317 | + def foo(key=None): |
318 | + if key is None: |
319 | + return config_dict |
320 | + else: |
321 | + return config_dict.get(key) |
322 | + |
323 | + _config.side_effect = _ip_config.side_effect = foo |
324 | + _unit_get.return_value = _service_name.return_value = 'swift-proxy' |
325 | + _local_unit.return_value = 'swift-proxy/0' |
326 | + _is_clustered.return_value = False |
327 | + |
328 | + swift_hooks.keystone_joined() |
329 | + |
330 | + _relation_set.assert_called_with( |
331 | + service='swift', |
332 | + region='RegionOne', |
333 | + public_url=('http://public.example.com:1234/' |
334 | + 'v1/AUTH_$(tenant_id)s'), |
335 | + internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s', |
336 | + admin_url='http://swift-proxy:1234', |
337 | + requested_roles='Operator,Monitor', |
338 | + relation_id=None |
339 | + ) |
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/