diff --git a/IM/SSH.py b/IM/SSH.py index 966793fc..8090e5cd 100644 --- a/IM/SSH.py +++ b/IM/SSH.py @@ -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 @@ -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() diff --git a/contextualization/ctxt_agent_dist.py b/contextualization/ctxt_agent_dist.py index af981185..f96a8a01 100755 --- a/contextualization/ctxt_agent_dist.py +++ b/contextualization/ctxt_agent_dist.py @@ -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'] diff --git a/test/integration/TestIM.py b/test/integration/TestIM.py index 1b937d36..94728e5c 100755 --- a/test/integration/TestIM.py +++ b/test/integration/TestIM.py @@ -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( @@ -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).")