Skip to content

Commit 9e54bc1

Browse files
authored
Merge pull request #1632 from grycap/boto3
Fix test
2 parents ebc958b + e273623 commit 9e54bc1

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

IM/SSH.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
118118
private_key_obj = StringIO()
119119
if os.path.isfile(private_key):
120120
pkfile = open(private_key)
121+
self.private_key = ""
121122
for line in pkfile.readlines():
122123
private_key_obj.write(line)
124+
self.private_key += line
123125
pkfile.close()
124126
else:
125127
# Avoid windows line endings
@@ -128,18 +130,31 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
128130
if not private_key.endswith("\n"):
129131
private_key += "\n"
130132
private_key_obj.write(private_key)
133+
self.private_key = private_key
131134

132-
self.private_key = private_key
133-
private_key_obj.seek(0)
135+
self.private_key_obj = self._load_private_key(private_key_obj)
134136

135-
if "BEGIN RSA PRIVATE KEY" in private_key:
136-
self.private_key_obj = paramiko.RSAKey.from_private_key(private_key_obj)
137-
elif "BEGIN DSA PRIVATE KEY" in private_key:
138-
self.private_key_obj = paramiko.DSSKey.from_private_key(private_key_obj)
139-
elif "BEGIN EC PRIVATE KEY" in private_key:
140-
self.private_key_obj = paramiko.ECDSAKey.from_private_key(private_key_obj)
141-
elif "BEGIN OPENSSH PRIVATE KEY" in private_key:
142-
self.private_key_obj = paramiko.Ed25519Key.from_private_key(private_key_obj)
137+
@staticmethod
138+
def _load_private_key(private_key_obj):
139+
""" Load a private key from a file-like object"""
140+
private_key_obj.seek(0)
141+
try:
142+
return paramiko.RSAKey.from_private_key(private_key_obj)
143+
except Exception:
144+
private_key_obj.seek(0)
145+
try:
146+
return paramiko.DSSKey.from_private_key(private_key_obj)
147+
except Exception:
148+
private_key_obj.seek(0)
149+
try:
150+
return paramiko.ECDSAKey.from_private_key(private_key_obj)
151+
except Exception:
152+
private_key_obj.seek(0)
153+
try:
154+
return paramiko.Ed25519Key.from_private_key(private_key_obj)
155+
except Exception:
156+
private_key_obj.seek(0)
157+
raise Exception("Invalid private key")
143158

144159
def __del__(self):
145160
self.close()

contextualization/ctxt_agent_dist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def get_master_ssh(self, general_conf_data):
211211
return SSHRetry(vm_ip, ctxt_vm['user'], passwd, private_key, ctxt_vm['remote_port'])
212212

213213
@staticmethod
214-
def get_ssh(vm, pk_file, changed_pass=None):
214+
def get_ssh(vm, pk_file, changed_pass=None, use_proxy=False):
215215
passwd = vm['passwd']
216216
if 'new_passwd' in vm and vm['new_passwd'] and changed_pass:
217217
passwd = vm['new_passwd']

test/integration/TestIM.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_19_addresource(self):
261261
Test AddResource function
262262
"""
263263
(success, res) = self.server.AddResource(
264-
self.inf_id, RADL_ADD_WIN, self.auth_data)
264+
self.inf_id, RADL_ADD, self.auth_data)
265265
self.assertTrue(success, msg="ERROR calling AddResource: " + str(res))
266266

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

274274
all_configured = self.wait_inf_state(
275-
self.inf_id, VirtualMachine.CONFIGURED, 2700)
275+
self.inf_id, VirtualMachine.CONFIGURED, 2400)
276276
self.assertTrue(
277277
all_configured, msg="ERROR waiting the infrastructure to be configured (timeout).")
278278

0 commit comments

Comments
 (0)