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