Merge "Allow overriding of /etc/hosts entries"
This commit is contained in:
commit
b5f7491540
@ -103,6 +103,20 @@ dns_opts = [
|
|||||||
"This is required if 'use_designate' is True")
|
"This is required if 'use_designate' is True")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
accessible_ip_opts = [
|
||||||
|
cfg.IPOpt('identity_ip_accessible',
|
||||||
|
default=None,
|
||||||
|
help='IP address of Keystone endpoint, accessible by tenant'
|
||||||
|
' machines. If not set, the results of the DNS lookup'
|
||||||
|
' performed where Sahara services are running will be'
|
||||||
|
' used.'),
|
||||||
|
cfg.IPOpt('object_store_ip_accessible',
|
||||||
|
default=None,
|
||||||
|
help='IP address of Swift endpoint, accessible by tenant'
|
||||||
|
' machines. If not set, the results of the DNS lookup'
|
||||||
|
' performed where Sahara services are running will be'
|
||||||
|
' used.'),
|
||||||
|
]
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
CONF.register_cli_opts(cli_opts)
|
CONF.register_cli_opts(cli_opts)
|
||||||
@ -110,6 +124,7 @@ CONF.register_opts(networking_opts)
|
|||||||
CONF.register_opts(edp_opts)
|
CONF.register_opts(edp_opts)
|
||||||
CONF.register_opts(db_opts)
|
CONF.register_opts(db_opts)
|
||||||
CONF.register_opts(dns_opts)
|
CONF.register_opts(dns_opts)
|
||||||
|
CONF.register_opts(accessible_ip_opts)
|
||||||
|
|
||||||
log.register_options(CONF)
|
log.register_options(CONF)
|
||||||
|
|
||||||
@ -158,6 +173,7 @@ def list_opts():
|
|||||||
networking_opts,
|
networking_opts,
|
||||||
dns_opts,
|
dns_opts,
|
||||||
db_opts,
|
db_opts,
|
||||||
|
accessible_ip_opts,
|
||||||
plugins_base.opts,
|
plugins_base.opts,
|
||||||
topology_helper.opts,
|
topology_helper.opts,
|
||||||
keystone.opts,
|
keystone.opts,
|
||||||
|
@ -170,3 +170,19 @@ class UtilsClusterTest(base.SaharaWithDbTestCase):
|
|||||||
expected = ("nameserver 1.1.1.1\n"
|
expected = ("nameserver 1.1.1.1\n"
|
||||||
"nameserver 2.2.2.2\n")
|
"nameserver 2.2.2.2\n")
|
||||||
self.assertEqual(expected, value)
|
self.assertEqual(expected, value)
|
||||||
|
|
||||||
|
@mock.patch("socket.gethostbyname")
|
||||||
|
@mock.patch("sahara.utils.openstack.base.url_for")
|
||||||
|
def test_etc_hosts_entry_for_service_overrides(self, mock_url,
|
||||||
|
mock_get_host):
|
||||||
|
self.override_config("object_store_ip_accessible", None)
|
||||||
|
mock_url.return_value = "http://swift.org"
|
||||||
|
mock_get_host.return_value = '1.1.1.1'
|
||||||
|
|
||||||
|
res = cluster_utils.etc_hosts_entry_for_service('object-store')
|
||||||
|
self.assertEqual('1.1.1.1 swift.org\n', res)
|
||||||
|
|
||||||
|
self.override_config("object_store_ip_accessible", '2.2.2.2')
|
||||||
|
|
||||||
|
res = cluster_utils.etc_hosts_entry_for_service('object-store')
|
||||||
|
self.assertEqual('2.2.2.2 swift.org\n', res)
|
||||||
|
@ -143,6 +143,13 @@ def etc_hosts_entry_for_service(service):
|
|||||||
except keystone_ex.EndpointNotFound:
|
except keystone_ex.EndpointNotFound:
|
||||||
LOG.debug("Endpoint not found for service: '{}'".format(service))
|
LOG.debug("Endpoint not found for service: '{}'".format(service))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
overridden_ip = (
|
||||||
|
getattr(CONF, "%s_ip_accessible" % service.replace('-', '_'), None)
|
||||||
|
)
|
||||||
|
if overridden_ip is not None:
|
||||||
|
return "%s %s\n" % (overridden_ip, hostname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = "%s %s\n" % (socket.gethostbyname(hostname), hostname)
|
result = "%s %s\n" % (socket.gethostbyname(hostname), hostname)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
|
Loading…
Reference in New Issue
Block a user