From 1ab9ca3ed98fa0b51258efba44bbbe0cf905baf4 Mon Sep 17 00:00:00 2001
From: Benjamin Schanzel <benjamin.schanzel@bmw.de>
Date: Wed, 30 Jun 2021 10:11:49 +0200
Subject: [PATCH] Fix a bug in s3 log uploader with .gz files

When trying to upload .gz files, we do not set the ContentEncoding
argument to upload_fileobj but leave it as None. The upload then fails
because NoneType is not allowed. Therefore, leave out this parameter,
and also the ContentType parameter, from the extra args completely if
they are not set.

Change-Id: I601944ac83d5e823aa4dcfd0db880a38474288af
---
 roles/upload-logs-base/library/zuul_s3_upload.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/roles/upload-logs-base/library/zuul_s3_upload.py b/roles/upload-logs-base/library/zuul_s3_upload.py
index 6a8d7964c..8d2bc4278 100755
--- a/roles/upload-logs-base/library/zuul_s3_upload.py
+++ b/roles/upload-logs-base/library/zuul_s3_upload.py
@@ -169,10 +169,11 @@ class Uploader():
                     content_encoding = file_detail.encoding
                 data = open(file_detail.full_path, 'rb')
 
-            extra_args = dict(
-                ContentType=file_detail.mimetype,
-                ContentEncoding=content_encoding
-            )
+            extra_args = {}
+            if file_detail.mimetype:
+                extra_args['ContentType'] = file_detail.mimetype
+            if content_encoding:
+                extra_args['ContentEncoding'] = content_encoding
             if self.public:
                 extra_args['ACL'] = 'public-read'