From 5758d2e2f0f56682fccb0a5fe05d7f6fb37f0b14 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Fri, 8 Nov 2024 11:50:12 +0100 Subject: [PATCH 1/3] Fix test --- test/integration/TestIM.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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).") From 06f2180679bd1056e61b996c453dabd438997d97 Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Mon, 11 Nov 2024 09:57:24 +0100 Subject: [PATCH 2/3] Fix error in ctxt dist --- contextualization/ctxt_agent_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'] From 3db3189a76ed11709e9fd76d24aca22eafcda75a Mon Sep 17 00:00:00 2001 From: Miguel Caballer Date: Thu, 14 Nov 2024 12:44:13 +0100 Subject: [PATCH 3/3] Fix SSH #1633 --- IM/SSH.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) 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()