MCPcopy Create free account
hub / github.com/apache/cloudstack / matchResourceCount

Function matchResourceCount

tools/marvin/marvin/lib/common.py:1484–1526  ·  view source on GitHub ↗

Match the resource count of account/project with the expected resource count

(apiclient, expectedCount, resourceType,
                              accountid=None, projectid=None)

Source from the content-addressed store, hash-verified

1482 return [PASS, volume]
1483
1484def matchResourceCount(apiclient, expectedCount, resourceType,
1485 accountid=None, projectid=None):
1486 """Match the resource count of account/project with the expected
1487 resource count"""
1488 expected = int(expectedCount) # initialise as int to make sure floats passed are acceptable
1489 try:
1490 resourceholderlist = None
1491 if accountid:
1492 resourceholderlist = Account.list(apiclient, id=accountid)
1493 elif projectid:
1494 resourceholderlist = Project.list(apiclient, id=projectid, listall=True)
1495 validationresult = validateList(resourceholderlist)
1496 assert validationresult[0] == PASS,\
1497 "accounts list validation failed"
1498 if resourceType == RESOURCE_PRIMARY_STORAGE:
1499 resourceCount = resourceholderlist[0].primarystoragetotal
1500 elif resourceType == RESOURCE_SECONDARY_STORAGE:
1501 resourceCount = resourceholderlist[0].secondarystoragetotal
1502 expected = expectedCount # as the exception, an original value is needed here (should be of type float)
1503 elif resourceType == RESOURCE_CPU:
1504 resourceCount = resourceholderlist[0].cputotal
1505 elif resourceType == RESOURCE_MEMORY:
1506 resourceCount = resourceholderlist[0].memorytotal
1507 elif resourceType == RESOURCE_USER_VM:
1508 resourceCount = resourceholderlist[0].vmtotal
1509 elif resourceType == RESOURCE_PUBLIC_IP:
1510 resourceCount = resourceholderlist[0].iptotal
1511 elif resourceType == RESOURCE_VOLUME:
1512 resourceCount = resourceholderlist[0].volumetotal
1513 elif resourceType == RESOURCE_SNAPSHOT:
1514 resourceCount = resourceholderlist[0].snapshottotal
1515 elif resourceType == RESOURCE_TEMPLATE:
1516 resourceCount = resourceholderlist[0].templatetotal
1517 elif resourceType == RESOURCE_NETWORK:
1518 resourceCount = resourceholderlist[0].networktotal
1519 elif resourceType == RESOURCE_VPC:
1520 resourceCount = resourceholderlist[0].vpctotal
1521 assert str(resourceCount) == str(expected),\
1522 "Resource count %s should match with the expected resource count %s" %\
1523 (resourceCount, expectedCount)
1524 except Exception as e:
1525 return [FAIL, e]
1526 return [PASS, None]
1527
1528def createSnapshotFromVirtualMachineVolume(apiclient, account, vmid):
1529 """Create snapshot from volume"""

Calls 3

validateListFunction · 0.90
intFunction · 0.85
listMethod · 0.65