summaryrefslogtreecommitdiff
path: root/mason/tests/build.py
diff options
context:
space:
mode:
Diffstat (limited to 'mason/tests/build.py')
-rw-r--r--mason/tests/build.py71
1 files changed, 56 insertions, 15 deletions
diff --git a/mason/tests/build.py b/mason/tests/build.py
index d347eb9..de5a178 100644
--- a/mason/tests/build.py
+++ b/mason/tests/build.py
@@ -1,10 +1,25 @@
# 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
import logging
import morphlib
import os
+import subprocess
+import time
import urlparse
import mason
@@ -14,20 +29,26 @@ class Build(object):
"""A single build instance."""
- def __init__(self, name, controller):
+ def __init__(self, name, controller, logfile):
self.system_name = name
self.controller = controller
+ self.log_path = logfile
+ self.logfile = open(logfile, 'w+')
+ #TODO: use distbuild not local build
self.command = [
'morph', 'build', self.system_name]
def start(self):
- self.process = subprocess.Popen(self.command)
+ self.process = subprocess.Popen(self.command, stdout=self.logfile, stderr=self.logfile)
def completed(self):
return (self.process.poll() is not None)
+ def close_log(self):
+ self.logfile.close()
-class Runner(mason.util.JobRunner):
+
+class Runner(mason.runners.JobRunner):
"""This thread handles running the build-deploy-build test,
which is used to ensure that Baserock can build Baserock."""
@@ -37,24 +58,27 @@ class Runner(mason.util.JobRunner):
def __init__(self, worker_server, plugin_config, job_name):
super(Runner, self).__init__(worker_server, plugin_config, job_name)
- self.total_steps = 3
+ self.total_steps = 4
- def do_job_steps(self):
+ def run_job(self):
self.log.info('Step 1: Creating a workspace')
self._create_workspace()
- self.log.info('Step 2: Building the systems')
+ self.log.info('Step 2: Prepare build log directory')
+ self._prepare_build_log_dir()
+
+ self.log.info('Step 3: Building the systems')
self._build_systems()
- #TODO: provide logs
- self.log.info('Step 3: Clean up')
+ self.log.info('Step 4: Clean up')
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'])
+ def _do_git_config(self, name='Mason Test Runner', email='mason@runner'):
+ cliapp.runcmd(['git', 'config', '--global', 'user.name', name])
+ cliapp.runcmd(['git', 'config', '--global', 'user.email', email])
def _parse_controllers(self, conf):
+ print 'parsing controllers'
controllers = {}
for arch, addr in (item.split(':') for item in conf['controllers']):
controllers[arch] = addr
@@ -67,10 +91,14 @@ class Runner(mason.util.JobRunner):
builds = []
for system_name in systems:
system = self.morph_helper.load_morphology(system_name)
+ print 'loaded %s' % system_name
if system['arch'] in controllers:
- builds.append(Build(system_name, controllers['arch']))
+ logfile = os.path.join(self.logdir, '%s.log' % system['name'])
+ builds.append(Build(system_name, controllers[system['arch']], logfile))
+ print 'prepared builds'
return builds
+ @mason.util.job_step
def _create_workspace(self):
self.commit = self.job_arguments['ZUUL_COMMIT']
self.project = self.job_arguments['ZUUL_PROJECT']
@@ -84,7 +112,6 @@ class Runner(mason.util.JobRunner):
url.hostname,
'8080',
self.project)
- self.morph_helper = mason.util.MorphologyHelper(self.defs_checkout)
self._do_git_config()
cliapp.runcmd(['morph', 'init', self.workspace])
@@ -92,7 +119,16 @@ class Runner(mason.util.JobRunner):
repo = 'http://%s:8080/%s' % (url.hostname, self.project)
cliapp.runcmd(['morph', 'checkout', repo, self.commit],
cwd=self.workspace)
+ self.morph_helper = mason.util.MorphologyHelper(self.defs_checkout)
+
+ @mason.util.job_step
+ def _prepare_build_log_dir(self):
+ self.logdir = '/var/www/logs/%s-%s/build' % \
+ (self.project, self.commit[:7])
+ if not os.path.exists(self.logdir):
+ os.makedirs(self.logdir)
+ @mason.util.job_step
def _build_systems(self):
builds = self._prepare_builds(self.plugin_config['config'])
os.chdir(self.defs_checkout)
@@ -104,12 +140,17 @@ class Runner(mason.util.JobRunner):
fail = False
for build in builds:
+ build.close_log()
if build.process.returncode != 0:
fail = True
- sys.stderr.write(
- 'Building failed for %s\n' % build.system_name)
+ logging.error('Building failed for %s. Log is at %s.' %
+ (build.system_name, build.log_path))
if fail:
raise cliapp.AppException('Building of systems failed.')
+ @mason.util.job_step
def _clean_up(self):
+ os.chdir('/root')
+ #TODO: don't do this in production
+ self._do_git_config(name='Adam Coldrick', email='adam.coldrick@codethink.co.uk')
cliapp.runcmd(['rm', '-rf', self.workspace])