Skip to content

Commit 0324b67

Browse files
committed
Implements: #1353
1 parent ced555a commit 0324b67

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

IM/InfrastructureManager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ def GetStats(date, auth):
17471747
# First check the auth data
17481748
auth = InfrastructureManager.check_auth_data(auth)
17491749
stats = Stats.get_stats(date, auth)
1750-
if not stats:
1750+
if stats is None:
17511751
raise Exception("ERROR connecting with the database!.")
17521752
else:
17531753
return stats

IM/Stats.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class Stats():
3434
@staticmethod
3535
def _get_data(str_data, auth=None):
3636
dic = json.loads(str_data)
37-
inf_auth = Authentication(dic['auth'])
38-
if auth is not None and not inf_auth.compare(auth, 'InfrastructureManager'):
37+
inf_auth = Authentication.deserialize(dic['auth']).getAuthInfo('InfrastructureManager')[0]
38+
user_auth = auth.getAuthInfo('InfrastructureManager')[0]
39+
if inf_auth['username'] != user_auth['username'] or inf_auth['password'] != user_auth['password']:
3940
return None
4041

4142
resp = {'creation_date': None}
@@ -73,8 +74,7 @@ def _get_data(str_data, auth=None):
7374
resp['memory_size'] += vm_sys.getFeature('memory.size').getValue('M')
7475
resp['vm_count'] += 1
7576

76-
im_auth = inf_auth.getAuthInfo("InfrastructureManager")[0]
77-
resp['im_user'] = im_auth.get('username', "")
77+
resp['im_user'] = inf_auth.get('username')
7878
return resp
7979

8080
@staticmethod
@@ -108,12 +108,14 @@ def get_stats(init_date="1970-01-01", auth=None):
108108
data = elem[0]
109109
date = elem[1]
110110
inf_id = elem[2]
111-
res = Stats._get_data(data.decode(), auth)
112-
if res:
113-
res['inf_id'] = inf_id
114-
res['last_date'] = str(date)
115-
stats.append(res)
116-
111+
try:
112+
res = Stats._get_data(data, auth)
113+
if res:
114+
res['inf_id'] = inf_id
115+
res['last_date'] = str(date)
116+
stats.append(res)
117+
except Exception:
118+
Stats.logger.exception("ERROR reading infrastructure info from Inf ID: %s" % inf_id)
117119
db.close()
118120
return stats
119121
else:

test/unit/test_im_logic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1401,13 +1401,13 @@ def test_get_stats(self, check_auth_data, DataBase):
14011401
)"""
14021402

14031403
auth = Authentication([{'type': 'InfrastructureManager', 'token': 'atoken',
1404-
'username': '__OPENID__mcaballer', 'pass': 'pass'}])
1404+
'username': '__OPENID__mcaballer', 'password': 'pass'}])
14051405
check_auth_data.return_value = auth
14061406

14071407
db = MagicMock()
14081408
inf_data = {
14091409
"id": "1",
1410-
"auth": auth.auth_list,
1410+
"auth": auth.serialize(),
14111411
"creation_date": 1646655374,
14121412
"extra_info": {"TOSCA": yaml.dump({"metadata": {"icon": "kubernetes.png"}})},
14131413
"vm_list": [
@@ -1427,7 +1427,7 @@ def test_get_stats(self, check_auth_data, DataBase):
14271427
}
14281428
]
14291429
}
1430-
db.select.return_value = [(json.dumps(inf_data).encode(), '2022-03-23', '1')]
1430+
db.select.return_value = [(json.dumps(inf_data), '2022-03-23', '1')]
14311431
DataBase.return_value = db
14321432

14331433
stats = IM.GetStats('2001-01-01', auth)

0 commit comments

Comments
 (0)