Skip to content

Commit

Permalink
Merge pull request #1634 from grycap/boto3
Browse files Browse the repository at this point in the history
Fix stats wihtout init_date
  • Loading branch information
micafer authored Nov 18, 2024
2 parents 9e54bc1 + 132369d commit 057f105
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
2 changes: 2 additions & 0 deletions IM/InfrastructureManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,8 @@ def GetStats(init_date, end_date, auth):
"""
# First check the auth data
auth = InfrastructureManager.check_auth_data(auth)
if not init_date:
init_date = "1970-01-01"
stats = Stats.get_stats(init_date, end_date, auth)
if stats is None:
raise Exception("ERROR connecting with the database!.")
Expand Down
23 changes: 6 additions & 17 deletions IM/SSH.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,17 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
private_key_obj.write(private_key)
self.private_key = private_key

private_key_obj.seek(0)
self.private_key_obj = self._load_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)
for kype in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey, paramiko.Ed25519Key]:
try:
return kype.from_private_key(private_key_obj)
except Exception:
private_key_obj.seek(0)
raise Exception("Invalid private key")

def __del__(self):
Expand Down
8 changes: 4 additions & 4 deletions IM/Stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Stats():
@staticmethod
def _get_data(str_data, init_date=None, end_date=None):
dic = json.loads(str_data)
resp = {'creation_date': None}
resp = {'creation_date': ''}
if 'creation_date' in dic and dic['creation_date']:
creation_date = datetime.datetime.fromtimestamp(float(dic['creation_date']))
resp['creation_date'] = str(creation_date)
Expand All @@ -44,7 +44,7 @@ def _get_data(str_data, init_date=None, end_date=None):
if end_date and creation_date > end_date:
return None

resp['tosca_name'] = None
resp['tosca_name'] = ''
if 'extra_info' in dic and dic['extra_info'] and "TOSCA" in dic['extra_info']:
try:
tosca = yaml.safe_load(dic['extra_info']['TOSCA'])
Expand All @@ -56,8 +56,8 @@ def _get_data(str_data, init_date=None, end_date=None):
resp['vm_count'] = 0
resp['cpu_count'] = 0
resp['memory_size'] = 0
resp['cloud_type'] = None
resp['cloud_host'] = None
resp['cloud_type'] = ''
resp['cloud_host'] = ''
resp['hybrid'] = False
resp['deleted'] = True if 'deleted' in dic and dic['deleted'] else False
for str_vm_data in dic['vm_list']:
Expand Down
4 changes: 2 additions & 2 deletions test/integration/TestIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ def test_40_export_import(self):
success, msg="ERROR calling ImportInfrastructure: " + str(res))

def test_45_stats(self):
(success, res) = self.server.GetStats(None, None, self.auth_data)
(success, res) = self.server.GetStats('', '', self.auth_data)
self.assertTrue(
success, msg="ERROR calling GetStats: " + str(res))
self.assertEqual(len(res), 3, msg="ERROR getting stats: Incorrect number of infrastructures")
self.assertEqual(len(res), 4, msg="ERROR getting stats: Incorrect number of infrastructures")

def test_50_destroy(self):
"""
Expand Down

0 comments on commit 057f105

Please sign in to comment.