Merge lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next

Proposed by Billy Olsen
Status: Merged
Merged at revision: 98
Proposed branch: lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next
Diff against target: 291 lines (+155/-48)
3 files modified
config.yaml (+12/-0)
hooks/charmhelpers/contrib/openstack/ip.py (+49/-44)
unit_tests/test_swift_hooks.py (+94/-4)
To merge this branch: bzr merge lp:~billy-olsen/charms/trusty/swift-proxy/public-endpoint-host
Reviewer Review Type Date Requested Status
Corey Bryant (community) Approve
Review via email: mp+261005@code.launchpad.net

Description of the change

Provides a config option which allows the user to specify the public hostname used to advertise to keystone when creating endpoints.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #5043 swift-proxy-next for billy-olsen mp261005
    LINT OK: passed

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

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

charm_unit_test #4723 swift-proxy-next for billy-olsen mp261005
    UNIT OK: passed

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

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

charm_amulet_test #4449 swift-proxy-next for billy-olsen mp261005
    AMULET OK: passed

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

99. By Billy Olsen

c-h sync

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

charm_lint_check #5074 swift-proxy-next for billy-olsen mp261005
    LINT OK: passed

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

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

charm_unit_test #4753 swift-proxy-next for billy-olsen mp261005
    UNIT OK: passed

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

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

charm_amulet_test #4481 swift-proxy-next for billy-olsen mp261005
    AMULET OK: passed

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

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

Looks good! Mind adding a unit test?

100. By Billy Olsen

Add unit test for public hostname.

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

charm_lint_check #5344 swift-proxy-next for billy-olsen mp261005
    LINT OK: passed

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

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

charm_unit_test #4976 swift-proxy-next for billy-olsen mp261005
    UNIT OK: passed

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

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

