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