Allow to specify empty value for tripleo.undercloud_ssh_hostname option
Change-Id: Ifa5232a70406901048c8f7156b2869e0ab640190
This commit is contained in:
parent
5e4c1f78c3
commit
f13aa0fbc9
@ -13,6 +13,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import typing
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
import tobiko
|
import tobiko
|
||||||
@ -26,20 +28,22 @@ CONF = config.CONF
|
|||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def undercloud_ssh_client():
|
def undercloud_ssh_client() -> ssh.SSHClientFixture:
|
||||||
host_config = undercloud_host_config()
|
host_config = undercloud_host_config()
|
||||||
return ssh.ssh_client(host='undercloud-0', host_config=host_config)
|
if not host_config.hostname:
|
||||||
|
raise NoSuchUndercloudHostname('No such undercloud hostname')
|
||||||
|
return ssh.ssh_client(host=host_config.hostname, host_config=host_config)
|
||||||
|
|
||||||
|
|
||||||
def undercloud_host_config():
|
class NoSuchUndercloudHostname(tobiko.TobikoException):
|
||||||
return tobiko.setup_fixture(UndecloudHostConfig)
|
message = "Undercloud hostname not specified"
|
||||||
|
|
||||||
|
|
||||||
class InvalidRCFile(tobiko.TobikoException):
|
class InvalidRCFile(tobiko.TobikoException):
|
||||||
message = "Invalid RC file: {rcfile}"
|
message = "Invalid RC file: {rcfile}"
|
||||||
|
|
||||||
|
|
||||||
def fetch_os_env(rcfile, *rcfiles):
|
def fetch_os_env(rcfile, *rcfiles) -> typing.Dict[str, str]:
|
||||||
rcfiles = (rcfile,) + rcfiles
|
rcfiles = (rcfile,) + rcfiles
|
||||||
errors = []
|
errors = []
|
||||||
for rcfile in rcfiles:
|
for rcfile in rcfiles:
|
||||||
@ -63,22 +67,29 @@ def fetch_os_env(rcfile, *rcfiles):
|
|||||||
raise InvalidRCFile(rcfile=", ".join(rcfiles))
|
raise InvalidRCFile(rcfile=", ".join(rcfiles))
|
||||||
|
|
||||||
|
|
||||||
def load_undercloud_rcfile():
|
def load_undercloud_rcfile() -> typing.Dict[str, str]:
|
||||||
return fetch_os_env(*CONF.tobiko.tripleo.undercloud_rcfile)
|
return fetch_os_env(*CONF.tobiko.tripleo.undercloud_rcfile)
|
||||||
|
|
||||||
|
|
||||||
class UndercloudKeystoneCredentialsFixture(
|
class UndercloudKeystoneCredentialsFixture(
|
||||||
keystone.EnvironKeystoneCredentialsFixture):
|
keystone.EnvironKeystoneCredentialsFixture):
|
||||||
def get_environ(self):
|
def get_environ(self) -> typing.Dict[str, str]:
|
||||||
return load_undercloud_rcfile()
|
return load_undercloud_rcfile()
|
||||||
|
|
||||||
|
|
||||||
class HasUndercloudFixture(tobiko.SharedFixture):
|
class HasUndercloudFixture(tobiko.SharedFixture):
|
||||||
|
|
||||||
has_undercloud = None
|
has_undercloud: typing.Optional[bool] = None
|
||||||
|
|
||||||
def setup_fixture(self):
|
def setup_fixture(self):
|
||||||
|
self.has_undercloud = check_undercloud()
|
||||||
|
|
||||||
|
|
||||||
|
def check_undercloud() -> bool:
|
||||||
|
try:
|
||||||
ssh_client = undercloud_ssh_client()
|
ssh_client = undercloud_ssh_client()
|
||||||
|
except NoSuchUndercloudHostname:
|
||||||
|
return False
|
||||||
try:
|
try:
|
||||||
ssh_client.connect(retry_count=1,
|
ssh_client.connect(retry_count=1,
|
||||||
connection_attempts=1,
|
connection_attempts=1,
|
||||||
@ -86,12 +97,11 @@ class HasUndercloudFixture(tobiko.SharedFixture):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.debug('Unable to connect to undercloud host: %s', ex,
|
LOG.debug('Unable to connect to undercloud host: %s', ex,
|
||||||
exc_info=1)
|
exc_info=1)
|
||||||
self.has_undercloud = False
|
return False
|
||||||
else:
|
return True
|
||||||
self.has_undercloud = True
|
|
||||||
|
|
||||||
|
|
||||||
def has_undercloud():
|
def has_undercloud() -> bool:
|
||||||
return tobiko.setup_fixture(HasUndercloudFixture).has_undercloud
|
return tobiko.setup_fixture(HasUndercloudFixture).has_undercloud
|
||||||
|
|
||||||
|
|
||||||
@ -101,18 +111,17 @@ skip_if_missing_undercloud = tobiko.skip_unless(
|
|||||||
|
|
||||||
class UndecloudHostConfig(tobiko.SharedFixture):
|
class UndecloudHostConfig(tobiko.SharedFixture):
|
||||||
|
|
||||||
host = 'undercloud-0'
|
hostname: typing.Optional[str] = None
|
||||||
hostname = None
|
port: typing.Optional[int] = None
|
||||||
port = None
|
username: typing.Optional[str] = None
|
||||||
username = None
|
key_filename: typing.Optional[str] = None
|
||||||
key_filename = None
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(UndecloudHostConfig, self).__init__()
|
super(UndecloudHostConfig, self).__init__()
|
||||||
self._connect_parameters = ssh.gather_ssh_connect_parameters(**kwargs)
|
self._connect_parameters = ssh.gather_ssh_connect_parameters(**kwargs)
|
||||||
|
|
||||||
def setup_fixture(self):
|
def setup_fixture(self):
|
||||||
self.hostname = CONF.tobiko.tripleo.undercloud_ssh_hostname
|
self.hostname = CONF.tobiko.tripleo.undercloud_ssh_hostname.strip()
|
||||||
self.port = CONF.tobiko.tripleo.undercloud_ssh_port
|
self.port = CONF.tobiko.tripleo.undercloud_ssh_port
|
||||||
self.username = CONF.tobiko.tripleo.undercloud_ssh_username
|
self.username = CONF.tobiko.tripleo.undercloud_ssh_username
|
||||||
self.key_filename = CONF.tobiko.tripleo.undercloud_ssh_key_filename
|
self.key_filename = CONF.tobiko.tripleo.undercloud_ssh_key_filename
|
||||||
@ -124,6 +133,10 @@ class UndecloudHostConfig(tobiko.SharedFixture):
|
|||||||
return parameters
|
return parameters
|
||||||
|
|
||||||
|
|
||||||
|
def undercloud_host_config() -> UndecloudHostConfig:
|
||||||
|
return tobiko.setup_fixture(UndecloudHostConfig)
|
||||||
|
|
||||||
|
|
||||||
def undercloud_keystone_client():
|
def undercloud_keystone_client():
|
||||||
session = undercloud_keystone_session()
|
session = undercloud_keystone_session()
|
||||||
return keystone.get_keystone_client(session=session)
|
return keystone.get_keystone_client(session=session)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user