Merge lp:~fginther/adt-result-checker/add-called-by-tarmac into lp:adt-result-checker

Proposed by Francis Ginther
Status: Merged
Approved by: Francis Ginther
Approved revision: 6
Merged at revision: 7
Proposed branch: lp:~fginther/adt-result-checker/add-called-by-tarmac
Merge into: lp:adt-result-checker
Diff against target: 106 lines (+102/-0)
1 file modified
called-by-tarmac.py (+102/-0)
To merge this branch: bzr merge lp:~fginther/adt-result-checker/add-called-by-tarmac
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+253462@code.launchpad.net

Commit message

Add called-by-tarmac.py for automatic execution of unit tests by tarmac.

Description of the change

Add called-by-tarmac.py for automatic execution of unit tests by tarmac.

Copied from lp:adt-cloud-service.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

Not much for it to do right now since there are no tests, but will still be useful in the future. +1

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

tarmac config has been updated, ready to land this.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'called-by-tarmac.py'
--- called-by-tarmac.py 1970-01-01 00:00:00 +0000
+++ called-by-tarmac.py 2015-03-19 03:54:49 +0000
@@ -0,0 +1,102 @@
1#!/usr/bin/env python3
2#
3# adt-result-checker
4# Copyright (C) 2015 Canonical
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19# called-by-tarmac.py is intended to be called by the tarmac merge engine
20# to perform automatic unit testing on branch landing.
21# It replaces the manual commands:
22# bzr branch $PIP_CACHE_BRANCH pip_cache
23# virtualenv -p python3 ve && \
24# ./ve/bin/pip install --no-index --find-links=pip-cache \
25# -r requirements.txt && \
26# ./ve/bin/pip install -r test_requirements.txt && \
27# ./ve/bin/python3 setup.py test && \
28# rm -rf ve
29#
30
31import os
32import subprocess
33import sys
34import tempfile
35
36SERVICE_NAME = 'adt-result-checker'
37VENV_DIR = 'venv-{}'.format(SERVICE_NAME)
38PIP_DIR = 'pip-cache-'.format(SERVICE_NAME)
39PIP_CACHE_BRANCH = 'lp:~canonical-ci-engineering/{}/' \
40 'pip-cache'.format(SERVICE_NAME)
41
42
43def _run_command(cmd):
44 '''Run the command and return the return code or 0 on success.'''
45
46 print('INFO: Executing: {}'.format(' '.join(cmd)))
47 try:
48 subprocess.check_call(cmd, stderr=subprocess.STDOUT)
49 except subprocess.CalledProcessError as e:
50 print('ERROR: Calling `{}` failed (with code {})'.format(
51 e.cmd, e.returncode))
52 return e.returncode
53 return 0
54
55
56def main():
57 with tempfile.TemporaryDirectory(PIP_DIR) as pip_dir, \
58 tempfile.TemporaryDirectory(prefix=VENV_DIR) as ve_dir:
59 pip_cache = os.path.join(pip_dir, 'cache')
60 all_cmds = (
61 [
62 'bzr',
63 'branch',
64 PIP_CACHE_BRANCH,
65 pip_cache,
66 ],
67 [
68 'virtualenv',
69 '-p',
70 'python3',
71 ve_dir,
72 ],
73 [
74 os.path.join(ve_dir, 'bin', 'pip'),
75 'install',
76 '--no-index',
77 '--find-links={}'.format(pip_cache),
78 '-r',
79 'requirements.txt',
80 ],
81 [
82 os.path.join(ve_dir, 'bin', 'pip'),
83 'install',
84 '-r',
85 'test_requirements.txt',
86 ],
87 [
88 os.path.join(ve_dir, 'bin', 'python3'),
89 'setup.py',
90 'test',
91 ],
92 )
93 for cmd in all_cmds:
94 ret = _run_command(cmd)
95 if ret:
96 # A cmd failed, bubble up the return code to the caller
97 return ret
98 return 0
99
100
101if __name__ == '__main__':
102 sys.exit(main())

Subscribers

People subscribed via source and target branches