|
23 | 23 | import sys
|
24 | 24 | import json
|
25 | 25 | import base64
|
| 26 | +import yaml |
26 | 27 |
|
27 | 28 | from mock import Mock, patch, MagicMock
|
28 | 29 |
|
@@ -1390,72 +1391,58 @@ def test_change_inf_auth(self):
|
1390 | 1391 | " provided for the InfrastructureManager."))
|
1391 | 1392 |
|
1392 | 1393 | @patch('IM.Stats.DataBase')
|
1393 |
| - def test_get_stats(self, DataBase): |
| 1394 | + @patch('IM.InfrastructureManager.InfrastructureManager.check_auth_data') |
| 1395 | + def test_get_stats(self, check_auth_data, DataBase): |
1394 | 1396 |
|
1395 | 1397 | radl = """
|
1396 |
| - network public ( outbound = 'yes' ) |
1397 |
| - system plants ( |
1398 |
| - name = 'plants' and |
1399 |
| - memory.size = 488M and |
1400 |
| - script = '#!/bin/bash |
1401 |
| - echo "Hola" |
1402 |
| - ' and |
1403 |
| - cpu.count = 0.5 and |
1404 |
| - disk.0.image.url = 'oscar://sharp-elbakyan5.im.grycap.net/grycap/image' and |
1405 |
| - input.0.provider = 'minio.default' and |
1406 |
| - input.0.path = 'input' and |
1407 |
| - output.0.provider = 'minio.default' and |
1408 |
| - output.0.path = 'output' and |
1409 |
| - alpine = 0 and |
1410 |
| - net_interface.0.connection = 'public' and |
1411 |
| - state = 'configured' and |
1412 |
| - provider.type = 'OSCAR' and |
1413 |
| - instance_id = 'plants' and |
1414 |
| - net_interface.0.dns_name = 'vnode-0' and |
1415 |
| - token = 'ebfb145ab57a35520669fc89bc115edab1b231a5c8f92e895ecaee256f841bac' |
1416 |
| - ) |
1417 |
| -
|
1418 |
| - configure plants () |
1419 |
| - contextualize ( |
1420 |
| - system plants configure plants step 1 |
1421 |
| - ) |
1422 |
| - deploy plants 1 |
| 1398 | + system node ( |
| 1399 | + memory.size = 512M and |
| 1400 | + cpu.count = 2 |
| 1401 | + )""" |
1423 | 1402 |
|
1424 |
| - """ |
| 1403 | + auth = Authentication([{'type': 'InfrastructureManager', 'token': 'atoken', |
| 1404 | + 'username': '__OPENID__mcaballer', 'pass': 'pass'}]) |
| 1405 | + check_auth_data.return_value = auth |
1425 | 1406 |
|
1426 | 1407 | db = MagicMock()
|
1427 | 1408 | inf_data = {
|
1428 | 1409 | "id": "1",
|
1429 |
| - "auth": [ |
1430 |
| - {"password": "https://aai.egi.eu/oidc/a67fff9c06e62401975aeb29ad35b8faf7c4fc74b4526a5504e5132b01496831@egi.eu", |
1431 |
| - "type": "InfrastructureManager", |
1432 |
| - "username": "__OPENID__mcaballer" |
1433 |
| - } |
1434 |
| - ], |
| 1410 | + "auth": auth.auth_list, |
| 1411 | + "creation_date": 1646655374, |
| 1412 | + "extra_info": {"TOSCA": yaml.dump({"metadata": {"icon": "kubernetes.png"}})}, |
1435 | 1413 | "vm_list": [
|
1436 |
| - {"last_update": 1646656730, |
1437 |
| - "destroy": True, |
1438 |
| - "state": "deleting", |
1439 |
| - "id": "plants", |
1440 |
| - "im_id": 0, |
| 1414 | + { |
1441 | 1415 | "cloud": {
|
1442 |
| - "id": "oscar", |
1443 | 1416 | "type": "OSCAR",
|
1444 | 1417 | "server": "sharp-elbakyan5.im.grycap.net",
|
1445 |
| - "protocol": "https" |
1446 | 1418 | },
|
1447 |
| - "info": radl, |
1448 |
| - "cont_out": "", |
1449 |
| - "configured": True, |
1450 |
| - "creation_date": 1646655378 |
| 1419 | + "info": radl |
1451 | 1420 | },
|
1452 |
| - "extra_info": {"TOSCA": {"metadata": {"icon": "kubernetes.png"}}} |
| 1421 | + { |
| 1422 | + "cloud": { |
| 1423 | + "type": "OSCAR", |
| 1424 | + "server": "sharp-elbakyan5.im.grycap.net", |
| 1425 | + }, |
| 1426 | + "info": radl |
| 1427 | + } |
1453 | 1428 | ]
|
1454 | 1429 | }
|
1455 |
| - db.select.return_value = [(inf_data, '2022-03-23', '1')] |
| 1430 | + db.select.return_value = [(json.dumps(inf_data).encode(), '2022-03-23', '1')] |
1456 | 1431 | DataBase.return_value = db
|
1457 | 1432 |
|
1458 |
| - IM.GetStats() |
| 1433 | + stats = IM.GetStats('2001-01-01', auth) |
| 1434 | + expected_res = [{'creation_date': '2022-03-07 13:16:14', |
| 1435 | + 'icon': 'kubernetes', |
| 1436 | + 'vm_count': 2, |
| 1437 | + 'cpu_count': 4, |
| 1438 | + 'memory_size': 1024, |
| 1439 | + 'cloud_type': 'OSCAR', |
| 1440 | + 'cloud_host': 'sharp-elbakyan5.im.grycap.net', |
| 1441 | + 'hybrid': False, |
| 1442 | + 'im_user': '__OPENID__mcaballer', |
| 1443 | + 'inf_id': '1', |
| 1444 | + 'last_date': '2022-03-23'}] |
| 1445 | + self.assertEqual(stats, expected_res) |
1459 | 1446 |
|
1460 | 1447 |
|
1461 | 1448 | if __name__ == "__main__":
|
|
0 commit comments