Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test #1632

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions IM/SSH.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
private_key_obj = StringIO()
if os.path.isfile(private_key):
pkfile = open(private_key)
self.private_key = ""
for line in pkfile.readlines():
private_key_obj.write(line)
self.private_key += line
pkfile.close()
else:
# Avoid windows line endings
Expand All @@ -128,18 +130,31 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
if not private_key.endswith("\n"):
private_key += "\n"
private_key_obj.write(private_key)
self.private_key = private_key

self.private_key = private_key
private_key_obj.seek(0)
self.private_key_obj = self._load_private_key(private_key_obj)

if "BEGIN RSA PRIVATE KEY" in private_key:
self.private_key_obj = paramiko.RSAKey.from_private_key(private_key_obj)
elif "BEGIN DSA PRIVATE KEY" in private_key:
self.private_key_obj = paramiko.DSSKey.from_private_key(private_key_obj)
elif "BEGIN EC PRIVATE KEY" in private_key:
self.private_key_obj = paramiko.ECDSAKey.from_private_key(private_key_obj)
elif "BEGIN OPENSSH PRIVATE KEY" in private_key:
self.private_key_obj = paramiko.Ed25519Key.from_private_key(private_key_obj)
@staticmethod
def _load_private_key(private_key_obj):
""" Load a private key from a file-like object"""
private_key_obj.seek(0)
try:
return paramiko.RSAKey.from_private_key(private_key_obj)
except Exception:
private_key_obj.seek(0)
try:
return paramiko.DSSKey.from_private_key(private_key_obj)
except Exception:
private_key_obj.seek(0)
try:
return paramiko.ECDSAKey.from_private_key(private_key_obj)
except Exception:
private_key_obj.seek(0)
try:
return paramiko.Ed25519Key.from_private_key(private_key_obj)
except Exception:
private_key_obj.seek(0)
raise Exception("Invalid private key")

def __del__(self):
self.close()
Expand Down
2 changes: 1 addition & 1 deletion contextualization/ctxt_agent_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_master_ssh(self, general_conf_data):
return SSHRetry(vm_ip, ctxt_vm['user'], passwd, private_key, ctxt_vm['remote_port'])

@staticmethod
def get_ssh(vm, pk_file, changed_pass=None):
def get_ssh(vm, pk_file, changed_pass=None, use_proxy=False):
passwd = vm['passwd']
if 'new_passwd' in vm and vm['new_passwd'] and changed_pass:
passwd = vm['new_passwd']
Expand Down
4 changes: 2 additions & 2 deletions test/integration/TestIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_19_addresource(self):
Test AddResource function
"""
(success, res) = self.server.AddResource(
self.inf_id, RADL_ADD_WIN, self.auth_data)
self.inf_id, RADL_ADD, self.auth_data)
self.assertTrue(success, msg="ERROR calling AddResource: " + str(res))

(success, vm_ids) = self.server.GetInfrastructureInfo(
Expand All @@ -272,7 +272,7 @@ def test_19_addresource(self):
str(len(vm_ids)) + "). It must be 4"))

all_configured = self.wait_inf_state(
self.inf_id, VirtualMachine.CONFIGURED, 2700)
self.inf_id, VirtualMachine.CONFIGURED, 2400)
self.assertTrue(
all_configured, msg="ERROR waiting the infrastructure to be configured (timeout).")

Expand Down