@@ -201,6 +201,21 @@ def get_context_data(self, **kwargs):
201201 attributes = list (alloc_attr_set )
202202
203203 allocation_changes = allocation_obj .allocationchangerequest_set .all ().order_by ('-pk' )
204+ allocation_changes = list (allocation_changes )
205+ approved_status = AllocationChangeStatusChoice .objects .get (name = 'Approved' )
206+ approved_by_lookup = {}
207+ if allocation_changes :
208+ change_request_ids = [change .pk for change in allocation_changes ]
209+ history_model = AllocationChangeRequest .history .model
210+ approved_histories = history_model .objects .filter (
211+ id__in = change_request_ids ,
212+ status = approved_status ,
213+ ).exclude (history_user__isnull = True ).order_by ('id' , '-history_date' )
214+ for history_entry in approved_histories :
215+ if history_entry .id not in approved_by_lookup :
216+ approved_by_lookup [history_entry .id ] = history_entry .history_user
217+ for allocation_change in allocation_changes :
218+ allocation_change .approved_by = approved_by_lookup .get (allocation_change .pk )
204219
205220 guage_data = []
206221 invalid_attributes = []
@@ -411,7 +426,7 @@ def post(self, request, *args, **kwargs):
411426 return HttpResponseRedirect (reverse ('allocation-detail' , kwargs = {'pk' : pk }))
412427 logger .info (
413428 "Auto-created allocation during approval. "
414- "requesting_user=%s, allocation_pk=%s, project=%s, size=%s" ,
429+ "requesting_user=%s allocation_pk=%s project=%s size=%s" ,
415430 request .user , allocation_obj .pk , allocation_obj .project .title , allocation_obj .size ,
416431 extra = {'category' : 'integration' , 'status' : 'success' },
417432 )
@@ -1003,7 +1018,7 @@ def post(self, request, *args, **kwargs):
10031018 )
10041019 logger .info (
10051020 'added user to slurm account. '
1006- 'requesting_user=%s, user=%s, account=%s, cluster=%s' ,
1021+ 'requesting_user=%s user=%s account=%s cluster=%s' ,
10071022 requester_uname , username , allocation_obj .project .title , cluster ,
10081023 extra = {
10091024 'username' : username ,
@@ -1032,7 +1047,8 @@ def post(self, request, *args, **kwargs):
10321047 )
10331048 except Exception as e :
10341049 logger .exception (
1035- "signal processes for allocationuser activation failed. allocationuser_pk=%s,project_title=%s,resource_name=%s,error=%s" ,
1050+ "signal processes for allocationuser activation failed. "
1051+ "allocationuser_pk=%s project_title=%s resource_name=%s error=%s" ,
10361052 allocation_user_obj .pk , allocation_obj .project .title ,
10371053 allocation_obj .get_parent_resource .name , e
10381054 )
@@ -1142,7 +1158,10 @@ def post(self, request, *args, **kwargs):
11421158 raw_share = form_data ['value' ]
11431159 )
11441160 except Exception as e :
1145- logger .exception (f'error encountered while trying to update allocationuser { allocation_obj } :{ allocationuser_obj } rawshare: { e } ' )
1161+ logger .exception (
1162+ 'allocationuser rawshare update failed. user=%s allocation_pk=%s error=%s' ,
1163+ allocationuser_obj .user .username , allocation_obj .pk , e
1164+ )
11461165 messages .error (request , f'error encountered while trying to update allocationuser { allocation_obj } :{ allocationuser_obj } rawshare: { e } ' )
11471166 return HttpResponseRedirect (
11481167 reverse ('allocation-edit-user' , kwargs = self .kwargs )
@@ -1266,15 +1285,15 @@ def post(self, request, *args, **kwargs):
12661285 error_message = f"You can't remove this AllocationUser ({ user_form_data .get ('username' )} ) while they are running a job using this account. Try again after the job has been completed or cancelled."
12671286 logger .exception (
12681287 'could not remove user from slurm account. '
1269- 'requesting_user=%s, username=%s, error=%s' ,
1288+ 'requesting_user=%s username=%s error=%s' ,
12701289 requester_uname , user_form_data .get ('username' ), e ,
12711290 extra = {'category' : 'integration:slurmrest' , 'status' : 'failure' })
12721291 messages .error (request , error_message )
12731292 except Exception as e :
12741293 error_message = f"An error occurred while trying to remove AllocationUser ({ user_form_data .get ('username' )} ): { e } "
12751294 logger .exception (
12761295 'could not remove user from slurm account. '
1277- 'requesting_user=%s, username=%s, error=%s' ,
1296+ 'requesting_user=%s username=%s error=%s' ,
12781297 requester_uname , user_form_data .get ('username' ), e ,
12791298 extra = {'category' : 'integration:slurmrest' , 'status' : 'failure' }
12801299 )
@@ -1284,8 +1303,9 @@ def post(self, request, *args, **kwargs):
12841303 msg = f'Removed { remove_users_count } { user_plural } from allocation.'
12851304 messages .success (request , msg )
12861305 logger .info (
1287- "Removed %s %s from allocation %s" ,
1288- remove_users_count , user_plural , allocation_obj .pk
1306+ "Removed allocationusers. user_count=%s allocation_pk=%s project=%s resource=%s" ,
1307+ remove_users_count , allocation_obj .pk , allocation_obj .project .title ,
1308+ allocation_obj .get_parent_resource .name
12891309 )
12901310 else :
12911311 for error in formset .errors :
@@ -1585,7 +1605,8 @@ def post(self, request, *args, **kwargs):
15851605 cluster = allocation .get_parent_resource .get_attribute ('slurm_cluster' )
15861606 try :
15871607 logger .info (
1588- "Triggered update of Slurm user %s rawshare from %s to %s via account %s on cluster %s" ,
1608+ "Triggered update of Slurm user rawshare. target_user=%s "
1609+ "old_rawshare=%s new_rawshare=%s account=%s cluster=%s" ,
15891610 username , allocuser_current_rawshare_val ,
15901611 allocuser_new_rawshare_val , account , cluster
15911612 )
@@ -2478,7 +2499,7 @@ def post(self, request, *args, **kwargs):
24782499 except Exception as e :
24792500 logger .exception (
24802501 'Auto-update of allocation quota failed. '
2481- 'requesting_user=%s, allocation_pk=%s, change_request_pk=%s, error=%s' ,
2502+ 'requesting_user=%s allocation_pk=%s change_request_pk=%s error=%s' ,
24822503 request .user , alloc_change_obj .allocation .pk ,
24832504 alloc_change_obj .pk , str (e ),
24842505 extra = {'category' : 'integration' , 'status' : 'error' }
0 commit comments