@@ -566,3 +566,39 @@ def test_limitrange_defaults_update(self):
566566 ),
567567 [],
568568 )
569+
570+ def test_preexisting_project (self ):
571+ """Test allocation activation and validation when the project already exists on OpenShift."""
572+ user = self .new_user ()
573+ project = self .new_project (pi = user )
574+ allocation = self .new_allocation (project , self .resource , 1 )
575+ self .new_allocation_user (allocation , user )
576+ allocator = openshift .OpenShiftResourceAllocator (self .resource , allocation )
577+
578+ project_id = allocator .create_project (project .title ).id
579+
580+ self .assertEqual (allocator .get_quota (project_id ), {})
581+ self .assertEqual (allocator .get_users (project_id ), set ())
582+
583+ utils .set_attribute_on_allocation (
584+ allocation , attributes .ALLOCATION_PROJECT_ID , project_id
585+ )
586+ utils .set_attribute_on_allocation (
587+ allocation , attributes .ALLOCATION_PROJECT_NAME , project_id
588+ )
589+ tasks .activate_allocation (allocation .pk )
590+ call_command ("validate_allocations" , apply = True )
591+
592+ self .assertEqual (
593+ allocator .get_quota (project_id ),
594+ {
595+ "limits.cpu" : "1" ,
596+ "limits.memory" : "4Gi" ,
597+ "limits.ephemeral-storage" : "5Gi" ,
598+ "ocs-external-storagecluster-ceph-rbd.storageclass.storage.k8s.io/requests.storage" : "20Gi" ,
599+ "ibm-spectrum-scale-fileset.storageclass.storage.k8s.io/requests.storage" : "0" ,
600+ "requests.nvidia.com/gpu" : "0" ,
601+ "persistentvolumeclaims" : "2" ,
602+ },
603+ )
604+ assert set ([user .username ]) == allocator .get_users (project_id )
0 commit comments