Skip to content

Commit

Permalink
Merge pull request #119 from nerc-project/change_default_quota_attrib…
Browse files Browse the repository at this point in the history
…utes
  • Loading branch information
knikolla authored Nov 7, 2023
2 parents bce3374 + fac7bbf commit f49b176
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/coldfront_plugin_cloud/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
UNIT_QUOTA_MULTIPLIERS = {
'openstack': {
attributes.QUOTA_INSTANCES: 1,
attributes.QUOTA_VCPU: 2,
attributes.QUOTA_VCPU: 1,
attributes.QUOTA_RAM: 4096,
attributes.QUOTA_VOLUMES: 2,
attributes.QUOTA_VOLUMES_GB: 100,
attributes.QUOTA_VOLUMES_GB: 20,
attributes.QUOTA_FLOATING_IPS: 0,
attributes.QUOTA_OBJECT_GB: 1,
attributes.QUOTA_GPU: 0,
},
'openshift': {
attributes.QUOTA_LIMITS_CPU: 2,
attributes.QUOTA_LIMITS_MEMORY: 2048,
attributes.QUOTA_LIMITS_CPU: 1,
attributes.QUOTA_LIMITS_MEMORY: 4096,
attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB: 5,
attributes.QUOTA_REQUESTS_STORAGE: 10,
attributes.QUOTA_REQUESTS_STORAGE: 20,
attributes.QUOTA_PVC: 2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ def test_new_allocation_quota(self):

project_id = allocation.get_attribute(attributes.ALLOCATION_PROJECT_ID)

self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_CPU), 2 * 2)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_MEMORY), 2 * 2048)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_CPU), 2 * 1)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_MEMORY), 2 * 4096)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB), 2 * 5)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_REQUESTS_STORAGE), 2 * 10)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_REQUESTS_STORAGE), 2 * 20)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_PVC), 2 * 2)

quota = allocator.get_quota(project_id)['Quota']
quota = {k: v for k, v in quota.items() if v is not None}
# The return value will update to the most relevant unit, so
# 4000m cores becomes 4 and 4096Mi becomes 4Gi
# 2000m cores becomes 2 and 8192Mi becomes 8Gi
self.assertEqual(quota, {
":limits.cpu": "4",
":limits.memory": "4Gi",
":limits.cpu": "2",
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "20Gi",
":requests.storage": "40Gi",
":persistentvolumeclaims": "4",
})

Expand Down Expand Up @@ -173,19 +173,19 @@ def test_reactivate_allocation(self):

project_id = allocation.get_attribute(attributes.ALLOCATION_PROJECT_ID)

self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_CPU), 4)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_CPU), 2)

quota = allocator.get_quota(project_id)['Quota']

# https://github.com/CCI-MOC/openshift-acct-mgt
quota = {k: v for k, v in quota.items() if v is not None}
# The return value will update to the most relevant unit, so
# 4000m cores becomes 4 and 4096Mi becomes 4Gi
# 2000m cores becomes 2 and 8192Mi becomes 8Gi
self.assertEqual(quota, {
":limits.cpu": "4",
":limits.memory": "4Gi",
":limits.cpu": "2",
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "20Gi",
":requests.storage": "40Gi",
":persistentvolumeclaims": "4",
})

Expand All @@ -198,12 +198,12 @@ def test_reactivate_allocation(self):
quota = allocator.get_quota(project_id)['Quota']
quota = {k: v for k, v in quota.items() if v is not None}
# The return value will update to the most relevant unit, so
# 4000m cores becomes 4 and 4096Mi becomes 4Gi
# 3000m cores becomes 3 and 8192Mi becomes 8Gi
self.assertEqual(quota, {
":limits.cpu": "3",
":limits.memory": "4Gi",
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "20Gi",
":requests.storage": "40Gi",
":persistentvolumeclaims": "4",
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_new_allocation(self):
# Check nova quota
expected_nova_quota = {
'instances': 1,
'cores': 2,
'cores': 1,
'ram': 4096,
}
actual_nova_quota = self.compute.quotas.get(openstack_project.id)
Expand All @@ -78,7 +78,7 @@ def test_new_allocation(self):
# Check cinder quota
expected_cinder_quota = {
'volumes': 2,
'gigabytes': 100,
'gigabytes': 20,
}
actual_cinder_quota = self.volume.quotas.get(openstack_project.id)
for k, v in expected_cinder_quota.items():
Expand All @@ -95,10 +95,10 @@ def test_new_allocation(self):
# Validate get_quota
expected_quota = {
'instances': 1,
'cores': 2,
'cores': 1,
'ram': 4096,
'volumes': 2,
'gigabytes': 100,
'gigabytes': 20,
'floatingip': 2,
'x-account-meta-quota-bytes': 1,
}
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_new_allocation_with_quantity(self):
# Check nova quota
expected_nova_quota = {
'instances': 1 * 3,
'cores': 2 * 3,
'cores': 1 * 3,
'ram': 4096 * 3,
}
actual_nova_quota = self.compute.quotas.get(openstack_project.id)
Expand All @@ -154,7 +154,7 @@ def test_new_allocation_with_quantity(self):
# Check cinder quota
expected_cinder_quota = {
'volumes': 2 * 3,
'gigabytes': 100 * 3,
'gigabytes': 20 * 3,
}
actual_cinder_quota = self.volume.quotas.get(openstack_project.id)
for k, v in expected_cinder_quota.items():
Expand All @@ -170,7 +170,7 @@ def test_new_allocation_with_quantity(self):

# Change allocation attribute for floating ips and cores
self.assertEqual(allocation.get_attribute(attributes.QUOTA_FLOATING_IPS), 2)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_VCPU), 2 * 3)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_VCPU), 1 * 3)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_FLOATING_IPS, 3)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_VCPU, 100)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_FLOATING_IPS), 3)
Expand Down

0 comments on commit f49b176

Please sign in to comment.