Use generated RSA key while accessing nodes via SSH
Generate RSA key pair (optionally it could be provided by
operator via environment variable) and use it for SSH
authentication instead of password.
Also it's possible to provide the key from a local file now.
Change-Id: I5fea4d55337f294cd7829392b91b2cca7b85ead5
Reviewed-on: https://review.gerrithub.io/367254
Reviewed-by: Victor Ryzhenkin <vryzhenkin@mirantis.com>
Reviewed-by: Dennis Dmitriev <dis.xcom@gmail.com>
Tested-by: Dennis Dmitriev <dis.xcom@gmail.com>
diff --git a/tcp_tests/fixtures/common_fixtures.py b/tcp_tests/fixtures/common_fixtures.py
index f03a7d3..ad9ce46 100644
--- a/tcp_tests/fixtures/common_fixtures.py
+++ b/tcp_tests/fixtures/common_fixtures.py
@@ -25,16 +25,6 @@
LOG = logger.logger
-@pytest.yield_fixture(scope='session')
-def ssh_keys_dir(request):
- ssh_keys_dir = utils.generate_keys()
- LOG.info("SSH keys were generated in {}".format(ssh_keys_dir))
- yield ssh_keys_dir
- utils.clean_dir(ssh_keys_dir)
- LOG.info("Tmp dir {} with generated ssh keys was cleaned".format(
- ssh_keys_dir))
-
-
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
diff --git a/tcp_tests/fixtures/config_fixtures.py b/tcp_tests/fixtures/config_fixtures.py
index 8a2aa27..973e034 100644
--- a/tcp_tests/fixtures/config_fixtures.py
+++ b/tcp_tests/fixtures/config_fixtures.py
@@ -15,7 +15,11 @@
import pytest
+from tcp_tests import logger
from tcp_tests import settings_oslo
+from tcp_tests.helpers import utils
+
+LOG = logger.logger
@pytest.fixture(scope='session')
@@ -30,4 +34,20 @@
config_opts = settings_oslo.load_config(config_files)
+ if os.path.isfile(config_opts.underlay.ssh_key_file):
+ LOG.debug('Loading SSH key from file: {0}'.format(
+ config_opts.underlay.ssh_key_file))
+ key_from_file = utils.load_keyfile(config_opts.underlay.ssh_key_file)
+ if key_from_file not in config_opts.underlay.ssh_keys:
+ config_opts.underlay.ssh_keys.append(key_from_file)
+ else:
+ if not config_opts.underlay.ssh_keys:
+ config_opts.underlay.ssh_keys.append(utils.generate_keys())
+ utils.dump_keyfile(config_opts.underlay.ssh_key_file,
+ config_opts.underlay.ssh_keys[0])
+ LOG.debug('Saving SSH key to file: {0}'.format(
+ config_opts.underlay.ssh_key_file))
+ utils.dump_keyfile(config_opts.underlay.ssh_key_file,
+ config_opts.underlay.ssh_keys[0])
+
return config_opts