Skip to content

Commit 1cb7589

Browse files
authored
Merge pull request #247 from QuanMPhm/246/storage_renewal
Allow validation of allocations with status `Active (Needs Renewal)`
2 parents 1b2338d + 8d892d9 commit 1cb7589

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/coldfront_plugin_cloud/management/commands/validate_allocations.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
logger = logging.getLogger(__name__)
2121

22+
STATES_TO_VALIDATE = ["Active", "Active (Needs Renewal)"]
23+
2224

2325
class Command(BaseCommand):
2426
help = "Validates quotas and users in resource allocations."
@@ -108,7 +110,9 @@ def handle(self, *args, **options):
108110
)
109111
openstack_allocations = Allocation.objects.filter(
110112
resources__in=openstack_resources,
111-
status=AllocationStatusChoice.objects.get(name="Active"),
113+
status__in=AllocationStatusChoice.objects.filter(
114+
name__in=STATES_TO_VALIDATE
115+
),
112116
)
113117
for allocation in openstack_allocations:
114118
self.check_institution_specific_code(allocation, options["apply"])
@@ -206,7 +210,9 @@ def handle(self, *args, **options):
206210
)
207211
openshift_allocations = Allocation.objects.filter(
208212
resources__in=openshift_resources,
209-
status=AllocationStatusChoice.objects.get(name="Active"),
213+
status__in=AllocationStatusChoice.objects.filter(
214+
name__in=STATES_TO_VALIDATE
215+
),
210216
)
211217

212218
for allocation in openshift_allocations:

src/coldfront_plugin_cloud/tests/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def setUp(self) -> None:
3434
call_command("register_cloud_attributes")
3535
sys.stdout = backup
3636

37+
# For testing we can validate allocations with this status
38+
AllocationStatusChoice.objects.get_or_create(name="Active (Needs Renewal)")
39+
3740
@staticmethod
3841
def new_user(username=None) -> User:
3942
username = username or f"{uuid.uuid4().hex}@example.com"
@@ -115,12 +118,14 @@ def new_project_user(self, user, project, role="Manager", status="Active"):
115118
)
116119
return pu
117120

118-
def new_allocation(self, project, resource, quantity) -> Allocation:
121+
def new_allocation(
122+
self, project, resource, quantity, status="Active"
123+
) -> Allocation:
119124
allocation, _ = Allocation.objects.get_or_create(
120125
project=project,
121126
justification="a justification for testing data",
122127
quantity=quantity,
123-
status=AllocationStatusChoice.objects.get(name="Active"),
128+
status=AllocationStatusChoice.objects.get(name=status),
124129
)
125130
allocation.resources.add(resource)
126131
return allocation

src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,23 @@ def test_ibm_storage_not_available(self):
483483
"persistentvolumeclaims": "2",
484484
},
485485
)
486+
487+
def test_needs_renewal_allocation(self):
488+
"""Simple test to validate allocations in `Active (Needs Renewal)` status."""
489+
user = self.new_user()
490+
project = self.new_project(pi=user)
491+
allocation = self.new_allocation(
492+
project, self.resource, 1, "Active (Needs Renewal)"
493+
)
494+
allocator = openshift.OpenShiftResourceAllocator(self.resource, allocation)
495+
496+
tasks.activate_allocation(allocation.pk)
497+
allocation.refresh_from_db()
498+
499+
user2 = self.new_user()
500+
self.new_allocation_user(allocation, user2)
501+
502+
project_id = allocation.get_attribute(attributes.ALLOCATION_PROJECT_ID)
503+
assert user2.username not in allocator.get_users(project_id)
504+
call_command("validate_allocations", apply=True)
505+
assert user2.username in allocator.get_users(project_id)

0 commit comments

Comments
 (0)