From d9196acd269b91fae14e9fffcc49425c4908aedc Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Tue, 31 Jul 2018 09:22:07 +0100 Subject: LAVA-1397 - fix crash in callback data Fix logical error for test jobs which have not started and therefore have no job.output_dir into which to try to write the job_data.gz Change-Id: I8552a5a9ec7e18e41b10a80573ec69f825fad67a --- lava_scheduler_app/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lava_scheduler_app/models.py b/lava_scheduler_app/models.py index 9070f9508..f1f587f2b 100644 --- a/lava_scheduler_app/models.py +++ b/lava_scheduler_app/models.py @@ -2310,9 +2310,13 @@ class NotificationCallback(models.Model): token=self.token, output=output, results=results) # store callback_data for later retrieval & triage job_data_file = os.path.join(self.notification.test_job.output_dir, 'job_data.gz') - if callback_data and not os.path.exists(job_data_file): - with gzip.open(job_data_file, 'wb') as output: - output.write(simplejson.dumps(callback_data).encode('utf-8')) + if callback_data: + # allow for jobs cancelled in submitted state + utils.mkdir(self.notification.test_job.output_dir) + # only write the file once + if not os.path.exists(job_data_file): + with gzip.open(job_data_file, 'wb') as output: + output.write(simplejson.dumps(callback_data).encode('utf-8')) headers = {} if callback_data: -- cgit v1.2.3