Merge lp:~corey.bryant/charms/trusty/openstack-dashboard/fix-global-reqs into lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/next
- Trusty Tahr (14.04)
- fix-global-reqs
- Merge into next
Proposed by
Corey Bryant
Status: | Merged |
---|---|
Approved by: | Billy Olsen |
Approved revision: | 68 |
Merged at revision: | 67 |
Proposed branch: | lp:~corey.bryant/charms/trusty/openstack-dashboard/fix-global-reqs |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/openstack-dashboard/next |
Diff against target: |
1554 lines (+687/-111) 15 files modified
hooks/charmhelpers/contrib/hahelpers/cluster.py (+47/-3) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+6/-2) hooks/charmhelpers/contrib/openstack/amulet/utils.py (+122/-3) hooks/charmhelpers/contrib/openstack/context.py (+1/-1) hooks/charmhelpers/contrib/openstack/ip.py (+49/-44) hooks/charmhelpers/contrib/openstack/neutron.py (+16/-9) hooks/charmhelpers/contrib/openstack/utils.py (+21/-8) hooks/charmhelpers/core/hookenv.py (+147/-10) hooks/charmhelpers/core/host.py (+25/-7) hooks/charmhelpers/core/services/base.py (+32/-11) hooks/charmhelpers/fetch/__init__.py (+1/-1) tests/charmhelpers/contrib/amulet/utils.py (+91/-6) tests/charmhelpers/contrib/openstack/amulet/deployment.py (+6/-2) tests/charmhelpers/contrib/openstack/amulet/utils.py (+122/-3) unit_tests/test_horizon_hooks.py (+1/-1) |
To merge this branch: | bzr merge lp:~corey.bryant/charms/trusty/openstack-dashboard/fix-global-reqs |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Billy Olsen | Approve | ||
Review via email: mp+262472@code.launchpad.net |
Commit message
Description of the change
See https:/
for details explaining this merge.
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #5107 openstack-
UNIT OK: passed
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4682 openstack-
AMULET OK: passed
Build: http://
Revision history for this message
Billy Olsen (billy-olsen) wrote : | # |
LGTM, Approved
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
2 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-02-26 10:11:26 +0000 | |||
3 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-19 16:15:40 +0000 | |||
4 | @@ -44,6 +44,7 @@ | |||
5 | 44 | ERROR, | 44 | ERROR, |
6 | 45 | WARNING, | 45 | WARNING, |
7 | 46 | unit_get, | 46 | unit_get, |
8 | 47 | is_leader as juju_is_leader | ||
9 | 47 | ) | 48 | ) |
10 | 48 | from charmhelpers.core.decorators import ( | 49 | from charmhelpers.core.decorators import ( |
11 | 49 | retry_on_exception, | 50 | retry_on_exception, |
12 | @@ -52,6 +53,8 @@ | |||
13 | 52 | bool_from_string, | 53 | bool_from_string, |
14 | 53 | ) | 54 | ) |
15 | 54 | 55 | ||
16 | 56 | DC_RESOURCE_NAME = 'DC' | ||
17 | 57 | |||
18 | 55 | 58 | ||
19 | 56 | class HAIncompleteConfig(Exception): | 59 | class HAIncompleteConfig(Exception): |
20 | 57 | pass | 60 | pass |
21 | @@ -61,17 +64,30 @@ | |||
22 | 61 | pass | 64 | pass |
23 | 62 | 65 | ||
24 | 63 | 66 | ||
25 | 67 | class CRMDCNotFound(Exception): | ||
26 | 68 | pass | ||
27 | 69 | |||
28 | 70 | |||
29 | 64 | def is_elected_leader(resource): | 71 | def is_elected_leader(resource): |
30 | 65 | """ | 72 | """ |
31 | 66 | Returns True if the charm executing this is the elected cluster leader. | 73 | Returns True if the charm executing this is the elected cluster leader. |
32 | 67 | 74 | ||
33 | 68 | It relies on two mechanisms to determine leadership: | 75 | It relies on two mechanisms to determine leadership: |
35 | 69 | 1. If the charm is part of a corosync cluster, call corosync to | 76 | 1. If juju is sufficiently new and leadership election is supported, |
36 | 77 | the is_leader command will be used. | ||
37 | 78 | 2. If the charm is part of a corosync cluster, call corosync to | ||
38 | 70 | determine leadership. | 79 | determine leadership. |
40 | 71 | 2. If the charm is not part of a corosync cluster, the leader is | 80 | 3. If the charm is not part of a corosync cluster, the leader is |
41 | 72 | determined as being "the alive unit with the lowest unit numer". In | 81 | determined as being "the alive unit with the lowest unit numer". In |
42 | 73 | other words, the oldest surviving unit. | 82 | other words, the oldest surviving unit. |
43 | 74 | """ | 83 | """ |
44 | 84 | try: | ||
45 | 85 | return juju_is_leader() | ||
46 | 86 | except NotImplementedError: | ||
47 | 87 | log('Juju leadership election feature not enabled' | ||
48 | 88 | ', using fallback support', | ||
49 | 89 | level=WARNING) | ||
50 | 90 | |||
51 | 75 | if is_clustered(): | 91 | if is_clustered(): |
52 | 76 | if not is_crm_leader(resource): | 92 | if not is_crm_leader(resource): |
53 | 77 | log('Deferring action to CRM leader.', level=INFO) | 93 | log('Deferring action to CRM leader.', level=INFO) |
54 | @@ -95,7 +111,33 @@ | |||
55 | 95 | return False | 111 | return False |
56 | 96 | 112 | ||
57 | 97 | 113 | ||
59 | 98 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) | 114 | def is_crm_dc(): |
60 | 115 | """ | ||
61 | 116 | Determine leadership by querying the pacemaker Designated Controller | ||
62 | 117 | """ | ||
63 | 118 | cmd = ['crm', 'status'] | ||
64 | 119 | try: | ||
65 | 120 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | ||
66 | 121 | if not isinstance(status, six.text_type): | ||
67 | 122 | status = six.text_type(status, "utf-8") | ||
68 | 123 | except subprocess.CalledProcessError as ex: | ||
69 | 124 | raise CRMDCNotFound(str(ex)) | ||
70 | 125 | |||
71 | 126 | current_dc = '' | ||
72 | 127 | for line in status.split('\n'): | ||
73 | 128 | if line.startswith('Current DC'): | ||
74 | 129 | # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum | ||
75 | 130 | current_dc = line.split(':')[1].split()[0] | ||
76 | 131 | if current_dc == get_unit_hostname(): | ||
77 | 132 | return True | ||
78 | 133 | elif current_dc == 'NONE': | ||
79 | 134 | raise CRMDCNotFound('Current DC: NONE') | ||
80 | 135 | |||
81 | 136 | return False | ||
82 | 137 | |||
83 | 138 | |||
84 | 139 | @retry_on_exception(5, base_delay=2, | ||
85 | 140 | exc_type=(CRMResourceNotFound, CRMDCNotFound)) | ||
86 | 99 | def is_crm_leader(resource, retry=False): | 141 | def is_crm_leader(resource, retry=False): |
87 | 100 | """ | 142 | """ |
88 | 101 | Returns True if the charm calling this is the elected corosync leader, | 143 | Returns True if the charm calling this is the elected corosync leader, |
89 | @@ -104,6 +146,8 @@ | |||
90 | 104 | We allow this operation to be retried to avoid the possibility of getting a | 146 | We allow this operation to be retried to avoid the possibility of getting a |
91 | 105 | false negative. See LP #1396246 for more info. | 147 | false negative. See LP #1396246 for more info. |
92 | 106 | """ | 148 | """ |
93 | 149 | if resource == DC_RESOURCE_NAME: | ||
94 | 150 | return is_crm_dc() | ||
95 | 107 | cmd = ['crm', 'resource', 'show', resource] | 151 | cmd = ['crm', 'resource', 'show', resource] |
96 | 108 | try: | 152 | try: |
97 | 109 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) | 153 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
98 | 110 | 154 | ||
99 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
100 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-05-05 20:28:18 +0000 | |||
101 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2015-06-19 16:15:40 +0000 | |||
102 | @@ -110,7 +110,8 @@ | |||
103 | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, |
104 | 111 | self.precise_havana, self.precise_icehouse, | 111 | self.precise_havana, self.precise_icehouse, |
105 | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
107 | 113 | self.trusty_kilo, self.vivid_kilo) = range(10) | 113 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, |
108 | 114 | self.wily_liberty) = range(12) | ||
109 | 114 | 115 | ||
110 | 115 | releases = { | 116 | releases = { |
111 | 116 | ('precise', None): self.precise_essex, | 117 | ('precise', None): self.precise_essex, |
112 | @@ -121,8 +122,10 @@ | |||
113 | 121 | ('trusty', None): self.trusty_icehouse, | 122 | ('trusty', None): self.trusty_icehouse, |
114 | 122 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, | 123 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, |
115 | 123 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, | 124 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, |
116 | 125 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, | ||
117 | 124 | ('utopic', None): self.utopic_juno, | 126 | ('utopic', None): self.utopic_juno, |
119 | 125 | ('vivid', None): self.vivid_kilo} | 127 | ('vivid', None): self.vivid_kilo, |
120 | 128 | ('wily', None): self.wily_liberty} | ||
121 | 126 | return releases[(self.series, self.openstack)] | 129 | return releases[(self.series, self.openstack)] |
122 | 127 | 130 | ||
123 | 128 | def _get_openstack_release_string(self): | 131 | def _get_openstack_release_string(self): |
124 | @@ -138,6 +141,7 @@ | |||
125 | 138 | ('trusty', 'icehouse'), | 141 | ('trusty', 'icehouse'), |
126 | 139 | ('utopic', 'juno'), | 142 | ('utopic', 'juno'), |
127 | 140 | ('vivid', 'kilo'), | 143 | ('vivid', 'kilo'), |
128 | 144 | ('wily', 'liberty'), | ||
129 | 141 | ]) | 145 | ]) |
130 | 142 | if self.openstack: | 146 | if self.openstack: |
131 | 143 | os_origin = self.openstack.split(':')[1] | 147 | os_origin = self.openstack.split(':')[1] |
132 | 144 | 148 | ||
133 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py' | |||
134 | --- hooks/charmhelpers/contrib/openstack/amulet/utils.py 2015-01-26 09:46:38 +0000 | |||
135 | +++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2015-06-19 16:15:40 +0000 | |||
136 | @@ -16,15 +16,15 @@ | |||
137 | 16 | 16 | ||
138 | 17 | import logging | 17 | import logging |
139 | 18 | import os | 18 | import os |
140 | 19 | import six | ||
141 | 19 | import time | 20 | import time |
142 | 20 | import urllib | 21 | import urllib |
143 | 21 | 22 | ||
144 | 22 | import glanceclient.v1.client as glance_client | 23 | import glanceclient.v1.client as glance_client |
145 | 24 | import heatclient.v1.client as heat_client | ||
146 | 23 | import keystoneclient.v2_0 as keystone_client | 25 | import keystoneclient.v2_0 as keystone_client |
147 | 24 | import novaclient.v1_1.client as nova_client | 26 | import novaclient.v1_1.client as nova_client |
148 | 25 | 27 | ||
149 | 26 | import six | ||
150 | 27 | |||
151 | 28 | from charmhelpers.contrib.amulet.utils import ( | 28 | from charmhelpers.contrib.amulet.utils import ( |
152 | 29 | AmuletUtils | 29 | AmuletUtils |
153 | 30 | ) | 30 | ) |
154 | @@ -37,7 +37,7 @@ | |||
155 | 37 | """OpenStack amulet utilities. | 37 | """OpenStack amulet utilities. |
156 | 38 | 38 | ||
157 | 39 | This class inherits from AmuletUtils and has additional support | 39 | This class inherits from AmuletUtils and has additional support |
159 | 40 | that is specifically for use by OpenStack charms. | 40 | that is specifically for use by OpenStack charm tests. |
160 | 41 | """ | 41 | """ |
161 | 42 | 42 | ||
162 | 43 | def __init__(self, log_level=ERROR): | 43 | def __init__(self, log_level=ERROR): |
163 | @@ -51,6 +51,8 @@ | |||
164 | 51 | Validate actual endpoint data vs expected endpoint data. The ports | 51 | Validate actual endpoint data vs expected endpoint data. The ports |
165 | 52 | are used to find the matching endpoint. | 52 | are used to find the matching endpoint. |
166 | 53 | """ | 53 | """ |
167 | 54 | self.log.debug('Validating endpoint data...') | ||
168 | 55 | self.log.debug('actual: {}'.format(repr(endpoints))) | ||
169 | 54 | found = False | 56 | found = False |
170 | 55 | for ep in endpoints: | 57 | for ep in endpoints: |
171 | 56 | self.log.debug('endpoint: {}'.format(repr(ep))) | 58 | self.log.debug('endpoint: {}'.format(repr(ep))) |
172 | @@ -77,6 +79,7 @@ | |||
173 | 77 | Validate a list of actual service catalog endpoints vs a list of | 79 | Validate a list of actual service catalog endpoints vs a list of |
174 | 78 | expected service catalog endpoints. | 80 | expected service catalog endpoints. |
175 | 79 | """ | 81 | """ |
176 | 82 | self.log.debug('Validating service catalog endpoint data...') | ||
177 | 80 | self.log.debug('actual: {}'.format(repr(actual))) | 83 | self.log.debug('actual: {}'.format(repr(actual))) |
178 | 81 | for k, v in six.iteritems(expected): | 84 | for k, v in six.iteritems(expected): |
179 | 82 | if k in actual: | 85 | if k in actual: |
180 | @@ -93,6 +96,7 @@ | |||
181 | 93 | Validate a list of actual tenant data vs list of expected tenant | 96 | Validate a list of actual tenant data vs list of expected tenant |
182 | 94 | data. | 97 | data. |
183 | 95 | """ | 98 | """ |
184 | 99 | self.log.debug('Validating tenant data...') | ||
185 | 96 | self.log.debug('actual: {}'.format(repr(actual))) | 100 | self.log.debug('actual: {}'.format(repr(actual))) |
186 | 97 | for e in expected: | 101 | for e in expected: |
187 | 98 | found = False | 102 | found = False |
188 | @@ -114,6 +118,7 @@ | |||
189 | 114 | Validate a list of actual role data vs a list of expected role | 118 | Validate a list of actual role data vs a list of expected role |
190 | 115 | data. | 119 | data. |
191 | 116 | """ | 120 | """ |
192 | 121 | self.log.debug('Validating role data...') | ||
193 | 117 | self.log.debug('actual: {}'.format(repr(actual))) | 122 | self.log.debug('actual: {}'.format(repr(actual))) |
194 | 118 | for e in expected: | 123 | for e in expected: |
195 | 119 | found = False | 124 | found = False |
196 | @@ -134,6 +139,7 @@ | |||
197 | 134 | Validate a list of actual user data vs a list of expected user | 139 | Validate a list of actual user data vs a list of expected user |
198 | 135 | data. | 140 | data. |
199 | 136 | """ | 141 | """ |
200 | 142 | self.log.debug('Validating user data...') | ||
201 | 137 | self.log.debug('actual: {}'.format(repr(actual))) | 143 | self.log.debug('actual: {}'.format(repr(actual))) |
202 | 138 | for e in expected: | 144 | for e in expected: |
203 | 139 | found = False | 145 | found = False |
204 | @@ -155,17 +161,20 @@ | |||
205 | 155 | 161 | ||
206 | 156 | Validate a list of actual flavors vs a list of expected flavors. | 162 | Validate a list of actual flavors vs a list of expected flavors. |
207 | 157 | """ | 163 | """ |
208 | 164 | self.log.debug('Validating flavor data...') | ||
209 | 158 | self.log.debug('actual: {}'.format(repr(actual))) | 165 | self.log.debug('actual: {}'.format(repr(actual))) |
210 | 159 | act = [a.name for a in actual] | 166 | act = [a.name for a in actual] |
211 | 160 | return self._validate_list_data(expected, act) | 167 | return self._validate_list_data(expected, act) |
212 | 161 | 168 | ||
213 | 162 | def tenant_exists(self, keystone, tenant): | 169 | def tenant_exists(self, keystone, tenant): |
214 | 163 | """Return True if tenant exists.""" | 170 | """Return True if tenant exists.""" |
215 | 171 | self.log.debug('Checking if tenant exists ({})...'.format(tenant)) | ||
216 | 164 | return tenant in [t.name for t in keystone.tenants.list()] | 172 | return tenant in [t.name for t in keystone.tenants.list()] |
217 | 165 | 173 | ||
218 | 166 | def authenticate_keystone_admin(self, keystone_sentry, user, password, | 174 | def authenticate_keystone_admin(self, keystone_sentry, user, password, |
219 | 167 | tenant): | 175 | tenant): |
220 | 168 | """Authenticates admin user with the keystone admin endpoint.""" | 176 | """Authenticates admin user with the keystone admin endpoint.""" |
221 | 177 | self.log.debug('Authenticating keystone admin...') | ||
222 | 169 | unit = keystone_sentry | 178 | unit = keystone_sentry |
223 | 170 | service_ip = unit.relation('shared-db', | 179 | service_ip = unit.relation('shared-db', |
224 | 171 | 'mysql:shared-db')['private-address'] | 180 | 'mysql:shared-db')['private-address'] |
225 | @@ -175,6 +184,7 @@ | |||
226 | 175 | 184 | ||
227 | 176 | def authenticate_keystone_user(self, keystone, user, password, tenant): | 185 | def authenticate_keystone_user(self, keystone, user, password, tenant): |
228 | 177 | """Authenticates a regular user with the keystone public endpoint.""" | 186 | """Authenticates a regular user with the keystone public endpoint.""" |
229 | 187 | self.log.debug('Authenticating keystone user ({})...'.format(user)) | ||
230 | 178 | ep = keystone.service_catalog.url_for(service_type='identity', | 188 | ep = keystone.service_catalog.url_for(service_type='identity', |
231 | 179 | endpoint_type='publicURL') | 189 | endpoint_type='publicURL') |
232 | 180 | return keystone_client.Client(username=user, password=password, | 190 | return keystone_client.Client(username=user, password=password, |
233 | @@ -182,12 +192,21 @@ | |||
234 | 182 | 192 | ||
235 | 183 | def authenticate_glance_admin(self, keystone): | 193 | def authenticate_glance_admin(self, keystone): |
236 | 184 | """Authenticates admin user with glance.""" | 194 | """Authenticates admin user with glance.""" |
237 | 195 | self.log.debug('Authenticating glance admin...') | ||
238 | 185 | ep = keystone.service_catalog.url_for(service_type='image', | 196 | ep = keystone.service_catalog.url_for(service_type='image', |
239 | 186 | endpoint_type='adminURL') | 197 | endpoint_type='adminURL') |
240 | 187 | return glance_client.Client(ep, token=keystone.auth_token) | 198 | return glance_client.Client(ep, token=keystone.auth_token) |
241 | 188 | 199 | ||
242 | 200 | def authenticate_heat_admin(self, keystone): | ||
243 | 201 | """Authenticates the admin user with heat.""" | ||
244 | 202 | self.log.debug('Authenticating heat admin...') | ||
245 | 203 | ep = keystone.service_catalog.url_for(service_type='orchestration', | ||
246 | 204 | endpoint_type='publicURL') | ||
247 | 205 | return heat_client.Client(endpoint=ep, token=keystone.auth_token) | ||
248 | 206 | |||
249 | 189 | def authenticate_nova_user(self, keystone, user, password, tenant): | 207 | def authenticate_nova_user(self, keystone, user, password, tenant): |
250 | 190 | """Authenticates a regular user with nova-api.""" | 208 | """Authenticates a regular user with nova-api.""" |
251 | 209 | self.log.debug('Authenticating nova user ({})...'.format(user)) | ||
252 | 191 | ep = keystone.service_catalog.url_for(service_type='identity', | 210 | ep = keystone.service_catalog.url_for(service_type='identity', |
253 | 192 | endpoint_type='publicURL') | 211 | endpoint_type='publicURL') |
254 | 193 | return nova_client.Client(username=user, api_key=password, | 212 | return nova_client.Client(username=user, api_key=password, |
255 | @@ -195,6 +214,7 @@ | |||
256 | 195 | 214 | ||
257 | 196 | def create_cirros_image(self, glance, image_name): | 215 | def create_cirros_image(self, glance, image_name): |
258 | 197 | """Download the latest cirros image and upload it to glance.""" | 216 | """Download the latest cirros image and upload it to glance.""" |
259 | 217 | self.log.debug('Creating glance image ({})...'.format(image_name)) | ||
260 | 198 | http_proxy = os.getenv('AMULET_HTTP_PROXY') | 218 | http_proxy = os.getenv('AMULET_HTTP_PROXY') |
261 | 199 | self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy)) | 219 | self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy)) |
262 | 200 | if http_proxy: | 220 | if http_proxy: |
263 | @@ -235,6 +255,11 @@ | |||
264 | 235 | 255 | ||
265 | 236 | def delete_image(self, glance, image): | 256 | def delete_image(self, glance, image): |
266 | 237 | """Delete the specified image.""" | 257 | """Delete the specified image.""" |
267 | 258 | |||
268 | 259 | # /!\ DEPRECATION WARNING | ||
269 | 260 | self.log.warn('/!\\ DEPRECATION WARNING: use ' | ||
270 | 261 | 'delete_resource instead of delete_image.') | ||
271 | 262 | self.log.debug('Deleting glance image ({})...'.format(image)) | ||
272 | 238 | num_before = len(list(glance.images.list())) | 263 | num_before = len(list(glance.images.list())) |
273 | 239 | glance.images.delete(image) | 264 | glance.images.delete(image) |
274 | 240 | 265 | ||
275 | @@ -254,6 +279,8 @@ | |||
276 | 254 | 279 | ||
277 | 255 | def create_instance(self, nova, image_name, instance_name, flavor): | 280 | def create_instance(self, nova, image_name, instance_name, flavor): |
278 | 256 | """Create the specified instance.""" | 281 | """Create the specified instance.""" |
279 | 282 | self.log.debug('Creating instance ' | ||
280 | 283 | '({}|{}|{})'.format(instance_name, image_name, flavor)) | ||
281 | 257 | image = nova.images.find(name=image_name) | 284 | image = nova.images.find(name=image_name) |
282 | 258 | flavor = nova.flavors.find(name=flavor) | 285 | flavor = nova.flavors.find(name=flavor) |
283 | 259 | instance = nova.servers.create(name=instance_name, image=image, | 286 | instance = nova.servers.create(name=instance_name, image=image, |
284 | @@ -276,6 +303,11 @@ | |||
285 | 276 | 303 | ||
286 | 277 | def delete_instance(self, nova, instance): | 304 | def delete_instance(self, nova, instance): |
287 | 278 | """Delete the specified instance.""" | 305 | """Delete the specified instance.""" |
288 | 306 | |||
289 | 307 | # /!\ DEPRECATION WARNING | ||
290 | 308 | self.log.warn('/!\\ DEPRECATION WARNING: use ' | ||
291 | 309 | 'delete_resource instead of delete_instance.') | ||
292 | 310 | self.log.debug('Deleting instance ({})...'.format(instance)) | ||
293 | 279 | num_before = len(list(nova.servers.list())) | 311 | num_before = len(list(nova.servers.list())) |
294 | 280 | nova.servers.delete(instance) | 312 | nova.servers.delete(instance) |
295 | 281 | 313 | ||
296 | @@ -292,3 +324,90 @@ | |||
297 | 292 | return False | 324 | return False |
298 | 293 | 325 | ||
299 | 294 | return True | 326 | return True |
300 | 327 | |||
301 | 328 | def create_or_get_keypair(self, nova, keypair_name="testkey"): | ||
302 | 329 | """Create a new keypair, or return pointer if it already exists.""" | ||
303 | 330 | try: | ||
304 | 331 | _keypair = nova.keypairs.get(keypair_name) | ||
305 | 332 | self.log.debug('Keypair ({}) already exists, ' | ||
306 | 333 | 'using it.'.format(keypair_name)) | ||
307 | 334 | return _keypair | ||
308 | 335 | except: | ||
309 | 336 | self.log.debug('Keypair ({}) does not exist, ' | ||
310 | 337 | 'creating it.'.format(keypair_name)) | ||
311 | 338 | |||
312 | 339 | _keypair = nova.keypairs.create(name=keypair_name) | ||
313 | 340 | return _keypair | ||
314 | 341 | |||
315 | 342 | def delete_resource(self, resource, resource_id, | ||
316 | 343 | msg="resource", max_wait=120): | ||
317 | 344 | """Delete one openstack resource, such as one instance, keypair, | ||
318 | 345 | image, volume, stack, etc., and confirm deletion within max wait time. | ||
319 | 346 | |||
320 | 347 | :param resource: pointer to os resource type, ex:glance_client.images | ||
321 | 348 | :param resource_id: unique name or id for the openstack resource | ||
322 | 349 | :param msg: text to identify purpose in logging | ||
323 | 350 | :param max_wait: maximum wait time in seconds | ||
324 | 351 | :returns: True if successful, otherwise False | ||
325 | 352 | """ | ||
326 | 353 | num_before = len(list(resource.list())) | ||
327 | 354 | resource.delete(resource_id) | ||
328 | 355 | |||
329 | 356 | tries = 0 | ||
330 | 357 | num_after = len(list(resource.list())) | ||
331 | 358 | while num_after != (num_before - 1) and tries < (max_wait / 4): | ||
332 | 359 | self.log.debug('{} delete check: ' | ||
333 | 360 | '{} [{}:{}] {}'.format(msg, tries, | ||
334 | 361 | num_before, | ||
335 | 362 | num_after, | ||
336 | 363 | resource_id)) | ||
337 | 364 | time.sleep(4) | ||
338 | 365 | num_after = len(list(resource.list())) | ||
339 | 366 | tries += 1 | ||
340 | 367 | |||
341 | 368 | self.log.debug('{}: expected, actual count = {}, ' | ||
342 | 369 | '{}'.format(msg, num_before - 1, num_after)) | ||
343 | 370 | |||
344 | 371 | if num_after == (num_before - 1): | ||
345 | 372 | return True | ||
346 | 373 | else: | ||
347 | 374 | self.log.error('{} delete timed out'.format(msg)) | ||
348 | 375 | return False | ||
349 | 376 | |||
350 | 377 | def resource_reaches_status(self, resource, resource_id, | ||
351 | 378 | expected_stat='available', | ||
352 | 379 | msg='resource', max_wait=120): | ||
353 | 380 | """Wait for an openstack resources status to reach an | ||
354 | 381 | expected status within a specified time. Useful to confirm that | ||
355 | 382 | nova instances, cinder vols, snapshots, glance images, heat stacks | ||
356 | 383 | and other resources eventually reach the expected status. | ||
357 | 384 | |||
358 | 385 | :param resource: pointer to os resource type, ex: heat_client.stacks | ||
359 | 386 | :param resource_id: unique id for the openstack resource | ||
360 | 387 | :param expected_stat: status to expect resource to reach | ||
361 | 388 | :param msg: text to identify purpose in logging | ||
362 | 389 | :param max_wait: maximum wait time in seconds | ||
363 | 390 | :returns: True if successful, False if status is not reached | ||
364 | 391 | """ | ||
365 | 392 | |||
366 | 393 | tries = 0 | ||
367 | 394 | resource_stat = resource.get(resource_id).status | ||
368 | 395 | while resource_stat != expected_stat and tries < (max_wait / 4): | ||
369 | 396 | self.log.debug('{} status check: ' | ||
370 | 397 | '{} [{}:{}] {}'.format(msg, tries, | ||
371 | 398 | resource_stat, | ||
372 | 399 | expected_stat, | ||
373 | 400 | resource_id)) | ||
374 | 401 | time.sleep(4) | ||
375 | 402 | resource_stat = resource.get(resource_id).status | ||
376 | 403 | tries += 1 | ||
377 | 404 | |||
378 | 405 | self.log.debug('{}: expected, actual status = {}, ' | ||
379 | 406 | '{}'.format(msg, resource_stat, expected_stat)) | ||
380 | 407 | |||
381 | 408 | if resource_stat == expected_stat: | ||
382 | 409 | return True | ||
383 | 410 | else: | ||
384 | 411 | self.log.debug('{} never reached expected status: ' | ||
385 | 412 | '{}'.format(resource_id, expected_stat)) | ||
386 | 413 | return False | ||
387 | 295 | 414 | ||
388 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
389 | --- hooks/charmhelpers/contrib/openstack/context.py 2015-04-16 21:35:02 +0000 | |||
390 | +++ hooks/charmhelpers/contrib/openstack/context.py 2015-06-19 16:15:40 +0000 | |||
391 | @@ -240,7 +240,7 @@ | |||
392 | 240 | if self.relation_prefix: | 240 | if self.relation_prefix: |
393 | 241 | password_setting = self.relation_prefix + '_password' | 241 | password_setting = self.relation_prefix + '_password' |
394 | 242 | 242 | ||
396 | 243 | for rid in relation_ids('shared-db'): | 243 | for rid in relation_ids(self.interfaces[0]): |
397 | 244 | for unit in related_units(rid): | 244 | for unit in related_units(rid): |
398 | 245 | rdata = relation_get(rid=rid, unit=unit) | 245 | rdata = relation_get(rid=rid, unit=unit) |
399 | 246 | host = rdata.get('db_host') | 246 | host = rdata.get('db_host') |
400 | 247 | 247 | ||
401 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
402 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-02-26 10:11:26 +0000 | |||
403 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-19 16:15:40 +0000 | |||
404 | @@ -17,6 +17,7 @@ | |||
405 | 17 | from charmhelpers.core.hookenv import ( | 17 | from charmhelpers.core.hookenv import ( |
406 | 18 | config, | 18 | config, |
407 | 19 | unit_get, | 19 | unit_get, |
408 | 20 | service_name, | ||
409 | 20 | ) | 21 | ) |
410 | 21 | from charmhelpers.contrib.network.ip import ( | 22 | from charmhelpers.contrib.network.ip import ( |
411 | 22 | get_address_in_network, | 23 | get_address_in_network, |
412 | @@ -26,8 +27,6 @@ | |||
413 | 26 | ) | 27 | ) |
414 | 27 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 28 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
415 | 28 | 29 | ||
416 | 29 | from functools import partial | ||
417 | 30 | |||
418 | 31 | PUBLIC = 'public' | 30 | PUBLIC = 'public' |
419 | 32 | INTERNAL = 'int' | 31 | INTERNAL = 'int' |
420 | 33 | ADMIN = 'admin' | 32 | ADMIN = 'admin' |
421 | @@ -35,15 +34,18 @@ | |||
422 | 35 | ADDRESS_MAP = { | 34 | ADDRESS_MAP = { |
423 | 36 | PUBLIC: { | 35 | PUBLIC: { |
424 | 37 | 'config': 'os-public-network', | 36 | 'config': 'os-public-network', |
426 | 38 | 'fallback': 'public-address' | 37 | 'fallback': 'public-address', |
427 | 38 | 'override': 'os-public-hostname', | ||
428 | 39 | }, | 39 | }, |
429 | 40 | INTERNAL: { | 40 | INTERNAL: { |
430 | 41 | 'config': 'os-internal-network', | 41 | 'config': 'os-internal-network', |
432 | 42 | 'fallback': 'private-address' | 42 | 'fallback': 'private-address', |
433 | 43 | 'override': 'os-internal-hostname', | ||
434 | 43 | }, | 44 | }, |
435 | 44 | ADMIN: { | 45 | ADMIN: { |
436 | 45 | 'config': 'os-admin-network', | 46 | 'config': 'os-admin-network', |
438 | 46 | 'fallback': 'private-address' | 47 | 'fallback': 'private-address', |
439 | 48 | 'override': 'os-admin-hostname', | ||
440 | 47 | } | 49 | } |
441 | 48 | } | 50 | } |
442 | 49 | 51 | ||
443 | @@ -57,15 +59,50 @@ | |||
444 | 57 | :param endpoint_type: str endpoint type to resolve. | 59 | :param endpoint_type: str endpoint type to resolve. |
445 | 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. |
446 | 59 | """ | 61 | """ |
450 | 60 | scheme = 'http' | 62 | scheme = _get_scheme(configs) |
451 | 61 | if 'https' in configs.complete_contexts(): | 63 | |
449 | 62 | scheme = 'https' | ||
452 | 63 | address = resolve_address(endpoint_type) | 64 | address = resolve_address(endpoint_type) |
453 | 64 | if is_ipv6(address): | 65 | if is_ipv6(address): |
454 | 65 | address = "[{}]".format(address) | 66 | address = "[{}]".format(address) |
455 | 67 | |||
456 | 66 | return '%s://%s' % (scheme, address) | 68 | return '%s://%s' % (scheme, address) |
457 | 67 | 69 | ||
458 | 68 | 70 | ||
459 | 71 | def _get_scheme(configs): | ||
460 | 72 | """Returns the scheme to use for the url (either http or https) | ||
461 | 73 | depending upon whether https is in the configs value. | ||
462 | 74 | |||
463 | 75 | :param configs: OSTemplateRenderer config templating object to inspect | ||
464 | 76 | for a complete https context. | ||
465 | 77 | :returns: either 'http' or 'https' depending on whether https is | ||
466 | 78 | configured within the configs context. | ||
467 | 79 | """ | ||
468 | 80 | scheme = 'http' | ||
469 | 81 | if configs and 'https' in configs.complete_contexts(): | ||
470 | 82 | scheme = 'https' | ||
471 | 83 | return scheme | ||
472 | 84 | |||
473 | 85 | |||
474 | 86 | def _get_address_override(endpoint_type=PUBLIC): | ||
475 | 87 | """Returns any address overrides that the user has defined based on the | ||
476 | 88 | endpoint type. | ||
477 | 89 | |||
478 | 90 | Note: this function allows for the service name to be inserted into the | ||
479 | 91 | address if the user specifies {service_name}.somehost.org. | ||
480 | 92 | |||
481 | 93 | :param endpoint_type: the type of endpoint to retrieve the override | ||
482 | 94 | value for. | ||
483 | 95 | :returns: any endpoint address or hostname that the user has overridden | ||
484 | 96 | or None if an override is not present. | ||
485 | 97 | """ | ||
486 | 98 | override_key = ADDRESS_MAP[endpoint_type]['override'] | ||
487 | 99 | addr_override = config(override_key) | ||
488 | 100 | if not addr_override: | ||
489 | 101 | return None | ||
490 | 102 | else: | ||
491 | 103 | return addr_override.format(service_name=service_name()) | ||
492 | 104 | |||
493 | 105 | |||
494 | 69 | def resolve_address(endpoint_type=PUBLIC): | 106 | def resolve_address(endpoint_type=PUBLIC): |
495 | 70 | """Return unit address depending on net config. | 107 | """Return unit address depending on net config. |
496 | 71 | 108 | ||
497 | @@ -77,7 +114,10 @@ | |||
498 | 77 | 114 | ||
499 | 78 | :param endpoint_type: Network endpoing type | 115 | :param endpoint_type: Network endpoing type |
500 | 79 | """ | 116 | """ |
502 | 80 | resolved_address = None | 117 | resolved_address = _get_address_override(endpoint_type) |
503 | 118 | if resolved_address: | ||
504 | 119 | return resolved_address | ||
505 | 120 | |||
506 | 81 | vips = config('vip') | 121 | vips = config('vip') |
507 | 82 | if vips: | 122 | if vips: |
508 | 83 | vips = vips.split() | 123 | vips = vips.split() |
509 | @@ -109,38 +149,3 @@ | |||
510 | 109 | "clustered=%s)" % (net_type, clustered)) | 149 | "clustered=%s)" % (net_type, clustered)) |
511 | 110 | 150 | ||
512 | 111 | return resolved_address | 151 | return resolved_address |
513 | 112 | |||
514 | 113 | |||
515 | 114 | def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, | ||
516 | 115 | override=None): | ||
517 | 116 | """Returns the correct endpoint URL to advertise to Keystone. | ||
518 | 117 | |||
519 | 118 | This method provides the correct endpoint URL which should be advertised to | ||
520 | 119 | the keystone charm for endpoint creation. This method allows for the url to | ||
521 | 120 | be overridden to force a keystone endpoint to have specific URL for any of | ||
522 | 121 | the defined scopes (admin, internal, public). | ||
523 | 122 | |||
524 | 123 | :param configs: OSTemplateRenderer config templating object to inspect | ||
525 | 124 | for a complete https context. | ||
526 | 125 | :param url_template: str format string for creating the url template. Only | ||
527 | 126 | two values will be passed - the scheme+hostname | ||
528 | 127 | returned by the canonical_url and the port. | ||
529 | 128 | :param endpoint_type: str endpoint type to resolve. | ||
530 | 129 | :param override: str the name of the config option which overrides the | ||
531 | 130 | endpoint URL defined by the charm itself. None will | ||
532 | 131 | disable any overrides (default). | ||
533 | 132 | """ | ||
534 | 133 | if override: | ||
535 | 134 | # Return any user-defined overrides for the keystone endpoint URL. | ||
536 | 135 | user_value = config(override) | ||
537 | 136 | if user_value: | ||
538 | 137 | return user_value.strip() | ||
539 | 138 | |||
540 | 139 | return url_template % (canonical_url(configs, endpoint_type), port) | ||
541 | 140 | |||
542 | 141 | |||
543 | 142 | public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) | ||
544 | 143 | |||
545 | 144 | internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) | ||
546 | 145 | |||
547 | 146 | admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) | ||
548 | 147 | 152 | ||
549 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
550 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2015-04-16 20:24:28 +0000 | |||
551 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-06-19 16:15:40 +0000 | |||
552 | @@ -172,14 +172,16 @@ | |||
553 | 172 | 'services': ['calico-felix', | 172 | 'services': ['calico-felix', |
554 | 173 | 'bird', | 173 | 'bird', |
555 | 174 | 'neutron-dhcp-agent', | 174 | 'neutron-dhcp-agent', |
557 | 175 | 'nova-api-metadata'], | 175 | 'nova-api-metadata', |
558 | 176 | 'etcd'], | ||
559 | 176 | 'packages': [[headers_package()] + determine_dkms_package(), | 177 | 'packages': [[headers_package()] + determine_dkms_package(), |
560 | 177 | ['calico-compute', | 178 | ['calico-compute', |
561 | 178 | 'bird', | 179 | 'bird', |
562 | 179 | 'neutron-dhcp-agent', | 180 | 'neutron-dhcp-agent', |
566 | 180 | 'nova-api-metadata']], | 181 | 'nova-api-metadata', |
567 | 181 | 'server_packages': ['neutron-server', 'calico-control'], | 182 | 'etcd']], |
568 | 182 | 'server_services': ['neutron-server'] | 183 | 'server_packages': ['neutron-server', 'calico-control', 'etcd'], |
569 | 184 | 'server_services': ['neutron-server', 'etcd'] | ||
570 | 183 | }, | 185 | }, |
571 | 184 | 'vsp': { | 186 | 'vsp': { |
572 | 185 | 'config': '/etc/neutron/plugins/nuage/nuage_plugin.ini', | 187 | 'config': '/etc/neutron/plugins/nuage/nuage_plugin.ini', |
573 | @@ -256,11 +258,14 @@ | |||
574 | 256 | def parse_mappings(mappings): | 258 | def parse_mappings(mappings): |
575 | 257 | parsed = {} | 259 | parsed = {} |
576 | 258 | if mappings: | 260 | if mappings: |
578 | 259 | mappings = mappings.split(' ') | 261 | mappings = mappings.split() |
579 | 260 | for m in mappings: | 262 | for m in mappings: |
580 | 261 | p = m.partition(':') | 263 | p = m.partition(':') |
583 | 262 | if p[1] == ':': | 264 | key = p[0].strip() |
584 | 263 | parsed[p[0].strip()] = p[2].strip() | 265 | if p[1]: |
585 | 266 | parsed[key] = p[2].strip() | ||
586 | 267 | else: | ||
587 | 268 | parsed[key] = '' | ||
588 | 264 | 269 | ||
589 | 265 | return parsed | 270 | return parsed |
590 | 266 | 271 | ||
591 | @@ -283,13 +288,13 @@ | |||
592 | 283 | Returns dict of the form {bridge:port}. | 288 | Returns dict of the form {bridge:port}. |
593 | 284 | """ | 289 | """ |
594 | 285 | _mappings = parse_mappings(mappings) | 290 | _mappings = parse_mappings(mappings) |
596 | 286 | if not _mappings: | 291 | if not _mappings or list(_mappings.values()) == ['']: |
597 | 287 | if not mappings: | 292 | if not mappings: |
598 | 288 | return {} | 293 | return {} |
599 | 289 | 294 | ||
600 | 290 | # For backwards-compatibility we need to support port-only provided in | 295 | # For backwards-compatibility we need to support port-only provided in |
601 | 291 | # config. | 296 | # config. |
603 | 292 | _mappings = {default_bridge: mappings.split(' ')[0]} | 297 | _mappings = {default_bridge: mappings.split()[0]} |
604 | 293 | 298 | ||
605 | 294 | bridges = _mappings.keys() | 299 | bridges = _mappings.keys() |
606 | 295 | ports = _mappings.values() | 300 | ports = _mappings.values() |
607 | @@ -309,6 +314,8 @@ | |||
608 | 309 | 314 | ||
609 | 310 | Mappings must be a space-delimited list of provider:start:end mappings. | 315 | Mappings must be a space-delimited list of provider:start:end mappings. |
610 | 311 | 316 | ||
611 | 317 | The start:end range is optional and may be omitted. | ||
612 | 318 | |||
613 | 312 | Returns dict of the form {provider: (start, end)}. | 319 | Returns dict of the form {provider: (start, end)}. |
614 | 313 | """ | 320 | """ |
615 | 314 | _mappings = parse_mappings(mappings) | 321 | _mappings = parse_mappings(mappings) |
616 | 315 | 322 | ||
617 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
618 | --- hooks/charmhelpers/contrib/openstack/utils.py 2015-05-12 14:25:49 +0000 | |||
619 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2015-06-19 16:15:40 +0000 | |||
620 | @@ -79,6 +79,7 @@ | |||
621 | 79 | ('trusty', 'icehouse'), | 79 | ('trusty', 'icehouse'), |
622 | 80 | ('utopic', 'juno'), | 80 | ('utopic', 'juno'), |
623 | 81 | ('vivid', 'kilo'), | 81 | ('vivid', 'kilo'), |
624 | 82 | ('wily', 'liberty'), | ||
625 | 82 | ]) | 83 | ]) |
626 | 83 | 84 | ||
627 | 84 | 85 | ||
628 | @@ -91,6 +92,7 @@ | |||
629 | 91 | ('2014.1', 'icehouse'), | 92 | ('2014.1', 'icehouse'), |
630 | 92 | ('2014.2', 'juno'), | 93 | ('2014.2', 'juno'), |
631 | 93 | ('2015.1', 'kilo'), | 94 | ('2015.1', 'kilo'), |
632 | 95 | ('2015.2', 'liberty'), | ||
633 | 94 | ]) | 96 | ]) |
634 | 95 | 97 | ||
635 | 96 | # The ugly duckling | 98 | # The ugly duckling |
636 | @@ -113,6 +115,7 @@ | |||
637 | 113 | ('2.2.0', 'juno'), | 115 | ('2.2.0', 'juno'), |
638 | 114 | ('2.2.1', 'kilo'), | 116 | ('2.2.1', 'kilo'), |
639 | 115 | ('2.2.2', 'kilo'), | 117 | ('2.2.2', 'kilo'), |
640 | 118 | ('2.3.0', 'liberty'), | ||
641 | 116 | ]) | 119 | ]) |
642 | 117 | 120 | ||
643 | 118 | DEFAULT_LOOPBACK_SIZE = '5G' | 121 | DEFAULT_LOOPBACK_SIZE = '5G' |
644 | @@ -321,6 +324,9 @@ | |||
645 | 321 | 'kilo': 'trusty-updates/kilo', | 324 | 'kilo': 'trusty-updates/kilo', |
646 | 322 | 'kilo/updates': 'trusty-updates/kilo', | 325 | 'kilo/updates': 'trusty-updates/kilo', |
647 | 323 | 'kilo/proposed': 'trusty-proposed/kilo', | 326 | 'kilo/proposed': 'trusty-proposed/kilo', |
648 | 327 | 'liberty': 'trusty-updates/liberty', | ||
649 | 328 | 'liberty/updates': 'trusty-updates/liberty', | ||
650 | 329 | 'liberty/proposed': 'trusty-proposed/liberty', | ||
651 | 324 | } | 330 | } |
652 | 325 | 331 | ||
653 | 326 | try: | 332 | try: |
654 | @@ -549,6 +555,11 @@ | |||
655 | 549 | 555 | ||
656 | 550 | pip_create_virtualenv(os.path.join(parent_dir, 'venv')) | 556 | pip_create_virtualenv(os.path.join(parent_dir, 'venv')) |
657 | 551 | 557 | ||
658 | 558 | # Upgrade setuptools from default virtualenv version. The default version | ||
659 | 559 | # in trusty breaks update.py in global requirements master branch. | ||
660 | 560 | pip_install('setuptools', upgrade=True, proxy=http_proxy, | ||
661 | 561 | venv=os.path.join(parent_dir, 'venv')) | ||
662 | 562 | |||
663 | 552 | for p in projects['repositories']: | 563 | for p in projects['repositories']: |
664 | 553 | repo = p['repository'] | 564 | repo = p['repository'] |
665 | 554 | branch = p['branch'] | 565 | branch = p['branch'] |
666 | @@ -610,24 +621,24 @@ | |||
667 | 610 | else: | 621 | else: |
668 | 611 | repo_dir = dest_dir | 622 | repo_dir = dest_dir |
669 | 612 | 623 | ||
670 | 624 | venv = os.path.join(parent_dir, 'venv') | ||
671 | 625 | |||
672 | 613 | if update_requirements: | 626 | if update_requirements: |
673 | 614 | if not requirements_dir: | 627 | if not requirements_dir: |
674 | 615 | error_out('requirements repo must be cloned before ' | 628 | error_out('requirements repo must be cloned before ' |
675 | 616 | 'updating from global requirements.') | 629 | 'updating from global requirements.') |
677 | 617 | _git_update_requirements(repo_dir, requirements_dir) | 630 | _git_update_requirements(venv, repo_dir, requirements_dir) |
678 | 618 | 631 | ||
679 | 619 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) | 632 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) |
680 | 620 | if http_proxy: | 633 | if http_proxy: |
683 | 621 | pip_install(repo_dir, proxy=http_proxy, | 634 | pip_install(repo_dir, proxy=http_proxy, venv=venv) |
682 | 622 | venv=os.path.join(parent_dir, 'venv')) | ||
684 | 623 | else: | 635 | else: |
687 | 624 | pip_install(repo_dir, | 636 | pip_install(repo_dir, venv=venv) |
686 | 625 | venv=os.path.join(parent_dir, 'venv')) | ||
688 | 626 | 637 | ||
689 | 627 | return repo_dir | 638 | return repo_dir |
690 | 628 | 639 | ||
691 | 629 | 640 | ||
693 | 630 | def _git_update_requirements(package_dir, reqs_dir): | 641 | def _git_update_requirements(venv, package_dir, reqs_dir): |
694 | 631 | """ | 642 | """ |
695 | 632 | Update from global requirements. | 643 | Update from global requirements. |
696 | 633 | 644 | ||
697 | @@ -636,12 +647,14 @@ | |||
698 | 636 | """ | 647 | """ |
699 | 637 | orig_dir = os.getcwd() | 648 | orig_dir = os.getcwd() |
700 | 638 | os.chdir(reqs_dir) | 649 | os.chdir(reqs_dir) |
702 | 639 | cmd = ['python', 'update.py', package_dir] | 650 | python = os.path.join(venv, 'bin/python') |
703 | 651 | cmd = [python, 'update.py', package_dir] | ||
704 | 640 | try: | 652 | try: |
705 | 641 | subprocess.check_call(cmd) | 653 | subprocess.check_call(cmd) |
706 | 642 | except subprocess.CalledProcessError: | 654 | except subprocess.CalledProcessError: |
707 | 643 | package = os.path.basename(package_dir) | 655 | package = os.path.basename(package_dir) |
709 | 644 | error_out("Error updating {} from global-requirements.txt".format(package)) | 656 | error_out("Error updating {} from " |
710 | 657 | "global-requirements.txt".format(package)) | ||
711 | 645 | os.chdir(orig_dir) | 658 | os.chdir(orig_dir) |
712 | 646 | 659 | ||
713 | 647 | 660 | ||
714 | 648 | 661 | ||
715 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
716 | --- hooks/charmhelpers/core/hookenv.py 2015-04-16 20:24:28 +0000 | |||
717 | +++ hooks/charmhelpers/core/hookenv.py 2015-06-19 16:15:40 +0000 | |||
718 | @@ -21,12 +21,14 @@ | |||
719 | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> | 21 | # Charm Helpers Developers <juju@lists.ubuntu.com> |
720 | 22 | 22 | ||
721 | 23 | from __future__ import print_function | 23 | from __future__ import print_function |
722 | 24 | from functools import wraps | ||
723 | 24 | import os | 25 | import os |
724 | 25 | import json | 26 | import json |
725 | 26 | import yaml | 27 | import yaml |
726 | 27 | import subprocess | 28 | import subprocess |
727 | 28 | import sys | 29 | import sys |
728 | 29 | import errno | 30 | import errno |
729 | 31 | import tempfile | ||
730 | 30 | from subprocess import CalledProcessError | 32 | from subprocess import CalledProcessError |
731 | 31 | 33 | ||
732 | 32 | import six | 34 | import six |
733 | @@ -58,15 +60,17 @@ | |||
734 | 58 | 60 | ||
735 | 59 | will cache the result of unit_get + 'test' for future calls. | 61 | will cache the result of unit_get + 'test' for future calls. |
736 | 60 | """ | 62 | """ |
737 | 63 | @wraps(func) | ||
738 | 61 | def wrapper(*args, **kwargs): | 64 | def wrapper(*args, **kwargs): |
739 | 62 | global cache | 65 | global cache |
740 | 63 | key = str((func, args, kwargs)) | 66 | key = str((func, args, kwargs)) |
741 | 64 | try: | 67 | try: |
742 | 65 | return cache[key] | 68 | return cache[key] |
743 | 66 | except KeyError: | 69 | except KeyError: |
747 | 67 | res = func(*args, **kwargs) | 70 | pass # Drop out of the exception handler scope. |
748 | 68 | cache[key] = res | 71 | res = func(*args, **kwargs) |
749 | 69 | return res | 72 | cache[key] = res |
750 | 73 | return res | ||
751 | 70 | return wrapper | 74 | return wrapper |
752 | 71 | 75 | ||
753 | 72 | 76 | ||
754 | @@ -178,7 +182,7 @@ | |||
755 | 178 | 182 | ||
756 | 179 | def remote_unit(): | 183 | def remote_unit(): |
757 | 180 | """The remote unit for the current relation hook""" | 184 | """The remote unit for the current relation hook""" |
759 | 181 | return os.environ['JUJU_REMOTE_UNIT'] | 185 | return os.environ.get('JUJU_REMOTE_UNIT', None) |
760 | 182 | 186 | ||
761 | 183 | 187 | ||
762 | 184 | def service_name(): | 188 | def service_name(): |
763 | @@ -250,6 +254,12 @@ | |||
764 | 250 | except KeyError: | 254 | except KeyError: |
765 | 251 | return (self._prev_dict or {})[key] | 255 | return (self._prev_dict or {})[key] |
766 | 252 | 256 | ||
767 | 257 | def get(self, key, default=None): | ||
768 | 258 | try: | ||
769 | 259 | return self[key] | ||
770 | 260 | except KeyError: | ||
771 | 261 | return default | ||
772 | 262 | |||
773 | 253 | def keys(self): | 263 | def keys(self): |
774 | 254 | prev_keys = [] | 264 | prev_keys = [] |
775 | 255 | if self._prev_dict is not None: | 265 | if self._prev_dict is not None: |
776 | @@ -353,18 +363,49 @@ | |||
777 | 353 | """Set relation information for the current unit""" | 363 | """Set relation information for the current unit""" |
778 | 354 | relation_settings = relation_settings if relation_settings else {} | 364 | relation_settings = relation_settings if relation_settings else {} |
779 | 355 | relation_cmd_line = ['relation-set'] | 365 | relation_cmd_line = ['relation-set'] |
780 | 366 | accepts_file = "--file" in subprocess.check_output( | ||
781 | 367 | relation_cmd_line + ["--help"], universal_newlines=True) | ||
782 | 356 | if relation_id is not None: | 368 | if relation_id is not None: |
783 | 357 | relation_cmd_line.extend(('-r', relation_id)) | 369 | relation_cmd_line.extend(('-r', relation_id)) |
790 | 358 | for k, v in (list(relation_settings.items()) + list(kwargs.items())): | 370 | settings = relation_settings.copy() |
791 | 359 | if v is None: | 371 | settings.update(kwargs) |
792 | 360 | relation_cmd_line.append('{}='.format(k)) | 372 | for key, value in settings.items(): |
793 | 361 | else: | 373 | # Force value to be a string: it always should, but some call |
794 | 362 | relation_cmd_line.append('{}={}'.format(k, v)) | 374 | # sites pass in things like dicts or numbers. |
795 | 363 | subprocess.check_call(relation_cmd_line) | 375 | if value is not None: |
796 | 376 | settings[key] = "{}".format(value) | ||
797 | 377 | if accepts_file: | ||
798 | 378 | # --file was introduced in Juju 1.23.2. Use it by default if | ||
799 | 379 | # available, since otherwise we'll break if the relation data is | ||
800 | 380 | # too big. Ideally we should tell relation-set to read the data from | ||
801 | 381 | # stdin, but that feature is broken in 1.23.2: Bug #1454678. | ||
802 | 382 | with tempfile.NamedTemporaryFile(delete=False) as settings_file: | ||
803 | 383 | settings_file.write(yaml.safe_dump(settings).encode("utf-8")) | ||
804 | 384 | subprocess.check_call( | ||
805 | 385 | relation_cmd_line + ["--file", settings_file.name]) | ||
806 | 386 | os.remove(settings_file.name) | ||
807 | 387 | else: | ||
808 | 388 | for key, value in settings.items(): | ||
809 | 389 | if value is None: | ||
810 | 390 | relation_cmd_line.append('{}='.format(key)) | ||
811 | 391 | else: | ||
812 | 392 | relation_cmd_line.append('{}={}'.format(key, value)) | ||
813 | 393 | subprocess.check_call(relation_cmd_line) | ||
814 | 364 | # Flush cache of any relation-gets for local unit | 394 | # Flush cache of any relation-gets for local unit |
815 | 365 | flush(local_unit()) | 395 | flush(local_unit()) |
816 | 366 | 396 | ||
817 | 367 | 397 | ||
818 | 398 | def relation_clear(r_id=None): | ||
819 | 399 | ''' Clears any relation data already set on relation r_id ''' | ||
820 | 400 | settings = relation_get(rid=r_id, | ||
821 | 401 | unit=local_unit()) | ||
822 | 402 | for setting in settings: | ||
823 | 403 | if setting not in ['public-address', 'private-address']: | ||
824 | 404 | settings[setting] = None | ||
825 | 405 | relation_set(relation_id=r_id, | ||
826 | 406 | **settings) | ||
827 | 407 | |||
828 | 408 | |||
829 | 368 | @cached | 409 | @cached |
830 | 369 | def relation_ids(reltype=None): | 410 | def relation_ids(reltype=None): |
831 | 370 | """A list of relation_ids""" | 411 | """A list of relation_ids""" |
832 | @@ -509,6 +550,11 @@ | |||
833 | 509 | return None | 550 | return None |
834 | 510 | 551 | ||
835 | 511 | 552 | ||
836 | 553 | def unit_public_ip(): | ||
837 | 554 | """Get this unit's public IP address""" | ||
838 | 555 | return unit_get('public-address') | ||
839 | 556 | |||
840 | 557 | |||
841 | 512 | def unit_private_ip(): | 558 | def unit_private_ip(): |
842 | 513 | """Get this unit's private IP address""" | 559 | """Get this unit's private IP address""" |
843 | 514 | return unit_get('private-address') | 560 | return unit_get('private-address') |
844 | @@ -605,3 +651,94 @@ | |||
845 | 605 | 651 | ||
846 | 606 | The results set by action_set are preserved.""" | 652 | The results set by action_set are preserved.""" |
847 | 607 | subprocess.check_call(['action-fail', message]) | 653 | subprocess.check_call(['action-fail', message]) |
848 | 654 | |||
849 | 655 | |||
850 | 656 | def status_set(workload_state, message): | ||
851 | 657 | """Set the workload state with a message | ||
852 | 658 | |||
853 | 659 | Use status-set to set the workload state with a message which is visible | ||
854 | 660 | to the user via juju status. If the status-set command is not found then | ||
855 | 661 | assume this is juju < 1.23 and juju-log the message unstead. | ||
856 | 662 | |||
857 | 663 | workload_state -- valid juju workload state. | ||
858 | 664 | message -- status update message | ||
859 | 665 | """ | ||
860 | 666 | valid_states = ['maintenance', 'blocked', 'waiting', 'active'] | ||
861 | 667 | if workload_state not in valid_states: | ||
862 | 668 | raise ValueError( | ||
863 | 669 | '{!r} is not a valid workload state'.format(workload_state) | ||
864 | 670 | ) | ||
865 | 671 | cmd = ['status-set', workload_state, message] | ||
866 | 672 | try: | ||
867 | 673 | ret = subprocess.call(cmd) | ||
868 | 674 | if ret == 0: | ||
869 | 675 | return | ||
870 | 676 | except OSError as e: | ||
871 | 677 | if e.errno != errno.ENOENT: | ||
872 | 678 | raise | ||
873 | 679 | log_message = 'status-set failed: {} {}'.format(workload_state, | ||
874 | 680 | message) | ||
875 | 681 | log(log_message, level='INFO') | ||
876 | 682 | |||
877 | 683 | |||
878 | 684 | def status_get(): | ||
879 | 685 | """Retrieve the previously set juju workload state | ||
880 | 686 | |||
881 | 687 | If the status-set command is not found then assume this is juju < 1.23 and | ||
882 | 688 | return 'unknown' | ||
883 | 689 | """ | ||
884 | 690 | cmd = ['status-get'] | ||
885 | 691 | try: | ||
886 | 692 | raw_status = subprocess.check_output(cmd, universal_newlines=True) | ||
887 | 693 | status = raw_status.rstrip() | ||
888 | 694 | return status | ||
889 | 695 | except OSError as e: | ||
890 | 696 | if e.errno == errno.ENOENT: | ||
891 | 697 | return 'unknown' | ||
892 | 698 | else: | ||
893 | 699 | raise | ||
894 | 700 | |||
895 | 701 | |||
896 | 702 | def translate_exc(from_exc, to_exc): | ||
897 | 703 | def inner_translate_exc1(f): | ||
898 | 704 | def inner_translate_exc2(*args, **kwargs): | ||
899 | 705 | try: | ||
900 | 706 | return f(*args, **kwargs) | ||
901 | 707 | except from_exc: | ||
902 | 708 | raise to_exc | ||
903 | 709 | |||
904 | 710 | return inner_translate_exc2 | ||
905 | 711 | |||
906 | 712 | return inner_translate_exc1 | ||
907 | 713 | |||
908 | 714 | |||
909 | 715 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
910 | 716 | def is_leader(): | ||
911 | 717 | """Does the current unit hold the juju leadership | ||
912 | 718 | |||
913 | 719 | Uses juju to determine whether the current unit is the leader of its peers | ||
914 | 720 | """ | ||
915 | 721 | cmd = ['is-leader', '--format=json'] | ||
916 | 722 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
917 | 723 | |||
918 | 724 | |||
919 | 725 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
920 | 726 | def leader_get(attribute=None): | ||
921 | 727 | """Juju leader get value(s)""" | ||
922 | 728 | cmd = ['leader-get', '--format=json'] + [attribute or '-'] | ||
923 | 729 | return json.loads(subprocess.check_output(cmd).decode('UTF-8')) | ||
924 | 730 | |||
925 | 731 | |||
926 | 732 | @translate_exc(from_exc=OSError, to_exc=NotImplementedError) | ||
927 | 733 | def leader_set(settings=None, **kwargs): | ||
928 | 734 | """Juju leader set value(s)""" | ||
929 | 735 | log("Juju leader-set '%s'" % (settings), level=DEBUG) | ||
930 | 736 | cmd = ['leader-set'] | ||
931 | 737 | settings = settings or {} | ||
932 | 738 | settings.update(kwargs) | ||
933 | 739 | for k, v in settings.iteritems(): | ||
934 | 740 | if v is None: | ||
935 | 741 | cmd.append('{}='.format(k)) | ||
936 | 742 | else: | ||
937 | 743 | cmd.append('{}={}'.format(k, v)) | ||
938 | 744 | subprocess.check_call(cmd) | ||
939 | 608 | 745 | ||
940 | === modified file 'hooks/charmhelpers/core/host.py' | |||
941 | --- hooks/charmhelpers/core/host.py 2015-04-16 20:24:28 +0000 | |||
942 | +++ hooks/charmhelpers/core/host.py 2015-06-19 16:15:40 +0000 | |||
943 | @@ -24,6 +24,7 @@ | |||
944 | 24 | import os | 24 | import os |
945 | 25 | import re | 25 | import re |
946 | 26 | import pwd | 26 | import pwd |
947 | 27 | import glob | ||
948 | 27 | import grp | 28 | import grp |
949 | 28 | import random | 29 | import random |
950 | 29 | import string | 30 | import string |
951 | @@ -90,7 +91,7 @@ | |||
952 | 90 | ['service', service_name, 'status'], | 91 | ['service', service_name, 'status'], |
953 | 91 | stderr=subprocess.STDOUT).decode('UTF-8') | 92 | stderr=subprocess.STDOUT).decode('UTF-8') |
954 | 92 | except subprocess.CalledProcessError as e: | 93 | except subprocess.CalledProcessError as e: |
956 | 93 | return 'unrecognized service' not in e.output | 94 | return b'unrecognized service' not in e.output |
957 | 94 | else: | 95 | else: |
958 | 95 | return True | 96 | return True |
959 | 96 | 97 | ||
960 | @@ -269,6 +270,21 @@ | |||
961 | 269 | return None | 270 | return None |
962 | 270 | 271 | ||
963 | 271 | 272 | ||
964 | 273 | def path_hash(path): | ||
965 | 274 | """ | ||
966 | 275 | Generate a hash checksum of all files matching 'path'. Standard wildcards | ||
967 | 276 | like '*' and '?' are supported, see documentation for the 'glob' module for | ||
968 | 277 | more information. | ||
969 | 278 | |||
970 | 279 | :return: dict: A { filename: hash } dictionary for all matched files. | ||
971 | 280 | Empty if none found. | ||
972 | 281 | """ | ||
973 | 282 | return { | ||
974 | 283 | filename: file_hash(filename) | ||
975 | 284 | for filename in glob.iglob(path) | ||
976 | 285 | } | ||
977 | 286 | |||
978 | 287 | |||
979 | 272 | def check_hash(path, checksum, hash_type='md5'): | 288 | def check_hash(path, checksum, hash_type='md5'): |
980 | 273 | """ | 289 | """ |
981 | 274 | Validate a file using a cryptographic checksum. | 290 | Validate a file using a cryptographic checksum. |
982 | @@ -296,23 +312,25 @@ | |||
983 | 296 | 312 | ||
984 | 297 | @restart_on_change({ | 313 | @restart_on_change({ |
985 | 298 | '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] | 314 | '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ] |
986 | 315 | '/etc/apache/sites-enabled/*': [ 'apache2' ] | ||
987 | 299 | }) | 316 | }) |
989 | 300 | def ceph_client_changed(): | 317 | def config_changed(): |
990 | 301 | pass # your code here | 318 | pass # your code here |
991 | 302 | 319 | ||
992 | 303 | In this example, the cinder-api and cinder-volume services | 320 | In this example, the cinder-api and cinder-volume services |
993 | 304 | would be restarted if /etc/ceph/ceph.conf is changed by the | 321 | would be restarted if /etc/ceph/ceph.conf is changed by the |
995 | 305 | ceph_client_changed function. | 322 | ceph_client_changed function. The apache2 service would be |
996 | 323 | restarted if any file matching the pattern got changed, created | ||
997 | 324 | or removed. Standard wildcards are supported, see documentation | ||
998 | 325 | for the 'glob' module for more information. | ||
999 | 306 | """ | 326 | """ |
1000 | 307 | def wrap(f): | 327 | def wrap(f): |
1001 | 308 | def wrapped_f(*args, **kwargs): | 328 | def wrapped_f(*args, **kwargs): |
1005 | 309 | checksums = {} | 329 | checksums = {path: path_hash(path) for path in restart_map} |
1003 | 310 | for path in restart_map: | ||
1004 | 311 | checksums[path] = file_hash(path) | ||
1006 | 312 | f(*args, **kwargs) | 330 | f(*args, **kwargs) |
1007 | 313 | restarts = [] | 331 | restarts = [] |
1008 | 314 | for path in restart_map: | 332 | for path in restart_map: |
1010 | 315 | if checksums[path] != file_hash(path): | 333 | if path_hash(path) != checksums[path]: |
1011 | 316 | restarts += restart_map[path] | 334 | restarts += restart_map[path] |
1012 | 317 | services_list = list(OrderedDict.fromkeys(restarts)) | 335 | services_list = list(OrderedDict.fromkeys(restarts)) |
1013 | 318 | if not stopstart: | 336 | if not stopstart: |
1014 | 319 | 337 | ||
1015 | === modified file 'hooks/charmhelpers/core/services/base.py' | |||
1016 | --- hooks/charmhelpers/core/services/base.py 2015-01-26 09:46:38 +0000 | |||
1017 | +++ hooks/charmhelpers/core/services/base.py 2015-06-19 16:15:40 +0000 | |||
1018 | @@ -15,9 +15,9 @@ | |||
1019 | 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/>. |
1020 | 16 | 16 | ||
1021 | 17 | import os | 17 | import os |
1022 | 18 | import re | ||
1023 | 19 | import json | 18 | import json |
1025 | 20 | from collections import Iterable | 19 | from inspect import getargspec |
1026 | 20 | from collections import Iterable, OrderedDict | ||
1027 | 21 | 21 | ||
1028 | 22 | from charmhelpers.core import host | 22 | from charmhelpers.core import host |
1029 | 23 | from charmhelpers.core import hookenv | 23 | from charmhelpers.core import hookenv |
1030 | @@ -119,7 +119,7 @@ | |||
1031 | 119 | """ | 119 | """ |
1032 | 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') |
1033 | 121 | self._ready = None | 121 | self._ready = None |
1035 | 122 | self.services = {} | 122 | self.services = OrderedDict() |
1036 | 123 | for service in services or []: | 123 | for service in services or []: |
1037 | 124 | service_name = service['service'] | 124 | service_name = service['service'] |
1038 | 125 | self.services[service_name] = service | 125 | self.services[service_name] = service |
1039 | @@ -132,8 +132,8 @@ | |||
1040 | 132 | if hook_name == 'stop': | 132 | if hook_name == 'stop': |
1041 | 133 | self.stop_services() | 133 | self.stop_services() |
1042 | 134 | else: | 134 | else: |
1043 | 135 | self.reconfigure_services() | ||
1044 | 135 | self.provide_data() | 136 | self.provide_data() |
1045 | 136 | self.reconfigure_services() | ||
1046 | 137 | cfg = hookenv.config() | 137 | cfg = hookenv.config() |
1047 | 138 | if cfg.implicit_save: | 138 | if cfg.implicit_save: |
1048 | 139 | cfg.save() | 139 | cfg.save() |
1049 | @@ -145,15 +145,36 @@ | |||
1050 | 145 | A provider must have a `name` attribute, which indicates which relation | 145 | A provider must have a `name` attribute, which indicates which relation |
1051 | 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 |
1052 | 147 | data to set. | 147 | data to set. |
1053 | 148 | |||
1054 | 149 | The `provide_data()` method can optionally accept two parameters: | ||
1055 | 150 | |||
1056 | 151 | * ``remote_service`` The name of the remote service that the data will | ||
1057 | 152 | be provided to. The `provide_data()` method will be called once | ||
1058 | 153 | for each connected service (not unit). This allows the method to | ||
1059 | 154 | tailor its data to the given service. | ||
1060 | 155 | * ``service_ready`` Whether or not the service definition had all of | ||
1061 | 156 | its requirements met, and thus the ``data_ready`` callbacks run. | ||
1062 | 157 | |||
1063 | 158 | Note that the ``provided_data`` methods are now called **after** the | ||
1064 | 159 | ``data_ready`` callbacks are run. This gives the ``data_ready`` callbacks | ||
1065 | 160 | a chance to generate any data necessary for the providing to the remote | ||
1066 | 161 | services. | ||
1067 | 148 | """ | 162 | """ |
1070 | 149 | hook_name = hookenv.hook_name() | 163 | for service_name, service in self.services.items(): |
1071 | 150 | for service in self.services.values(): | 164 | service_ready = self.is_ready(service_name) |
1072 | 151 | for provider in service.get('provided_data', []): | 165 | for provider in service.get('provided_data', []): |
1078 | 152 | if re.match(r'{}-relation-(joined|changed)'.format(provider.name), hook_name): | 166 | for relid in hookenv.relation_ids(provider.name): |
1079 | 153 | data = provider.provide_data() | 167 | units = hookenv.related_units(relid) |
1080 | 154 | _ready = provider._is_ready(data) if hasattr(provider, '_is_ready') else data | 168 | if not units: |
1081 | 155 | if _ready: | 169 | continue |
1082 | 156 | hookenv.relation_set(None, data) | 170 | remote_service = units[0].split('/')[0] |
1083 | 171 | argspec = getargspec(provider.provide_data) | ||
1084 | 172 | if len(argspec.args) > 1: | ||
1085 | 173 | data = provider.provide_data(remote_service, service_ready) | ||
1086 | 174 | else: | ||
1087 | 175 | data = provider.provide_data() | ||
1088 | 176 | if data: | ||
1089 | 177 | hookenv.relation_set(relid, data) | ||
1090 | 157 | 178 | ||
1091 | 158 | def reconfigure_services(self, *service_names): | 179 | def reconfigure_services(self, *service_names): |
1092 | 159 | """ | 180 | """ |
1093 | 160 | 181 | ||
1094 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
1095 | --- hooks/charmhelpers/fetch/__init__.py 2015-05-01 14:57:35 +0000 | |||
1096 | +++ hooks/charmhelpers/fetch/__init__.py 2015-06-19 16:15:40 +0000 | |||
1097 | @@ -158,7 +158,7 @@ | |||
1098 | 158 | 158 | ||
1099 | 159 | def apt_cache(in_memory=True): | 159 | def apt_cache(in_memory=True): |
1100 | 160 | """Build and return an apt cache""" | 160 | """Build and return an apt cache""" |
1102 | 161 | import apt_pkg | 161 | from apt import apt_pkg |
1103 | 162 | apt_pkg.init() | 162 | apt_pkg.init() |
1104 | 163 | if in_memory: | 163 | if in_memory: |
1105 | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") | 164 | apt_pkg.config.set("Dir::Cache::pkgcache", "") |
1106 | 165 | 165 | ||
1107 | === modified file 'tests/charmhelpers/contrib/amulet/utils.py' | |||
1108 | --- tests/charmhelpers/contrib/amulet/utils.py 2015-05-05 20:28:18 +0000 | |||
1109 | +++ tests/charmhelpers/contrib/amulet/utils.py 2015-06-19 16:15:40 +0000 | |||
1110 | @@ -15,13 +15,15 @@ | |||
1111 | 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/>. |
1112 | 16 | 16 | ||
1113 | 17 | import ConfigParser | 17 | import ConfigParser |
1114 | 18 | import distro_info | ||
1115 | 18 | import io | 19 | import io |
1116 | 19 | import logging | 20 | import logging |
1117 | 21 | import os | ||
1118 | 20 | import re | 22 | import re |
1119 | 23 | import six | ||
1120 | 21 | import sys | 24 | import sys |
1121 | 22 | import time | 25 | import time |
1124 | 23 | 26 | import urlparse | |
1123 | 24 | import six | ||
1125 | 25 | 27 | ||
1126 | 26 | 28 | ||
1127 | 27 | class AmuletUtils(object): | 29 | class AmuletUtils(object): |
1128 | @@ -33,6 +35,7 @@ | |||
1129 | 33 | 35 | ||
1130 | 34 | def __init__(self, log_level=logging.ERROR): | 36 | def __init__(self, log_level=logging.ERROR): |
1131 | 35 | self.log = self.get_logger(level=log_level) | 37 | self.log = self.get_logger(level=log_level) |
1132 | 38 | self.ubuntu_releases = self.get_ubuntu_releases() | ||
1133 | 36 | 39 | ||
1134 | 37 | def get_logger(self, name="amulet-logger", level=logging.DEBUG): | 40 | def get_logger(self, name="amulet-logger", level=logging.DEBUG): |
1135 | 38 | """Get a logger object that will log to stdout.""" | 41 | """Get a logger object that will log to stdout.""" |
1136 | @@ -70,12 +73,44 @@ | |||
1137 | 70 | else: | 73 | else: |
1138 | 71 | return False | 74 | return False |
1139 | 72 | 75 | ||
1140 | 76 | def get_ubuntu_release_from_sentry(self, sentry_unit): | ||
1141 | 77 | """Get Ubuntu release codename from sentry unit. | ||
1142 | 78 | |||
1143 | 79 | :param sentry_unit: amulet sentry/service unit pointer | ||
1144 | 80 | :returns: list of strings - release codename, failure message | ||
1145 | 81 | """ | ||
1146 | 82 | msg = None | ||
1147 | 83 | cmd = 'lsb_release -cs' | ||
1148 | 84 | release, code = sentry_unit.run(cmd) | ||
1149 | 85 | if code == 0: | ||
1150 | 86 | self.log.debug('{} lsb_release: {}'.format( | ||
1151 | 87 | sentry_unit.info['unit_name'], release)) | ||
1152 | 88 | else: | ||
1153 | 89 | msg = ('{} `{}` returned {} ' | ||
1154 | 90 | '{}'.format(sentry_unit.info['unit_name'], | ||
1155 | 91 | cmd, release, code)) | ||
1156 | 92 | if release not in self.ubuntu_releases: | ||
1157 | 93 | msg = ("Release ({}) not found in Ubuntu releases " | ||
1158 | 94 | "({})".format(release, self.ubuntu_releases)) | ||
1159 | 95 | return release, msg | ||
1160 | 96 | |||
1161 | 73 | def validate_services(self, commands): | 97 | def validate_services(self, commands): |
1165 | 74 | """Validate services. | 98 | """Validate that lists of commands succeed on service units. Can be |
1166 | 75 | 99 | used to verify system services are running on the corresponding | |
1164 | 76 | Verify the specified services are running on the corresponding | ||
1167 | 77 | service units. | 100 | service units. |
1169 | 78 | """ | 101 | |
1170 | 102 | :param commands: dict with sentry keys and arbitrary command list vals | ||
1171 | 103 | :returns: None if successful, Failure string message otherwise | ||
1172 | 104 | """ | ||
1173 | 105 | self.log.debug('Checking status of system services...') | ||
1174 | 106 | |||
1175 | 107 | # /!\ DEPRECATION WARNING (beisner): | ||
1176 | 108 | # New and existing tests should be rewritten to use | ||
1177 | 109 | # validate_services_by_name() as it is aware of init systems. | ||
1178 | 110 | self.log.warn('/!\\ DEPRECATION WARNING: use ' | ||
1179 | 111 | 'validate_services_by_name instead of validate_services ' | ||
1180 | 112 | 'due to init system differences.') | ||
1181 | 113 | |||
1182 | 79 | for k, v in six.iteritems(commands): | 114 | for k, v in six.iteritems(commands): |
1183 | 80 | for cmd in v: | 115 | for cmd in v: |
1184 | 81 | output, code = k.run(cmd) | 116 | output, code = k.run(cmd) |
1185 | @@ -86,6 +121,41 @@ | |||
1186 | 86 | return "command `{}` returned {}".format(cmd, str(code)) | 121 | return "command `{}` returned {}".format(cmd, str(code)) |
1187 | 87 | return None | 122 | return None |
1188 | 88 | 123 | ||
1189 | 124 | def validate_services_by_name(self, sentry_services): | ||
1190 | 125 | """Validate system service status by service name, automatically | ||
1191 | 126 | detecting init system based on Ubuntu release codename. | ||
1192 | 127 | |||
1193 | 128 | :param sentry_services: dict with sentry keys and svc list values | ||
1194 | 129 | :returns: None if successful, Failure string message otherwise | ||
1195 | 130 | """ | ||
1196 | 131 | self.log.debug('Checking status of system services...') | ||
1197 | 132 | |||
1198 | 133 | # Point at which systemd became a thing | ||
1199 | 134 | systemd_switch = self.ubuntu_releases.index('vivid') | ||
1200 | 135 | |||
1201 | 136 | for sentry_unit, services_list in six.iteritems(sentry_services): | ||
1202 | 137 | # Get lsb_release codename from unit | ||
1203 | 138 | release, ret = self.get_ubuntu_release_from_sentry(sentry_unit) | ||
1204 | 139 | if ret: | ||
1205 | 140 | return ret | ||
1206 | 141 | |||
1207 | 142 | for service_name in services_list: | ||
1208 | 143 | if (self.ubuntu_releases.index(release) >= systemd_switch or | ||
1209 | 144 | service_name == "rabbitmq-server"): | ||
1210 | 145 | # init is systemd | ||
1211 | 146 | cmd = 'sudo service {} status'.format(service_name) | ||
1212 | 147 | elif self.ubuntu_releases.index(release) < systemd_switch: | ||
1213 | 148 | # init is upstart | ||
1214 | 149 | cmd = 'sudo status {}'.format(service_name) | ||
1215 | 150 | |||
1216 | 151 | output, code = sentry_unit.run(cmd) | ||
1217 | 152 | self.log.debug('{} `{}` returned ' | ||
1218 | 153 | '{}'.format(sentry_unit.info['unit_name'], | ||
1219 | 154 | cmd, code)) | ||
1220 | 155 | if code != 0: | ||
1221 | 156 | return "command `{}` returned {}".format(cmd, str(code)) | ||
1222 | 157 | return None | ||
1223 | 158 | |||
1224 | 89 | def _get_config(self, unit, filename): | 159 | def _get_config(self, unit, filename): |
1225 | 90 | """Get a ConfigParser object for parsing a unit's config file.""" | 160 | """Get a ConfigParser object for parsing a unit's config file.""" |
1226 | 91 | file_contents = unit.file_contents(filename) | 161 | file_contents = unit.file_contents(filename) |
1227 | @@ -104,6 +174,9 @@ | |||
1228 | 104 | Verify that the specified section of the config file contains | 174 | Verify that the specified section of the config file contains |
1229 | 105 | the expected option key:value pairs. | 175 | the expected option key:value pairs. |
1230 | 106 | """ | 176 | """ |
1231 | 177 | self.log.debug('Validating config file data ({} in {} on {})' | ||
1232 | 178 | '...'.format(section, config_file, | ||
1233 | 179 | sentry_unit.info['unit_name'])) | ||
1234 | 107 | config = self._get_config(sentry_unit, config_file) | 180 | config = self._get_config(sentry_unit, config_file) |
1235 | 108 | 181 | ||
1236 | 109 | if section != 'DEFAULT' and not config.has_section(section): | 182 | if section != 'DEFAULT' and not config.has_section(section): |
1237 | @@ -321,3 +394,15 @@ | |||
1238 | 321 | 394 | ||
1239 | 322 | def endpoint_error(self, name, data): | 395 | def endpoint_error(self, name, data): |
1240 | 323 | return 'unexpected endpoint data in {} - {}'.format(name, data) | 396 | return 'unexpected endpoint data in {} - {}'.format(name, data) |
1241 | 397 | |||
1242 | 398 | def get_ubuntu_releases(self): | ||
1243 | 399 | """Return a list of all Ubuntu releases in order of release.""" | ||
1244 | 400 | _d = distro_info.UbuntuDistroInfo() | ||
1245 | 401 | _release_list = _d.all | ||
1246 | 402 | self.log.debug('Ubuntu release list: {}'.format(_release_list)) | ||
1247 | 403 | return _release_list | ||
1248 | 404 | |||
1249 | 405 | def file_to_url(self, file_rel_path): | ||
1250 | 406 | """Convert a relative file path to a file URL.""" | ||
1251 | 407 | _abs_path = os.path.abspath(file_rel_path) | ||
1252 | 408 | return urlparse.urlparse(_abs_path, scheme='file').geturl() | ||
1253 | 324 | 409 | ||
1254 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
1255 | --- tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-05-05 20:28:18 +0000 | |||
1256 | +++ tests/charmhelpers/contrib/openstack/amulet/deployment.py 2015-06-19 16:15:40 +0000 | |||
1257 | @@ -110,7 +110,8 @@ | |||
1258 | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, | 110 | (self.precise_essex, self.precise_folsom, self.precise_grizzly, |
1259 | 111 | self.precise_havana, self.precise_icehouse, | 111 | self.precise_havana, self.precise_icehouse, |
1260 | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, | 112 | self.trusty_icehouse, self.trusty_juno, self.utopic_juno, |
1262 | 113 | self.trusty_kilo, self.vivid_kilo) = range(10) | 113 | self.trusty_kilo, self.vivid_kilo, self.trusty_liberty, |
1263 | 114 | self.wily_liberty) = range(12) | ||
1264 | 114 | 115 | ||
1265 | 115 | releases = { | 116 | releases = { |
1266 | 116 | ('precise', None): self.precise_essex, | 117 | ('precise', None): self.precise_essex, |
1267 | @@ -121,8 +122,10 @@ | |||
1268 | 121 | ('trusty', None): self.trusty_icehouse, | 122 | ('trusty', None): self.trusty_icehouse, |
1269 | 122 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, | 123 | ('trusty', 'cloud:trusty-juno'): self.trusty_juno, |
1270 | 123 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, | 124 | ('trusty', 'cloud:trusty-kilo'): self.trusty_kilo, |
1271 | 125 | ('trusty', 'cloud:trusty-liberty'): self.trusty_liberty, | ||
1272 | 124 | ('utopic', None): self.utopic_juno, | 126 | ('utopic', None): self.utopic_juno, |
1274 | 125 | ('vivid', None): self.vivid_kilo} | 127 | ('vivid', None): self.vivid_kilo, |
1275 | 128 | ('wily', None): self.wily_liberty} | ||
1276 | 126 | return releases[(self.series, self.openstack)] | 129 | return releases[(self.series, self.openstack)] |
1277 | 127 | 130 | ||
1278 | 128 | def _get_openstack_release_string(self): | 131 | def _get_openstack_release_string(self): |
1279 | @@ -138,6 +141,7 @@ | |||
1280 | 138 | ('trusty', 'icehouse'), | 141 | ('trusty', 'icehouse'), |
1281 | 139 | ('utopic', 'juno'), | 142 | ('utopic', 'juno'), |
1282 | 140 | ('vivid', 'kilo'), | 143 | ('vivid', 'kilo'), |
1283 | 144 | ('wily', 'liberty'), | ||
1284 | 141 | ]) | 145 | ]) |
1285 | 142 | if self.openstack: | 146 | if self.openstack: |
1286 | 143 | os_origin = self.openstack.split(':')[1] | 147 | os_origin = self.openstack.split(':')[1] |
1287 | 144 | 148 | ||
1288 | === modified file 'tests/charmhelpers/contrib/openstack/amulet/utils.py' | |||
1289 | --- tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-02-10 18:50:39 +0000 | |||
1290 | +++ tests/charmhelpers/contrib/openstack/amulet/utils.py 2015-06-19 16:15:40 +0000 | |||
1291 | @@ -16,15 +16,15 @@ | |||
1292 | 16 | 16 | ||
1293 | 17 | import logging | 17 | import logging |
1294 | 18 | import os | 18 | import os |
1295 | 19 | import six | ||
1296 | 19 | import time | 20 | import time |
1297 | 20 | import urllib | 21 | import urllib |
1298 | 21 | 22 | ||
1299 | 22 | import glanceclient.v1.client as glance_client | 23 | import glanceclient.v1.client as glance_client |
1300 | 24 | import heatclient.v1.client as heat_client | ||
1301 | 23 | import keystoneclient.v2_0 as keystone_client | 25 | import keystoneclient.v2_0 as keystone_client |
1302 | 24 | import novaclient.v1_1.client as nova_client | 26 | import novaclient.v1_1.client as nova_client |
1303 | 25 | 27 | ||
1304 | 26 | import six | ||
1305 | 27 | |||
1306 | 28 | from charmhelpers.contrib.amulet.utils import ( | 28 | from charmhelpers.contrib.amulet.utils import ( |
1307 | 29 | AmuletUtils | 29 | AmuletUtils |
1308 | 30 | ) | 30 | ) |
1309 | @@ -37,7 +37,7 @@ | |||
1310 | 37 | """OpenStack amulet utilities. | 37 | """OpenStack amulet utilities. |
1311 | 38 | 38 | ||
1312 | 39 | This class inherits from AmuletUtils and has additional support | 39 | This class inherits from AmuletUtils and has additional support |
1314 | 40 | that is specifically for use by OpenStack charms. | 40 | that is specifically for use by OpenStack charm tests. |
1315 | 41 | """ | 41 | """ |
1316 | 42 | 42 | ||
1317 | 43 | def __init__(self, log_level=ERROR): | 43 | def __init__(self, log_level=ERROR): |
1318 | @@ -51,6 +51,8 @@ | |||
1319 | 51 | Validate actual endpoint data vs expected endpoint data. The ports | 51 | Validate actual endpoint data vs expected endpoint data. The ports |
1320 | 52 | are used to find the matching endpoint. | 52 | are used to find the matching endpoint. |
1321 | 53 | """ | 53 | """ |
1322 | 54 | self.log.debug('Validating endpoint data...') | ||
1323 | 55 | self.log.debug('actual: {}'.format(repr(endpoints))) | ||
1324 | 54 | found = False | 56 | found = False |
1325 | 55 | for ep in endpoints: | 57 | for ep in endpoints: |
1326 | 56 | self.log.debug('endpoint: {}'.format(repr(ep))) | 58 | self.log.debug('endpoint: {}'.format(repr(ep))) |
1327 | @@ -77,6 +79,7 @@ | |||
1328 | 77 | Validate a list of actual service catalog endpoints vs a list of | 79 | Validate a list of actual service catalog endpoints vs a list of |
1329 | 78 | expected service catalog endpoints. | 80 | expected service catalog endpoints. |
1330 | 79 | """ | 81 | """ |
1331 | 82 | self.log.debug('Validating service catalog endpoint data...') | ||
1332 | 80 | self.log.debug('actual: {}'.format(repr(actual))) | 83 | self.log.debug('actual: {}'.format(repr(actual))) |
1333 | 81 | for k, v in six.iteritems(expected): | 84 | for k, v in six.iteritems(expected): |
1334 | 82 | if k in actual: | 85 | if k in actual: |
1335 | @@ -93,6 +96,7 @@ | |||
1336 | 93 | Validate a list of actual tenant data vs list of expected tenant | 96 | Validate a list of actual tenant data vs list of expected tenant |
1337 | 94 | data. | 97 | data. |
1338 | 95 | """ | 98 | """ |
1339 | 99 | self.log.debug('Validating tenant data...') | ||
1340 | 96 | self.log.debug('actual: {}'.format(repr(actual))) | 100 | self.log.debug('actual: {}'.format(repr(actual))) |
1341 | 97 | for e in expected: | 101 | for e in expected: |
1342 | 98 | found = False | 102 | found = False |
1343 | @@ -114,6 +118,7 @@ | |||
1344 | 114 | Validate a list of actual role data vs a list of expected role | 118 | Validate a list of actual role data vs a list of expected role |
1345 | 115 | data. | 119 | data. |
1346 | 116 | """ | 120 | """ |
1347 | 121 | self.log.debug('Validating role data...') | ||
1348 | 117 | self.log.debug('actual: {}'.format(repr(actual))) | 122 | self.log.debug('actual: {}'.format(repr(actual))) |
1349 | 118 | for e in expected: | 123 | for e in expected: |
1350 | 119 | found = False | 124 | found = False |
1351 | @@ -134,6 +139,7 @@ | |||
1352 | 134 | Validate a list of actual user data vs a list of expected user | 139 | Validate a list of actual user data vs a list of expected user |
1353 | 135 | data. | 140 | data. |
1354 | 136 | """ | 141 | """ |
1355 | 142 | self.log.debug('Validating user data...') | ||
1356 | 137 | self.log.debug('actual: {}'.format(repr(actual))) | 143 | self.log.debug('actual: {}'.format(repr(actual))) |
1357 | 138 | for e in expected: | 144 | for e in expected: |
1358 | 139 | found = False | 145 | found = False |
1359 | @@ -155,17 +161,20 @@ | |||
1360 | 155 | 161 | ||
1361 | 156 | Validate a list of actual flavors vs a list of expected flavors. | 162 | Validate a list of actual flavors vs a list of expected flavors. |
1362 | 157 | """ | 163 | """ |
1363 | 164 | self.log.debug('Validating flavor data...') | ||
1364 | 158 | self.log.debug('actual: {}'.format(repr(actual))) | 165 | self.log.debug('actual: {}'.format(repr(actual))) |
1365 | 159 | act = [a.name for a in actual] | 166 | act = [a.name for a in actual] |
1366 | 160 | return self._validate_list_data(expected, act) | 167 | return self._validate_list_data(expected, act) |
1367 | 161 | 168 | ||
1368 | 162 | def tenant_exists(self, keystone, tenant): | 169 | def tenant_exists(self, keystone, tenant): |
1369 | 163 | """Return True if tenant exists.""" | 170 | """Return True if tenant exists.""" |
1370 | 171 | self.log.debug('Checking if tenant exists ({})...'.format(tenant)) | ||
1371 | 164 | return tenant in [t.name for t in keystone.tenants.list()] | 172 | return tenant in [t.name for t in keystone.tenants.list()] |
1372 | 165 | 173 | ||
1373 | 166 | def authenticate_keystone_admin(self, keystone_sentry, user, password, | 174 | def authenticate_keystone_admin(self, keystone_sentry, user, password, |
1374 | 167 | tenant): | 175 | tenant): |
1375 | 168 | """Authenticates admin user with the keystone admin endpoint.""" | 176 | """Authenticates admin user with the keystone admin endpoint.""" |
1376 | 177 | self.log.debug('Authenticating keystone admin...') | ||
1377 | 169 | unit = keystone_sentry | 178 | unit = keystone_sentry |
1378 | 170 | service_ip = unit.relation('shared-db', | 179 | service_ip = unit.relation('shared-db', |
1379 | 171 | 'mysql:shared-db')['private-address'] | 180 | 'mysql:shared-db')['private-address'] |
1380 | @@ -175,6 +184,7 @@ | |||
1381 | 175 | 184 | ||
1382 | 176 | def authenticate_keystone_user(self, keystone, user, password, tenant): | 185 | def authenticate_keystone_user(self, keystone, user, password, tenant): |
1383 | 177 | """Authenticates a regular user with the keystone public endpoint.""" | 186 | """Authenticates a regular user with the keystone public endpoint.""" |
1384 | 187 | self.log.debug('Authenticating keystone user ({})...'.format(user)) | ||
1385 | 178 | ep = keystone.service_catalog.url_for(service_type='identity', | 188 | ep = keystone.service_catalog.url_for(service_type='identity', |
1386 | 179 | endpoint_type='publicURL') | 189 | endpoint_type='publicURL') |
1387 | 180 | return keystone_client.Client(username=user, password=password, | 190 | return keystone_client.Client(username=user, password=password, |
1388 | @@ -182,12 +192,21 @@ | |||
1389 | 182 | 192 | ||
1390 | 183 | def authenticate_glance_admin(self, keystone): | 193 | def authenticate_glance_admin(self, keystone): |
1391 | 184 | """Authenticates admin user with glance.""" | 194 | """Authenticates admin user with glance.""" |
1392 | 195 | self.log.debug('Authenticating glance admin...') | ||
1393 | 185 | ep = keystone.service_catalog.url_for(service_type='image', | 196 | ep = keystone.service_catalog.url_for(service_type='image', |
1394 | 186 | endpoint_type='adminURL') | 197 | endpoint_type='adminURL') |
1395 | 187 | return glance_client.Client(ep, token=keystone.auth_token) | 198 | return glance_client.Client(ep, token=keystone.auth_token) |
1396 | 188 | 199 | ||
1397 | 200 | def authenticate_heat_admin(self, keystone): | ||
1398 | 201 | """Authenticates the admin user with heat.""" | ||
1399 | 202 | self.log.debug('Authenticating heat admin...') | ||
1400 | 203 | ep = keystone.service_catalog.url_for(service_type='orchestration', | ||
1401 | 204 | endpoint_type='publicURL') | ||
1402 | 205 | return heat_client.Client(endpoint=ep, token=keystone.auth_token) | ||
1403 | 206 | |||
1404 | 189 | def authenticate_nova_user(self, keystone, user, password, tenant): | 207 | def authenticate_nova_user(self, keystone, user, password, tenant): |
1405 | 190 | """Authenticates a regular user with nova-api.""" | 208 | """Authenticates a regular user with nova-api.""" |
1406 | 209 | self.log.debug('Authenticating nova user ({})...'.format(user)) | ||
1407 | 191 | ep = keystone.service_catalog.url_for(service_type='identity', | 210 | ep = keystone.service_catalog.url_for(service_type='identity', |
1408 | 192 | endpoint_type='publicURL') | 211 | endpoint_type='publicURL') |
1409 | 193 | return nova_client.Client(username=user, api_key=password, | 212 | return nova_client.Client(username=user, api_key=password, |
1410 | @@ -195,6 +214,7 @@ | |||
1411 | 195 | 214 | ||
1412 | 196 | def create_cirros_image(self, glance, image_name): | 215 | def create_cirros_image(self, glance, image_name): |
1413 | 197 | """Download the latest cirros image and upload it to glance.""" | 216 | """Download the latest cirros image and upload it to glance.""" |
1414 | 217 | self.log.debug('Creating glance image ({})...'.format(image_name)) | ||
1415 | 198 | http_proxy = os.getenv('AMULET_HTTP_PROXY') | 218 | http_proxy = os.getenv('AMULET_HTTP_PROXY') |
1416 | 199 | self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy)) | 219 | self.log.debug('AMULET_HTTP_PROXY: {}'.format(http_proxy)) |
1417 | 200 | if http_proxy: | 220 | if http_proxy: |
1418 | @@ -235,6 +255,11 @@ | |||
1419 | 235 | 255 | ||
1420 | 236 | def delete_image(self, glance, image): | 256 | def delete_image(self, glance, image): |
1421 | 237 | """Delete the specified image.""" | 257 | """Delete the specified image.""" |
1422 | 258 | |||
1423 | 259 | # /!\ DEPRECATION WARNING | ||
1424 | 260 | self.log.warn('/!\\ DEPRECATION WARNING: use ' | ||
1425 | 261 | 'delete_resource instead of delete_image.') | ||
1426 | 262 | self.log.debug('Deleting glance image ({})...'.format(image)) | ||
1427 | 238 | num_before = len(list(glance.images.list())) | 263 | num_before = len(list(glance.images.list())) |
1428 | 239 | glance.images.delete(image) | 264 | glance.images.delete(image) |
1429 | 240 | 265 | ||
1430 | @@ -254,6 +279,8 @@ | |||
1431 | 254 | 279 | ||
1432 | 255 | def create_instance(self, nova, image_name, instance_name, flavor): | 280 | def create_instance(self, nova, image_name, instance_name, flavor): |
1433 | 256 | """Create the specified instance.""" | 281 | """Create the specified instance.""" |
1434 | 282 | self.log.debug('Creating instance ' | ||
1435 | 283 | '({}|{}|{})'.format(instance_name, image_name, flavor)) | ||
1436 | 257 | image = nova.images.find(name=image_name) | 284 | image = nova.images.find(name=image_name) |
1437 | 258 | flavor = nova.flavors.find(name=flavor) | 285 | flavor = nova.flavors.find(name=flavor) |
1438 | 259 | instance = nova.servers.create(name=instance_name, image=image, | 286 | instance = nova.servers.create(name=instance_name, image=image, |
1439 | @@ -276,6 +303,11 @@ | |||
1440 | 276 | 303 | ||
1441 | 277 | def delete_instance(self, nova, instance): | 304 | def delete_instance(self, nova, instance): |
1442 | 278 | """Delete the specified instance.""" | 305 | """Delete the specified instance.""" |
1443 | 306 | |||
1444 | 307 | # /!\ DEPRECATION WARNING | ||
1445 | 308 | self.log.warn('/!\\ DEPRECATION WARNING: use ' | ||
1446 | 309 | 'delete_resource instead of delete_instance.') | ||
1447 | 310 | self.log.debug('Deleting instance ({})...'.format(instance)) | ||
1448 | 279 | num_before = len(list(nova.servers.list())) | 311 | num_before = len(list(nova.servers.list())) |
1449 | 280 | nova.servers.delete(instance) | 312 | nova.servers.delete(instance) |
1450 | 281 | 313 | ||
1451 | @@ -292,3 +324,90 @@ | |||
1452 | 292 | return False | 324 | return False |
1453 | 293 | 325 | ||
1454 | 294 | return True | 326 | return True |
1455 | 327 | |||
1456 | 328 | def create_or_get_keypair(self, nova, keypair_name="testkey"): | ||
1457 | 329 | """Create a new keypair, or return pointer if it already exists.""" | ||
1458 | 330 | try: | ||
1459 | 331 | _keypair = nova.keypairs.get(keypair_name) | ||
1460 | 332 | self.log.debug('Keypair ({}) already exists, ' | ||
1461 | 333 | 'using it.'.format(keypair_name)) | ||
1462 | 334 | return _keypair | ||
1463 | 335 | except: | ||
1464 | 336 | self.log.debug('Keypair ({}) does not exist, ' | ||
1465 | 337 | 'creating it.'.format(keypair_name)) | ||
1466 | 338 | |||
1467 | 339 | _keypair = nova.keypairs.create(name=keypair_name) | ||
1468 | 340 | return _keypair | ||
1469 | 341 | |||
1470 | 342 | def delete_resource(self, resource, resource_id, | ||
1471 | 343 | msg="resource", max_wait=120): | ||
1472 | 344 | """Delete one openstack resource, such as one instance, keypair, | ||
1473 | 345 | image, volume, stack, etc., and confirm deletion within max wait time. | ||
1474 | 346 | |||
1475 | 347 | :param resource: pointer to os resource type, ex:glance_client.images | ||
1476 | 348 | :param resource_id: unique name or id for the openstack resource | ||
1477 | 349 | :param msg: text to identify purpose in logging | ||
1478 | 350 | :param max_wait: maximum wait time in seconds | ||
1479 | 351 | :returns: True if successful, otherwise False | ||
1480 | 352 | """ | ||
1481 | 353 | num_before = len(list(resource.list())) | ||
1482 | 354 | resource.delete(resource_id) | ||
1483 | 355 | |||
1484 | 356 | tries = 0 | ||
1485 | 357 | num_after = len(list(resource.list())) | ||
1486 | 358 | while num_after != (num_before - 1) and tries < (max_wait / 4): | ||
1487 | 359 | self.log.debug('{} delete check: ' | ||
1488 | 360 | '{} [{}:{}] {}'.format(msg, tries, | ||
1489 | 361 | num_before, | ||
1490 | 362 | num_after, | ||
1491 | 363 | resource_id)) | ||
1492 | 364 | time.sleep(4) | ||
1493 | 365 | num_after = len(list(resource.list())) | ||
1494 | 366 | tries += 1 | ||
1495 | 367 | |||
1496 | 368 | self.log.debug('{}: expected, actual count = {}, ' | ||
1497 | 369 | '{}'.format(msg, num_before - 1, num_after)) | ||
1498 | 370 | |||
1499 | 371 | if num_after == (num_before - 1): | ||
1500 | 372 | return True | ||
1501 | 373 | else: | ||
1502 | 374 | self.log.error('{} delete timed out'.format(msg)) | ||
1503 | 375 | return False | ||
1504 | 376 | |||
1505 | 377 | def resource_reaches_status(self, resource, resource_id, | ||
1506 | 378 | expected_stat='available', | ||
1507 | 379 | msg='resource', max_wait=120): | ||
1508 | 380 | """Wait for an openstack resources status to reach an | ||
1509 | 381 | expected status within a specified time. Useful to confirm that | ||
1510 | 382 | nova instances, cinder vols, snapshots, glance images, heat stacks | ||
1511 | 383 | and other resources eventually reach the expected status. | ||
1512 | 384 | |||
1513 | 385 | :param resource: pointer to os resource type, ex: heat_client.stacks | ||
1514 | 386 | :param resource_id: unique id for the openstack resource | ||
1515 | 387 | :param expected_stat: status to expect resource to reach | ||
1516 | 388 | :param msg: text to identify purpose in logging | ||
1517 | 389 | :param max_wait: maximum wait time in seconds | ||
1518 | 390 | :returns: True if successful, False if status is not reached | ||
1519 | 391 | """ | ||
1520 | 392 | |||
1521 | 393 | tries = 0 | ||
1522 | 394 | resource_stat = resource.get(resource_id).status | ||
1523 | 395 | while resource_stat != expected_stat and tries < (max_wait / 4): | ||
1524 | 396 | self.log.debug('{} status check: ' | ||
1525 | 397 | '{} [{}:{}] {}'.format(msg, tries, | ||
1526 | 398 | resource_stat, | ||
1527 | 399 | expected_stat, | ||
1528 | 400 | resource_id)) | ||
1529 | 401 | time.sleep(4) | ||
1530 | 402 | resource_stat = resource.get(resource_id).status | ||
1531 | 403 | tries += 1 | ||
1532 | 404 | |||
1533 | 405 | self.log.debug('{}: expected, actual status = {}, ' | ||
1534 | 406 | '{}'.format(msg, resource_stat, expected_stat)) | ||
1535 | 407 | |||
1536 | 408 | if resource_stat == expected_stat: | ||
1537 | 409 | return True | ||
1538 | 410 | else: | ||
1539 | 411 | self.log.debug('{} never reached expected status: ' | ||
1540 | 412 | '{}'.format(resource_id, expected_stat)) | ||
1541 | 413 | return False | ||
1542 | 295 | 414 | ||
1543 | === modified file 'unit_tests/test_horizon_hooks.py' | |||
1544 | --- unit_tests/test_horizon_hooks.py 2015-04-07 13:58:41 +0000 | |||
1545 | +++ unit_tests/test_horizon_hooks.py 2015-06-19 16:15:40 +0000 | |||
1546 | @@ -129,7 +129,7 @@ | |||
1547 | 129 | self.apt_install.assert_called_with(['foo', 'bar'], fatal=True) | 129 | self.apt_install.assert_called_with(['foo', 'bar'], fatal=True) |
1548 | 130 | self.git_install.assert_called_with(projects_yaml) | 130 | self.git_install.assert_called_with(projects_yaml) |
1549 | 131 | 131 | ||
1551 | 132 | @patch('charmhelpers.core.host.file_hash') | 132 | @patch('charmhelpers.core.host.path_hash') |
1552 | 133 | @patch('charmhelpers.core.host.service') | 133 | @patch('charmhelpers.core.host.service') |
1553 | 134 | @patch.object(utils, 'git_install_requested') | 134 | @patch.object(utils, 'git_install_requested') |
1554 | 135 | def test_upgrade_charm_hook(self, _git_requested, _service, _hash): | 135 | def test_upgrade_charm_hook(self, _git_requested, _service, _hash): |
charm_lint_check #5475 openstack- dashboard- next for corey.bryant mp262472
LINT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_lint_ check/5475/