Merge lp:~billy-olsen/charms/trusty/ceilometer/backport-lp1398182 into lp:~openstack-charmers-archive/charms/trusty/ceilometer/trunk
- Trusty Tahr (14.04)
- backport-lp1398182
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 85 |
Proposed branch: | lp:~billy-olsen/charms/trusty/ceilometer/backport-lp1398182 |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/ceilometer/trunk |
Diff against target: |
276 lines (+113/-47) 4 files modified
config.yaml (+12/-0) hooks/charmhelpers/contrib/hahelpers/cluster.py (+25/-0) hooks/charmhelpers/contrib/openstack/ip.py (+49/-44) unit_tests/test_ceilometer_hooks.py (+27/-3) |
To merge this branch: | bzr merge lp:~billy-olsen/charms/trusty/ceilometer/backport-lp1398182 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corey Bryant (community) | Approve | ||
charmers | Pending | ||
Review via email: mp+261999@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5402 ceilometer for billy-olsen mp261999
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4645 ceilometer for billy-olsen mp261999
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Corey Bryant (corey.bryant) wrote : | # |
The amulet failure looks like a pre-existing condition.
Corey Bryant (corey.bryant) wrote : | # |
Yep, amulet test needs a fix backported so ignoring that.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4664 ceilometer for billy-olsen mp261999
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
- 86. By Billy Olsen
-
[billy-
olsen,trivial] Official charm-helper stable branch sync to include
charm-helper change for public-hostname.
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #5461 ceilometer for billy-olsen mp261999
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #5093 ceilometer for billy-olsen mp261999
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #4665 ceilometer for billy-olsen mp261999
AMULET FAIL: amulet-test failed
AMULET Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.
Full amulet test output: http://
Build: http://
Preview Diff
1 | === modified file 'config.yaml' |
2 | --- config.yaml 2015-02-19 02:03:06 +0000 |
3 | +++ config.yaml 2015-06-18 23:03:27 +0000 |
4 | @@ -100,6 +100,18 @@ |
5 | 192.168.0.0/24) |
6 | . |
7 | This network will be used for public endpoints. |
8 | + os-public-hostname: |
9 | + type: string |
10 | + default: |
11 | + description: | |
12 | + The hostname or address of the public endpoints created for ceilometer |
13 | + in the keystone identity provider. |
14 | + . |
15 | + This value will be used for public endpoints. For example, an |
16 | + os-public-hostname set to 'ceilometer.example.com' with ssl enabled will |
17 | + create the following public endpoints for ceilometer: |
18 | + . |
19 | + https://ceilometer.example.com:8777/ |
20 | # HA configuration settings |
21 | vip: |
22 | type: string |
23 | |
24 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' |
25 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-03-13 12:57:45 +0000 |
26 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2015-06-18 23:03:27 +0000 |
27 | @@ -52,6 +52,8 @@ |
28 | bool_from_string, |
29 | ) |
30 | |
31 | +DC_RESOURCE_NAME = 'DC' |
32 | + |
33 | |
34 | class HAIncompleteConfig(Exception): |
35 | pass |
36 | @@ -95,6 +97,27 @@ |
37 | return False |
38 | |
39 | |
40 | +def is_crm_dc(): |
41 | + """ |
42 | + Determine leadership by querying the pacemaker Designated Controller |
43 | + """ |
44 | + cmd = ['crm', 'status'] |
45 | + try: |
46 | + status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
47 | + if not isinstance(status, six.text_type): |
48 | + status = six.text_type(status, "utf-8") |
49 | + except subprocess.CalledProcessError: |
50 | + return False |
51 | + current_dc = '' |
52 | + for line in status.split('\n'): |
53 | + if line.startswith('Current DC'): |
54 | + # Current DC: juju-lytrusty-machine-2 (168108163) - partition with quorum |
55 | + current_dc = line.split(':')[1].split()[0] |
56 | + if current_dc == get_unit_hostname(): |
57 | + return True |
58 | + return False |
59 | + |
60 | + |
61 | @retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound) |
62 | def is_crm_leader(resource, retry=False): |
63 | """ |
64 | @@ -104,6 +127,8 @@ |
65 | We allow this operation to be retried to avoid the possibility of getting a |
66 | false negative. See LP #1396246 for more info. |
67 | """ |
68 | + if resource == DC_RESOURCE_NAME: |
69 | + return is_crm_dc() |
70 | cmd = ['crm', 'resource', 'show', resource] |
71 | try: |
72 | status = subprocess.check_output(cmd, stderr=subprocess.STDOUT) |
73 | |
74 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' |
75 | --- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-13 12:57:45 +0000 |
76 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-18 23:03:27 +0000 |
77 | @@ -17,6 +17,7 @@ |
78 | from charmhelpers.core.hookenv import ( |
79 | config, |
80 | unit_get, |
81 | + service_name, |
82 | ) |
83 | from charmhelpers.contrib.network.ip import ( |
84 | get_address_in_network, |
85 | @@ -26,8 +27,6 @@ |
86 | ) |
87 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
88 | |
89 | -from functools import partial |
90 | - |
91 | PUBLIC = 'public' |
92 | INTERNAL = 'int' |
93 | ADMIN = 'admin' |
94 | @@ -35,15 +34,18 @@ |
95 | ADDRESS_MAP = { |
96 | PUBLIC: { |
97 | 'config': 'os-public-network', |
98 | - 'fallback': 'public-address' |
99 | + 'fallback': 'public-address', |
100 | + 'override': 'os-public-hostname', |
101 | }, |
102 | INTERNAL: { |
103 | 'config': 'os-internal-network', |
104 | - 'fallback': 'private-address' |
105 | + 'fallback': 'private-address', |
106 | + 'override': 'os-internal-hostname', |
107 | }, |
108 | ADMIN: { |
109 | 'config': 'os-admin-network', |
110 | - 'fallback': 'private-address' |
111 | + 'fallback': 'private-address', |
112 | + 'override': 'os-admin-hostname', |
113 | } |
114 | } |
115 | |
116 | @@ -57,15 +59,50 @@ |
117 | :param endpoint_type: str endpoint type to resolve. |
118 | :param returns: str base URL for services on the current service unit. |
119 | """ |
120 | - scheme = 'http' |
121 | - if 'https' in configs.complete_contexts(): |
122 | - scheme = 'https' |
123 | + scheme = _get_scheme(configs) |
124 | + |
125 | address = resolve_address(endpoint_type) |
126 | if is_ipv6(address): |
127 | address = "[{}]".format(address) |
128 | + |
129 | return '%s://%s' % (scheme, address) |
130 | |
131 | |
132 | +def _get_scheme(configs): |
133 | + """Returns the scheme to use for the url (either http or https) |
134 | + depending upon whether https is in the configs value. |
135 | + |
136 | + :param configs: OSTemplateRenderer config templating object to inspect |
137 | + for a complete https context. |
138 | + :returns: either 'http' or 'https' depending on whether https is |
139 | + configured within the configs context. |
140 | + """ |
141 | + scheme = 'http' |
142 | + if configs and 'https' in configs.complete_contexts(): |
143 | + scheme = 'https' |
144 | + return scheme |
145 | + |
146 | + |
147 | +def _get_address_override(endpoint_type=PUBLIC): |
148 | + """Returns any address overrides that the user has defined based on the |
149 | + endpoint type. |
150 | + |
151 | + Note: this function allows for the service name to be inserted into the |
152 | + address if the user specifies {service_name}.somehost.org. |
153 | + |
154 | + :param endpoint_type: the type of endpoint to retrieve the override |
155 | + value for. |
156 | + :returns: any endpoint address or hostname that the user has overridden |
157 | + or None if an override is not present. |
158 | + """ |
159 | + override_key = ADDRESS_MAP[endpoint_type]['override'] |
160 | + addr_override = config(override_key) |
161 | + if not addr_override: |
162 | + return None |
163 | + else: |
164 | + return addr_override.format(service_name=service_name()) |
165 | + |
166 | + |
167 | def resolve_address(endpoint_type=PUBLIC): |
168 | """Return unit address depending on net config. |
169 | |
170 | @@ -77,7 +114,10 @@ |
171 | |
172 | :param endpoint_type: Network endpoing type |
173 | """ |
174 | - resolved_address = None |
175 | + resolved_address = _get_address_override(endpoint_type) |
176 | + if resolved_address: |
177 | + return resolved_address |
178 | + |
179 | vips = config('vip') |
180 | if vips: |
181 | vips = vips.split() |
182 | @@ -109,38 +149,3 @@ |
183 | "clustered=%s)" % (net_type, clustered)) |
184 | |
185 | return resolved_address |
186 | - |
187 | - |
188 | -def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC, |
189 | - override=None): |
190 | - """Returns the correct endpoint URL to advertise to Keystone. |
191 | - |
192 | - This method provides the correct endpoint URL which should be advertised to |
193 | - the keystone charm for endpoint creation. This method allows for the url to |
194 | - be overridden to force a keystone endpoint to have specific URL for any of |
195 | - the defined scopes (admin, internal, public). |
196 | - |
197 | - :param configs: OSTemplateRenderer config templating object to inspect |
198 | - for a complete https context. |
199 | - :param url_template: str format string for creating the url template. Only |
200 | - two values will be passed - the scheme+hostname |
201 | - returned by the canonical_url and the port. |
202 | - :param endpoint_type: str endpoint type to resolve. |
203 | - :param override: str the name of the config option which overrides the |
204 | - endpoint URL defined by the charm itself. None will |
205 | - disable any overrides (default). |
206 | - """ |
207 | - if override: |
208 | - # Return any user-defined overrides for the keystone endpoint URL. |
209 | - user_value = config(override) |
210 | - if user_value: |
211 | - return user_value.strip() |
212 | - |
213 | - return url_template % (canonical_url(configs, endpoint_type), port) |
214 | - |
215 | - |
216 | -public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC) |
217 | - |
218 | -internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL) |
219 | - |
220 | -admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN) |
221 | |
222 | === modified file 'unit_tests/test_ceilometer_hooks.py' |
223 | --- unit_tests/test_ceilometer_hooks.py 2015-04-08 15:49:34 +0000 |
224 | +++ unit_tests/test_ceilometer_hooks.py 2015-06-18 23:03:27 +0000 |
225 | @@ -31,7 +31,6 @@ |
226 | 'get_ceilometer_context', |
227 | 'lsb_release', |
228 | 'get_packages', |
229 | - 'canonical_url', |
230 | 'service_restart', |
231 | 'update_nrpe_config', |
232 | 'configure_https', |
233 | @@ -136,9 +135,10 @@ |
234 | self.assertTrue(self.CONFIGS.write_all.called) |
235 | self.assertTrue(joined.called) |
236 | |
237 | + @patch.object(hooks, 'canonical_url') |
238 | @patch('charmhelpers.core.hookenv.config') |
239 | - def test_keystone_joined(self, mock_config): |
240 | - self.canonical_url.return_value = "http://thishost" |
241 | + def test_keystone_joined(self, mock_config, _canonical_url): |
242 | + _canonical_url.return_value = "http://thishost" |
243 | self.test_config.set('region', 'myregion') |
244 | hooks.hooks.execute(['hooks/identity-service-relation-joined']) |
245 | url = "http://{}:{}".format('thishost', hooks.CEILOMETER_PORT) |
246 | @@ -148,6 +148,30 @@ |
247 | requested_roles=hooks.CEILOMETER_ROLE, |
248 | region='myregion', relation_id=None) |
249 | |
250 | + @patch('charmhelpers.contrib.openstack.ip.service_name', |
251 | + lambda *args: 'ceilometer') |
252 | + @patch('charmhelpers.contrib.openstack.ip.unit_get') |
253 | + @patch('charmhelpers.contrib.openstack.ip.is_clustered') |
254 | + @patch('charmhelpers.core.hookenv.config') |
255 | + @patch('charmhelpers.contrib.openstack.ip.config') |
256 | + def test_keystone_joined_url_override(self, _config, mock_config, |
257 | + _is_clustered, _unit_get): |
258 | + _unit_get.return_value = "thishost" |
259 | + _is_clustered.return_value = False |
260 | + _config.side_effect = self.test_config.get |
261 | + mock_config.side_effect = self.test_config.get |
262 | + self.test_config.set('region', 'myregion') |
263 | + self.test_config.set('os-public-hostname', 'ceilometer.example.com') |
264 | + hooks.keystone_joined(None) |
265 | + url = "http://{}:{}".format('thishost', hooks.CEILOMETER_PORT) |
266 | + public_url = "http://{}:{}".format('ceilometer.example.com', |
267 | + hooks.CEILOMETER_PORT) |
268 | + self.relation_set.assert_called_with( |
269 | + service=hooks.CEILOMETER_SERVICE, |
270 | + public_url=public_url, admin_url=url, internal_url=url, |
271 | + requested_roles=hooks.CEILOMETER_ROLE, |
272 | + region='myregion', relation_id=None) |
273 | + |
274 | @patch('charmhelpers.core.hookenv.config') |
275 | def test_ceilometer_joined(self, mock_config): |
276 | self.relation_ids.return_value = ['ceilometer:0'] |
charm_unit_test #5034 ceilometer for billy-olsen mp261999
UNIT OK: passed
Build: http:// 10.245. 162.77: 8080/job/ charm_unit_ test/5034/