Merge lp:~billy-olsen/charms/trusty/ceph-radosgw/backport-lp1398182 into lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk

Proposed by Billy Olsen
Status: Merged
Merged at revision: 40
Proposed branch: lp:~billy-olsen/charms/trusty/ceph-radosgw/backport-lp1398182
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph-radosgw/trunk
Diff against target: 308 lines (+106/-66)
4 files modified
config.yaml (+12/-0)
hooks/charmhelpers/contrib/openstack/ip.py (+49/-44)
hooks/hooks.py (+4/-15)
unit_tests/test_hooks.py (+41/-7)
To merge this branch: bzr merge lp:~billy-olsen/charms/trusty/ceph-radosgw/backport-lp1398182
Reviewer Review Type Date Requested Status
Corey Bryant (community) Approve
Review via email: mp+262000@code.launchpad.net
To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #5403 ceph-radosgw for billy-olsen mp262000
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/5403/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #5035 ceph-radosgw for billy-olsen mp262000
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/5035/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #4646 ceph-radosgw for billy-olsen mp262000
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/4646/

Revision history for this message
Corey Bryant (corey.bryant) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-01-14 13:27:02 +0000
+++ config.yaml 2015-06-15 18:43:37 +0000
@@ -87,3 +87,15 @@
87 description: |87 description: |
88 Default multicast port number that will be used to communicate between88 Default multicast port number that will be used to communicate between
89 HA Cluster nodes.89 HA Cluster nodes.
90 os-public-hostname:
91 type: string
92 default:
93 description: |
94 The hostname or address of the public endpoints created for ceph-radosgw
95 in the keystone identity provider.
96 .
97 This value will be used for public endpoints. For example, an
98 os-public-hostname set to 'files.example.com' with will create
99 the following public endpoint for the ceph-radosgw:
100 .
101 https://files.example.com:80/swift/v1
90102
=== modified file 'hooks/charmhelpers/contrib/openstack/ip.py'
--- hooks/charmhelpers/contrib/openstack/ip.py 2015-02-24 11:02:02 +0000
+++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-15 18:43:37 +0000
@@ -17,6 +17,7 @@
17from charmhelpers.core.hookenv import (17from charmhelpers.core.hookenv import (
18 config,18 config,
19 unit_get,19 unit_get,
20 service_name,
20)21)
21from charmhelpers.contrib.network.ip import (22from charmhelpers.contrib.network.ip import (
22 get_address_in_network,23 get_address_in_network,
@@ -26,8 +27,6 @@
26)27)
27from charmhelpers.contrib.hahelpers.cluster import is_clustered28from charmhelpers.contrib.hahelpers.cluster import is_clustered
2829
29from functools import partial
30
31PUBLIC = 'public'30PUBLIC = 'public'
32INTERNAL = 'int'31INTERNAL = 'int'
33ADMIN = 'admin'32ADMIN = 'admin'
@@ -35,15 +34,18 @@
35ADDRESS_MAP = {34ADDRESS_MAP = {
36 PUBLIC: {35 PUBLIC: {
37 'config': 'os-public-network',36 'config': 'os-public-network',
38 'fallback': 'public-address'37 'fallback': 'public-address',
38 'override': 'os-public-hostname',
39 },39 },
40 INTERNAL: {40 INTERNAL: {
41 'config': 'os-internal-network',41 'config': 'os-internal-network',
42 'fallback': 'private-address'42 'fallback': 'private-address',
43 'override': 'os-internal-hostname',
43 },44 },
44 ADMIN: {45 ADMIN: {
45 'config': 'os-admin-network',46 'config': 'os-admin-network',
46 'fallback': 'private-address'47 'fallback': 'private-address',
48 'override': 'os-admin-hostname',
47 }49 }
48}50}
4951
@@ -57,15 +59,50 @@
57 :param endpoint_type: str endpoint type to resolve.59 :param endpoint_type: str endpoint type to resolve.
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.
59 """61 """
60 scheme = 'http'62 scheme = _get_scheme(configs)
61 if 'https' in configs.complete_contexts():63
62 scheme = 'https'
63 address = resolve_address(endpoint_type)64 address = resolve_address(endpoint_type)
64 if is_ipv6(address):65 if is_ipv6(address):
65 address = "[{}]".format(address)66 address = "[{}]".format(address)
67
66 return '%s://%s' % (scheme, address)68 return '%s://%s' % (scheme, address)
6769
6870
71def _get_scheme(configs):
72 """Returns the scheme to use for the url (either http or https)
73 depending upon whether https is in the configs value.
74
75 :param configs: OSTemplateRenderer config templating object to inspect
76 for a complete https context.
77 :returns: either 'http' or 'https' depending on whether https is
78 configured within the configs context.
79 """
80 scheme = 'http'
81 if configs and 'https' in configs.complete_contexts():
82 scheme = 'https'
83 return scheme
84
85
86def _get_address_override(endpoint_type=PUBLIC):
87 """Returns any address overrides that the user has defined based on the
88 endpoint type.
89
90 Note: this function allows for the service name to be inserted into the
91 address if the user specifies {service_name}.somehost.org.
92
93 :param endpoint_type: the type of endpoint to retrieve the override
94 value for.
95 :returns: any endpoint address or hostname that the user has overridden
96 or None if an override is not present.
97 """
98 override_key = ADDRESS_MAP[endpoint_type]['override']
99 addr_override = config(override_key)
100 if not addr_override:
101 return None
102 else:
103 return addr_override.format(service_name=service_name())
104
105
69def resolve_address(endpoint_type=PUBLIC):106def resolve_address(endpoint_type=PUBLIC):
70 """Return unit address depending on net config.107 """Return unit address depending on net config.
71108
@@ -77,7 +114,10 @@
77114
78 :param endpoint_type: Network endpoing type115 :param endpoint_type: Network endpoing type
79 """116 """
80 resolved_address = None117 resolved_address = _get_address_override(endpoint_type)
118 if resolved_address:
119 return resolved_address
120
81 vips = config('vip')121 vips = config('vip')
82 if vips:122 if vips:
83 vips = vips.split()123 vips = vips.split()
@@ -109,38 +149,3 @@
109 "clustered=%s)" % (net_type, clustered))149 "clustered=%s)" % (net_type, clustered))
110150
111 return resolved_address151 return resolved_address
112
113
114def endpoint_url(configs, url_template, port, endpoint_type=PUBLIC,
115 override=None):
116 """Returns the correct endpoint URL to advertise to Keystone.
117
118 This method provides the correct endpoint URL which should be advertised to
119 the keystone charm for endpoint creation. This method allows for the url to
120 be overridden to force a keystone endpoint to have specific URL for any of
121 the defined scopes (admin, internal, public).
122
123 :param configs: OSTemplateRenderer config templating object to inspect
124 for a complete https context.
125 :param url_template: str format string for creating the url template. Only
126 two values will be passed - the scheme+hostname
127 returned by the canonical_url and the port.
128 :param endpoint_type: str endpoint type to resolve.
129 :param override: str the name of the config option which overrides the
130 endpoint URL defined by the charm itself. None will
131 disable any overrides (default).
132 """
133 if override:
134 # Return any user-defined overrides for the keystone endpoint URL.
135 user_value = config(override)
136 if user_value:
137 return user_value.strip()
138
139 return url_template % (canonical_url(configs, endpoint_type), port)
140
141
142public_endpoint = partial(endpoint_url, endpoint_type=PUBLIC)
143
144internal_endpoint = partial(endpoint_url, endpoint_type=INTERNAL)
145
146admin_endpoint = partial(endpoint_url, endpoint_type=ADMIN)
147152
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-04-28 21:18:24 +0000
+++ hooks/hooks.py 2015-06-15 18:43:37 +0000
@@ -50,10 +50,9 @@
50from charmhelpers.contrib.network.ip import (50from charmhelpers.contrib.network.ip import (
51 get_iface_for_address,51 get_iface_for_address,
52 get_netmask_for_address,52 get_netmask_for_address,
53 is_ipv6,
54)53)
55from charmhelpers.contrib.openstack.ip import (54from charmhelpers.contrib.openstack.ip import (
56 resolve_address,55 canonical_url,
57 PUBLIC, INTERNAL, ADMIN,56 PUBLIC, INTERNAL, ADMIN,
58)57)
5958
@@ -273,16 +272,6 @@
273 open_port(port=80)272 open_port(port=80)
274273
275274
276# XXX Define local canonical_url until charm has been updated to use the
277# standard context architecture.
278def canonical_url(configs, endpoint_type=PUBLIC):
279 scheme = 'http'
280 address = resolve_address(endpoint_type)
281 if is_ipv6(address):
282 address = "[{}]".format(address)
283 return '%s://%s' % (scheme, address)
284
285
286@hooks.hook('identity-service-relation-joined')275@hooks.hook('identity-service-relation-joined')
287def identity_joined(relid=None):276def identity_joined(relid=None):
288 if cmp_pkgrevno('radosgw', '0.55') < 0:277 if cmp_pkgrevno('radosgw', '0.55') < 0:
@@ -290,11 +279,11 @@
290 sys.exit(1)279 sys.exit(1)
291280
292 port = 80281 port = 80
293 admin_url = '%s:%i/swift' % (canonical_url(ADMIN), port)282 admin_url = '%s:%i/swift' % (canonical_url(None, ADMIN), port)
294 internal_url = '%s:%s/swift/v1' % \283 internal_url = '%s:%s/swift/v1' % \
295 (canonical_url(INTERNAL), port)284 (canonical_url(None, INTERNAL), port)
296 public_url = '%s:%s/swift/v1' % \285 public_url = '%s:%s/swift/v1' % \
297 (canonical_url(PUBLIC), port)286 (canonical_url(None, PUBLIC), port)
298 relation_set(service='swift',287 relation_set(service='swift',
299 region=config('region'),288 region=config('region'),
300 public_url=public_url, internal_url=internal_url,289 public_url=public_url, internal_url=internal_url,
301290
=== modified file 'unit_tests/test_hooks.py'
--- unit_tests/test_hooks.py 2015-04-28 21:18:24 +0000
+++ unit_tests/test_hooks.py 2015-06-15 18:43:37 +0000
@@ -8,6 +8,7 @@
8 CharmTestCase,8 CharmTestCase,
9 patch_open9 patch_open
10)10)
11from charmhelpers.contrib.openstack.ip import PUBLIC
1112
12dnsmock = MagicMock()13dnsmock = MagicMock()
13modules = {14modules = {
@@ -45,7 +46,6 @@
45 'relation_set',46 'relation_set',
46 'relation_get',47 'relation_get',
47 'render_template',48 'render_template',
48 'resolve_address',
49 'shutil',49 'shutil',
50 'subprocess',50 'subprocess',
51 'sys',51 'sys',
@@ -323,14 +323,22 @@
323 cmd = ['service', 'radosgw', 'restart']323 cmd = ['service', 'radosgw', 'restart']
324 self.subprocess.call.assert_called_with(cmd)324 self.subprocess.call.assert_called_with(cmd)
325325
326 def test_identity_joined_early_version(self):326 @patch('charmhelpers.contrib.openstack.ip.service_name',
327 lambda *args: 'ceph-radosgw')
328 @patch('charmhelpers.contrib.openstack.ip.config')
329 def test_identity_joined_early_version(self, _config):
327 self.cmp_pkgrevno.return_value = -1330 self.cmp_pkgrevno.return_value = -1
328 ceph_hooks.identity_joined()331 ceph_hooks.identity_joined()
329 self.sys.exit.assert_called_with(1)332 self.sys.exit.assert_called_with(1)
330333
331 def test_identity_joined(self):334 @patch('charmhelpers.contrib.openstack.ip.service_name',
335 lambda *args: 'ceph-radosgw')
336 @patch('charmhelpers.contrib.openstack.ip.resolve_address')
337 @patch('charmhelpers.contrib.openstack.ip.config')
338 def test_identity_joined(self, _config, _resolve_address):
332 self.cmp_pkgrevno.return_value = 1339 self.cmp_pkgrevno.return_value = 1
333 self.resolve_address.return_value = 'myserv'340 _resolve_address.return_value = 'myserv'
341 _config.side_effect = self.test_config.get
334 self.test_config.set('region', 'region1')342 self.test_config.set('region', 'region1')
335 self.test_config.set('operator-roles', 'admin')343 self.test_config.set('operator-roles', 'admin')
336 self.unit_get.return_value = 'myserv'344 self.unit_get.return_value = 'myserv'
@@ -344,6 +352,27 @@
344 relation_id='rid',352 relation_id='rid',
345 admin_url='http://myserv:80/swift')353 admin_url='http://myserv:80/swift')
346354
355 @patch('charmhelpers.contrib.openstack.ip.service_name',
356 lambda *args: 'ceph-radosgw')
357 @patch('charmhelpers.contrib.openstack.ip.is_clustered')
358 @patch('charmhelpers.contrib.openstack.ip.unit_get')
359 @patch('charmhelpers.contrib.openstack.ip.config')
360 def test_identity_joined_public_name(self, _config, _unit_get,
361 _is_clustered):
362 _config.side_effect = self.test_config.get
363 self.test_config.set('os-public-hostname', 'files.example.com')
364 _unit_get.return_value = 'myserv'
365 _is_clustered.return_value = False
366 ceph_hooks.identity_joined(relid='rid')
367 self.relation_set.assert_called_with(
368 service='swift',
369 region='RegionOne',
370 public_url='http://files.example.com:80/swift/v1',
371 internal_url='http://myserv:80/swift/v1',
372 requested_roles='Member,Admin',
373 relation_id='rid',
374 admin_url='http://myserv:80/swift')
375
347 def test_identity_changed(self):376 def test_identity_changed(self):
348 _emit_cephconf = self.patch('emit_cephconf')377 _emit_cephconf = self.patch('emit_cephconf')
349 _restart = self.patch('restart')378 _restart = self.patch('restart')
@@ -351,10 +380,15 @@
351 _emit_cephconf.assert_called()380 _emit_cephconf.assert_called()
352 _restart.assert_called()381 _restart.assert_called()
353382
354 def test_canonical_url_ipv6(self):383 @patch('charmhelpers.contrib.openstack.ip.is_clustered')
384 @patch('charmhelpers.contrib.openstack.ip.unit_get')
385 @patch('charmhelpers.contrib.openstack.ip.config')
386 def test_canonical_url_ipv6(self, _config, _unit_get, _is_clustered):
355 ipv6_addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348'387 ipv6_addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348'
356 self.resolve_address.return_value = ipv6_addr388 _config.side_effect = self.test_config.get
357 self.assertEquals(ceph_hooks.canonical_url({}),389 _unit_get.return_value = ipv6_addr
390 _is_clustered.return_value = False
391 self.assertEquals(ceph_hooks.canonical_url({}, PUBLIC),
358 'http://[%s]' % ipv6_addr)392 'http://[%s]' % ipv6_addr)
359393
360 @patch.object(ceph_hooks, 'CONFIGS')394 @patch.object(ceph_hooks, 'CONFIGS')

Subscribers

People subscribed via source and target branches