Merge lp:~pwlars/core-selftest-agent/core-selftest-agent-3 into lp:core-selftest-agent

Proposed by Paul Larson
Status: Merged
Merged at revision: 4
Proposed branch: lp:~pwlars/core-selftest-agent/core-selftest-agent-3
Merge into: lp:core-selftest-agent
Prerequisite: lp:~pwlars/core-selftest-agent/core-selftest-agent-2
Diff against target: 132 lines (+113/-0)
3 files modified
called-by-tarmac.py (+109/-0)
core_selftest_agent/__init__.py (+1/-0)
test_requirements.txt (+3/-0)
To merge this branch: bzr merge lp:~pwlars/core-selftest-agent/core-selftest-agent-3
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+259658@code.launchpad.net

Commit message

Add tarmac support

Description of the change

Add tarmac support

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM, but I think you'll regret adding pylint support. Then again, it's your service to do with as you will :D

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches