summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Hesketh <josh@nitrotech.org>2014-01-22 16:09:58 +1100
committerJoshua Hesketh <josh@nitrotech.org>2014-01-22 16:10:30 +1100
commit221ae7442ad077105f4f028ba5b2fb47c409ad9b (patch)
treec5211a9f90df63324a7cfbc543cb9e8bef9015ff
parent6055f3187c989a1d4c46a9400084a3347f38c847 (diff)
downloadturbo-hipster-221ae7442ad077105f4f028ba5b2fb47c409ad9b.tar.gz
Follow zuul's instructions to upload via swift
Change-Id: Ib6a5b0701f53d2edef8bc617dbc5a2812d5bb056
-rw-r--r--requirements.txt2
-rw-r--r--turbo_hipster/lib/models.py17
-rw-r--r--turbo_hipster/lib/utils.py39
3 files changed, 53 insertions, 5 deletions
diff --git a/requirements.txt b/requirements.txt
index 70b81b9..f1d17dc 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,3 +11,5 @@ sphinxcontrib-programoutput
sphinxcontrib-seqdiag
mysql-python
+
+requests
diff --git a/turbo_hipster/lib/models.py b/turbo_hipster/lib/models.py
index 59ed786..d4da8e0 100644
--- a/turbo_hipster/lib/models.py
+++ b/turbo_hipster/lib/models.py
@@ -218,9 +218,16 @@ class ShellTask(Task):
def _handle_results(self):
"""Upload the contents of the working dir either using the instructions
provided by zuul and/or our configuration"""
+
self.log.debug("Process the resulting files (upload/push)")
- index_url = utils.push_file(self.results_set_name,
- self.job_working_dir,
- self.global_config['publish_logs'])
- self.log.debug("Index URL found at %s" % index_url)
- self.work_data['url'] = index_url
+
+ if 'publish_logs' in self.global_config:
+ index_url = utils.push_file(self.results_set_name,
+ self.job_working_dir,
+ self.global_config['publish_logs'])
+ self.log.debug("Index URL found at %s" % index_url)
+ self.work_data['url'] = index_url
+
+ if 'ZUUL_EXTRA_SWIFT_URL' in self.job_arguments:
+ # Upload to zuul's url as instructed
+ utils.zuul_swift_upload(self.job_working_dir, self.job_arguments)
diff --git a/turbo_hipster/lib/utils.py b/turbo_hipster/lib/utils.py
index 3bc2505..85e2183 100644
--- a/turbo_hipster/lib/utils.py
+++ b/turbo_hipster/lib/utils.py
@@ -16,6 +16,7 @@
import git
import logging
import os
+import requests
import select
import shutil
import subprocess
@@ -267,3 +268,41 @@ def determine_job_identifier(zuul_arguments, job, unique):
log.info('Converted args: %s, job: %s and unique: %s to %s'
% (zuul_arguments, job, unique, path))
return path
+
+
+def zuul_swift_upload(file_path, job_arguments):
+ """Upload working_dir to swift as per zuul's instructions"""
+ # NOTE(jhesketh): Zuul specifies an object prefix in the destination so
+ # we don't need to be concerned with results_set_name
+
+ file_list = []
+ if os.path.isfile(file_path):
+ file_list.append(file_path)
+ elif os.path.isdir(file_path):
+ for path, folders, files in os.walk(file_path):
+ for f in files:
+ f_path = os.path.join(path, f)
+ file_list.append(f_path)
+
+ # We are uploading the file_list as an HTTP POST multipart encoded.
+ # First grab out the information we need to send back from the hmac_body
+ payload = {}
+ (object_prefix,
+ payload['redirect'],
+ payload['max_file_size'],
+ payload['max_file_count'],
+ payload['expires']) = \
+ job_arguments['ZUUL_EXTRA_SWIFT_HMAC_BODY'].split('\n')
+
+ url = job_arguments['ZUUL_EXTRA_SWIFT_URL']
+ payload['signature'] = job_arguments['ZUUL_EXTRA_SWIFT_SIGNATURE']
+ logserver_prefix = job_arguments['ZUUL_EXTRA_SWIFT_LOGSERVER_PREFIX']
+
+ files = {}
+ for i, f in enumerate(file_list):
+ files['file%d' % (i + 1)] = open(f, 'rb')
+
+ requests.post(url, data=payload, files=files)
+
+ return (logserver_prefix +
+ job_arguments['ZUUL_EXTRA_SWIFT_DESTINATION_PREFIX'])