Merge lp:~billy-olsen/charms/trusty/ceilometer/public-endpoint-host into lp:~openstack-charmers-archive/charms/trusty/ceilometer/next
- Trusty Tahr (14.04)
- public-endpoint-host
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 85 |
Proposed branch: | lp:~billy-olsen/charms/trusty/ceilometer/public-endpoint-host |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/ceilometer/next |
Diff against target: |
924 lines (+404/-103) 12 files modified
config.yaml (+12/-0) hooks/charmhelpers/contrib/hahelpers/cluster.py (+25/-0) 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) unit_tests/test_ceilometer_hooks.py (+27/-3) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/ceilometer/public-endpoint-host |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+261004@code.launchpad.net |
Commit message
Description of the change
Provides a config option which allows the user to specify the public hostname used to advertise to keystone when creating endpoints.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4722 ceilometer-next for billy-olsen mp261004
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4448 ceilometer-next for billy-olsen mp261004
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
ERROR subprocess encountered error code 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Ryan Beisner (1chb1n) wrote : | # |
Amulet test also fails for trusty-icehouse ceilometer/next. It looks like either mongodb or ceilometer have had a change in expected behaviors and/or relations since the 15.04 release, and the functional test didn't get updated to reflect that.
So this failure is not specific to your proposal, but until I can track down the change that broke the test, your proposal can't be validated via the functional tests.
00:28:14.389 unexpected relation data in mongodb database - key 'replset' does not exist
Ryan Beisner (1chb1n) wrote : | # |
FYI, tracking bug for the amulet test. I'll work on that. https:/
Ryan Beisner (1chb1n) wrote : | # |
2015-06-04 11:19:46,514 _validate_dict_data DEBUG: actual: {u'private-
2015-06-04 11:19:46,514 _validate_dict_data DEBUG: expected: {'private-address': <bound method OpenStackAmulet
unexpected relation data in mongodb database - key 'replset' does not exist
Ryan Beisner (1chb1n) wrote : | # |
FYI, ceilometer/next amulet tests fixed and landed re: bug 1461911.
You may want to pull those changes into your branch.
- 87. By Billy Olsen
-
Merge with /next
- 88. By Billy Olsen
-
c-h sync
- 89. By Billy Olsen
-
Fix broken unit test from c-h sync
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4745 ceilometer-next for billy-olsen mp261004
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5066 ceilometer-next for billy-olsen mp261004
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5067 ceilometer-next for billy-olsen mp261004
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #4746 ceilometer-next for billy-olsen mp261004
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4473 ceilometer-next for billy-olsen mp261004
AMULET OK: passed
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4474 ceilometer-next for billy-olsen mp261004
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Corey Bryant (corey.bryant) wrote : | # |
Looks good, but are amulet tests still failing?
Billy Olsen (billy-olsen) wrote : | # |
Amulet tests were due to timeout unfortunately
Corey Bryant (corey.bryant) wrote : | # |
Fyi, I ran the amulet tests manually and they were successful:
Results: 6 passed, 0 failed, 0 errored
Preview Diff
1 | === modified file 'config.yaml' | |||
2 | --- config.yaml 2015-02-19 02:03:06 +0000 | |||
3 | +++ config.yaml 2015-06-04 23:04:28 +0000 | |||
4 | @@ -100,6 +100,18 @@ | |||
5 | 100 | 192.168.0.0/24) | 100 | 192.168.0.0/24) |
6 | 101 | . | 101 | . |
7 | 102 | This network will be used for public endpoints. | 102 | This network will be used for public endpoints. |
8 | 103 | os-public-hostname: | ||
9 | 104 | type: string | ||
10 | 105 | default: | ||
11 | 106 | description: | | ||
12 | 107 | The hostname or address of the public endpoints created for ceilometer | ||
13 | 108 | in the keystone identity provider. | ||
14 | 109 | . | ||
15 | 110 | This value will be used for public endpoints. For example, an | ||
16 | 111 | os-public-hostname set to 'ceilometer.example.com' with ssl enabled will | ||
17 | 112 | create the following public endpoints for ceilometer. | ||
18 | 113 | . | ||
19 | 114 | https://ceilometer.example.com:8777/ | ||
20 | 103 | # HA configuration settings | 115 | # HA configuration settings |
21 | 104 | vip: | 116 | vip: |
22 | 105 | type: string | 117 | type: string |
23 | 106 | 118 | ||
24 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
25 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-03-13 12:57:45 +0000 | |||
26 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-04 23:04:28 +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 12:57:45 +0000 | |||
76 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-04 23:04:28 +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 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
223 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2015-04-16 10:29:08 +0000 | |||
224 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-06-04 23:04:28 +0000 | |||
225 | @@ -256,11 +256,14 @@ | |||
226 | 256 | def parse_mappings(mappings): | 256 | def parse_mappings(mappings): |
227 | 257 | parsed = {} | 257 | parsed = {} |
228 | 258 | if mappings: | 258 | if mappings: |
230 | 259 | mappings = mappings.split(' ') | 259 | mappings = mappings.split() |
231 | 260 | for m in mappings: | 260 | for m in mappings: |
232 | 261 | p = m.partition(':') | 261 | p = m.partition(':') |
235 | 262 | if p[1] == ':': | 262 | key = p[0].strip() |
236 | 263 | parsed[p[0].strip()] = p[2].strip() | 263 | if p[1]: |
237 | 264 | parsed[key] = p[2].strip() | ||
238 | 265 | else: | ||
239 | 266 | parsed[key] = '' | ||
240 | 264 | 267 | ||
241 | 265 | return parsed | 268 | return parsed |
242 | 266 | 269 | ||
243 | @@ -283,13 +286,13 @@ | |||
244 | 283 | Returns dict of the form {bridge:port}. | 286 | Returns dict of the form {bridge:port}. |
245 | 284 | """ | 287 | """ |
246 | 285 | _mappings = parse_mappings(mappings) | 288 | _mappings = parse_mappings(mappings) |
248 | 286 | if not _mappings: | 289 | if not _mappings or list(_mappings.values()) == ['']: |
249 | 287 | if not mappings: | 290 | if not mappings: |
250 | 288 | return {} | 291 | return {} |
251 | 289 | 292 | ||
252 | 290 | # For backwards-compatibility we need to support port-only provided in | 293 | # For backwards-compatibility we need to support port-only provided in |
253 | 291 | # config. | 294 | # config. |
255 | 292 | _mappings = {default_bridge: mappings.split(' ')[0]} | 295 | _mappings = {default_bridge: mappings.split()[0]} |
256 | 293 | 296 | ||
257 | 294 | bridges = _mappings.keys() | 297 | bridges = _mappings.keys() |
258 | 295 | ports = _mappings.values() | 298 | ports = _mappings.values() |
259 | @@ -309,6 +312,8 @@ | |||
260 | 309 | 312 | ||
261 | 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. |
262 | 311 | 314 | ||
263 | 315 | The start:end range is optional and may be omitted. | ||
264 | 316 | |||
265 | 312 | Returns dict of the form {provider: (start, end)}. | 317 | Returns dict of the form {provider: (start, end)}. |
266 | 313 | """ | 318 | """ |
267 | 314 | _mappings = parse_mappings(mappings) | 319 | _mappings = parse_mappings(mappings) |
268 | 315 | 320 | ||
269 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
270 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-04-16 21:32:20 +0000 | |||
271 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-06-04 23:04:28 +0000 | |||
272 | @@ -53,9 +53,13 @@ | |||
273 | 53 | get_ipv6_addr | 53 | get_ipv6_addr |
274 | 54 | ) | 54 | ) |
275 | 55 | 55 | ||
276 | 56 | from charmhelpers.contrib.python.packages import ( | ||
277 | 57 | pip_create_virtualenv, | ||
278 | 58 | pip_install, | ||
279 | 59 | ) | ||
280 | 60 | |||
281 | 56 | from charmhelpers.core.host import lsb_release, mounts, umount | 61 | from charmhelpers.core.host import lsb_release, mounts, umount |
282 | 57 | from charmhelpers.fetch import apt_install, apt_cache, install_remote | 62 | from charmhelpers.fetch import apt_install, apt_cache, install_remote |
283 | 58 | from charmhelpers.contrib.python.packages import pip_install | ||
284 | 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 |
285 | 60 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device | 64 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device |
286 | 61 | 65 | ||
287 | @@ -497,7 +501,17 @@ | |||
288 | 497 | requirements_dir = None | 501 | requirements_dir = None |
289 | 498 | 502 | ||
290 | 499 | 503 | ||
292 | 500 | def git_clone_and_install(projects_yaml, core_project): | 504 | def _git_yaml_load(projects_yaml): |
293 | 505 | """ | ||
294 | 506 | Load the specified yaml into a dictionary. | ||
295 | 507 | """ | ||
296 | 508 | if not projects_yaml: | ||
297 | 509 | return None | ||
298 | 510 | |||
299 | 511 | return yaml.load(projects_yaml) | ||
300 | 512 | |||
301 | 513 | |||
302 | 514 | def git_clone_and_install(projects_yaml, core_project, depth=1): | ||
303 | 501 | """ | 515 | """ |
304 | 502 | Clone/install all specified OpenStack repositories. | 516 | Clone/install all specified OpenStack repositories. |
305 | 503 | 517 | ||
306 | @@ -510,23 +524,22 @@ | |||
307 | 510 | repository: 'git://git.openstack.org/openstack/requirements.git', | 524 | repository: 'git://git.openstack.org/openstack/requirements.git', |
308 | 511 | branch: 'stable/icehouse'} | 525 | branch: 'stable/icehouse'} |
309 | 512 | directory: /mnt/openstack-git | 526 | directory: /mnt/openstack-git |
312 | 513 | http_proxy: http://squid.internal:3128 | 527 | http_proxy: squid-proxy-url |
313 | 514 | https_proxy: https://squid.internal:3128 | 528 | https_proxy: squid-proxy-url |
314 | 515 | 529 | ||
315 | 516 | The directory, http_proxy, and https_proxy keys are optional. | 530 | The directory, http_proxy, and https_proxy keys are optional. |
316 | 517 | """ | 531 | """ |
317 | 518 | global requirements_dir | 532 | global requirements_dir |
318 | 519 | parent_dir = '/mnt/openstack-git' | 533 | parent_dir = '/mnt/openstack-git' |
324 | 520 | 534 | http_proxy = None | |
325 | 521 | if not projects_yaml: | 535 | |
326 | 522 | return | 536 | projects = _git_yaml_load(projects_yaml) |
322 | 523 | |||
323 | 524 | projects = yaml.load(projects_yaml) | ||
327 | 525 | _git_validate_projects_yaml(projects, core_project) | 537 | _git_validate_projects_yaml(projects, core_project) |
328 | 526 | 538 | ||
329 | 527 | old_environ = dict(os.environ) | 539 | old_environ = dict(os.environ) |
330 | 528 | 540 | ||
331 | 529 | if 'http_proxy' in projects.keys(): | 541 | if 'http_proxy' in projects.keys(): |
332 | 542 | http_proxy = projects['http_proxy'] | ||
333 | 530 | os.environ['http_proxy'] = projects['http_proxy'] | 543 | os.environ['http_proxy'] = projects['http_proxy'] |
334 | 531 | if 'https_proxy' in projects.keys(): | 544 | if 'https_proxy' in projects.keys(): |
335 | 532 | os.environ['https_proxy'] = projects['https_proxy'] | 545 | os.environ['https_proxy'] = projects['https_proxy'] |
336 | @@ -534,15 +547,19 @@ | |||
337 | 534 | if 'directory' in projects.keys(): | 547 | if 'directory' in projects.keys(): |
338 | 535 | parent_dir = projects['directory'] | 548 | parent_dir = projects['directory'] |
339 | 536 | 549 | ||
340 | 550 | pip_create_virtualenv(os.path.join(parent_dir, 'venv')) | ||
341 | 551 | |||
342 | 537 | for p in projects['repositories']: | 552 | for p in projects['repositories']: |
343 | 538 | repo = p['repository'] | 553 | repo = p['repository'] |
344 | 539 | branch = p['branch'] | 554 | branch = p['branch'] |
345 | 540 | if p['name'] == 'requirements': | 555 | if p['name'] == 'requirements': |
347 | 541 | repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, | 556 | repo_dir = _git_clone_and_install_single(repo, branch, depth, |
348 | 557 | parent_dir, http_proxy, | ||
349 | 542 | update_requirements=False) | 558 | update_requirements=False) |
350 | 543 | requirements_dir = repo_dir | 559 | requirements_dir = repo_dir |
351 | 544 | else: | 560 | else: |
353 | 545 | repo_dir = _git_clone_and_install_single(repo, branch, parent_dir, | 561 | repo_dir = _git_clone_and_install_single(repo, branch, depth, |
354 | 562 | parent_dir, http_proxy, | ||
355 | 546 | update_requirements=True) | 563 | update_requirements=True) |
356 | 547 | 564 | ||
357 | 548 | os.environ = old_environ | 565 | os.environ = old_environ |
358 | @@ -574,7 +591,8 @@ | |||
359 | 574 | error_out('openstack-origin-git key \'{}\' is missing'.format(key)) | 591 | error_out('openstack-origin-git key \'{}\' is missing'.format(key)) |
360 | 575 | 592 | ||
361 | 576 | 593 | ||
363 | 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, |
364 | 595 | update_requirements): | ||
365 | 578 | """ | 596 | """ |
366 | 579 | Clone and install a single git repository. | 597 | Clone and install a single git repository. |
367 | 580 | """ | 598 | """ |
368 | @@ -587,7 +605,8 @@ | |||
369 | 587 | 605 | ||
370 | 588 | if not os.path.exists(dest_dir): | 606 | if not os.path.exists(dest_dir): |
371 | 589 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) | 607 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) |
373 | 590 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch) | 608 | repo_dir = install_remote(repo, dest=parent_dir, branch=branch, |
374 | 609 | depth=depth) | ||
375 | 591 | else: | 610 | else: |
376 | 592 | repo_dir = dest_dir | 611 | repo_dir = dest_dir |
377 | 593 | 612 | ||
378 | @@ -598,7 +617,12 @@ | |||
379 | 598 | _git_update_requirements(repo_dir, requirements_dir) | 617 | _git_update_requirements(repo_dir, requirements_dir) |
380 | 599 | 618 | ||
381 | 600 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) | 619 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) |
383 | 601 | pip_install(repo_dir) | 620 | if http_proxy: |
384 | 621 | pip_install(repo_dir, proxy=http_proxy, | ||
385 | 622 | venv=os.path.join(parent_dir, 'venv')) | ||
386 | 623 | else: | ||
387 | 624 | pip_install(repo_dir, | ||
388 | 625 | venv=os.path.join(parent_dir, 'venv')) | ||
389 | 602 | 626 | ||
390 | 603 | return repo_dir | 627 | return repo_dir |
391 | 604 | 628 | ||
392 | @@ -621,16 +645,27 @@ | |||
393 | 621 | os.chdir(orig_dir) | 645 | os.chdir(orig_dir) |
394 | 622 | 646 | ||
395 | 623 | 647 | ||
396 | 648 | def git_pip_venv_dir(projects_yaml): | ||
397 | 649 | """ | ||
398 | 650 | Return the pip virtualenv path. | ||
399 | 651 | """ | ||
400 | 652 | parent_dir = '/mnt/openstack-git' | ||
401 | 653 | |||
402 | 654 | projects = _git_yaml_load(projects_yaml) | ||
403 | 655 | |||
404 | 656 | if 'directory' in projects.keys(): | ||
405 | 657 | parent_dir = projects['directory'] | ||
406 | 658 | |||
407 | 659 | return os.path.join(parent_dir, 'venv') | ||
408 | 660 | |||
409 | 661 | |||
410 | 624 | def git_src_dir(projects_yaml, project): | 662 | def git_src_dir(projects_yaml, project): |
411 | 625 | """ | 663 | """ |
412 | 626 | Return the directory where the specified project's source is located. | 664 | Return the directory where the specified project's source is located. |
413 | 627 | """ | 665 | """ |
414 | 628 | parent_dir = '/mnt/openstack-git' | 666 | parent_dir = '/mnt/openstack-git' |
415 | 629 | 667 | ||
420 | 630 | if not projects_yaml: | 668 | projects = _git_yaml_load(projects_yaml) |
417 | 631 | return | ||
418 | 632 | |||
419 | 633 | projects = yaml.load(projects_yaml) | ||
421 | 634 | 669 | ||
422 | 635 | if 'directory' in projects.keys(): | 670 | if 'directory' in projects.keys(): |
423 | 636 | parent_dir = projects['directory'] | 671 | parent_dir = projects['directory'] |
424 | @@ -640,3 +675,15 @@ | |||
425 | 640 | return os.path.join(parent_dir, os.path.basename(p['repository'])) | 675 | return os.path.join(parent_dir, os.path.basename(p['repository'])) |
426 | 641 | 676 | ||
427 | 642 | return None | 677 | return None |
428 | 678 | |||
429 | 679 | |||
430 | 680 | def git_yaml_value(projects_yaml, key): | ||
431 | 681 | """ | ||
432 | 682 | Return the value in projects_yaml for the specified key. | ||
433 | 683 | """ | ||
434 | 684 | projects = _git_yaml_load(projects_yaml) | ||
435 | 685 | |||
436 | 686 | if key in projects.keys(): | ||
437 | 687 | return projects[key] | ||
438 | 688 | |||
439 | 689 | return None | ||
440 | 643 | 690 | ||
441 | === modified file 'hooks/charmhelpers/contrib/python/packages.py' | |||
442 | --- hooks/charmhelpers/contrib/python/packages.py 2015-03-13 12:57:45 +0000 | |||
443 | +++ hooks/charmhelpers/contrib/python/packages.py 2015-06-04 23:04:28 +0000 | |||
444 | @@ -17,8 +17,11 @@ | |||
445 | 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 |
446 | 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/>. |
447 | 19 | 19 | ||
448 | 20 | import os | ||
449 | 21 | import subprocess | ||
450 | 22 | |||
451 | 20 | from charmhelpers.fetch import apt_install, apt_update | 23 | from charmhelpers.fetch import apt_install, apt_update |
453 | 21 | from charmhelpers.core.hookenv import log | 24 | from charmhelpers.core.hookenv import charm_dir, log |
454 | 22 | 25 | ||
455 | 23 | try: | 26 | try: |
456 | 24 | from pip import main as pip_execute | 27 | from pip import main as pip_execute |
457 | @@ -51,11 +54,15 @@ | |||
458 | 51 | pip_execute(command) | 54 | pip_execute(command) |
459 | 52 | 55 | ||
460 | 53 | 56 | ||
462 | 54 | def pip_install(package, fatal=False, upgrade=False, **options): | 57 | def pip_install(package, fatal=False, upgrade=False, venv=None, **options): |
463 | 55 | """Install a python package""" | 58 | """Install a python package""" |
465 | 56 | command = ["install"] | 59 | if venv: |
466 | 60 | venv_python = os.path.join(venv, 'bin/pip') | ||
467 | 61 | command = [venv_python, "install"] | ||
468 | 62 | else: | ||
469 | 63 | command = ["install"] | ||
470 | 57 | 64 | ||
472 | 58 | available_options = ('proxy', 'src', 'log', "index-url", ) | 65 | available_options = ('proxy', 'src', 'log', 'index-url', ) |
473 | 59 | for option in parse_options(options, available_options): | 66 | for option in parse_options(options, available_options): |
474 | 60 | command.append(option) | 67 | command.append(option) |
475 | 61 | 68 | ||
476 | @@ -69,7 +76,10 @@ | |||
477 | 69 | 76 | ||
478 | 70 | log("Installing {} package with options: {}".format(package, | 77 | log("Installing {} package with options: {}".format(package, |
479 | 71 | command)) | 78 | command)) |
481 | 72 | pip_execute(command) | 79 | if venv: |
482 | 80 | subprocess.check_call(command) | ||
483 | 81 | else: | ||
484 | 82 | pip_execute(command) | ||
485 | 73 | 83 | ||
486 | 74 | 84 | ||
487 | 75 | def pip_uninstall(package, **options): | 85 | def pip_uninstall(package, **options): |
488 | @@ -94,3 +104,16 @@ | |||
489 | 94 | """Returns the list of current python installed packages | 104 | """Returns the list of current python installed packages |
490 | 95 | """ | 105 | """ |
491 | 96 | return pip_execute(["list"]) | 106 | return pip_execute(["list"]) |
492 | 107 | |||
493 | 108 | |||
494 | 109 | def pip_create_virtualenv(path=None): | ||
495 | 110 | """Create an isolated Python environment.""" | ||
496 | 111 | apt_install('python-virtualenv') | ||
497 | 112 | |||
498 | 113 | if path: | ||
499 | 114 | venv_path = path | ||
500 | 115 | else: | ||
501 | 116 | venv_path = os.path.join(charm_dir(), 'venv') | ||
502 | 117 | |||
503 | 118 | if not os.path.exists(venv_path): | ||
504 | 119 | subprocess.check_call(['virtualenv', venv_path]) | ||
505 | 97 | 120 | ||
506 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
507 | --- hooks/charmhelpers/core/hookenv.py 2015-04-16 11:21:16 +0000 | |||
508 | +++ hooks/charmhelpers/core/hookenv.py 2015-06-04 23:04:28 +0000 | |||
509 | @@ -21,12 +21,14 @@ | |||
510 | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> |
511 | 22 | 22 | ||
512 | 23 | from __future__ import print_function | 23 | from __future__ import print_function |
513 | 24 | from functools import wraps | ||
514 | 24 | import os | 25 | import os |
515 | 25 | import json | 26 | import json |
516 | 26 | import yaml | 27 | import yaml |
517 | 27 | import subprocess | 28 | import subprocess |
518 | 28 | import sys | 29 | import sys |
519 | 29 | import errno | 30 | import errno |
520 | 31 | import tempfile | ||
521 | 30 | from subprocess import CalledProcessError | 32 | from subprocess import CalledProcessError |
522 | 31 | 33 | ||
523 | 32 | import six | 34 | import six |
524 | @@ -58,15 +60,17 @@ | |||
525 | 58 | 60 | ||
526 | 59 | will cache the result of unit_get + 'test' for future calls. | 61 | will cache the result of unit_get + 'test' for future calls. |
527 | 60 | """ | 62 | """ |
528 | 63 | @wraps(func) | ||
529 | 61 | def wrapper(*args, **kwargs): | 64 | def wrapper(*args, **kwargs): |
530 | 62 | global cache | 65 | global cache |
531 | 63 | key = str((func, args, kwargs)) | 66 | key = str((func, args, kwargs)) |
532 | 64 | try: | 67 | try: |
533 | 65 | return cache[key] | 68 | return cache[key] |
534 | 66 | except KeyError: | 69 | except KeyError: |
538 | 67 | res = func(*args, **kwargs) | 70 | pass # Drop out of the exception handler scope. |
539 | 68 | cache[key] = res | 71 | res = func(*args, **kwargs) |
540 | 69 | return res | 72 | cache[key] = res |
541 | 73 | return res | ||
542 | 70 | return wrapper | 74 | return wrapper |
543 | 71 | 75 | ||
544 | 72 | 76 | ||
545 | @@ -178,7 +182,7 @@ | |||
546 | 178 | 182 | ||
547 | 179 | def remote_unit(): | 183 | def remote_unit(): |
548 | 180 | """The remote unit for the current relation hook""" | 184 | """The remote unit for the current relation hook""" |
550 | 181 | return os.environ['JUJU_REMOTE_UNIT'] | 185 | return os.environ.get('JUJU_REMOTE_UNIT', None) |
551 | 182 | 186 | ||
552 | 183 | 187 | ||
553 | 184 | def service_name(): | 188 | def service_name(): |
554 | @@ -250,6 +254,12 @@ | |||
555 | 250 | except KeyError: | 254 | except KeyError: |
556 | 251 | return (self._prev_dict or {})[key] | 255 | return (self._prev_dict or {})[key] |
557 | 252 | 256 | ||
558 | 257 | def get(self, key, default=None): | ||
559 | 258 | try: | ||
560 | 259 | return self[key] | ||
561 | 260 | except KeyError: | ||
562 | 261 | return default | ||
563 | 262 | |||
564 | 253 | def keys(self): | 263 | def keys(self): |
565 | 254 | prev_keys = [] | 264 | prev_keys = [] |
566 | 255 | if self._prev_dict is not None: | 265 | if self._prev_dict is not None: |
567 | @@ -353,18 +363,49 @@ | |||
568 | 353 | """Set relation information for the current unit""" | 363 | """Set relation information for the current unit""" |
569 | 354 | relation_settings = relation_settings if relation_settings else {} | 364 | relation_settings = relation_settings if relation_settings else {} |
570 | 355 | relation_cmd_line = ['relation-set'] | 365 | relation_cmd_line = ['relation-set'] |
571 | 366 | accepts_file = "--file" in subprocess.check_output( | ||
572 | 367 | relation_cmd_line + ["--help"], universal_newlines=True) | ||
573 | 356 | if relation_id is not None: | 368 | if relation_id is not None: |
574 | 357 | relation_cmd_line.extend(('-r', relation_id)) | 369 | relation_cmd_line.extend(('-r', relation_id)) |
581 | 358 | for k, v in (list(relation_settings.items()) + list(kwargs.items())): | 370 | settings = relation_settings.copy() |
582 | 359 | if v is None: | 371 | settings.update(kwargs) |
583 | 360 | relation_cmd_line.append('{}='.format(k)) | 372 | for key, value in settings.items(): |
584 | 361 | else: | 373 | # Force value to be a string: it always should, but some call |
585 | 362 | relation_cmd_line.append('{}={}'.format(k, v)) | 374 | # sites pass in things like dicts or numbers. |
586 | 363 | subprocess.check_call(relation_cmd_line) | 375 | if value is not None: |
587 | 376 | settings[key] = "{}".format(value) | ||
588 | 377 | if accepts_file: | ||
589 | 378 | # --file was introduced in Juju 1.23.2. Use it by default if | ||
590 | 379 | # available, since otherwise we'll break if the relation data is | ||
591 | 380 | # too big. Ideally we should tell relation-set to read the data from | ||
592 | 381 | # stdin, but that feature is broken in 1.23.2: Bug #1454678. | ||
593 | 382 | with tempfile.NamedTemporaryFile(delete=False) as settings_file: | ||
594 | 383 | settings_file.write(yaml.safe_dump(settings).encode("utf-8")) | ||
595 | 384 | subprocess.check_call( | ||
596 | 385 | relation_cmd_line + ["--file", settings_file.name]) | ||
597 | 386 | os.remove(settings_file.name) | ||
598 | 387 | else: | ||
599 | 388 | for key, value in settings.items(): | ||
600 | 389 | if value is None: | ||
601 | 390 | relation_cmd_line.append('{}='.format(key)) | ||
602 | 391 | else: | ||
603 | 392 | relation_cmd_line.append('{}={}'.format(key, value)) | ||
604 | 393 | subprocess.check_call(relation_cmd_line) | ||
605 | 364 | # Flush cache of any relation-gets for local unit | 394 | # Flush cache of any relation-gets for local unit |
606 | 365 | flush(local_unit()) | 395 | flush(local_unit()) |
607 | 366 | 396 | ||
608 | 367 | 397 | ||
609 | 398 | def relation_clear(r_id=None): | ||
610 | 399 | ''' Clears any relation data already set on relation r_id ''' | ||
611 | 400 | settings = relation_get(rid=r_id, | ||
612 | 401 | unit=local_unit()) | ||
613 | 402 | for setting in settings: | ||
614 | 403 | if setting not in ['public-address', 'private-address']: | ||
615 | 404 | settings[setting] = None | ||
616 | 405 | relation_set(relation_id=r_id, | ||
617 | 406 | **settings) | ||
618 | 407 | |||
619 | 408 | |||
620 | 368 | @cached | 409 | @cached |
621 | 369 | def relation_ids(reltype=None): | 410 | def relation_ids(reltype=None): |
622 | 370 | """A list of relation_ids""" | 411 | """A list of relation_ids""" |
623 | @@ -509,6 +550,11 @@ | |||
624 | 509 | return None | 550 | return None |
625 | 510 | 551 | ||
626 | 511 | 552 | ||
627 | 553 | def unit_public_ip(): | ||
628 | 554 | """Get this unit's public IP address""" | ||
629 | 555 | return unit_get('public-address') | ||
630 | 556 | |||
631 | 557 | |||
632 | 512 | def unit_private_ip(): | 558 | def unit_private_ip(): |
633 | 513 | """Get this unit's private IP address""" | 559 | """Get this unit's private IP address""" |
634 | 514 | return unit_get('private-address') | 560 | return unit_get('private-address') |
635 | @@ -605,3 +651,94 @@ | |||
636 | 605 | 651 | ||
637 | 606 | The results set by action_set are preserved.""" | 652 | The results set by action_set are preserved.""" |
638 | 607 | subprocess.check_call(['action-fail', message]) | 653 | subprocess.check_call(['action-fail', message]) |
639 | 654 | |||
640 | 655 | |||
641 | 656 | def status_set(workload_state, message): | ||
642 | 657 | """Set the workload state with a message | ||
643 | 658 | |||
644 | 659 | Use status-set to set the workload state with a message which is visible | ||
645 | 660 | to the user via juju status. If the status-set command is not found then | ||
646 | 661 | assume this is juju < 1.23 and juju-log the message unstead. | ||
647 | 662 | |||
648 | 663 | workload_state -- valid juju workload state. | ||
649 | 664 | message -- status update message | ||
650 | 665 | """ | ||
651 | 666 | valid_states = ['maintenance', 'blocked', 'waiting', 'active'] | ||
652 | 667 | if workload_state not in valid_states: | ||
653 | 668 | raise ValueError( | ||
654 | 669 | '{!r} is not a valid workload state'.format(workload_state) | ||
655 | 670 | ) | ||
656 | 671 | cmd = ['status-set', workload_state, message] | ||
657 | 672 | try: | ||
658 | 673 | ret = subprocess.call(cmd) | ||
659 | 674 | if ret == 0: | ||
660 | 675 | return | ||
661 | 676 | except OSError as e: | ||
662 | 677 | if e.errno != errno.ENOENT: | ||
663 | 678 | raise | ||
664 | 679 | log_message = 'status-set failed: {} {}'.format(workload_state, | ||
665 | 680 | message) | ||
666 | 681 | log(log_message, level='INFO') | ||
667 | 682 | |||
668 | 683 | |||
669 | 684 | def status_get(): | ||
670 | 685 | """Retrieve the previously set juju workload state | ||
671 | 686 | |||
672 | 687 | If the status-set command is not found then assume this is juju < 1.23 and | ||
673 | 688 | return 'unknown' | ||
674 | 689 | """ | ||
675 | 690 | cmd = ['status-get'] | ||
676 | 691 | try: | ||
677 | 692 | raw_status = subprocess.check_output(cmd, universal_newlines=True) | ||
678 | 693 | status = raw_status.rstrip() | ||
679 | 694 | return status | ||
680 | 695 | except OSError as e: | ||
681 | 696 | if e.errno == errno.ENOENT: | ||
682 | 697 | return 'unknown' | ||
683 | 698 | else: | ||
684 | 699 | raise | ||
685 | 700 | |||
686 | 701 | |||
687 | 702 | def translate_exc(from_exc, to_exc): | ||
688 | 703 | def inner_translate_exc1(f): | ||
689 | 704 | def inner_translate_exc2(*args, **kwargs): | ||
690 | 705 | try: | ||
691 | 706 | return f(*args, **kwargs) | ||
692 | 707 | except from_exc: | ||
693 | 708 | raise to_exc | ||
694 | 709 | |||
695 | 710 | return inner_translate_exc2 | ||
696 | 711 | |||
697 | 712 | return inner_translate_exc1 | ||
698 | 713 | |||
699 | 714 | |||
700 | 715 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
701 | 716 | def is_leader(): | ||
702 | 717 | """Does the current unit hold the juju leadership | ||
703 | 718 | |||
704 | 719 | Uses juju to determine whether the current unit is the leader of its peers | ||
705 | 720 | """ | ||
706 | 721 | cmd = ['is-leader', '--format=json'] | ||
707 | 722 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
708 | 723 | |||
709 | 724 | |||
710 | 725 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
711 | 726 | def leader_get(attribute=None): | ||
712 | 727 | """Juju leader get value(s)""" | ||
713 | 728 | cmd = ['leader-get', '--format=json'] + [attribute or '-'] | ||
714 | 729 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
715 | 730 | |||
716 | 731 | |||
717 | 732 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
718 | 733 | def leader_set(settings=None, **kwargs): | ||
719 | 734 | """Juju leader set value(s)""" | ||
720 | 735 | log("Juju leader-set '%s'" % (settings), level=DEBUG) | ||
721 | 736 | cmd = ['leader-set'] | ||
722 | 737 | settings = settings or {} | ||
723 | 738 | settings.update(kwargs) | ||
724 | 739 | for k, v in settings.iteritems(): | ||
725 | 740 | if v is None: | ||
726 | 741 | cmd.append('{}='.format(k)) | ||
727 | 742 | else: | ||
728 | 743 | cmd.append('{}={}'.format(k, v)) | ||
729 | 744 | subprocess.check_call(cmd) | ||
730 | 608 | 745 | ||
731 | === modified file 'hooks/charmhelpers/core/host.py' | |||
732 | --- hooks/charmhelpers/core/host.py 2015-03-18 12:31:20 +0000 | |||
733 | +++ hooks/charmhelpers/core/host.py 2015-06-04 23:04:28 +0000 | |||
734 | @@ -90,7 +90,7 @@ | |||
735 | 90 | ['service', service_name, 'status'], | 90 | ['service', service_name, 'status'], |
736 | 91 | stderr=subprocess.STDOUT).decode('UTF-8') | 91 | stderr=subprocess.STDOUT).decode('UTF-8') |
737 | 92 | except subprocess.CalledProcessError as e: | 92 | except subprocess.CalledProcessError as e: |
739 | 93 | return 'unrecognized service' not in e.output | 93 | return b'unrecognized service' not in e.output |
740 | 94 | else: | 94 | else: |
741 | 95 | return True | 95 | return True |
742 | 96 | 96 | ||
743 | 97 | 97 | ||
744 | === modified file 'hooks/charmhelpers/core/services/base.py' | |||
745 | --- hooks/charmhelpers/core/services/base.py 2015-01-26 09:48:14 +0000 | |||
746 | +++ hooks/charmhelpers/core/services/base.py 2015-06-04 23:04:28 +0000 | |||
747 | @@ -15,9 +15,9 @@ | |||
748 | 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/>. |
749 | 16 | 16 | ||
750 | 17 | import os | 17 | import os |
751 | 18 | import re | ||
752 | 19 | import json | 18 | import json |
754 | 20 | from collections import Iterable | 19 | from inspect import getargspec |
755 | 20 | from collections import Iterable, OrderedDict | ||
756 | 21 | 21 | ||
757 | 22 | from charmhelpers.core import host | 22 | from charmhelpers.core import host |
758 | 23 | from charmhelpers.core import hookenv | 23 | from charmhelpers.core import hookenv |
759 | @@ -119,7 +119,7 @@ | |||
760 | 119 | """ | 119 | """ |
761 | 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') |
762 | 121 | self._ready = None | 121 | self._ready = None |
764 | 122 | self.services = {} | 122 | self.services = OrderedDict() |
765 | 123 | for service in services or []: | 123 | for service in services or []: |
766 | 124 | service_name = service['service'] | 124 | service_name = service['service'] |
767 | 125 | self.services[service_name] = service | 125 | self.services[service_name] = service |
768 | @@ -132,8 +132,8 @@ | |||
769 | 132 | if hook_name == 'stop': | 132 | if hook_name == 'stop': |
770 | 133 | self.stop_services() | 133 | self.stop_services() |
771 | 134 | else: | 134 | else: |
772 | 135 | self.reconfigure_services() | ||
773 | 135 | self.provide_data() | 136 | self.provide_data() |
774 | 136 | self.reconfigure_services() | ||
775 | 137 | cfg = hookenv.config() | 137 | cfg = hookenv.config() |
776 | 138 | if cfg.implicit_save: | 138 | if cfg.implicit_save: |
777 | 139 | cfg.save() | 139 | cfg.save() |
778 | @@ -145,15 +145,36 @@ | |||
779 | 145 | A provider must have a `name` attribute, which indicates which relation | 145 | A provider must have a `name` attribute, which indicates which relation |
780 | 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 |
781 | 147 | data to set. | 147 | data to set. |
782 | 148 | |||
783 | 149 | The `provide_data()` method can optionally accept two parameters: | ||
784 | 150 | |||
785 | 151 | * ``remote_service`` The name of the remote service that the data will | ||
786 | 152 | be provided to. The `provide_data()` method will be called once | ||
787 | 153 | for each connected service (not unit). This allows the method to | ||
788 | 154 | tailor its data to the given service. | ||
789 | 155 | * ``service_ready`` Whether or not the service definition had all of | ||
790 | 156 | its requirements met, and thus the ``data_ready`` callbacks run. | ||
791 | 157 | |||
792 | 158 | Note that the ``provided_data`` methods are now called **after** the | ||
793 | 159 | ``data_ready`` callbacks are run. This gives the ``data_ready`` callbacks | ||
794 | 160 | a chance to generate any data necessary for the providing to the remote | ||
795 | 161 | services. | ||
796 | 148 | """ | 162 | """ |
799 | 149 | hook_name = hookenv.hook_name() | 163 | for service_name, service in self.services.items(): |
800 | 150 | for service in self.services.values(): | 164 | service_ready = self.is_ready(service_name) |
801 | 151 | for provider in service.get('provided_data', []): | 165 | for provider in service.get('provided_data', []): |
807 | 152 | if re.match(r'{}-relation-(joined|changed)'.format(provider.name), hook_name): | 166 | for relid in hookenv.relation_ids(provider.name): |
808 | 153 | data = provider.provide_data() | 167 | units = hookenv.related_units(relid) |
809 | 154 | _ready = provider._is_ready(data) if hasattr(provider, '_is_ready') else data | 168 | if not units: |
810 | 155 | if _ready: | 169 | continue |
811 | 156 | hookenv.relation_set(None, data) | 170 | remote_service = units[0].split('/')[0] |
812 | 171 | argspec = getargspec(provider.provide_data) | ||
813 | 172 | if len(argspec.args) > 1: | ||
814 | 173 | data = provider.provide_data(remote_service, service_ready) | ||
815 | 174 | else: | ||
816 | 175 | data = provider.provide_data() | ||
817 | 176 | if data: | ||
818 | 177 | hookenv.relation_set(relid, data) | ||
819 | 157 | 178 | ||
820 | 158 | def reconfigure_services(self, *service_names): | 179 | def reconfigure_services(self, *service_names): |
821 | 159 | """ | 180 | """ |
822 | 160 | 181 | ||
823 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
824 | --- hooks/charmhelpers/fetch/__init__.py 2015-01-26 09:48:14 +0000 | |||
825 | +++ hooks/charmhelpers/fetch/__init__.py 2015-06-04 23:04:28 +0000 | |||
826 | @@ -158,7 +158,7 @@ | |||
827 | 158 | 158 | ||
828 | 159 | def apt_cache(in_memory=True): | 159 | def apt_cache(in_memory=True): |
829 | 160 | """Build and return an apt cache""" | 160 | """Build and return an apt cache""" |
831 | 161 | import apt_pkg | 161 | from apt import apt_pkg |
832 | 162 | apt_pkg.init() | 162 | apt_pkg.init() |
833 | 163 | if in_memory: | 163 | if in_memory: |
834 | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") |
835 | 165 | 165 | ||
836 | === modified file 'hooks/charmhelpers/fetch/giturl.py' | |||
837 | --- hooks/charmhelpers/fetch/giturl.py 2015-03-13 12:57:45 +0000 | |||
838 | +++ hooks/charmhelpers/fetch/giturl.py 2015-06-04 23:04:28 +0000 | |||
839 | @@ -45,14 +45,16 @@ | |||
840 | 45 | else: | 45 | else: |
841 | 46 | return True | 46 | return True |
842 | 47 | 47 | ||
844 | 48 | def clone(self, source, dest, branch): | 48 | def clone(self, source, dest, branch, depth=None): |
845 | 49 | if not self.can_handle(source): | 49 | if not self.can_handle(source): |
846 | 50 | raise UnhandledSource("Cannot handle {}".format(source)) | 50 | raise UnhandledSource("Cannot handle {}".format(source)) |
847 | 51 | 51 | ||
850 | 52 | repo = Repo.clone_from(source, dest) | 52 | if depth: |
851 | 53 | repo.git.checkout(branch) | 53 | Repo.clone_from(source, dest, branch=branch, depth=depth) |
852 | 54 | else: | ||
853 | 55 | Repo.clone_from(source, dest, branch=branch) | ||
854 | 54 | 56 | ||
856 | 55 | def install(self, source, branch="master", dest=None): | 57 | def install(self, source, branch="master", dest=None, depth=None): |
857 | 56 | url_parts = self.parse_url(source) | 58 | url_parts = self.parse_url(source) |
858 | 57 | branch_name = url_parts.path.strip("/").split("/")[-1] | 59 | branch_name = url_parts.path.strip("/").split("/")[-1] |
859 | 58 | if dest: | 60 | if dest: |
860 | @@ -63,7 +65,7 @@ | |||
861 | 63 | if not os.path.exists(dest_dir): | 65 | if not os.path.exists(dest_dir): |
862 | 64 | mkdir(dest_dir, perms=0o755) | 66 | mkdir(dest_dir, perms=0o755) |
863 | 65 | try: | 67 | try: |
865 | 66 | self.clone(source, dest_dir, branch) | 68 | self.clone(source, dest_dir, branch, depth) |
866 | 67 | except GitCommandError as e: | 69 | except GitCommandError as e: |
867 | 68 | raise UnhandledSource(e.message) | 70 | raise UnhandledSource(e.message) |
868 | 69 | except OSError as e: | 71 | except OSError as e: |
869 | 70 | 72 | ||
870 | === modified file 'unit_tests/test_ceilometer_hooks.py' | |||
871 | --- unit_tests/test_ceilometer_hooks.py 2015-04-08 15:49:34 +0000 | |||
872 | +++ unit_tests/test_ceilometer_hooks.py 2015-06-04 23:04:28 +0000 | |||
873 | @@ -31,7 +31,6 @@ | |||
874 | 31 | 'get_ceilometer_context', | 31 | 'get_ceilometer_context', |
875 | 32 | 'lsb_release', | 32 | 'lsb_release', |
876 | 33 | 'get_packages', | 33 | 'get_packages', |
877 | 34 | 'canonical_url', | ||
878 | 35 | 'service_restart', | 34 | 'service_restart', |
879 | 36 | 'update_nrpe_config', | 35 | 'update_nrpe_config', |
880 | 37 | 'configure_https', | 36 | 'configure_https', |
881 | @@ -136,9 +135,10 @@ | |||
882 | 136 | self.assertTrue(self.CONFIGS.write_all.called) | 135 | self.assertTrue(self.CONFIGS.write_all.called) |
883 | 137 | self.assertTrue(joined.called) | 136 | self.assertTrue(joined.called) |
884 | 138 | 137 | ||
885 | 138 | @patch.object(hooks, 'canonical_url') | ||
886 | 139 | @patch('charmhelpers.core.hookenv.config') | 139 | @patch('charmhelpers.core.hookenv.config') |
889 | 140 | def test_keystone_joined(self, mock_config): | 140 | def test_keystone_joined(self, mock_config, _canonical_url): |
890 | 141 | self.canonical_url.return_value = "http://thishost" | 141 | _canonical_url.return_value = "http://thishost" |
891 | 142 | self.test_config.set('region', 'myregion') | 142 | self.test_config.set('region', 'myregion') |
892 | 143 | hooks.hooks.execute(['hooks/identity-service-relation-joined']) | 143 | hooks.hooks.execute(['hooks/identity-service-relation-joined']) |
893 | 144 | url = "http://{}:{}".format('thishost', hooks.CEILOMETER_PORT) | 144 | url = "http://{}:{}".format('thishost', hooks.CEILOMETER_PORT) |
894 | @@ -148,6 +148,30 @@ | |||
895 | 148 | requested_roles=hooks.CEILOMETER_ROLE, | 148 | requested_roles=hooks.CEILOMETER_ROLE, |
896 | 149 | region='myregion', relation_id=None) | 149 | region='myregion', relation_id=None) |
897 | 150 | 150 | ||
898 | 151 | @patch('charmhelpers.contrib.openstack.ip.service_name', | ||
899 | 152 | lambda *args: 'ceilometer') | ||
900 | 153 | @patch('charmhelpers.contrib.openstack.ip.unit_get') | ||
901 | 154 | @patch('charmhelpers.contrib.openstack.ip.is_clustered') | ||
902 | 155 | @patch('charmhelpers.core.hookenv.config') | ||
903 | 156 | @patch('charmhelpers.contrib.openstack.ip.config') | ||
904 | 157 | def test_keystone_joined_url_override(self, _config, mock_config, | ||
905 | 158 | _is_clustered, _unit_get): | ||
906 | 159 | _unit_get.return_value = "thishost" | ||
907 | 160 | _is_clustered.return_value = False | ||
908 | 161 | _config.side_effect = self.test_config.get | ||
909 | 162 | mock_config.side_effect = self.test_config.get | ||
910 | 163 | self.test_config.set('region', 'myregion') | ||
911 | 164 | self.test_config.set('os-public-hostname', 'ceilometer.example.com') | ||
912 | 165 | hooks.keystone_joined(None) | ||
913 | 166 | url = "http://{}:{}".format('thishost', hooks.CEILOMETER_PORT) | ||
914 | 167 | public_url = "http://{}:{}".format('ceilometer.example.com', | ||
915 | 168 | hooks.CEILOMETER_PORT) | ||
916 | 169 | self.relation_set.assert_called_with( | ||
917 | 170 | service=hooks.CEILOMETER_SERVICE, | ||
918 | 171 | public_url=public_url, admin_url=url, internal_url=url, | ||
919 | 172 | requested_roles=hooks.CEILOMETER_ROLE, | ||
920 | 173 | region='myregion', relation_id=None) | ||
921 | 174 | |||
922 | 151 | @patch('charmhelpers.core.hookenv.config') | 175 | @patch('charmhelpers.core.hookenv.config') |
923 | 152 | def test_ceilometer_joined(self, mock_config): | 176 | def test_ceilometer_joined(self, mock_config): |
924 | 153 | self.relation_ids.return_value = ['ceilometer:0'] | 177 | self.relation_ids.return_value = ['ceilometer:0'] |
charm_lint_check #5042 ceilometer-next for billy-olsen mp261004
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5042/