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/helpers/utils.py b/tcp_tests/helpers/utils.py
index 001cf3e..b300168 100644
--- a/tcp_tests/helpers/utils.py
+++ b/tcp_tests/helpers/utils.py
@@ -15,6 +15,7 @@
import copy
import os
import shutil
+import StringIO
import tempfile
import time
import traceback
@@ -148,13 +149,28 @@
def generate_keys():
+ file_obj = StringIO.StringIO()
key = paramiko.RSAKey.generate(1024)
+ key.write_private_key(file_obj)
public = key.get_base64()
- dirpath = tempfile.mkdtemp()
- key.write_private_key_file(os.path.join(dirpath, 'id_rsa'))
- with open(os.path.join(dirpath, 'id_rsa.pub'), 'w') as pub_file:
- pub_file.write(public)
- return dirpath
+ private = file_obj.getvalue()
+ file_obj.close()
+ return {'private': private,
+ 'public': public}
+
+
+def load_keyfile(file_path):
+ with open(file_path, 'r') as private_key_file:
+ private = private_key_file.read()
+ key = paramiko.RSAKey(file_obj=StringIO.StringIO(private))
+ public = key.get_base64()
+ return {'private': private,
+ 'public': public}
+
+
+def dump_keyfile(file_path, key):
+ key = paramiko.RSAKey(file_obj=StringIO.StringIO(key['private']))
+ key.write_private_key_file(file_path)
def clean_dir(dirpath):