3
# Copyright 2014 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU Affero General Public License version 3, as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU Affero General Public License for more details.
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
from ci_utils import (
22
from tstrun import testbed
25
class TestRunnerWorker(amqp_worker.AMQPWorker):
28
super(TestRunnerWorker, self).__init__('test_runner')
29
self.data_store = None
31
def save_subunit(self, log, package, stream, retval):
32
# make this exception-safe since we can already report pass/fail
33
# with or without this file
35
log.info('saving subunit results for {}'.format(package))
36
name = 'test-runner.{}-subunit-stream'.format(package)
37
url = self.data_store.put_file(name, stream, 'text/plain')
38
retval.setdefault('artifacts', []).append({
45
'unable to upload subunit result for {}'.format(package))
47
def save_testbed_console(self, log, test_bed, retval):
48
# make this exception-safe since we can already report pass/fail
49
# with or without this file
51
log.info('saving testbed console}')
52
name = 'test-runner.testbed-cloud-init.log'
53
console = test_bed.get_cloud_init_console()
54
url = self.data_store.put_file(name, console, 'text/plain')
55
retval.setdefault('artifacts', []).append({
61
log.exception('unable to upload testbed console')
63
def handle_request(self, log, params):
64
progress_queue = params['progress_trigger']
65
image_id = params['image_id']
66
package_list = params['package_list']
70
amqp_utils.progress_update(progress_queue, {'message': msg})
72
self.data_store = self._create_data_store(params['ticket_id'])
73
# The tests will succeed unless they fail ;)
74
notify = amqp_utils.progress_completed
77
flavors = tstrun.get_auth_config()['tr_flavors']
79
test_bed = testbed.TestBed('testbed-{}'.format(progress_queue),
80
flavors, image_id, status_cb)
82
for package in package_list:
83
if params.get('cancelled'):
84
log.error('request has been cancelled, exiting')
85
return amqp_utils.progress_failed, results
86
status_cb('testing %s' % package)
87
# uci-vms shell adt-run ... --- adt-virt-null
88
return_code, subunit_stream = test_bed.run_test(package)
89
# 0 is success, 8 is skipped and considered a success
90
if return_code not in (0, 8):
91
# At least one test failed
92
notify = amqp_utils.progress_failed
93
self.save_subunit(log, package, subunit_stream, results)
94
return notify, results
97
self.save_testbed_console(log, test_bed, results)
101
if __name__ == '__main__':
102
TestRunnerWorker().main(tstrun.internal_rabbit_queue)