Merge lp:~billy-olsen/charms/trusty/ceph-radosgw/public-endpoint-host into lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/next
- Trusty Tahr (14.04)
- public-endpoint-host
- Merge into next
Proposed by
Billy Olsen
Status: | Merged |
---|---|
Merged at revision: | 39 |
Proposed branch: | lp:~billy-olsen/charms/trusty/ceph-radosgw/public-endpoint-host |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/next |
Diff against target: |
1126 lines (+460/-135) 16 files modified
config.yaml (+12/-0) hooks/charmhelpers/contrib/hahelpers/cluster.py (+25/-0) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+15/-6) hooks/charmhelpers/contrib/openstack/ip.py (+49/-44) hooks/charmhelpers/contrib/openstack/neutron.py (+10/-5) hooks/charmhelpers/contrib/openstack/utils.py (+65/-18) hooks/charmhelpers/contrib/python/packages.py (+28/-5) hooks/charmhelpers/core/hookenv.py (+147/-10) hooks/charmhelpers/core/host.py (+1/-1) hooks/charmhelpers/core/services/base.py (+32/-11) hooks/charmhelpers/fetch/__init__.py (+1/-1) hooks/charmhelpers/fetch/giturl.py (+7/-5) hooks/hooks.py (+4/-15) tests/charmhelpers/contrib/amulet/utils.py (+8/-1) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+15/-6) unit_tests/test_hooks.py (+41/-7) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/ceph-radosgw/public-endpoint-host |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant (community) | Approve | ||
Review via email: mp+261011@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 #4729 ceph-radosgw-next for billy-olsen mp261011
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4455 ceph-radosgw-next for billy-olsen mp261011
AMULET OK: passed
Build: http://
- 42. By Billy Olsen
-
c-h sync. unit test updates for sync
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5073 ceph-radosgw-next for billy-olsen mp261011
LINT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4752 ceph-radosgw-next for billy-olsen mp261011
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4480 ceph-radosgw-next for billy-olsen mp261011
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-01-14 13:27:02 +0000 | |||
3 | +++ config.yaml 2015-06-04 23:07:06 +0000 | |||
4 | @@ -87,3 +87,15 @@ | |||
5 | 87 | description: | | 87 | description: | |
6 | 88 | Default multicast port number that will be used to communicate between | 88 | Default multicast port number that will be used to communicate between |
7 | 89 | HA Cluster nodes. | 89 | HA Cluster nodes. |
8 | 90 | os-public-hostname: | ||
9 | 91 | type: string | ||
10 | 92 | default: | ||
11 | 93 | description: | | ||
12 | 94 | The hostname or address of the public endpoints created for ceph-radosgw | ||
13 | 95 | in the keystone identity provider. | ||
14 | 96 | . | ||
15 | 97 | This value will be used for public endpoints. For example, an | ||
16 | 98 | os-public-hostname set to 'files.example.com' with will create | ||
17 | 99 | the following public endpoint for the ceph-radosgw. | ||
18 | 100 | . | ||
19 | 101 | https://files.example.com:80/swift/v1 | ||
20 | 90 | \ No newline at end of file | 102 | \ No newline at end of file |
21 | 91 | 103 | ||
22 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
23 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-02-24 11:02:02 +0000 | |||
24 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-04 23:07:06 +0000 | |||
25 | @@ -52,6 +52,8 @@ | |||
26 | 52 | bool_from_string, | 52 | bool_from_string, |
27 | 53 | ) | 53 | ) |
28 | 54 | 54 | ||
29 | 55 | DC_RESOURCE_NAME = 'DC' | ||
30 | 56 | |||
31 | 55 | 57 | ||
32 | 56 | class HAIncompleteConfig(Exception): | 58 | class HAIncompleteConfig(Exception): |
33 | 57 | pass | 59 | pass |
34 | @@ -95,6 +97,27 @@ | |||
35 | 95 | return False | 97 | return False |
36 | 96 | 98 | ||
37 | 97 | 99 | ||
38 | 100 | def is_crm_dc(): | ||
39 | 101 | """ | ||
40 | 102 | Determine leadership by querying the pacemaker Designated Controller | ||
41 | 103 | """ | ||
42 | 104 | cmd = ['crm', 'status'] | ||
43 | 105 | try: | ||
44 | 106 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
45 | 107 | if not isinstance(status, six.text_type): | ||
46 | 108 | status = six.text_type(status, "utf-8") | ||
47 | 109 | except subprocess.CalledProcessError: | ||
48 | 110 | return False | ||
49 | 111 | current_dc = '' | ||
50 | 112 | for line in status.split('\n'): | ||
51 | 113 | if line.startswith('Current DC'): | ||
52 | 114 | # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum | ||
53 | 115 | current_dc = line.split(':')[1].split()[0] | ||
54 | 116 | if current_dc == get_unit_hostname(): | ||
55 | 117 | return True | ||
56 | 118 | return False | ||
57 | 119 | |||
58 | 120 | |||
59 | 98 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) | 121 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) |
60 | 99 | def is_crm_leader(resource, retry=False): | 122 | def is_crm_leader(resource, retry=False): |
61 | 100 | """ | 123 | """ |
62 | @@ -104,6 +127,8 @@ | |||
63 | 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 |
64 | 105 | false negative. See LP #1396246 for more info. | 128 | false negative. See LP #1396246 for more info. |
65 | 106 | """ | 129 | """ |
66 | 130 | if resource == DC_RESOURCE_NAME: | ||
67 | 131 | return is_crm_dc() | ||
68 | 107 | cmd = ['crm', 'resource', 'show', resource] | 132 | cmd = ['crm', 'resource', 'show', resource] |
69 | 108 | try: | 133 | try: |
70 | 109 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | 134 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
71 | 110 | 135 | ||
72 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
73 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-04-16 21:32:59 +0000 | |||
74 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-06-04 23:07:06 +0000 | |||
75 | @@ -46,15 +46,22 @@ | |||
76 | 46 | stable or next branches for the other_services.""" | 46 | stable or next branches for the other_services.""" |
77 | 47 | base_charms = ['mysql', 'mongodb'] | 47 | base_charms = ['mysql', 'mongodb'] |
78 | 48 | 48 | ||
79 | 49 | if self.series in ['precise', 'trusty']: | ||
80 | 50 | base_series = self.series | ||
81 | 51 | else: | ||
82 | 52 | base_series = self.current_next | ||
83 | 53 | |||
84 | 49 | if self.stable: | 54 | if self.stable: |
85 | 50 | for svc in other_services: | 55 | for svc in other_services: |
88 | 51 | temp = 'lp:charms/{}' | 56 | temp = 'lp:charms/{}/{}' |
89 | 52 | svc['location'] = temp.format(svc['name']) | 57 | svc['location'] = temp.format(base_series, |
90 | 58 | svc['name']) | ||
91 | 53 | else: | 59 | else: |
92 | 54 | for svc in other_services: | 60 | for svc in other_services: |
93 | 55 | if svc['name'] in base_charms: | 61 | if svc['name'] in base_charms: |
96 | 56 | temp = 'lp:charms/{}' | 62 | temp = 'lp:charms/{}/{}' |
97 | 57 | svc['location'] = temp.format(svc['name']) | 63 | svc['location'] = temp.format(base_series, |
98 | 64 | svc['name']) | ||
99 | 58 | else: | 65 | else: |
100 | 59 | temp = 'lp:~openstack-charmers/charms/{}/{}/next' | 66 | temp = 'lp:~openstack-charmers/charms/{}/{}/next' |
101 | 60 | svc['location'] = temp.format(self.current_next, | 67 | svc['location'] = temp.format(self.current_next, |
102 | @@ -99,10 +106,12 @@ | |||
103 | 99 | Return an integer representing the enum value of the openstack | 106 | Return an integer representing the enum value of the openstack |
104 | 100 | release. | 107 | release. |
105 | 101 | """ | 108 | """ |
106 | 109 | # Must be ordered by OpenStack release (not by Ubuntu release): | ||
107 | 102 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, |
108 | 103 | self.precise_havana, self.precise_icehouse, | 111 | self.precise_havana, self.precise_icehouse, |
111 | 104 | self.trusty_icehouse, self.trusty_juno, self.trusty_kilo, | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
112 | 105 | self.utopic_juno, self.vivid_kilo) = range(10) | 113 | self.trusty_kilo, self.vivid_kilo) = range(10) |
113 | 114 | |||
114 | 106 | releases = { | 115 | releases = { |
115 | 107 | ('precise', None): self.precise_essex, | 116 | ('precise', None): self.precise_essex, |
116 | 108 | ('precise', 'cloud:precise-folsom'): self.precise_folsom, | 117 | ('precise', 'cloud:precise-folsom'): self.precise_folsom, |
117 | 109 | 118 | ||
118 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
119 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-02-24 11:02:02 +0000 | |||
120 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-04 23:07:06 +0000 | |||
121 | @@ -17,6 +17,7 @@ | |||
122 | 17 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
123 | 18 | config, | 18 | config, |
124 | 19 | unit_get, | 19 | unit_get, |
125 | 20 | service_name, | ||
126 | 20 | ) | 21 | ) |
127 | 21 | from charmhelpers.contrib.network.ip import ( | 22 | from charmhelpers.contrib.network.ip import ( |
128 | 22 | get_address_in_network, | 23 | get_address_in_network, |
129 | @@ -26,8 +27,6 @@ | |||
130 | 26 | ) | 27 | ) |
131 | 27 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 28 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
132 | 28 | 29 | ||
133 | 29 | from functools import partial | ||
134 | 30 | |||
135 | 31 | PUBLIC = 'public' | 30 | PUBLIC = 'public' |
136 | 32 | INTERNAL = 'int' | 31 | INTERNAL = 'int' |
137 | 33 | ADMIN = 'admin' | 32 | ADMIN = 'admin' |
138 | @@ -35,15 +34,18 @@ | |||
139 | 35 | ADDRESS_MAP = { | 34 | ADDRESS_MAP = { |
140 | 36 | PUBLIC: { | 35 | PUBLIC: { |
141 | 37 | 'config': 'os-public-network', | 36 | 'config': 'os-public-network', |
143 | 38 | 'fallback': 'public-address' | 37 | 'fallback': 'public-address', |
144 | 38 | 'override': 'os-public-hostname', | ||
145 | 39 | }, | 39 | }, |
146 | 40 | INTERNAL: { | 40 | INTERNAL: { |
147 | 41 | 'config': 'os-internal-network', | 41 | 'config': 'os-internal-network', |
149 | 42 | 'fallback': 'private-address' | 42 | 'fallback': 'private-address', |
150 | 43 | 'override': 'os-internal-hostname', | ||
151 | 43 | }, | 44 | }, |
152 | 44 | ADMIN: { | 45 | ADMIN: { |
153 | 45 | 'config': 'os-admin-network', | 46 | 'config': 'os-admin-network', |
155 | 46 | 'fallback': 'private-address' | 47 | 'fallback': 'private-address', |
156 | 48 | 'override': 'os-admin-hostname', | ||
157 | 47 | } | 49 | } |
158 | 48 | } | 50 | } |
159 | 49 | 51 | ||
160 | @@ -57,15 +59,50 @@ | |||
161 | 57 | :param endpoint_type: str endpoint type to resolve. | 59 | :param endpoint_type: str endpoint type to resolve. |
162 | 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. |
163 | 59 | """ | 61 | """ |
167 | 60 | scheme = 'http' | 62 | scheme = _get_scheme(configs) |
168 | 61 | if 'https' in configs.complete_contexts(): | 63 | |
166 | 62 | scheme = 'https' | ||
169 | 63 | address = resolve_address(endpoint_type) | 64 | address = resolve_address(endpoint_type) |
170 | 64 | if is_ipv6(address): | 65 | if is_ipv6(address): |
171 | 65 | address = "[{}]".format(address) | 66 | address = "[{}]".format(address) |
172 | 67 | |||
173 | 66 | return '%s://%s' % (scheme, address) | 68 | return '%s://%s' % (scheme, address) |
174 | 67 | 69 | ||
175 | 68 | 70 | ||
176 | 71 | def _get_scheme(configs): | ||
177 | 72 | """Returns the scheme to use for the url (either http or https) | ||
178 | 73 | depending upon whether https is in the configs value. | ||
179 | 74 | |||
180 | 75 | :param configs: OSTemplateRenderer config templating object to inspect | ||
181 | 76 | for a complete https context. | ||
182 | 77 | :returns: either 'http' or 'https' depending on whether https is | ||
183 | 78 | configured within the configs context. | ||
184 | 79 | """ | ||
185 | 80 | scheme = 'http' | ||
186 | 81 | if configs and 'https' in configs.complete_contexts(): | ||
187 | 82 | scheme = 'https' | ||
188 | 83 | return scheme | ||
189 | 84 | |||
190 | 85 | |||
191 | 86 | def _get_address_override(endpoint_type=PUBLIC): | ||
192 | 87 | """Returns any address overrides that the user has defined based on the | ||
193 | 88 | endpoint type. | ||
194 | 89 | |||
195 | 90 | Note: this function allows for the service name to be inserted into the | ||
196 | 91 | address if the user specifies {service_name}.somehost.org. | ||
197 | 92 | |||
198 | 93 | :param endpoint_type: the type of endpoint to retrieve the override | ||
199 | 94 | value for. | ||
200 | 95 | :returns: any endpoint address or hostname that the user has overridden | ||
201 | 96 | or None if an override is not present. | ||
202 | 97 | """ | ||
203 | 98 | override_key = ADDRESS_MAP[endpoint_type]['override'] | ||
204 | 99 | addr_override = config(override_key) | ||
205 | 100 | if not addr_override: | ||
206 | 101 | return None | ||
207 | 102 | else: | ||
208 | 103 | return addr_override.format(service_name=service_name()) | ||
209 | 104 | |||
210 | 105 | |||
211 | 69 | def resolve_address(endpoint_type=PUBLIC): | 106 | def resolve_address(endpoint_type=PUBLIC): |
212 | 70 | """Return unit address depending on net config. | 107 | """Return unit address depending on net config. |
213 | 71 | 108 | ||
214 | @@ -77,7 +114,10 @@ | |||
215 | 77 | 114 | ||
216 | 78 | :param endpoint_type: Network endpoing type | 115 | :param endpoint_type: Network endpoing type |
217 | 79 | """ | 116 | """ |
219 | 80 | resolved_address = None | 117 | resolved_address = _get_address_override(endpoint_type) |
220 | 118 | if resolved_address: | ||
221 | 119 | return resolved_address | ||
222 | 120 | |||
223 | 81 | vips = config('vip') | 121 | vips = config('vip') |
224 | 82 | if vips: | 122 | if vips: |
225 | 83 | vips = vips.split() | 123 | vips = vips.split() |
226 | @@ -109,38 +149,3 @@ | |||
227 | 109 | "clustered=%s)" % (net_type, clustered)) | 149 | "clustered=%s)" % (net_type, clustered)) |
228 | 110 | 150 | ||
229 | 111 | return resolved_address | 151 | return resolved_address |
230 | 112 | |||
231 | 113 | |||
232 | 114 | def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, | ||
233 | 115 | override=None): | ||
234 | 116 | """Returns the correct endpoint URL to advertise to Keystone. | ||
235 | 117 | |||
236 | 118 | This method provides the correct endpoint URL which should be advertised to | ||
237 | 119 | the keystone charm for endpoint creation. This method allows for the url to | ||
238 | 120 | be overridden to force a keystone endpoint to have specific URL for any of | ||
239 | 121 | the defined scopes (admin, internal, public). | ||
240 | 122 | |||
241 | 123 | :param configs: OSTemplateRenderer config templating object to inspect | ||
242 | 124 | for a complete https context. | ||
243 | 125 | :param url_template: str format string for creating the url template. Only | ||
244 | 126 | two values will be passed - the scheme+hostname | ||
245 | 127 | returned by the canonical_url and the port. | ||
246 | 128 | :param endpoint_type: str endpoint type to resolve. | ||
247 | 129 | :param override: str the name of the config option which overrides the | ||
248 | 130 | endpoint URL defined by the charm itself. None will | ||
249 | 131 | disable any overrides (default). | ||
250 | 132 | """ | ||
251 | 133 | if override: | ||
252 | 134 | # Return any user-defined overrides for the keystone endpoint URL. | ||
253 | 135 | user_value = config(override) | ||
254 | 136 | if user_value: | ||
255 | 137 | return user_value.strip() | ||
256 | 138 | |||
257 | 139 | return url_template % (canonical_url(configs, endpoint_type), port) | ||
258 | 140 | |||
259 | 141 | |||
260 | 142 | public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) | ||
261 | 143 | |||
262 | 144 | internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) | ||
263 | 145 | |||
264 | 146 | admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) | ||
265 | 147 | 152 | ||
266 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
267 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2015-04-16 21:32:59 +0000 | |||
268 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-06-04 23:07:06 +0000 | |||
269 | @@ -256,11 +256,14 @@ | |||
270 | 256 | def parse_mappings(mappings): | 256 | def parse_mappings(mappings): |
271 | 257 | parsed = {} | 257 | parsed = {} |
272 | 258 | if mappings: | 258 | if mappings: |
274 | 259 | mappings = mappings.split(' ') | 259 | mappings = mappings.split() |
275 | 260 | for m in mappings: | 260 | for m in mappings: |
276 | 261 | p = m.partition(':') | 261 | p = m.partition(':') |
279 | 262 | if p[1] == ':': | 262 | key = p[0].strip() |
280 | 263 | parsed[p[0].strip()] = p[2].strip() | 263 | if p[1]: |
281 | 264 | parsed[key] = p[2].strip() | ||
282 | 265 | else: | ||
283 | 266 | parsed[key] = '' | ||
284 | 264 | 267 | ||
285 | 265 | return parsed | 268 | return parsed |
286 | 266 | 269 | ||
287 | @@ -283,13 +286,13 @@ | |||
288 | 283 | Returns dict of the form {bridge:port}. | 286 | Returns dict of the form {bridge:port}. |
289 | 284 | """ | 287 | """ |
290 | 285 | _mappings = parse_mappings(mappings) | 288 | _mappings = parse_mappings(mappings) |
292 | 286 | if not _mappings: | 289 | if not _mappings or list(_mappings.values()) == ['']: |
293 | 287 | if not mappings: | 290 | if not mappings: |
294 | 288 | return {} | 291 | return {} |
295 | 289 | 292 | ||
296 | 290 | # For backwards-compatibility we need to support port-only provided in | 293 | # For backwards-compatibility we need to support port-only provided in |
297 | 291 | # config. | 294 | # config. |
299 | 292 | _mappings = {default_bridge: mappings.split(' ')[0]} | 295 | _mappings = {default_bridge: mappings.split()[0]} |
300 | 293 | 296 | ||
301 | 294 | bridges = _mappings.keys() | 297 | bridges = _mappings.keys() |
302 | 295 | ports = _mappings.values() | 298 | ports = _mappings.values() |
303 | @@ -309,6 +312,8 @@ | |||
304 | 309 | 312 | ||
305 | 310 | Mappings must be a space-delimited list of provider:start:end mappings. | 313 | Mappings must be a space-delimited list of provider:start:end mappings. |
306 | 311 | 314 | ||
307 | 315 | The start:end range is optional and may be omitted. | ||
308 | 316 | |||
309 | 312 | Returns dict of the form {provider: (start, end)}. | 317 | Returns dict of the form {provider: (start, end)}. |
310 | 313 | """ | 318 | """ |
311 | 314 | _mappings = parse_mappings(mappings) | 319 | _mappings = parse_mappings(mappings) |
312 | 315 | 320 | ||
313 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
314 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-04-16 21:32:59 +0000 | |||
315 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-06-04 23:07:06 +0000 | |||
316 | @@ -53,9 +53,13 @@ | |||
317 | 53 | get_ipv6_addr | 53 | get_ipv6_addr |
318 | 54 | ) | 54 | ) |
319 | 55 | 55 | ||
320 | 56 | from charmhelpers.contrib.python.packages import ( | ||
321 | 57 | pip_create_virtualenv, | ||
322 | 58 | pip_install, | ||
323 | 59 | ) | ||
324 | 60 | |||
325 | 56 | from charmhelpers.core.host import lsb_release, mounts, umount | 61 | from charmhelpers.core.host import lsb_release, mounts, umount |
326 | 57 | from charmhelpers.fetch import apt_install, apt_cache, install_remote | 62 | from charmhelpers.fetch import apt_install, apt_cache, install_remote |
327 | 58 | from charmhelpers.contrib.python.packages import pip_install | ||
328 | 59 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk | 63 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk |
329 | 60 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device | 64 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device |
330 | 61 | 65 | ||
331 | @@ -497,7 +501,17 @@ | |||
332 | 497 | requirements_dir = None | 501 | requirements_dir = None |
333 | 498 | 502 | ||
334 | 499 | 503 | ||
336 | 500 | def git_clone_and_install(projects_yaml, core_project): | 504 | def _git_yaml_load(projects_yaml): |
337 | 505 | """ | ||
338 | 506 | Load the specified yaml into a dictionary. | ||
339 | 507 | """ | ||
340 | 508 | if not projects_yaml: | ||
341 | 509 | return None | ||
342 | 510 | |||
343 | 511 | return yaml.load(projects_yaml) | ||
344 | 512 | |||
345 | 513 | |||
346 | 514 | def git_clone_and_install(projects_yaml, core_project, depth=1): | ||
347 | 501 | """ | 515 | """ |
348 | 502 | Clone/install all specified OpenStack repositories. | 516 | Clone/install all specified OpenStack repositories. |
349 | 503 | 517 | ||
350 | @@ -510,23 +524,22 @@ | |||
351 | 510 | repository: 'git://git.openstack.org/openstack/requirements.git', | 524 | repository: 'git://git.openstack.org/openstack/requirements.git', |
352 | 511 | branch: 'stable/icehouse'} | 525 | branch: 'stable/icehouse'} |
353 | 512 | directory: /mnt/openstack-git | 526 | directory: /mnt/openstack-git |
356 | 513 | http_proxy: http://squid.internal:3128 | 527 | http_proxy: squid-proxy-url |
357 | 514 | https_proxy: https://squid.internal:3128 | 528 | https_proxy: squid-proxy-url |
358 | 515 | 529 | ||
359 | 516 | The directory, http_proxy, and https_proxy keys are optional. | 530 | The directory, http_proxy, and https_proxy keys are optional. |
360 | 517 | """ | 531 | """ |
361 | 518 | global requirements_dir | 532 | global requirements_dir |
362 | 519 | parent_dir = '/mnt/openstack-git' | 533 | parent_dir = '/mnt/openstack-git' |
368 | 520 | 534 | http_proxy = None | |
369 | 521 | if not projects_yaml: | 535 | |
370 | 522 | return | 536 | projects = _git_yaml_load(projects_yaml) |
366 | 523 | |||
367 | 524 | projects = yaml.load(projects_yaml) | ||
371 | 525 | _git_validate_projects_yaml(projects, core_project) | 537 | _git_validate_projects_yaml(projects, core_project) |
372 | 526 | 538 | ||
373 | 527 | old_environ = dict(os.environ) | 539 | old_environ = dict(os.environ) |
374 | 528 | 540 | ||
375 | 529 | if 'http_proxy' in projects.keys(): | 541 | if 'http_proxy' in projects.keys(): |
376 | 542 | http_proxy = projects['http_proxy'] | ||
377 | 530 | os.environ['http_proxy'] = projects['http_proxy'] | 543 | os.environ['http_proxy'] = projects['http_proxy'] |
378 | 531 | if 'https_proxy' in projects.keys(): | 544 | if 'https_proxy' in projects.keys(): |
379 | 532 | os.environ['https_proxy'] = projects['https_proxy'] | 545 | os.environ['https_proxy'] = projects['https_proxy'] |
380 | @@ -534,15 +547,19 @@ | |||
381 | 534 | if 'directory' in projects.keys(): | 547 | if 'directory' in projects.keys(): |
382 | 535 | parent_dir = projects['directory'] | 548 | parent_dir = projects['directory'] |
383 | 536 | 549 | ||
384 | 550 | pip_create_virtualenv(os.path.join(parent_dir, 'venv')) | ||
385 | 551 | |||
386 | 537 | for p in projects['repositories']: | 552 | for p in projects['repositories']: |
387 | 538 | repo = p['repository'] | 553 | repo = p['repository'] |
388 | 539 | branch = p['branch'] | 554 | branch = p['branch'] |
389 | 540 | if p['name'] == 'requirements': | 555 | if p['name'] == 'requirements': |
391 | 541 | repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, | 556 | repo_dir = _git_clone_and_install_single(repo, branch, depth, |
392 | 557 | parent_dir, http_proxy, | ||
393 | 542 | update_requirements=False) | 558 | update_requirements=False) |
394 | 543 | requirements_dir = repo_dir | 559 | requirements_dir = repo_dir |
395 | 544 | else: | 560 | else: |
397 | 545 | repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, | 561 | repo_dir = _git_clone_and_install_single(repo, branch, depth, |
398 | 562 | parent_dir, http_proxy, | ||
399 | 546 | update_requirements=True) | 563 | update_requirements=True) |
400 | 547 | 564 | ||
401 | 548 | os.environ = old_environ | 565 | os.environ = old_environ |
402 | @@ -574,7 +591,8 @@ | |||
403 | 574 | error_out('openstack-origin-git key \'{}\' is missing'.format(key)) | 591 | error_out('openstack-origin-git key \'{}\' is missing'.format(key)) |
404 | 575 | 592 | ||
405 | 576 | 593 | ||
407 | 577 | def _git_clone_and_install_single(repo, branch, parent_dir, update_requirements): | 594 | def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy, |
408 | 595 | update_requirements): | ||
409 | 578 | """ | 596 | """ |
410 | 579 | Clone and install a single git repository. | 597 | Clone and install a single git repository. |
411 | 580 | """ | 598 | """ |
412 | @@ -587,7 +605,8 @@ | |||
413 | 587 | 605 | ||
414 | 588 | if not os.path.exists(dest_dir): | 606 | if not os.path.exists(dest_dir): |
415 | 589 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) | 607 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) |
417 | 590 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch) | 608 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch, |
418 | 609 | depth=depth) | ||
419 | 591 | else: | 610 | else: |
420 | 592 | repo_dir = dest_dir | 611 | repo_dir = dest_dir |
421 | 593 | 612 | ||
422 | @@ -598,7 +617,12 @@ | |||
423 | 598 | _git_update_requirements(repo_dir, requirements_dir) | 617 | _git_update_requirements(repo_dir, requirements_dir) |
424 | 599 | 618 | ||
425 | 600 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) | 619 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) |
427 | 601 | pip_install(repo_dir) | 620 | if http_proxy: |
428 | 621 | pip_install(repo_dir, proxy=http_proxy, | ||
429 | 622 | venv=os.path.join(parent_dir, 'venv')) | ||
430 | 623 | else: | ||
431 | 624 | pip_install(repo_dir, | ||
432 | 625 | venv=os.path.join(parent_dir, 'venv')) | ||
433 | 602 | 626 | ||
434 | 603 | return repo_dir | 627 | return repo_dir |
435 | 604 | 628 | ||
436 | @@ -621,16 +645,27 @@ | |||
437 | 621 | os.chdir(orig_dir) | 645 | os.chdir(orig_dir) |
438 | 622 | 646 | ||
439 | 623 | 647 | ||
440 | 648 | def git_pip_venv_dir(projects_yaml): | ||
441 | 649 | """ | ||
442 | 650 | Return the pip virtualenv path. | ||
443 | 651 | """ | ||
444 | 652 | parent_dir = '/mnt/openstack-git' | ||
445 | 653 | |||
446 | 654 | projects = _git_yaml_load(projects_yaml) | ||
447 | 655 | |||
448 | 656 | if 'directory' in projects.keys(): | ||
449 | 657 | parent_dir = projects['directory'] | ||
450 | 658 | |||
451 | 659 | return os.path.join(parent_dir, 'venv') | ||
452 | 660 | |||
453 | 661 | |||
454 | 624 | def git_src_dir(projects_yaml, project): | 662 | def git_src_dir(projects_yaml, project): |
455 | 625 | """ | 663 | """ |
456 | 626 | Return the directory where the specified project's source is located. | 664 | Return the directory where the specified project's source is located. |
457 | 627 | """ | 665 | """ |
458 | 628 | parent_dir = '/mnt/openstack-git' | 666 | parent_dir = '/mnt/openstack-git' |
459 | 629 | 667 | ||
464 | 630 | if not projects_yaml: | 668 | projects = _git_yaml_load(projects_yaml) |
461 | 631 | return | ||
462 | 632 | |||
463 | 633 | projects = yaml.load(projects_yaml) | ||
465 | 634 | 669 | ||
466 | 635 | if 'directory' in projects.keys(): | 670 | if 'directory' in projects.keys(): |
467 | 636 | parent_dir = projects['directory'] | 671 | parent_dir = projects['directory'] |
468 | @@ -640,3 +675,15 @@ | |||
469 | 640 | return os.path.join(parent_dir, os.path.basename(p['repository'])) | 675 | return os.path.join(parent_dir, os.path.basename(p['repository'])) |
470 | 641 | 676 | ||
471 | 642 | return None | 677 | return None |
472 | 678 | |||
473 | 679 | |||
474 | 680 | def git_yaml_value(projects_yaml, key): | ||
475 | 681 | """ | ||
476 | 682 | Return the value in projects_yaml for the specified key. | ||
477 | 683 | """ | ||
478 | 684 | projects = _git_yaml_load(projects_yaml) | ||
479 | 685 | |||
480 | 686 | if key in projects.keys(): | ||
481 | 687 | return projects[key] | ||
482 | 688 | |||
483 | 689 | return None | ||
484 | 643 | 690 | ||
485 | === modified file 'hooks/charmhelpers/contrib/python/packages.py' | |||
486 | --- hooks/charmhelpers/contrib/python/packages.py 2015-02-24 11:02:02 +0000 | |||
487 | +++ hooks/charmhelpers/contrib/python/packages.py 2015-06-04 23:07:06 +0000 | |||
488 | @@ -17,8 +17,11 @@ | |||
489 | 17 | # You should have received a copy of the GNU Lesser General Public License | 17 | # You should have received a copy of the GNU Lesser General Public License |
490 | 18 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
491 | 19 | 19 | ||
492 | 20 | import os | ||
493 | 21 | import subprocess | ||
494 | 22 | |||
495 | 20 | from charmhelpers.fetch import apt_install, apt_update | 23 | from charmhelpers.fetch import apt_install, apt_update |
497 | 21 | from charmhelpers.core.hookenv import log | 24 | from charmhelpers.core.hookenv import charm_dir, log |
498 | 22 | 25 | ||
499 | 23 | try: | 26 | try: |
500 | 24 | from pip import main as pip_execute | 27 | from pip import main as pip_execute |
501 | @@ -51,11 +54,15 @@ | |||
502 | 51 | pip_execute(command) | 54 | pip_execute(command) |
503 | 52 | 55 | ||
504 | 53 | 56 | ||
506 | 54 | def pip_install(package, fatal=False, upgrade=False, **options): | 57 | def pip_install(package, fatal=False, upgrade=False, venv=None, **options): |
507 | 55 | """Install a python package""" | 58 | """Install a python package""" |
509 | 56 | command = ["install"] | 59 | if venv: |
510 | 60 | venv_python = os.path.join(venv, 'bin/pip') | ||
511 | 61 | command = [venv_python, "install"] | ||
512 | 62 | else: | ||
513 | 63 | command = ["install"] | ||
514 | 57 | 64 | ||
516 | 58 | available_options = ('proxy', 'src', 'log', "index-url", ) | 65 | available_options = ('proxy', 'src', 'log', 'index-url', ) |
517 | 59 | for option in parse_options(options, available_options): | 66 | for option in parse_options(options, available_options): |
518 | 60 | command.append(option) | 67 | command.append(option) |
519 | 61 | 68 | ||
520 | @@ -69,7 +76,10 @@ | |||
521 | 69 | 76 | ||
522 | 70 | log("Installing {} package with options: {}".format(package, | 77 | log("Installing {} package with options: {}".format(package, |
523 | 71 | command)) | 78 | command)) |
525 | 72 | pip_execute(command) | 79 | if venv: |
526 | 80 | subprocess.check_call(command) | ||
527 | 81 | else: | ||
528 | 82 | pip_execute(command) | ||
529 | 73 | 83 | ||
530 | 74 | 84 | ||
531 | 75 | def pip_uninstall(package, **options): | 85 | def pip_uninstall(package, **options): |
532 | @@ -94,3 +104,16 @@ | |||
533 | 94 | """Returns the list of current python installed packages | 104 | """Returns the list of current python installed packages |
534 | 95 | """ | 105 | """ |
535 | 96 | return pip_execute(["list"]) | 106 | return pip_execute(["list"]) |
536 | 107 | |||
537 | 108 | |||
538 | 109 | def pip_create_virtualenv(path=None): | ||
539 | 110 | """Create an isolated Python environment.""" | ||
540 | 111 | apt_install('python-virtualenv') | ||
541 | 112 | |||
542 | 113 | if path: | ||
543 | 114 | venv_path = path | ||
544 | 115 | else: | ||
545 | 116 | venv_path = os.path.join(charm_dir(), 'venv') | ||
546 | 117 | |||
547 | 118 | if not os.path.exists(venv_path): | ||
548 | 119 | subprocess.check_call(['virtualenv', venv_path]) | ||
549 | 97 | 120 | ||
550 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
551 | --- hooks/charmhelpers/core/hookenv.py 2015-04-16 21:32:59 +0000 | |||
552 | +++ hooks/charmhelpers/core/hookenv.py 2015-06-04 23:07:06 +0000 | |||
553 | @@ -21,12 +21,14 @@ | |||
554 | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> |
555 | 22 | 22 | ||
556 | 23 | from __future__ import print_function | 23 | from __future__ import print_function |
557 | 24 | from functools import wraps | ||
558 | 24 | import os | 25 | import os |
559 | 25 | import json | 26 | import json |
560 | 26 | import yaml | 27 | import yaml |
561 | 27 | import subprocess | 28 | import subprocess |
562 | 28 | import sys | 29 | import sys |
563 | 29 | import errno | 30 | import errno |
564 | 31 | import tempfile | ||
565 | 30 | from subprocess import CalledProcessError | 32 | from subprocess import CalledProcessError |
566 | 31 | 33 | ||
567 | 32 | import six | 34 | import six |
568 | @@ -58,15 +60,17 @@ | |||
569 | 58 | 60 | ||
570 | 59 | will cache the result of unit_get + 'test' for future calls. | 61 | will cache the result of unit_get + 'test' for future calls. |
571 | 60 | """ | 62 | """ |
572 | 63 | @wraps(func) | ||
573 | 61 | def wrapper(*args, **kwargs): | 64 | def wrapper(*args, **kwargs): |
574 | 62 | global cache | 65 | global cache |
575 | 63 | key = str((func, args, kwargs)) | 66 | key = str((func, args, kwargs)) |
576 | 64 | try: | 67 | try: |
577 | 65 | return cache[key] | 68 | return cache[key] |
578 | 66 | except KeyError: | 69 | except KeyError: |
582 | 67 | res = func(*args, **kwargs) | 70 | pass # Drop out of the exception handler scope. |
583 | 68 | cache[key] = res | 71 | res = func(*args, **kwargs) |
584 | 69 | return res | 72 | cache[key] = res |
585 | 73 | return res | ||
586 | 70 | return wrapper | 74 | return wrapper |
587 | 71 | 75 | ||
588 | 72 | 76 | ||
589 | @@ -178,7 +182,7 @@ | |||
590 | 178 | 182 | ||
591 | 179 | def remote_unit(): | 183 | def remote_unit(): |
592 | 180 | """The remote unit for the current relation hook""" | 184 | """The remote unit for the current relation hook""" |
594 | 181 | return os.environ['JUJU_REMOTE_UNIT'] | 185 | return os.environ.get('JUJU_REMOTE_UNIT', None) |
595 | 182 | 186 | ||
596 | 183 | 187 | ||
597 | 184 | def service_name(): | 188 | def service_name(): |
598 | @@ -250,6 +254,12 @@ | |||
599 | 250 | except KeyError: | 254 | except KeyError: |
600 | 251 | return (self._prev_dict or {})[key] | 255 | return (self._prev_dict or {})[key] |
601 | 252 | 256 | ||
602 | 257 | def get(self, key, default=None): | ||
603 | 258 | try: | ||
604 | 259 | return self[key] | ||
605 | 260 | except KeyError: | ||
606 | 261 | return default | ||
607 | 262 | |||
608 | 253 | def keys(self): | 263 | def keys(self): |
609 | 254 | prev_keys = [] | 264 | prev_keys = [] |
610 | 255 | if self._prev_dict is not None: | 265 | if self._prev_dict is not None: |
611 | @@ -353,18 +363,49 @@ | |||
612 | 353 | """Set relation information for the current unit""" | 363 | """Set relation information for the current unit""" |
613 | 354 | relation_settings = relation_settings if relation_settings else {} | 364 | relation_settings = relation_settings if relation_settings else {} |
614 | 355 | relation_cmd_line = ['relation-set'] | 365 | relation_cmd_line = ['relation-set'] |
615 | 366 | accepts_file = "--file" in subprocess.check_output( | ||
616 | 367 | relation_cmd_line + ["--help"], universal_newlines=True) | ||
617 | 356 | if relation_id is not None: | 368 | if relation_id is not None: |
618 | 357 | relation_cmd_line.extend(('-r', relation_id)) | 369 | relation_cmd_line.extend(('-r', relation_id)) |
625 | 358 | for k, v in (list(relation_settings.items()) + list(kwargs.items())): | 370 | settings = relation_settings.copy() |
626 | 359 | if v is None: | 371 | settings.update(kwargs) |
627 | 360 | relation_cmd_line.append('{}='.format(k)) | 372 | for key, value in settings.items(): |
628 | 361 | else: | 373 | # Force value to be a string: it always should, but some call |
629 | 362 | relation_cmd_line.append('{}={}'.format(k, v)) | 374 | # sites pass in things like dicts or numbers. |
630 | 363 | subprocess.check_call(relation_cmd_line) | 375 | if value is not None: |
631 | 376 | settings[key] = "{}".format(value) | ||
632 | 377 | if accepts_file: | ||
633 | 378 | # --file was introduced in Juju 1.23.2. Use it by default if | ||
634 | 379 | # available, since otherwise we'll break if the relation data is | ||
635 | 380 | # too big. Ideally we should tell relation-set to read the data from | ||
636 | 381 | # stdin, but that feature is broken in 1.23.2: Bug #1454678. | ||
637 | 382 | with tempfile.NamedTemporaryFile(delete=False) as settings_file: | ||
638 | 383 | settings_file.write(yaml.safe_dump(settings).encode("utf-8")) | ||
639 | 384 | subprocess.check_call( | ||
640 | 385 | relation_cmd_line + ["--file", settings_file.name]) | ||
641 | 386 | os.remove(settings_file.name) | ||
642 | 387 | else: | ||
643 | 388 | for key, value in settings.items(): | ||
644 | 389 | if value is None: | ||
645 | 390 | relation_cmd_line.append('{}='.format(key)) | ||
646 | 391 | else: | ||
647 | 392 | relation_cmd_line.append('{}={}'.format(key, value)) | ||
648 | 393 | subprocess.check_call(relation_cmd_line) | ||
649 | 364 | # Flush cache of any relation-gets for local unit | 394 | # Flush cache of any relation-gets for local unit |
650 | 365 | flush(local_unit()) | 395 | flush(local_unit()) |
651 | 366 | 396 | ||
652 | 367 | 397 | ||
653 | 398 | def relation_clear(r_id=None): | ||
654 | 399 | ''' Clears any relation data already set on relation r_id ''' | ||
655 | 400 | settings = relation_get(rid=r_id, | ||
656 | 401 | unit=local_unit()) | ||
657 | 402 | for setting in settings: | ||
658 | 403 | if setting not in ['public-address', 'private-address']: | ||
659 | 404 | settings[setting] = None | ||
660 | 405 | relation_set(relation_id=r_id, | ||
661 | 406 | **settings) | ||
662 | 407 | |||
663 | 408 | |||
664 | 368 | @cached | 409 | @cached |
665 | 369 | def relation_ids(reltype=None): | 410 | def relation_ids(reltype=None): |
666 | 370 | """A list of relation_ids""" | 411 | """A list of relation_ids""" |
667 | @@ -509,6 +550,11 @@ | |||
668 | 509 | return None | 550 | return None |
669 | 510 | 551 | ||
670 | 511 | 552 | ||
671 | 553 | def unit_public_ip(): | ||
672 | 554 | """Get this unit's public IP address""" | ||
673 | 555 | return unit_get('public-address') | ||
674 | 556 | |||
675 | 557 | |||
676 | 512 | def unit_private_ip(): | 558 | def unit_private_ip(): |
677 | 513 | """Get this unit's private IP address""" | 559 | """Get this unit's private IP address""" |
678 | 514 | return unit_get('private-address') | 560 | return unit_get('private-address') |
679 | @@ -605,3 +651,94 @@ | |||
680 | 605 | 651 | ||
681 | 606 | The results set by action_set are preserved.""" | 652 | The results set by action_set are preserved.""" |
682 | 607 | subprocess.check_call(['action-fail', message]) | 653 | subprocess.check_call(['action-fail', message]) |
683 | 654 | |||
684 | 655 | |||
685 | 656 | def status_set(workload_state, message): | ||
686 | 657 | """Set the workload state with a message | ||
687 | 658 | |||
688 | 659 | Use status-set to set the workload state with a message which is visible | ||
689 | 660 | to the user via juju status. If the status-set command is not found then | ||
690 | 661 | assume this is juju < 1.23 and juju-log the message unstead. | ||
691 | 662 | |||
692 | 663 | workload_state -- valid juju workload state. | ||
693 | 664 | message -- status update message | ||
694 | 665 | """ | ||
695 | 666 | valid_states = ['maintenance', 'blocked', 'waiting', 'active'] | ||
696 | 667 | if workload_state not in valid_states: | ||
697 | 668 | raise ValueError( | ||
698 | 669 | '{!r} is not a valid workload state'.format(workload_state) | ||
699 | 670 | ) | ||
700 | 671 | cmd = ['status-set', workload_state, message] | ||
701 | 672 | try: | ||
702 | 673 | ret = subprocess.call(cmd) | ||
703 | 674 | if ret == 0: | ||
704 | 675 | return | ||
705 | 676 | except OSError as e: | ||
706 | 677 | if e.errno != errno.ENOENT: | ||
707 | 678 | raise | ||
708 | 679 | log_message = 'status-set failed: {} {}'.format(workload_state, | ||
709 | 680 | message) | ||
710 | 681 | log(log_message, level='INFO') | ||
711 | 682 | |||
712 | 683 | |||
713 | 684 | def status_get(): | ||
714 | 685 | """Retrieve the previously set juju workload state | ||
715 | 686 | |||
716 | 687 | If the status-set command is not found then assume this is juju < 1.23 and | ||
717 | 688 | return 'unknown' | ||
718 | 689 | """ | ||
719 | 690 | cmd = ['status-get'] | ||
720 | 691 | try: | ||
721 | 692 | raw_status = subprocess.check_output(cmd, universal_newlines=True) | ||
722 | 693 | status = raw_status.rstrip() | ||
723 | 694 | return status | ||
724 | 695 | except OSError as e: | ||
725 | 696 | if e.errno == errno.ENOENT: | ||
726 | 697 | return 'unknown' | ||
727 | 698 | else: | ||
728 | 699 | raise | ||
729 | 700 | |||
730 | 701 | |||
731 | 702 | def translate_exc(from_exc, to_exc): | ||
732 | 703 | def inner_translate_exc1(f): | ||
733 | 704 | def inner_translate_exc2(*args, **kwargs): | ||
734 | 705 | try: | ||
735 | 706 | return f(*args, **kwargs) | ||
736 | 707 | except from_exc: | ||
737 | 708 | raise to_exc | ||
738 | 709 | |||
739 | 710 | return inner_translate_exc2 | ||
740 | 711 | |||
741 | 712 | return inner_translate_exc1 | ||
742 | 713 | |||
743 | 714 | |||
744 | 715 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
745 | 716 | def is_leader(): | ||
746 | 717 | """Does the current unit hold the juju leadership | ||
747 | 718 | |||
748 | 719 | Uses juju to determine whether the current unit is the leader of its peers | ||
749 | 720 | """ | ||
750 | 721 | cmd = ['is-leader', '--format=json'] | ||
751 | 722 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
752 | 723 | |||
753 | 724 | |||
754 | 725 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
755 | 726 | def leader_get(attribute=None): | ||
756 | 727 | """Juju leader get value(s)""" | ||
757 | 728 | cmd = ['leader-get', '--format=json'] + [attribute or '-'] | ||
758 | 729 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
759 | 730 | |||
760 | 731 | |||
761 | 732 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
762 | 733 | def leader_set(settings=None, **kwargs): | ||
763 | 734 | """Juju leader set value(s)""" | ||
764 | 735 | log("Juju leader-set '%s'" % (settings), level=DEBUG) | ||
765 | 736 | cmd = ['leader-set'] | ||
766 | 737 | settings = settings or {} | ||
767 | 738 | settings.update(kwargs) | ||
768 | 739 | for k, v in settings.iteritems(): | ||
769 | 740 | if v is None: | ||
770 | 741 | cmd.append('{}='.format(k)) | ||
771 | 742 | else: | ||
772 | 743 | cmd.append('{}={}'.format(k, v)) | ||
773 | 744 | subprocess.check_call(cmd) | ||
774 | 608 | 745 | ||
775 | === modified file 'hooks/charmhelpers/core/host.py' | |||
776 | --- hooks/charmhelpers/core/host.py 2015-04-16 21:32:59 +0000 | |||
777 | +++ hooks/charmhelpers/core/host.py 2015-06-04 23:07:06 +0000 | |||
778 | @@ -90,7 +90,7 @@ | |||
779 | 90 | ['service', service_name, 'status'], | 90 | ['service', service_name, 'status'], |
780 | 91 | stderr=subprocess.STDOUT).decode('UTF-8') | 91 | stderr=subprocess.STDOUT).decode('UTF-8') |
781 | 92 | except subprocess.CalledProcessError as e: | 92 | except subprocess.CalledProcessError as e: |
783 | 93 | return 'unrecognized service' not in e.output | 93 | return b'unrecognized service' not in e.output |
784 | 94 | else: | 94 | else: |
785 | 95 | return True | 95 | return True |
786 | 96 | 96 | ||
787 | 97 | 97 | ||
788 | === modified file 'hooks/charmhelpers/core/services/base.py' | |||
789 | --- hooks/charmhelpers/core/services/base.py 2015-01-26 11:53:19 +0000 | |||
790 | +++ hooks/charmhelpers/core/services/base.py 2015-06-04 23:07:06 +0000 | |||
791 | @@ -15,9 +15,9 @@ | |||
792 | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with charm-helpers. If not, see <http://www.gnu.org/licenses/>. |
793 | 16 | 16 | ||
794 | 17 | import os | 17 | import os |
795 | 18 | import re | ||
796 | 19 | import json | 18 | import json |
798 | 20 | from collections import Iterable | 19 | from inspect import getargspec |
799 | 20 | from collections import Iterable, OrderedDict | ||
800 | 21 | 21 | ||
801 | 22 | from charmhelpers.core import host | 22 | from charmhelpers.core import host |
802 | 23 | from charmhelpers.core import hookenv | 23 | from charmhelpers.core import hookenv |
803 | @@ -119,7 +119,7 @@ | |||
804 | 119 | """ | 119 | """ |
805 | 120 | self._ready_file = os.path.join(hookenv.charm_dir(), 'READY-SERVICES.json') | 120 | self._ready_file = os.path.join(hookenv.charm_dir(), 'READY-SERVICES.json') |
806 | 121 | self._ready = None | 121 | self._ready = None |
808 | 122 | self.services = {} | 122 | self.services = OrderedDict() |
809 | 123 | for service in services or []: | 123 | for service in services or []: |
810 | 124 | service_name = service['service'] | 124 | service_name = service['service'] |
811 | 125 | self.services[service_name] = service | 125 | self.services[service_name] = service |
812 | @@ -132,8 +132,8 @@ | |||
813 | 132 | if hook_name == 'stop': | 132 | if hook_name == 'stop': |
814 | 133 | self.stop_services() | 133 | self.stop_services() |
815 | 134 | else: | 134 | else: |
816 | 135 | self.reconfigure_services() | ||
817 | 135 | self.provide_data() | 136 | self.provide_data() |
818 | 136 | self.reconfigure_services() | ||
819 | 137 | cfg = hookenv.config() | 137 | cfg = hookenv.config() |
820 | 138 | if cfg.implicit_save: | 138 | if cfg.implicit_save: |
821 | 139 | cfg.save() | 139 | cfg.save() |
822 | @@ -145,15 +145,36 @@ | |||
823 | 145 | A provider must have a `name` attribute, which indicates which relation | 145 | A provider must have a `name` attribute, which indicates which relation |
824 | 146 | to set data on, and a `provide_data()` method, which returns a dict of | 146 | to set data on, and a `provide_data()` method, which returns a dict of |
825 | 147 | data to set. | 147 | data to set. |
826 | 148 | |||
827 | 149 | The `provide_data()` method can optionally accept two parameters: | ||
828 | 150 | |||
829 | 151 | * ``remote_service`` The name of the remote service that the data will | ||
830 | 152 | be provided to. The `provide_data()` method will be called once | ||
831 | 153 | for each connected service (not unit). This allows the method to | ||
832 | 154 | tailor its data to the given service. | ||
833 | 155 | * ``service_ready`` Whether or not the service definition had all of | ||
834 | 156 | its requirements met, and thus the ``data_ready`` callbacks run. | ||
835 | 157 | |||
836 | 158 | Note that the ``provided_data`` methods are now called **after** the | ||
837 | 159 | ``data_ready`` callbacks are run. This gives the ``data_ready`` callbacks | ||
838 | 160 | a chance to generate any data necessary for the providing to the remote | ||
839 | 161 | services. | ||
840 | 148 | """ | 162 | """ |
843 | 149 | hook_name = hookenv.hook_name() | 163 | for service_name, service in self.services.items(): |
844 | 150 | for service in self.services.values(): | 164 | service_ready = self.is_ready(service_name) |
845 | 151 | for provider in service.get('provided_data', []): | 165 | for provider in service.get('provided_data', []): |
851 | 152 | if re.match(r'{}-relation-(joined|changed)'.format(provider.name), hook_name): | 166 | for relid in hookenv.relation_ids(provider.name): |
852 | 153 | data = provider.provide_data() | 167 | units = hookenv.related_units(relid) |
853 | 154 | _ready = provider._is_ready(data) if hasattr(provider, '_is_ready') else data | 168 | if not units: |
854 | 155 | if _ready: | 169 | continue |
855 | 156 | hookenv.relation_set(None, data) | 170 | remote_service = units[0].split('/')[0] |
856 | 171 | argspec = getargspec(provider.provide_data) | ||
857 | 172 | if len(argspec.args) > 1: | ||
858 | 173 | data = provider.provide_data(remote_service, service_ready) | ||
859 | 174 | else: | ||
860 | 175 | data = provider.provide_data() | ||
861 | 176 | if data: | ||
862 | 177 | hookenv.relation_set(relid, data) | ||
863 | 157 | 178 | ||
864 | 158 | def reconfigure_services(self, *service_names): | 179 | def reconfigure_services(self, *service_names): |
865 | 159 | """ | 180 | """ |
866 | 160 | 181 | ||
867 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
868 | --- hooks/charmhelpers/fetch/__init__.py 2015-01-26 11:53:19 +0000 | |||
869 | +++ hooks/charmhelpers/fetch/__init__.py 2015-06-04 23:07:06 +0000 | |||
870 | @@ -158,7 +158,7 @@ | |||
871 | 158 | 158 | ||
872 | 159 | def apt_cache(in_memory=True): | 159 | def apt_cache(in_memory=True): |
873 | 160 | """Build and return an apt cache""" | 160 | """Build and return an apt cache""" |
875 | 161 | import apt_pkg | 161 | from apt import apt_pkg |
876 | 162 | apt_pkg.init() | 162 | apt_pkg.init() |
877 | 163 | if in_memory: | 163 | if in_memory: |
878 | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") |
879 | 165 | 165 | ||
880 | === modified file 'hooks/charmhelpers/fetch/giturl.py' | |||
881 | --- hooks/charmhelpers/fetch/giturl.py 2015-02-24 11:02:02 +0000 | |||
882 | +++ hooks/charmhelpers/fetch/giturl.py 2015-06-04 23:07:06 +0000 | |||
883 | @@ -45,14 +45,16 @@ | |||
884 | 45 | else: | 45 | else: |
885 | 46 | return True | 46 | return True |
886 | 47 | 47 | ||
888 | 48 | def clone(self, source, dest, branch): | 48 | def clone(self, source, dest, branch, depth=None): |
889 | 49 | if not self.can_handle(source): | 49 | if not self.can_handle(source): |
890 | 50 | raise UnhandledSource("Cannot handle {}".format(source)) | 50 | raise UnhandledSource("Cannot handle {}".format(source)) |
891 | 51 | 51 | ||
894 | 52 | repo = Repo.clone_from(source, dest) | 52 | if depth: |
895 | 53 | repo.git.checkout(branch) | 53 | Repo.clone_from(source, dest, branch=branch, depth=depth) |
896 | 54 | else: | ||
897 | 55 | Repo.clone_from(source, dest, branch=branch) | ||
898 | 54 | 56 | ||
900 | 55 | def install(self, source, branch="master", dest=None): | 57 | def install(self, source, branch="master", dest=None, depth=None): |
901 | 56 | url_parts = self.parse_url(source) | 58 | url_parts = self.parse_url(source) |
902 | 57 | branch_name = url_parts.path.strip("/").split("/")[-1] | 59 | branch_name = url_parts.path.strip("/").split("/")[-1] |
903 | 58 | if dest: | 60 | if dest: |
904 | @@ -63,7 +65,7 @@ | |||
905 | 63 | if not os.path.exists(dest_dir): | 65 | if not os.path.exists(dest_dir): |
906 | 64 | mkdir(dest_dir, perms=0o755) | 66 | mkdir(dest_dir, perms=0o755) |
907 | 65 | try: | 67 | try: |
909 | 66 | self.clone(source, dest_dir, branch) | 68 | self.clone(source, dest_dir, branch, depth) |
910 | 67 | except GitCommandError as e: | 69 | except GitCommandError as e: |
911 | 68 | raise UnhandledSource(e.message) | 70 | raise UnhandledSource(e.message) |
912 | 69 | except OSError as e: | 71 | except OSError as e: |
913 | 70 | 72 | ||
914 | === modified file 'hooks/hooks.py' | |||
915 | --- hooks/hooks.py 2015-04-28 21:18:24 +0000 | |||
916 | +++ hooks/hooks.py 2015-06-04 23:07:06 +0000 | |||
917 | @@ -50,10 +50,9 @@ | |||
918 | 50 | from charmhelpers.contrib.network.ip import ( | 50 | from charmhelpers.contrib.network.ip import ( |
919 | 51 | get_iface_for_address, | 51 | get_iface_for_address, |
920 | 52 | get_netmask_for_address, | 52 | get_netmask_for_address, |
921 | 53 | is_ipv6, | ||
922 | 54 | ) | 53 | ) |
923 | 55 | from charmhelpers.contrib.openstack.ip import ( | 54 | from charmhelpers.contrib.openstack.ip import ( |
925 | 56 | resolve_address, | 55 | canonical_url, |
926 | 57 | PUBLIC, INTERNAL, ADMIN, | 56 | PUBLIC, INTERNAL, ADMIN, |
927 | 58 | ) | 57 | ) |
928 | 59 | 58 | ||
929 | @@ -273,16 +272,6 @@ | |||
930 | 273 | open_port(port=80) | 272 | open_port(port=80) |
931 | 274 | 273 | ||
932 | 275 | 274 | ||
933 | 276 | # XXX Define local canonical_url until charm has been updated to use the | ||
934 | 277 | # standard context architecture. | ||
935 | 278 | def canonical_url(configs, endpoint_type=PUBLIC): | ||
936 | 279 | scheme = 'http' | ||
937 | 280 | address = resolve_address(endpoint_type) | ||
938 | 281 | if is_ipv6(address): | ||
939 | 282 | address = "[{}]".format(address) | ||
940 | 283 | return '%s://%s' % (scheme, address) | ||
941 | 284 | |||
942 | 285 | |||
943 | 286 | @hooks.hook('identity-service-relation-joined') | 275 | @hooks.hook('identity-service-relation-joined') |
944 | 287 | def identity_joined(relid=None): | 276 | def identity_joined(relid=None): |
945 | 288 | if cmp_pkgrevno('radosgw', '0.55') < 0: | 277 | if cmp_pkgrevno('radosgw', '0.55') < 0: |
946 | @@ -290,11 +279,11 @@ | |||
947 | 290 | sys.exit(1) | 279 | sys.exit(1) |
948 | 291 | 280 | ||
949 | 292 | port = 80 | 281 | port = 80 |
951 | 293 | admin_url = '%s:%i/swift' % (canonical_url(ADMIN), port) | 282 | admin_url = '%s:%i/swift' % (canonical_url(None, ADMIN), port) |
952 | 294 | internal_url = '%s:%s/swift/v1' % \ | 283 | internal_url = '%s:%s/swift/v1' % \ |
954 | 295 | (canonical_url(INTERNAL), port) | 284 | (canonical_url(None, INTERNAL), port) |
955 | 296 | public_url = '%s:%s/swift/v1' % \ | 285 | public_url = '%s:%s/swift/v1' % \ |
957 | 297 | (canonical_url(PUBLIC), port) | 286 | (canonical_url(None, PUBLIC), port) |
958 | 298 | relation_set(service='swift', | 287 | relation_set(service='swift', |
959 | 299 | region=config('region'), | 288 | region=config('region'), |
960 | 300 | public_url=public_url, internal_url=internal_url, | 289 | public_url=public_url, internal_url=internal_url, |
961 | 301 | 290 | ||
962 | === modified file 'tests/charmhelpers/contrib/amulet/utils.py' | |||
963 | --- tests/charmhelpers/contrib/amulet/utils.py 2015-04-16 21:32:59 +0000 | |||
964 | +++ tests/charmhelpers/contrib/amulet/utils.py 2015-06-04 23:07:06 +0000 | |||
965 | @@ -79,6 +79,9 @@ | |||
966 | 79 | for k, v in six.iteritems(commands): | 79 | for k, v in six.iteritems(commands): |
967 | 80 | for cmd in v: | 80 | for cmd in v: |
968 | 81 | output, code = k.run(cmd) | 81 | output, code = k.run(cmd) |
969 | 82 | self.log.debug('{} `{}` returned ' | ||
970 | 83 | '{}'.format(k.info['unit_name'], | ||
971 | 84 | cmd, code)) | ||
972 | 82 | if code != 0: | 85 | if code != 0: |
973 | 83 | return "command `{}` returned {}".format(cmd, str(code)) | 86 | return "command `{}` returned {}".format(cmd, str(code)) |
974 | 84 | return None | 87 | return None |
975 | @@ -86,7 +89,11 @@ | |||
976 | 86 | def _get_config(self, unit, filename): | 89 | def _get_config(self, unit, filename): |
977 | 87 | """Get a ConfigParser object for parsing a unit's config file.""" | 90 | """Get a ConfigParser object for parsing a unit's config file.""" |
978 | 88 | file_contents = unit.file_contents(filename) | 91 | file_contents = unit.file_contents(filename) |
980 | 89 | config = ConfigParser.ConfigParser() | 92 | |
981 | 93 | # NOTE(beisner): by default, ConfigParser does not handle options | ||
982 | 94 | # with no value, such as the flags used in the mysql my.cnf file. | ||
983 | 95 | # https://bugs.python.org/issue7005 | ||
984 | 96 | config = ConfigParser.ConfigParser(allow_no_value=True) | ||
985 | 90 | config.readfp(io.StringIO(file_contents)) | 97 | config.readfp(io.StringIO(file_contents)) |
986 | 91 | return config | 98 | return config |
987 | 92 | 99 | ||
988 | 93 | 100 | ||
989 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
990 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-04-16 21:32:59 +0000 | |||
991 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-06-04 23:07:06 +0000 | |||
992 | @@ -46,15 +46,22 @@ | |||
993 | 46 | stable or next branches for the other_services.""" | 46 | stable or next branches for the other_services.""" |
994 | 47 | base_charms = ['mysql', 'mongodb'] | 47 | base_charms = ['mysql', 'mongodb'] |
995 | 48 | 48 | ||
996 | 49 | if self.series in ['precise', 'trusty']: | ||
997 | 50 | base_series = self.series | ||
998 | 51 | else: | ||
999 | 52 | base_series = self.current_next | ||
1000 | 53 | |||
1001 | 49 | if self.stable: | 54 | if self.stable: |
1002 | 50 | for svc in other_services: | 55 | for svc in other_services: |
1005 | 51 | temp = 'lp:charms/{}' | 56 | temp = 'lp:charms/{}/{}' |
1006 | 52 | svc['location'] = temp.format(svc['name']) | 57 | svc['location'] = temp.format(base_series, |
1007 | 58 | svc['name']) | ||
1008 | 53 | else: | 59 | else: |
1009 | 54 | for svc in other_services: | 60 | for svc in other_services: |
1010 | 55 | if svc['name'] in base_charms: | 61 | if svc['name'] in base_charms: |
1013 | 56 | temp = 'lp:charms/{}' | 62 | temp = 'lp:charms/{}/{}' |
1014 | 57 | svc['location'] = temp.format(svc['name']) | 63 | svc['location'] = temp.format(base_series, |
1015 | 64 | svc['name']) | ||
1016 | 58 | else: | 65 | else: |
1017 | 59 | temp = 'lp:~openstack-charmers/charms/{}/{}/next' | 66 | temp = 'lp:~openstack-charmers/charms/{}/{}/next' |
1018 | 60 | svc['location'] = temp.format(self.current_next, | 67 | svc['location'] = temp.format(self.current_next, |
1019 | @@ -99,10 +106,12 @@ | |||
1020 | 99 | Return an integer representing the enum value of the openstack | 106 | Return an integer representing the enum value of the openstack |
1021 | 100 | release. | 107 | release. |
1022 | 101 | """ | 108 | """ |
1023 | 109 | # Must be ordered by OpenStack release (not by Ubuntu release): | ||
1024 | 102 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, |
1025 | 103 | self.precise_havana, self.precise_icehouse, | 111 | self.precise_havana, self.precise_icehouse, |
1028 | 104 | self.trusty_icehouse, self.trusty_juno, self.trusty_kilo, | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
1029 | 105 | self.utopic_juno, self.vivid_kilo) = range(10) | 113 | self.trusty_kilo, self.vivid_kilo) = range(10) |
1030 | 114 | |||
1031 | 106 | releases = { | 115 | releases = { |
1032 | 107 | ('precise', None): self.precise_essex, | 116 | ('precise', None): self.precise_essex, |
1033 | 108 | ('precise', 'cloud:precise-folsom'): self.precise_folsom, | 117 | ('precise', 'cloud:precise-folsom'): self.precise_folsom, |
1034 | 109 | 118 | ||
1035 | === modified file 'unit_tests/test_hooks.py' | |||
1036 | --- unit_tests/test_hooks.py 2015-04-28 21:18:24 +0000 | |||
1037 | +++ unit_tests/test_hooks.py 2015-06-04 23:07:06 +0000 | |||
1038 | @@ -8,6 +8,7 @@ | |||
1039 | 8 | CharmTestCase, | 8 | CharmTestCase, |
1040 | 9 | patch_open | 9 | patch_open |
1041 | 10 | ) | 10 | ) |
1042 | 11 | from charmhelpers.contrib.openstack.ip import PUBLIC | ||
1043 | 11 | 12 | ||
1044 | 12 | dnsmock = MagicMock() | 13 | dnsmock = MagicMock() |
1045 | 13 | modules = { | 14 | modules = { |
1046 | @@ -45,7 +46,6 @@ | |||
1047 | 45 | 'relation_set', | 46 | 'relation_set', |
1048 | 46 | 'relation_get', | 47 | 'relation_get', |
1049 | 47 | 'render_template', | 48 | 'render_template', |
1050 | 48 | 'resolve_address', | ||
1051 | 49 | 'shutil', | 49 | 'shutil', |
1052 | 50 | 'subprocess', | 50 | 'subprocess', |
1053 | 51 | 'sys', | 51 | 'sys', |
1054 | @@ -323,14 +323,22 @@ | |||
1055 | 323 | cmd = ['service', 'radosgw', 'restart'] | 323 | cmd = ['service', 'radosgw', 'restart'] |
1056 | 324 | self.subprocess.call.assert_called_with(cmd) | 324 | self.subprocess.call.assert_called_with(cmd) |
1057 | 325 | 325 | ||
1059 | 326 | def test_identity_joined_early_version(self): | 326 | @patch('charmhelpers.contrib.openstack.ip.service_name', |
1060 | 327 | lambda *args: 'ceph-radosgw') | ||
1061 | 328 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
1062 | 329 | def test_identity_joined_early_version(self, _config): | ||
1063 | 327 | self.cmp_pkgrevno.return_value = -1 | 330 | self.cmp_pkgrevno.return_value = -1 |
1064 | 328 | ceph_hooks.identity_joined() | 331 | ceph_hooks.identity_joined() |
1065 | 329 | self.sys.exit.assert_called_with(1) | 332 | self.sys.exit.assert_called_with(1) |
1066 | 330 | 333 | ||
1068 | 331 | def test_identity_joined(self): | 334 | @patch('charmhelpers.contrib.openstack.ip.service_name', |
1069 | 335 | lambda *args: 'ceph-radosgw') | ||
1070 | 336 | @patch('charmhelpers.contrib.openstack.ip.resolve_address') | ||
1071 | 337 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
1072 | 338 | def test_identity_joined(self, _config, _resolve_address): | ||
1073 | 332 | self.cmp_pkgrevno.return_value = 1 | 339 | self.cmp_pkgrevno.return_value = 1 |
1075 | 333 | self.resolve_address.return_value = 'myserv' | 340 | _resolve_address.return_value = 'myserv' |
1076 | 341 | _config.side_effect = self.test_config.get | ||
1077 | 334 | self.test_config.set('region', 'region1') | 342 | self.test_config.set('region', 'region1') |
1078 | 335 | self.test_config.set('operator-roles', 'admin') | 343 | self.test_config.set('operator-roles', 'admin') |
1079 | 336 | self.unit_get.return_value = 'myserv' | 344 | self.unit_get.return_value = 'myserv' |
1080 | @@ -344,6 +352,27 @@ | |||
1081 | 344 | relation_id='rid', | 352 | relation_id='rid', |
1082 | 345 | admin_url='http://myserv:80/swift') | 353 | admin_url='http://myserv:80/swift') |
1083 | 346 | 354 | ||
1084 | 355 | @patch('charmhelpers.contrib.openstack.ip.service_name', | ||
1085 | 356 | lambda *args: 'ceph-radosgw') | ||
1086 | 357 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
1087 | 358 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
1088 | 359 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
1089 | 360 | def test_identity_joined_public_name(self, _config, _unit_get, | ||
1090 | 361 | _is_clustered): | ||
1091 | 362 | _config.side_effect = self.test_config.get | ||
1092 | 363 | self.test_config.set('os-public-hostname', 'files.example.com') | ||
1093 | 364 | _unit_get.return_value = 'myserv' | ||
1094 | 365 | _is_clustered.return_value = False | ||
1095 | 366 | ceph_hooks.identity_joined(relid='rid') | ||
1096 | 367 | self.relation_set.assert_called_with( | ||
1097 | 368 | service='swift', | ||
1098 | 369 | region='RegionOne', | ||
1099 | 370 | public_url='http://files.example.com:80/swift/v1', | ||
1100 | 371 | internal_url='http://myserv:80/swift/v1', | ||
1101 | 372 | requested_roles='Member,Admin', | ||
1102 | 373 | relation_id='rid', | ||
1103 | 374 | admin_url='http://myserv:80/swift') | ||
1104 | 375 | |||
1105 | 347 | def test_identity_changed(self): | 376 | def test_identity_changed(self): |
1106 | 348 | _emit_cephconf = self.patch('emit_cephconf') | 377 | _emit_cephconf = self.patch('emit_cephconf') |
1107 | 349 | _restart = self.patch('restart') | 378 | _restart = self.patch('restart') |
1108 | @@ -351,10 +380,15 @@ | |||
1109 | 351 | _emit_cephconf.assert_called() | 380 | _emit_cephconf.assert_called() |
1110 | 352 | _restart.assert_called() | 381 | _restart.assert_called() |
1111 | 353 | 382 | ||
1113 | 354 | def test_canonical_url_ipv6(self): | 383 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') |
1114 | 384 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
1115 | 385 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
1116 | 386 | def test_canonical_url_ipv6(self, _config, _unit_get, _is_clustered): | ||
1117 | 355 | ipv6_addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348' | 387 | ipv6_addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348' |
1120 | 356 | self.resolve_address.return_value = ipv6_addr | 388 | _config.side_effect = self.test_config.get |
1121 | 357 | self.assertEquals(ceph_hooks.canonical_url({}), | 389 | _unit_get.return_value = ipv6_addr |
1122 | 390 | _is_clustered.return_value = False | ||
1123 | 391 | self.assertEquals(ceph_hooks.canonical_url({}, PUBLIC), | ||
1124 | 358 | 'http://[%s]' % ipv6_addr) | 392 | 'http://[%s]' % ipv6_addr) |
1125 | 359 | 393 | ||
1126 | 360 | @patch.object(ceph_hooks, 'CONFIGS') | 394 | @patch.object(ceph_hooks, 'CONFIGS') |
charm_lint_check #5049 ceph-radosgw-next for billy-olsen mp261011
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5049/