From 0e23325a12651756faf5b99dda308a93788bd9db Mon Sep 17 00:00:00 2001 From: Clark Boylan <clark.boylan@gmail.com> Date: Mon, 6 Jan 2020 13:37:18 -0800 Subject: [PATCH] Swift upload logs without encoding type for gzip files When retrieving gzipped files out of swift with gzip encoding set some swift implementations return a decompressed version of the file if your client cannot accept gzip encoding. This causes problems when the file you want is actually compressed like a .tar.gz. Instead we avoid setting the encoding type of these files forcing swift to give them back as is. This change should only be approved after confirming its parent is tested and working. Change-Id: Ibcf478b572ba84273732e0ede17bf92bddd8c36f --- roles/upload-logs-swift/library/zuul_swift_upload.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/roles/upload-logs-swift/library/zuul_swift_upload.py b/roles/upload-logs-swift/library/zuul_swift_upload.py index fa7a70fb0..485f4fa47 100755 --- a/roles/upload-logs-swift/library/zuul_swift_upload.py +++ b/roles/upload-logs-swift/library/zuul_swift_upload.py @@ -746,7 +746,14 @@ class Uploader(): headers['content-encoding'] = 'gzip' data = GzipFilter(open(file_detail.full_path, 'rb')) else: - if file_detail.encoding: + if (not file_detail.filename.endswith(".gz") and + file_detail.encoding): + # Don't apply gzip encoding to files that we receive as + # already gzipped. The reason for this is swift will + # serve this back to users as an uncompressed file if they + # don't set an accept-encoding that includes gzip. This + # can cause problems when the desired file state is + # compressed as with .tar.gz tarballs. headers['content-encoding'] = file_detail.encoding data = open(file_detail.full_path, 'rb') else: