diff options
Diffstat (limited to 'mason/tests/artifact_upload.py')
-rw-r--r-- | mason/tests/artifact_upload.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/mason/tests/artifact_upload.py b/mason/tests/artifact_upload.py new file mode 100644 index 0000000..1167167 --- /dev/null +++ b/mason/tests/artifact_upload.py @@ -0,0 +1,112 @@ +# Copyright 2014-2015 Codethink Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import json +import logging +import os +import urlparse + +import cliapp + +import mason + +class Runner(mason.runners.JobRunner): + + """Uploads the artifacts produced during a build + + This handles running the build-deploy-build test, which + is used to ensure that Baserock can build Baserock. + """ + + log = logging.getLogger("mason.tests.artifact_upload.Runner") + + def __init__(self, worker_server, plugin_config, job_name): + super(Runner, self).__init__(worker_server, plugin_config, job_name) + self.config = self.plugin_config['config'] + self._set_defaults() + + self.total_steps = 2 + if self.config['upload-build-artifacts']: + self.total_steps += 1 + if self.config['upload-release-artifacts']: + self.total_steps += 1 + + def _set_defaults(self): + self.config['public-trove-host'] = \ + self.config.get('public-trove-host') or 'git.baserock.org' + self.config['public-trove-username'] = \ + self.config.get('public-trove-username') or 'root' + self.config['public-trove-artifact-dir'] = \ + self.config.get('public-trove-artifact-dir') \ + or '/home/cache/artifacts' + + self.config['download-server-address'] = \ + self.config.get('download-server-address') \ + or 'download.baserock.org' + self.config['download-server-username'] = \ + self.config.get('download-server-username') or 'root' + self.config['download-server-private-dir'] = \ + self.config.get('download-server-private-dir') \ + or '/srv/download.baserock.org/baserock/.publish-temp' + self.config['download-server-public-dir'] = \ + self.config.get('download-server-public-dir') \ + or '/srv/download.baserock.org/baserock' + + self.config['release-artifact-dir'] = \ + self.config.get('release-artifact-dir') or '.' + self.config['local-build-artifacts-dir'] = \ + self.config.get('local-build-artifacts-dir') or 'build-artifacts' + self.config['architecture'] = \ + self.config.get('architecture') or [] + + if 'upload-release-artifacts' not in self.config: + self.config['upload-release-artifacts'] = True + if 'upload-build-artifacts' not in self.config: + self.config['upload-build-artifacts'] = True + + def run_job(self): + self.log.info('Step 1 of %d: Creating a workspace' % + (self.total_steps)) + self._create_workspace() + + try: + if self.config['upload-build-artifacts']: + self.log.info('Step 2 of %d: Publish the build artifacts' % + (self.total_steps)) + self._publish_build_artifacts() + + if self.config['upload-release-artifacts']: + self.log.info('Step %d of %d: Publish the release artifacts' % + (self.current_step + 1, self.total_steps)) + self._publish_release_artifacts() + except Exception as e: + self.log.info('Exception: %s' % (e)) + self._remove_workspace() + raise e + + self.log.info('Step %d of %d: Clean up' % + (self.current_step + 1, self.total_steps)) + self._clean_up() + + @mason.util.job_step + def _publish_build_artifacts(self): + publisher = mason.publishers.BuildArtifactPublisher( + self.config, self.defs_checkout) + publisher.publish_build_artifacts() + + @mason.util.job_step + def _publish_release_artifacts(self): + publisher = mason.publishers.ReleaseArtifactPublisher(self.config) + publisher.publish_release_artifacts() |