Revert "Allow to configure undercloud via ssh_config file"

This reverts commit 8c33b9ac28.

Change-Id: Ib00cba30569c4971811f444697d10e12384ed81e

this is breaking doenstream CI again :

I'm reverting since the downstream CI is more important than any individual patch


2020-02-15 19:56:23.583 737695 DEBUG tobiko.common._fixture [-] Set up fixture 'tobiko.shell.sh._ssh.SSHShellProcessFixture' setUp /home/stack/tobiko/tobiko/common/_fixture.py:367
2020-02-15 19:56:23.584 737695 DEBUG tobiko.shell.sh._ssh [-] Executing remote command: 'hostname' (login='heat-admin@undercloud-0:22', timeout=None)... create_process /home/stack/tobiko/tobiko/shell/sh/_ssh.py:90
2020-02-15 19:56:23.584 737695 DEBUG tobiko.common._fixture [-] Set up fixture 'tobiko.shell.ssh._client.SSHClientFixture' setUp /home/stack/tobiko/tobiko/common/_fixture.py:367
2020-02-15 19:56:23.584 737695 DEBUG tobiko.shell.ssh._client [-] Logging in to 'heat-admin@undercloud-0:22' ({'key_filename': ['/home/stack/.ssh/id_rsa'], 'timeout': 10.0, 'allow_agent': False, 'compress': False})... attempt 1 out of 60 ssh_connect /home/stack/tobiko/tobiko/shell/ssh/_client.py:432
2020-02-15 19:56:23.629 737695 WARNING py.warnings [-] /home/stack/tobiko/.tox/scenario/lib/python3.6/site-packages/paramiko/client.py:837: UserWarning: Unknown ssh-ed25519 host key for undercloud-0: b'74d86f2d25b4898a737954b9a7b1822e'
  key.get_name(), hostname, hexlify(key.get_fingerprint())
: tobiko.openstack.topology._exception.NoSuchOpenStackTopologyNode: No such topology node: {'address': Selection([IPAddress('192.168.24.1'), IPAddress('127.0.0.1')])}
2020-02-15 19:56:23.704 737695 DEBUG tobiko.shell.ssh._client [-] Error logging in to 'heat-admin@undercloud-0:22': Authentication failed. ssh_connect /home/stack/tobiko/tobiko/shell/ssh/_client.py:449
This commit is contained in:
Pini Komarov 2020-02-16 20:02:33 +00:00
parent 8c33b9ac28
commit 1980cef3e7
8 changed files with 61 additions and 66 deletions

1
.gitignore vendored
View File

@ -40,4 +40,3 @@ Pipfile.lock
tobiko.conf tobiko.conf
clouds.yaml clouds.yaml
ssh_config ssh_config
ssh_id*

View File

@ -272,8 +272,8 @@ class DefaultKeystoneCredentialsFixture(KeystoneCredentialsFixture):
for fixture in self.fixtures: for fixture in self.fixtures:
try: try:
credentials = tobiko.setup_fixture(fixture).credentials credentials = tobiko.setup_fixture(fixture).credentials
except Exception as ex: except Exception:
LOG.debug("Error getting cretentials from %r: %s", fixture, ex) LOG.debug("Error getting cretentials from %r", fixture)
errors.append(tobiko.exc_info()) errors.append(tobiko.exc_info())
continue continue

View File

