@@ -52,6 +52,16 @@ def sync_users(project_id, allocation, allocator, apply):
52
52
53
53
return failed_validation
54
54
55
+ @staticmethod
56
+ def set_default_quota_on_allocation (allocation , allocator , coldfront_attr ):
57
+ uqm = tasks .UNIT_QUOTA_MULTIPLIERS [allocator .resource_type ]
58
+ value = allocation .quantity * uqm .get (coldfront_attr , 0 )
59
+ value += tasks .STATIC_QUOTA [allocator .resource_type ].get (coldfront_attr , 0 )
60
+ utils .set_attribute_on_allocation (
61
+ allocation , coldfront_attr , value
62
+ )
63
+ return value
64
+
55
65
def check_institution_specific_code (self , allocation , apply ):
56
66
attr = attributes .ALLOCATION_INSTITUTION_SPECIFIC_CODE
57
67
isc = allocation .get_attribute (attr )
@@ -249,19 +259,37 @@ def handle(self, *args, **options):
249
259
)
250
260
msg = f"{ msg } Attribute set to match current quota."
251
261
logger .warning (msg )
252
- elif not (current_value == expected_value ):
253
- msg = (
254
- f"Value for quota for { attr } = { current_value } does not match expected"
255
- f" value of { expected_value } on allocation { allocation_str } "
256
- )
257
- logger .warning (msg )
262
+ else :
263
+ # We just checked the case where the quota value is set in the cluster
264
+ # but not in coldfront. This is the only case the cluster value is the
265
+ # "source of truth" for the quota value
266
+ # If the coldfront value is set, it is always the source of truth.
267
+ # But first, we need to check if the quota value is set anywhere at all.
268
+ # TODO (Quan): Refactor these if statements so that we can remove this comment block
269
+ if current_value is None and expected_value is None :
270
+ msg = (
271
+ f"Value for quota for { attr } is not set anywhere"
272
+ f" on allocation { allocation_str } "
273
+ )
274
+ logger .warning (msg )
258
275
259
- if options ["apply" ]:
260
- try :
261
- allocator .set_quota (project_id )
262
- logger .warning (
263
- f"Quota for allocation { project_id } was out of date. Reapplied!"
264
- )
265
- except Exception as e :
266
- logger .error (f'setting openshift quota failed: { e } ' )
267
- continue
276
+ if options ["apply" ]:
277
+ expected_value = self .set_default_quota_on_allocation (allocation , allocator , attr )
278
+ logger .warning (f"Added default quota for { attr } to allocation { allocation_str } to { expected_value } " )
279
+
280
+ if not (current_value == expected_value ):
281
+ msg = (
282
+ f"Value for quota for { attr } = { current_value } does not match expected"
283
+ f" value of { expected_value } on allocation { allocation_str } "
284
+ )
285
+ logger .warning (msg )
286
+
287
+ if options ["apply" ]:
288
+ try :
289
+ allocator .set_quota (project_id )
290
+ logger .warning (
291
+ f"Quota for allocation { project_id } was out of date. Reapplied!"
292
+ )
293
+ except Exception as e :
294
+ logger .error (f'setting openshift quota failed: { e } ' )
295
+ continue
0 commit comments