Few changes to 'address' function for ingress
* scheme can be added with with_scheme=True flag * ingress port will be added to the end of the address Change-Id: I94efeea5a8a0acb67781d3e5a50b0c99601f7b4e
This commit is contained in:
parent
bc0137d632
commit
d720fb6fad
|
@ -118,8 +118,8 @@ def _cleanup_openstack_environment(configs, auth_url=None):
|
|||
'Run with --skip-os-cleanup flag if OpenStack '
|
||||
'is not deployed')
|
||||
|
||||
configs['auth_url'] = auth_url or 'http://%s/v3' % utils.address(
|
||||
'keystone', configs['keystone']['public_port'], True)
|
||||
configs['auth_url'] = auth_url or '%s/v3' % utils.address(
|
||||
'keystone', configs['keystone']['public_port'], True, True)
|
||||
|
||||
session = _get_session(
|
||||
configs['auth_url'], configs['openstack']['user_name'],
|
||||
|
|
|
@ -39,13 +39,16 @@ def get_config_paths():
|
|||
return paths
|
||||
|
||||
|
||||
def address(service, port=None, external=False):
|
||||
def address(service, port=None, external=False, with_scheme=False):
|
||||
addr = None
|
||||
scheme = 'http'
|
||||
if external:
|
||||
if not port:
|
||||
raise RuntimeError('Port config is required for external address')
|
||||
if CONF.configs.ingress.enabled and port.get('ingress'):
|
||||
addr = get_ingress_host(port['ingress'])
|
||||
scheme = 'https'
|
||||
addr = "%s:%s" % (get_ingress_host(port['ingress']),
|
||||
CONF.configs.ingress.port)
|
||||
elif port.get('node'):
|
||||
addr = '%s:%s' % (CONF.configs.k8s_external_ip, port['node'])
|
||||
|
||||
|
@ -54,6 +57,9 @@ def address(service, port=None, external=False):
|
|||
if port:
|
||||
addr = '%s:%s' % (addr, port['cont'])
|
||||
|
||||
if with_scheme:
|
||||
addr = "%s://%s" % (scheme, addr)
|
||||
|
||||
return addr
|
||||
|
||||
|
||||
|
|
|
@ -399,8 +399,9 @@ def _create_openrc(config):
|
|||
"export OS_USERNAME=%s" % config['openstack']['user_name'],
|
||||
"export OS_PASSWORD=%s" % config['openstack']['user_password'],
|
||||
"export OS_IDENTITY_API_VERSION=3",
|
||||
"export OS_AUTH_URL=http://%s/v3" %
|
||||
utils.address('keystone', config['keystone']['public_port'], True)
|
||||
"export OS_AUTH_URL=%s/v3" %
|
||||
utils.address('keystone', config['keystone']['public_port'], True,
|
||||
True)
|
||||
]
|
||||
with open('openrc-%s' % config['namespace'], 'w') as openrc_file:
|
||||
openrc_file.write("\n".join(openrc))
|
||||
|
|
|
@ -6,3 +6,4 @@ configs:
|
|||
ingress:
|
||||
enabled: False
|
||||
domain: external
|
||||
port: 8443
|
||||
|
|
|
@ -136,23 +136,31 @@ class TestAddress(testscenarios.WithScenarios, base.TestCase):
|
|||
{'address': 'service.ccp:1234', 'external': True, 'ingress': False,
|
||||
'port': {'cont': 1234, 'ingress': 'test'}}),
|
||||
('external_with_ingress_enabled',
|
||||
{'address': 'test.ccp.external', 'external': True, 'ingress': True,
|
||||
'port': {'cont': 1234, 'ingress': 'test'}}),
|
||||
{'address': 'test.ccp.external:8443', 'external': True,
|
||||
'ingress': True, 'port': {'cont': 1234, 'ingress': 'test'}}),
|
||||
('external_with_ingress_not_provided',
|
||||
{'address': '1.1.1.1:30000', 'external': True, 'ingress': True,
|
||||
'port': {'cont': 1234, 'node': 30000}}),
|
||||
('external_with_ingress_and_nodeport_not_provided',
|
||||
{'address': 'service.ccp:1234', 'external': True, 'ingress': True,
|
||||
'port': {'cont': 1234}}),
|
||||
('internal_with_scheme', {'address': 'http://service.ccp',
|
||||
'with_scheme': True}),
|
||||
('external_with_ingress_with_scheme',
|
||||
{'address': 'https://test.ccp.external:8443', 'external': True,
|
||||
'ingress': True, 'port': {'cont': 1234, 'ingress': 'test'},
|
||||
'with_scheme': True}),
|
||||
)
|
||||
|
||||
port = None
|
||||
external = None
|
||||
ingress = False
|
||||
with_scheme = False
|
||||
|
||||
def test_address(self):
|
||||
self.conf.configs._merge({'ingress': {'enabled': self.ingress,
|
||||
'domain': 'external'},
|
||||
'domain': 'external',
|
||||
'port': 8443},
|
||||
'k8s_external_ip': '1.1.1.1'})
|
||||
self.assertEqual(self.address,
|
||||
utils.address('service', self.port, self.external))
|
||||
self.assertEqual(self.address, utils.address(
|
||||
'service', self.port, self.external, self.with_scheme))
|
||||
|
|
Loading…
Reference in New Issue