diff --git a/src/coldfront_plugin_cloud/management/commands/validate_allocations.py b/src/coldfront_plugin_cloud/management/commands/validate_allocations.py index 71b9bf8e..5872dd2f 100644 --- a/src/coldfront_plugin_cloud/management/commands/validate_allocations.py +++ b/src/coldfront_plugin_cloud/management/commands/validate_allocations.py @@ -19,6 +19,8 @@ logger = logging.getLogger(__name__) +STATES_TO_VALIDATE = ["Active", "Active (Needs Renewal)"] + class Command(BaseCommand): help = "Validates quotas and users in resource allocations." @@ -108,7 +110,9 @@ def handle(self, *args, **options): ) openstack_allocations = Allocation.objects.filter( resources__in=openstack_resources, - status=AllocationStatusChoice.objects.get(name="Active"), + status__in=AllocationStatusChoice.objects.filter( + name__in=STATES_TO_VALIDATE + ), ) for allocation in openstack_allocations: self.check_institution_specific_code(allocation, options["apply"]) @@ -206,7 +210,9 @@ def handle(self, *args, **options): ) openshift_allocations = Allocation.objects.filter( resources__in=openshift_resources, - status=AllocationStatusChoice.objects.get(name="Active"), + status__in=AllocationStatusChoice.objects.filter( + name__in=STATES_TO_VALIDATE + ), ) for allocation in openshift_allocations: diff --git a/src/coldfront_plugin_cloud/tests/base.py b/src/coldfront_plugin_cloud/tests/base.py index 5a19857c..03d35d62 100644 --- a/src/coldfront_plugin_cloud/tests/base.py +++ b/src/coldfront_plugin_cloud/tests/base.py @@ -34,6 +34,9 @@ def setUp(self) -> None: call_command("register_cloud_attributes") sys.stdout = backup + # For testing we can validate allocations with this status + AllocationStatusChoice.objects.get_or_create(name="Active (Needs Renewal)") + @staticmethod def new_user(username=None) -> User: username = username or f"{uuid.uuid4().hex}@example.com" @@ -115,12 +118,14 @@ def new_project_user(self, user, project, role="Manager", status="Active"): ) return pu - def new_allocation(self, project, resource, quantity) -> Allocation: + def new_allocation( + self, project, resource, quantity, status="Active" + ) -> Allocation: allocation, _ = Allocation.objects.get_or_create( project=project, justification="a justification for testing data", quantity=quantity, - status=AllocationStatusChoice.objects.get(name="Active"), + status=AllocationStatusChoice.objects.get(name=status), ) allocation.resources.add(resource) return allocation diff --git a/src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py b/src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py index a3450c2e..a4177792 100644 --- a/src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py +++ b/src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py @@ -483,3 +483,23 @@ def test_ibm_storage_not_available(self): "persistentvolumeclaims": "2", }, ) + + def test_needs_renewal_allocation(self): + """Simple test to validate allocations in `Active (Needs Renewal)` status.""" + user = self.new_user() + project = self.new_project(pi=user) + allocation = self.new_allocation( + project, self.resource, 1, "Active (Needs Renewal)" + ) + allocator = openshift.OpenShiftResourceAllocator(self.resource, allocation) + + tasks.activate_allocation(allocation.pk) + allocation.refresh_from_db() + + user2 = self.new_user() + self.new_allocation_user(allocation, user2) + + project_id = allocation.get_attribute(attributes.ALLOCATION_PROJECT_ID) + assert user2.username not in allocator.get_users(project_id) + call_command("validate_allocations", apply=True) + assert user2.username in allocator.get_users(project_id)