charm_amulet_test #4585 swift-proxy-next for billy-olsen mp261005
    AMULET OK: passed

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

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-04-20 11:19:04 +0000
+++ config.yaml 2015-06-11 23:23:30 +0000
@@ -207,6 +207,18 @@
207 192.168.0.0/24)207 192.168.0.0/24)
208 .208 .
209 This network will be used for public endpoints.209 This network will be used for public endpoints.
210 os-public-hostname:
211 type: string
212 default:
213 description: |
214 The hostname or address of the public endpoints created for swift-proxy
215 in the keystone identity provider.
216 .
217 This value will be used for public endpoints. For example, an
218 os-public-hostname set to 'files.example.com' with will create
219 the following public endpoint for the swift-proxy:
220 .
221 https://files.example.com:80/swift/v1
210 prefer-ipv6:222 prefer-ipv6:
211 type: boolean223 type: boolean
212 default: False224 default: False
213225
=== modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py'
=== modified file 'hooks/charmhelpers/contrib/openstack/ip.py'
--- hooks/charmhelpers/contrib/openstack/ip.py 2015-03-13 13:02:08 +0000
+++ hooks/charmhelpers/contrib/openstack/ip.py 2015-06-11 23:23:30 +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/charmhelpers/contrib/peerstorage/__init__.py'
=== modified file 'unit_tests/test_swift_hooks.py'
--- unit_tests/test_swift_hooks.py 2014-12-05 13:21:52 +0000
+++ unit_tests/test_swift_hooks.py 2015-06-11 23:23:30 +0000
@@ -1,16 +1,16 @@
1import mock1from mock import patch
2import unittest2import unittest
3import uuid3import uuid
44
55
6with mock.patch('charmhelpers.core.hookenv.log'):6with patch('charmhelpers.core.hookenv.log'):
7 import swift_hooks7 import swift_hooks
88
99
10class SwiftHooksTestCase(unittest.TestCase):10class SwiftHooksTestCase(unittest.TestCase):
1111
12 @mock.patch("swift_hooks.relation_get")12 @patch("swift_hooks.relation_get")
13 @mock.patch("swift_hooks.local_unit")13 @patch("swift_hooks.local_unit")
14 def test_all_peers_stopped(self, mock_local_unit, mock_relation_get):14 def test_all_peers_stopped(self, mock_local_unit, mock_relation_get):
15 token1 = str(uuid.uuid4())15 token1 = str(uuid.uuid4())
16 token2 = str(uuid.uuid4())16 token2 = str(uuid.uuid4())
@@ -37,3 +37,93 @@
37 responses = [{'stop-proxy-service-ack': token1},37 responses = [{'stop-proxy-service-ack': token1},
38 {'stop-proxy-service-ack': token1}]38 {'stop-proxy-service-ack': token1}]
39 self.assertFalse(swift_hooks.all_peers_stopped(responses))39 self.assertFalse(swift_hooks.all_peers_stopped(responses))
40
41 @patch.object(swift_hooks, 'config')
42 @patch('charmhelpers.contrib.openstack.ip.config')
43 @patch.object(swift_hooks, 'CONFIGS')
44 @patch('charmhelpers.core.hookenv.local_unit')
45 @patch('charmhelpers.core.hookenv.service_name')
46 @patch('charmhelpers.contrib.openstack.ip.unit_get')
47 @patch('charmhelpers.contrib.openstack.ip.is_clustered')
48 @patch.object(swift_hooks, 'relation_set')
49 def test_keystone_joined(self, _relation_set, _is_clustered, _unit_get,
50 _service_name, _local_unit, _CONFIGS, _ip_config,
51 _config):
52 config_dict = {
53 'bind-port': '1234',
54 'region': 'RegionOne',
55 'operator-roles': 'Operator,Monitor'
56 }
57
58 def foo(key=None):
59 if key is None:
60 return config_dict
61 else:
62 return config_dict.get(key)
63
64 _config.side_effect = foo
65 _ip_config.side_effect = foo
66 _unit_get.return_value = 'swift-proxy'
67 _local_unit.return_value = 'swift-proxy/0'
68 _service_name.return_value = 'swift-proxy'
69 _is_clustered.return_value = False
70
71 swift_hooks.keystone_joined()
72
73 _relation_set.assert_called_with(
74 service='swift',
75 region='RegionOne',
76 public_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s',
77 internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s',
78 admin_url='http://swift-proxy:1234',
79 requested_roles='Operator,Monitor',
80 relation_id=None
81 )
82
83 @patch.object(swift_hooks, 'config')
84 @patch('charmhelpers.contrib.openstack.ip.config')
85 @patch.object(swift_hooks, 'CONFIGS')
86 @patch('charmhelpers.core.hookenv.local_unit')
87 @patch('charmhelpers.core.hookenv.service_name')
88 @patch('charmhelpers.contrib.openstack.ip.unit_get')
89 @patch('charmhelpers.contrib.openstack.ip.is_clustered')
90 @patch.object(swift_hooks, 'relation_set')
91 def test_keystone_joined_public_hostname(self,
92 _relation_set,
93 _is_clustered,
94 _unit_get,
95 _service_name,
96 _local_unit,
97 _CONFIGS,
98 _ip_config,
99 _config):
100 config_dict = {
101 'bind-port': '1234',
102 'region': 'RegionOne',
103 'operator-roles': 'Operator,Monitor',
104 'os-public-hostname': 'public.example.com'
105 }
106
107 def foo(key=None):
108 if key is None:
109 return config_dict
110 else:
111 return config_dict.get(key)
112
113 _config.side_effect = _ip_config.side_effect = foo
114 _unit_get.return_value = _service_name.return_value = 'swift-proxy'
115 _local_unit.return_value = 'swift-proxy/0'
116 _is_clustered.return_value = False
117
118 swift_hooks.keystone_joined()
119
120 _relation_set.assert_called_with(
121 service='swift',
122 region='RegionOne',
123 public_url=('http://public.example.com:1234/'
124 'v1/AUTH_$(tenant_id)s'),
125 internal_url='http://swift-proxy:1234/v1/AUTH_$(tenant_id)s',
126 admin_url='http://swift-proxy:1234',
127 requested_roles='Operator,Monitor',
128 relation_id=None
129 )

Subscribers

People subscribed via source and target branches