Skip to content

Commit 057f105

Browse files
authored
Merge pull request #1634 from grycap/boto3
Fix stats wihtout init_date
2 parents 9e54bc1 + 132369d commit 057f105

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

IM/InfrastructureManager.py

+2
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,8 @@ def GetStats(init_date, end_date, auth):
20562056
"""
20572057
# First check the auth data
20582058
auth = InfrastructureManager.check_auth_data(auth)
2059+
if not init_date:
2060+
init_date = "1970-01-01"
20592061
stats = Stats.get_stats(init_date, end_date, auth)
20602062
if stats is None:
20612063
raise Exception("ERROR connecting with the database!.")

IM/SSH.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,17 @@ def __init__(self, host, user, passwd=None, private_key=None, port=22, proxy_hos
132132
private_key_obj.write(private_key)
133133
self.private_key = private_key
134134

135+
private_key_obj.seek(0)
135136
self.private_key_obj = self._load_private_key(private_key_obj)
136137

137138
@staticmethod
138139
def _load_private_key(private_key_obj):
139140
""" 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)
141+
for kype in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey, paramiko.Ed25519Key]:
142+
try:
143+
return kype.from_private_key(private_key_obj)
144+
except Exception:
145+
private_key_obj.seek(0)
157146
raise Exception("Invalid private key")
158147

159148
def __del__(self):

IM/Stats.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Stats():
3535
@staticmethod
3636
def _get_data(str_data, init_date=None, end_date=None):
3737
dic = json.loads(str_data)
38-
resp = {'creation_date': None}
38+
resp = {'creation_date': ''}
3939
if 'creation_date' in dic and dic['creation_date']:
4040
creation_date = datetime.datetime.fromtimestamp(float(dic['creation_date']))
4141
resp['creation_date'] = str(creation_date)
@@ -44,7 +44,7 @@ def _get_data(str_data, init_date=None, end_date=None):
4444
if end_date and creation_date > end_date:
4545
return None
4646

47-
resp['tosca_name'] = None
47+
resp['tosca_name'] = ''
4848
if 'extra_info' in dic and dic['extra_info'] and "TOSCA" in dic['extra_info']:
4949
try:
5050
tosca = yaml.safe_load(dic['extra_info']['TOSCA'])
@@ -56,8 +56,8 @@ def _get_data(str_data, init_date=None, end_date=None):
5656
resp['vm_count'] = 0
5757
resp['cpu_count'] = 0
5858
resp['memory_size'] = 0
59-
resp['cloud_type'] = None
60-
resp['cloud_host'] = None
59+
resp['cloud_type'] = ''
60+
resp['cloud_host'] = ''
6161
resp['hybrid'] = False
6262
resp['deleted'] = True if 'deleted' in dic and dic['deleted'] else False
6363
for str_vm_data in dic['vm_list']:

test/integration/TestIM.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ def test_40_export_import(self):
510510
success, msg="ERROR calling ImportInfrastructure: " + str(res))
511511

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

518518
def test_50_destroy(self):
519519
"""

0 commit comments

Comments
 (0)