Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions src/coldfront_plugin_cloud/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)