Skip to content

Commit

Permalink
Merge pull request #127 from nerc-project/fix-gpu-quota-defaults-and-…
Browse files Browse the repository at this point in the history
…tests

fix default GPU quota and update tests
  • Loading branch information
jtriley authored Nov 27, 2023
2 parents 50ae320 + f4000db commit caacf91
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/coldfront_plugin_cloud/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def set_quota(self, project_id):
url = f"{self.auth_url}/projects/{project_id}/quota"
payload = dict()
for key, func in QUOTA_KEY_MAPPING.items():
if x := self.allocation.get_attribute(key):
if (x := self.allocation.get_attribute(key)) is not None:
payload.update(func(x))
r = self.session.put(url, data=json.dumps({'Quota': payload}))
self.check_response(r)
Expand Down
2 changes: 1 addition & 1 deletion src/coldfront_plugin_cloud/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
attributes.QUOTA_LIMITS_MEMORY: 4096,
attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB: 5,
attributes.QUOTA_REQUESTS_STORAGE: 20,
attributes.QUOTA_REQUESTS_GPU: 1,
attributes.QUOTA_REQUESTS_GPU: 0,
attributes.QUOTA_PVC: 2
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_new_allocation_quota(self):
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 * 20)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_REQUESTS_GPU), 2 * 0)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_PVC), 2 * 2)

quota = allocator.get_quota(project_id)['Quota']
Expand All @@ -131,6 +132,7 @@ def test_new_allocation_quota(self):
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "40Gi",
":requests.nvidia.com/gpu": "0",
":persistentvolumeclaims": "4",
})

Expand All @@ -139,12 +141,14 @@ def test_new_allocation_quota(self):
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_LIMITS_MEMORY, 8192)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB, 50)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_REQUESTS_STORAGE, 100)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_REQUESTS_GPU, 1)
utils.set_attribute_on_allocation(allocation, attributes.QUOTA_PVC, 10)

self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_CPU), 6)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_MEMORY), 8192)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB), 50)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_REQUESTS_STORAGE), 100)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_REQUESTS_GPU), 1)
self.assertEqual(allocation.get_attribute(attributes.QUOTA_PVC), 10)

# This call should update the openshift quota to match the current attributes
Expand All @@ -158,6 +162,7 @@ def test_new_allocation_quota(self):
":limits.memory": "8Gi",
":limits.ephemeral-storage": "50Gi",
":requests.storage": "100Gi",
":requests.nvidia.com/gpu": "1",
":persistentvolumeclaims": "10",
})

Expand Down Expand Up @@ -186,6 +191,7 @@ def test_reactivate_allocation(self):
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "40Gi",
":requests.nvidia.com/gpu": "0",
":persistentvolumeclaims": "4",
})

Expand All @@ -204,6 +210,7 @@ def test_reactivate_allocation(self):
":limits.memory": "8Gi",
":limits.ephemeral-storage": "10Gi",
":requests.storage": "40Gi",
":requests.nvidia.com/gpu": "0",
":persistentvolumeclaims": "4",
})

Expand Down

0 comments on commit caacf91

Please sign in to comment.