summaryrefslogtreecommitdiff
path: root/mason/tests/artifact_upload.py
diff options
context:
space:
mode:
Diffstat (limited to 'mason/tests/artifact_upload.py')
-rw-r--r--mason/tests/artifact_upload.py152
1 files changed, 82 insertions, 70 deletions
diff --git a/mason/tests/artifact_upload.py b/mason/tests/artifact_upload.py
index 21d1093..aa6c56f 100644
--- a/mason/tests/artifact_upload.py
+++ b/mason/tests/artifact_upload.py
@@ -1,4 +1,17 @@
# Copyright 2014 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 cliapp
import json
@@ -6,76 +19,80 @@ import logging
import os
import urlparse
-from turbo_hipster.lib import common
-from turbo_hipster.lib import models
+import mason
-
-#TODO: Less different instances of this would be nice
-class MorphologyHelper(object):
-
- def __init__(self, path):
- self.defs_repo = morphlib.gitdir.GitDirectory(path)
- self.loader = morphlib.morphloader.MorphologyLoader()
- self.finder = morphlib.morphologyfinder.MorphologyFinder(self.defs_repo)
-
- def load_morphology(self, path):
- text = self.finder.read_morphology(path)
- return self.loader.load_from_string(text)
-
- @classmethod
- def iterate_systems(cls, systems_list):
- for system in systems_list:
- yield morphlib.util.sanitise_morphology_path(system['morph'])
- if 'subsystems' in system:
- for subsystem in cls.iterate_systems(system['subsystems']):
- yield subsystem
-
- def iterate_cluster_deployments(cls, cluster_morph):
- for system in cluster_morph['systems']:
- path = morphlib.util.sanitise_morphology_path(system['morph'])
- defaults = system.get('deploy-defaults', {})
- for name, options in system['deploy'].iteritems():
- config = dict(defaults)
- config.update(options)
- yield path, name, config
-
- def load_cluster_systems(self, cluster_morph):
- for system_path in set(self.iterate_systems(cluster_morph['systems'])):
- system_morph = self.load_morphology(system_path)
- yield system_path, system_morph
-
-
-#TODO: Deployment
-
-
-class Runner(models.Task):
+class Runner(mason.runners.JobRunner):
"""This thread handles running the build-deploy-build test,
which is used to ensure that Baserock can build Baserock."""
- log = logging.getLogger("task_plugins.build_deploy_test.task.Runner")
+ 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.total_steps = 5
- print self.job_arguments
-
- def do_job_steps(self):
+ 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: Creating a workspace')
self._create_workspace()
- self.log.info('Step 2: Deploy and test the systems')
- self._deploy_and_test_systems()
+ if self.config['upload-build-artifacts']:
+ self.log.info('Step 2: Publish the build artifacts')
+ self._publish_build_artifacts()
- self.log.info('Step 3: Clean up')
+ if self.config['upload-release-artifacts']:
+ self.log.info('Step %d: Publish the release artifacts' %
+ (self.current_step + 1))
+ self._publish_release_artifacts()
+
+ self.log.info('Step %d: Clean up' % (self.current_step + 1))
self._clean_up()
def _do_git_config(self):
cliapp.runcmd(['git', 'config', 'user.name', 'Mason Test Runner'])
cliapp.runcmd(['git', 'config', 'user.email', 'mason@test.runner'])
- @common.task_step
+ @mason.util.job_step
def _create_workspace(self):
self.commit = self.job_arguments['ZUUL_COMMIT']
self.project = self.job_arguments['ZUUL_PROJECT']
@@ -89,6 +106,7 @@ class Runner(models.Task):
url.hostname,
'8080',
self.project)
+ self.morph_helper = mason.util.MorphologyHelper(self.defs_checkout)
self._do_git_config()
cliapp.runcmd(['morph', 'init', self.workspace])
@@ -96,23 +114,17 @@ class Runner(models.Task):
repo = 'http://%s:8080/%s' % (url.hostname, self.project)
cliapp.runcmd(['morph', 'checkout', repo, self.commit], cwd=self.workspace)
- @common.task_step
- def _test_systems(self):
- infrastructure = \
- self.plugin_config['config']['test-infrastructure-type']
- cmd = ['scripts/release-test']
- args = ['--deployment-host',
- self.plugin_config['config']['deployment-host'],
- '--trove-host', self.plugin_config['config']['trove-host'],
- '--trove-id', self.plugin_config['config']['trove-id'],
- '--test-ref', self.commit
- ]
- if infrastructure == 'openstack':
- cmd = ['/usr/lib/mason/mason-test-os']
- args += ['--net-id',
- self.plugin_config['config']['openstack-network-id']]
- args += [self.plugin_config['config']['cluster-morphology']]
-
- @common.task_step
+ @mason.util.job_step
+ def _publish_build_artifacts(self):
+ publisher = mason.publishers.BuildArtifactPublisher(
+ self.config, self.defs_repo)
+ publisher.publish_build_artifacts()
+
+ @mason.util.job_step
+ def _publish_release_artifacts(self):
+ publisher = mason.publishers.ReleaseArtifactPublisher(self.config)
+ publisher.publish_release_artifacts()
+
+ @mason.util.job_step
def _clean_up(self):
cliapp.runcmd(['rm', '-rf', self.workspace])