@@ -18,6 +18,7 @@ def setUp(self) -> None:
1818 self .resource = self .new_openshift_resource (
1919 name = "Microshift" ,
2020 api_url = os .getenv ("OS_API_URL" ),
21+ ibm_storage_available = True ,
2122 )
2223
2324 def test_new_allocation (self ):
@@ -135,7 +136,7 @@ def test_new_allocation_quota(self):
135136 2 * 5 ,
136137 )
137138 self .assertEqual (
138- allocation .get_attribute (attributes .QUOTA_REQUESTS_STORAGE ), 2 * 20
139+ allocation .get_attribute (attributes .QUOTA_REQUESTS_NESE_STORAGE ), 2 * 20
139140 )
140141 self .assertEqual (allocation .get_attribute (attributes .QUOTA_REQUESTS_GPU ), 2 * 0 )
141142 self .assertEqual (allocation .get_attribute (attributes .QUOTA_PVC ), 2 * 2 )
@@ -149,7 +150,8 @@ def test_new_allocation_quota(self):
149150 "limits.cpu" : "2" ,
150151 "limits.memory" : "8Gi" ,
151152 "limits.ephemeral-storage" : "10Gi" ,
152- "requests.storage" : "40Gi" ,
153+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "40Gi" ,
154+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
153155 "requests.nvidia.com/gpu" : "0" ,
154156 "persistentvolumeclaims" : "4" ,
155157 },
@@ -164,7 +166,7 @@ def test_new_allocation_quota(self):
164166 allocation , attributes .QUOTA_LIMITS_EPHEMERAL_STORAGE_GB , 50
165167 )
166168 utils .set_attribute_on_allocation (
167- allocation , attributes .QUOTA_REQUESTS_STORAGE , 100
169+ allocation , attributes .QUOTA_REQUESTS_NESE_STORAGE , 100
168170 )
169171 utils .set_attribute_on_allocation (allocation , attributes .QUOTA_REQUESTS_GPU , 1 )
170172 utils .set_attribute_on_allocation (allocation , attributes .QUOTA_PVC , 10 )
@@ -175,7 +177,7 @@ def test_new_allocation_quota(self):
175177 allocation .get_attribute (attributes .QUOTA_LIMITS_EPHEMERAL_STORAGE_GB ), 50
176178 )
177179 self .assertEqual (
178- allocation .get_attribute (attributes .QUOTA_REQUESTS_STORAGE ), 100
180+ allocation .get_attribute (attributes .QUOTA_REQUESTS_NESE_STORAGE ), 100
179181 )
180182 self .assertEqual (allocation .get_attribute (attributes .QUOTA_REQUESTS_GPU ), 1 )
181183 self .assertEqual (allocation .get_attribute (attributes .QUOTA_PVC ), 10 )
@@ -192,7 +194,8 @@ def test_new_allocation_quota(self):
192194 "limits.cpu" : "6" ,
193195 "limits.memory" : "8Gi" ,
194196 "limits.ephemeral-storage" : "50Gi" ,
195- "requests.storage" : "100Gi" ,
197+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "100Gi" ,
198+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
196199 "requests.nvidia.com/gpu" : "1" ,
197200 "persistentvolumeclaims" : "10" ,
198201 },
@@ -221,7 +224,8 @@ def test_reactivate_allocation(self):
221224 "limits.cpu" : "2" ,
222225 "limits.memory" : "8Gi" ,
223226 "limits.ephemeral-storage" : "10Gi" ,
224- "requests.storage" : "40Gi" ,
227+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "40Gi" ,
228+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
225229 "requests.nvidia.com/gpu" : "0" ,
226230 "persistentvolumeclaims" : "4" ,
227231 },
@@ -242,7 +246,8 @@ def test_reactivate_allocation(self):
242246 "limits.cpu" : "3" ,
243247 "limits.memory" : "8Gi" ,
244248 "limits.ephemeral-storage" : "10Gi" ,
245- "requests.storage" : "40Gi" ,
249+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "40Gi" ,
250+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
246251 "requests.nvidia.com/gpu" : "0" ,
247252 "persistentvolumeclaims" : "4" ,
248253 },
@@ -375,3 +380,106 @@ def test_allocation_new_attribute(self):
375380 "limits.memory" : "8Gi" ,
376381 },
377382 )
383+
384+ def test_migrate_quota_field_names (self ):
385+ """When a quota key in QUOTA_KEY_MAPPING changes to a new value, validate_allocations should update the quota."""
386+ user = self .new_user ()
387+ project = self .new_project (pi = user )
388+ allocation = self .new_allocation (project , self .resource , 1 )
389+ allocator = openshift .OpenShiftResourceAllocator (self .resource , allocation )
390+
391+ tasks .activate_allocation (allocation .pk )
392+ allocation .refresh_from_db ()
393+
394+ project_id = allocation .get_attribute (attributes .ALLOCATION_PROJECT_ID )
395+
396+ quota = allocator .get_quota (project_id )
397+ self .assertEqual (
398+ quota ,
399+ {
400+ "limits.cpu" : "1" ,
401+ "limits.memory" : "4Gi" ,
402+ "limits.ephemeral-storage" : "5Gi" ,
403+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "20Gi" ,
404+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
405+ "requests.nvidia.com/gpu" : "0" ,
406+ "persistentvolumeclaims" : "2" ,
407+ },
408+ )
409+
410+ # Now migrate NESE Storage quota field (ocs-external...) to fake storage quota
411+ with unittest .mock .patch .dict (
412+ openshift .OpenShiftResourceAllocator .QUOTA_KEY_MAPPING ,
413+ {
414+ attributes .QUOTA_REQUESTS_NESE_STORAGE : lambda x : {
415+ "fake-storage.storageclass.storage.k8s.io/requests.storage" : f"{ x } Gi"
416+ }
417+ },
418+ ):
419+ call_command ("validate_allocations" , apply = True )
420+
421+ # Check the quota after migration
422+ quota = allocator .get_quota (project_id )
423+ self .assertEqual (
424+ quota ,
425+ {
426+ "limits.cpu" : "1" ,
427+ "limits.memory" : "4Gi" ,
428+ "limits.ephemeral-storage" : "5Gi" ,
429+ "fake-storage.storageclass.storage.k8s.io/requests.storage" : "20Gi" , # Migrated key
430+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
431+ "requests.nvidia.com/gpu" : "0" ,
432+ "persistentvolumeclaims" : "2" ,
433+ },
434+ )
435+
436+ def test_ibm_storage_not_available (self ):
437+ """If IBM Scale storage is not available, the corresponding quotas should not be set."""
438+ user = self .new_user ()
439+ project = self .new_project (pi = user )
440+
441+ # Set ibm storage as not available
442+ self .resource .resourceattribute_set .filter (
443+ resource_attribute_type__name = attributes .RESOURCE_IBM_AVAILABLE
444+ ).update (value = "false" )
445+ allocation = self .new_allocation (project , self .resource , 1 )
446+ allocator = openshift .OpenShiftResourceAllocator (self .resource , allocation )
447+
448+ tasks .activate_allocation (allocation .pk )
449+ allocation .refresh_from_db ()
450+
451+ project_id = allocation .get_attribute (attributes .ALLOCATION_PROJECT_ID )
452+
453+ quota = allocator .get_quota (project_id )
454+ self .assertEqual (
455+ quota ,
456+ {
457+ "limits.cpu" : "1" ,
458+ "limits.memory" : "4Gi" ,
459+ "limits.ephemeral-storage" : "5Gi" ,
460+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "20Gi" ,
461+ "requests.nvidia.com/gpu" : "0" ,
462+ "persistentvolumeclaims" : "2" ,
463+ },
464+ )
465+
466+ # Now set IBM Scale storage as available
467+ self .resource .resourceattribute_set .filter (
468+ resource_attribute_type__name = attributes .RESOURCE_IBM_AVAILABLE
469+ ).update (value = "true" )
470+
471+ call_command ("validate_allocations" , apply = True )
472+
473+ quota = allocator .get_quota (project_id )
474+ self .assertEqual (
475+ quota ,
476+ {
477+ "limits.cpu" : "1" ,
478+ "limits.memory" : "4Gi" ,
479+ "limits.ephemeral-storage" : "5Gi" ,
480+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "20Gi" ,
481+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" , # Newly added IBM key
482+ "requests.nvidia.com/gpu" : "0" ,
483+ "persistentvolumeclaims" : "2" ,
484+ },
485+ )
0 commit comments