4
# Copyright (C) 2015 Canonical
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.
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.
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/>.
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 && \
36
SERVICE_NAME = 'core-image-builder'
37
VENV_DIR = 'venv-{}'.format(SERVICE_NAME)
38
PIP_DIR = 'pip-cache-'.format(SERVICE_NAME)
39
PIP_CACHE_BRANCH = 'lp:~canonical-ci-engineering/{}/' \
40
'pip-cache'.format(SERVICE_NAME)
43
def _run_command(cmd):
44
'''Run the command and return the return code or 0 on success.'''
46
print('INFO: Executing: {}'.format(' '.join(cmd)))
48
subprocess.check_call(cmd, stderr=subprocess.STDOUT)
49
except subprocess.CalledProcessError as e:
50
print('ERROR: Calling `{}` failed (with code {})'.format(
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')
74
os.path.join(ve_dir, 'bin', 'pip'),
77
'--find-links={}'.format(pip_cache),
82
os.path.join(ve_dir, 'bin', 'pip'),
85
'test_requirements.txt',
88
os.path.join(ve_dir, 'bin', 'python3'),
93
os.path.join(ve_dir, 'bin', 'python3'),
99
ret = _run_command(cmd)
101
# A cmd failed, bubble up the return code to the caller
106
if __name__ == '__main__':