@ -75,10 +75,7 @@ def positive_int(value):
def get_key_filename(value): def get_key_filename(value):
if isinstance(value, six.string_types): if isinstance(value, six.string_types):
value = [value] value = [value]
key_filename = [tobiko.tobiko_config_path(v) for v in value] return [os.path.realpath(os.path.expanduser(v)) for v in value]
return [f
for f in key_filename
if os.path.isfile(f)]
SSH_CONNECT_PARAMETERS = { SSH_CONNECT_PARAMETERS = {

View File

@ -27,43 +27,38 @@ import tobiko
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
def ssh_config(config_files=None, **defaults): def ssh_config(config_files=None):
if config_files or defaults: if config_files:
fixture = SSHConfigFixture(config_files=config_files, **defaults) fixture = SSHConfigFixture(config_files=config_files)
else: else:
fixture = SSHConfigFixture fixture = SSHConfigFixture
return tobiko.setup_fixture(fixture) return tobiko.setup_fixture(fixture)
def ssh_host_config(host=None, config_files=None, **defaults): def ssh_host_config(host=None, config_files=None):
return ssh_config(config_files=config_files, **defaults).lookup(host) return ssh_config(config_files=config_files).lookup(host)
class SSHDefaultConfigFixture(tobiko.SharedFixture): class SSHDefaultConfigFixture(tobiko.SharedFixture):
def __init__(self, **defaults): conf = None
super(SSHDefaultConfigFixture, self).__init__()
self.__dict__.update((key, value) def setup_fixture(self):
for key, value in defaults.items() self.conf = tobiko.tobiko_config().ssh
if value is not None)
def __getattr__(self, name): def __getattr__(self, name):
config = tobiko.tobiko_config().ssh return getattr(self.conf, name)
value = getattr(config, name)
self.__dict__[name] = value
return value
class SSHConfigFixture(tobiko.SharedFixture): class SSHConfigFixture(tobiko.SharedFixture):
default = None default = tobiko.required_setup_fixture(SSHDefaultConfigFixture)
config_files = None config_files = None
config = None config = None
def __init__(self, config_files=None, **defaults): def __init__(self, config_files=None):
super(SSHConfigFixture, self).__init__() super(SSHConfigFixture, self).__init__()
self.default = tobiko.setup_fixture(
SSHDefaultConfigFixture(**defaults))
if config_files: if config_files:
self.config_files = tuple(config_files) self.config_files = tuple(config_files)
else: else:
@ -92,8 +87,7 @@ class SSHConfigFixture(tobiko.SharedFixture):
return SSHHostConfig(host=host, return SSHHostConfig(host=host,
ssh_config=self, ssh_config=self,
host_config=host_config, host_config=host_config,
config_files=self.config_files, config_files=self.config_files)
default=self.default)
def __repr__(self): def __repr__(self):
return "{class_name!s}(config_files={config_files!r})".format( return "{class_name!s}(config_files={config_files!r})".format(
@ -103,8 +97,9 @@ class SSHConfigFixture(tobiko.SharedFixture):
class SSHHostConfig(collections.namedtuple('SSHHostConfig', ['host', class SSHHostConfig(collections.namedtuple('SSHHostConfig', ['host',
'ssh_config', 'ssh_config',
'host_config', 'host_config',
'config_files', 'config_files'])):
'default'])):
default = tobiko.required_setup_fixture(SSHDefaultConfigFixture)
@property @property
def hostname(self): def hostname(self):

View File

@ -37,9 +37,9 @@ OPTIONS = [
default=['/etc/ssh/ssh_config', '~/.ssh/config', default=['/etc/ssh/ssh_config', '~/.ssh/config',
'./ssh_config'], './ssh_config'],
help="Default user SSH configuration files"), help="Default user SSH configuration files"),
cfg.ListOpt('key_file', cfg.StrOpt('key_file',
default=['ssh_identity', '~/.ssh/id_rsa', '~/.ssh/id_dsa'], default='~/.ssh/id_rsa',
help="Default SSH private key file"), help="Default SSH private key file"),
cfg.BoolOpt('allow_agent', cfg.BoolOpt('allow_agent',
default=False, default=False,
help=("Set to False to disable connecting to the " help=("Set to False to disable connecting to the "

View File

@ -23,13 +23,14 @@ CONF = config.CONF
TIPLEO_CONF = CONF.tobiko.tripleo TIPLEO_CONF = CONF.tobiko.tripleo
class UndercloudConfigTest(unit.TobikoUnitTest): class TripleoConfigTest(unit.TobikoUnitTest):
def test_undercloud_ssh_key_filename(self): def test_ssh_key_filename(self):
value = TIPLEO_CONF.undercloud_ssh_key_filename self.assertIsInstance(TIPLEO_CONF.undercloud_ssh_key_filename,
if value is not None: six.string_types)
self.assertIsInstance(value,
six.string_types)
class UndercloudConfigTest(unit.TobikoUnitTest):
def test_undercloud_ssh_hostname(self): def test_undercloud_ssh_hostname(self):
value = TIPLEO_CONF.undercloud_ssh_hostname value = TIPLEO_CONF.undercloud_ssh_hostname

View File

@ -21,7 +21,7 @@ GROUP_NAME = 'tripleo'
OPTIONS = [ OPTIONS = [
# Undercloud options # Undercloud options
cfg.StrOpt('undercloud_ssh_hostname', cfg.StrOpt('undercloud_ssh_hostname',
default='undercloud-0', default=None,
help="hostname or IP address to be used to connect to " help="hostname or IP address to be used to connect to "
"undercloud host"), "undercloud host"),
cfg.IntOpt('undercloud_ssh_port', cfg.IntOpt('undercloud_ssh_port',
@ -30,9 +30,9 @@ OPTIONS = [
cfg.StrOpt('undercloud_ssh_username', cfg.StrOpt('undercloud_ssh_username',
default='stack', default='stack',
help="Username with access to stackrc and overcloudrc files"), help="Username with access to stackrc and overcloudrc files"),
cfg.ListOpt('undercloud_ssh_key_filename', cfg.StrOpt('undercloud_ssh_key_filename',
default=None, default='~/.ssh/id_rsa',
help="SSH key filename used to login to Undercloud node"), help="SSH key filename used to login to Undercloud node"),
cfg.StrOpt('undercloud_rcfile', cfg.StrOpt('undercloud_rcfile',
default='~/stackrc', default='~/stackrc',
help="Undercloud RC filename"), help="Undercloud RC filename"),

View File

@ -13,10 +13,6 @@
# under the License. # under the License.
from __future__ import absolute_import from __future__ import absolute_import
import socket
import netaddr
import tobiko import tobiko
from tobiko import config from tobiko import config
from tobiko.openstack import keystone from tobiko.openstack import keystone
@ -32,12 +28,7 @@ def undercloud_ssh_client():
def undercloud_host_config(): def undercloud_host_config():
tripleo_config = tobiko.tobiko_config().tripleo return tobiko.setup_fixture(UndecloudHostConfig)
return ssh.ssh_host_config(
host=tripleo_config.undercloud_ssh_hostname,
username=tripleo_config.undercloud_ssh_username,
port=tripleo_config.undercloud_ssh_port,
key_file=tripleo_config.undercloud_ssh_key_filename)
def fetch_os_env(rcfile): def fetch_os_env(rcfile):
@ -60,28 +51,40 @@ class UndercloudKeystoneCredentialsFixture(
return load_undercloud_rcfile() return load_undercloud_rcfile()
def gethost_by_name(hostname):
try:
return netaddr.IPAddress(hostname)
except Exception:
ip_address = socket.gethostbyname(hostname)
return netaddr.IPAddress(ip_address)
def has_undercloud(): def has_undercloud():
host_config = undercloud_host_config() host_config = undercloud_host_config()
try: return bool(host_config.hostname)
gethost_by_name(host_config.hostname)
except Exception:
return False
else:
return True
skip_if_missing_undercloud = tobiko.skip_unless( skip_if_missing_undercloud = tobiko.skip_unless(
'TripleO undercloud hostname not configured', has_undercloud) 'TripleO undercloud hostname not configured', has_undercloud)
class UndecloudHostConfig(tobiko.SharedFixture):
host = 'undercloud-0'
hostname = None
port = None
username = None
key_filename = None
def __init__(self, **kwargs):
super(UndecloudHostConfig, self).__init__()
self._connect_parameters = ssh.gather_ssh_connect_parameters(**kwargs)
def setup_fixture(self):
self.hostname = CONF.tobiko.tripleo.undercloud_ssh_hostname
self.port = CONF.tobiko.tripleo.undercloud_ssh_port
self.username = CONF.tobiko.tripleo.undercloud_ssh_username
self.key_filename = CONF.tobiko.tripleo.undercloud_ssh_key_filename
@property
def connect_parameters(self):
parameters = ssh.gather_ssh_connect_parameters(self)
parameters.update(self._connect_parameters)
return parameters
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)