Merge lp:~vila/ubuntu-ci-services-itself/1292461-testbed-console-acquisition into lp:ubuntu-ci-services-itself

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 390
Merged at revision: 391
Proposed branch: lp:~vila/ubuntu-ci-services-itself/1292461-testbed-console-acquisition
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 132 lines (+43/-20)
2 files modified
test_runner/tstrun/run_worker.py (+40/-18)
test_runner/tstrun/testbed.py (+3/-2)
To merge this branch: bzr merge lp:~vila/ubuntu-ci-services-itself/1292461-testbed-console-acquisition
Reviewer Review Type Date Requested Status
Andy Doan (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+211088@code.launchpad.net

Commit message

Better error handling when setting up the test bed.

Description of the change

This refactors the message handling for the test runner to better isolate the
failures during the testbed setup.

More details in the bug comment.

While I was there I added some more progress reports so we get a better idea
on how the time is spent during the request handling.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:390
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/427/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/427/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andy Doan (doanac) wrote :

The handle_request method is starting to get a little complex, but lets deal with that post-phase0

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

> The handle_request method is starting to get a little complex, but lets deal
> with that post-phase0

Yeah and requires a bit too much care, full agreement.

On the other hand, the plan AIUI is to make it handle even more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test_runner/tstrun/run_worker.py'
2--- test_runner/tstrun/run_worker.py 2014-03-14 10:37:28 +0000
3+++ test_runner/tstrun/run_worker.py 2014-03-14 16:30:25 +0000
4@@ -28,31 +28,31 @@
5 super(TestRunnerWorker, self).__init__('test_runner')
6 self.data_store = None
7
8- def save_subunit(self, log, package, stream, retval):
9+ def save_subunit(self, log, package, stream, results):
10 # make this exception-safe since we can already report pass/fail
11 # with or without this file
12 try:
13- log.info('saving subunit results for {}'.format(package))
14+ log.info('Saving subunit results for {}'.format(package))
15 name = 'test-runner.{}-subunit-stream'.format(package)
16 url = self.data_store.put_file(name, stream, 'text/plain')
17- retval.setdefault('artifacts', []).append({
18+ results.setdefault('artifacts', []).append({
19 'name': name,
20 'reference': url,
21 'type': 'RESULTS',
22 })
23 except:
24 log.exception(
25- 'unable to upload subunit result for {}'.format(package))
26+ 'Unable to upload subunit result for {}'.format(package))
27
28- def save_testbed_console(self, log, test_bed, retval):
29+ def save_testbed_console(self, log, test_bed, results):
30 # make this exception-safe since we can already report pass/fail
31 # with or without this file
32 try:
33- log.info('saving testbed console}')
34+ log.info('Saving testbed console')
35 name = 'test-runner.testbed-cloud-init.log'
36 console = test_bed.get_cloud_init_console()
37 url = self.data_store.put_file(name, console, 'text/plain')
38- retval.setdefault('artifacts', []).append({
39+ results.setdefault('artifacts', []).append({
40 'name': name,
41 'reference': url,
42 'type': 'LOGS',
43@@ -61,29 +61,48 @@
44 log.exception('unable to upload testbed console')
45
46 def handle_request(self, log, params):
47+ ticket_id = params['ticket_id']
48 progress_queue = params['progress_trigger']
49 image_id = params['image_id']
50 package_list = params['package_list']
51
52+ results = {}
53+
54 def status_cb(msg):
55 log.info(msg)
56 amqp_utils.progress_update(progress_queue, {'message': msg})
57
58- self.data_store = self._create_data_store(params['ticket_id'])
59- # The tests will succeed unless they fail ;)
60- notify = amqp_utils.progress_completed
61- results = {}
62- test_bed = None
63- flavors = tstrun.get_auth_config()['tr_flavors']
64+ self.data_store = self._create_data_store(ticket_id)
65 try:
66+ status_cb('Setting up the testbed for ticket {}'.format(ticket_id))
67+ flavors = tstrun.get_auth_config()['tr_flavors']
68 test_bed = testbed.TestBed('testbed-{}'.format(progress_queue),
69 flavors, image_id, status_cb)
70+ except:
71+ log.exception(
72+ 'The testbed creation for {} failed'.format(ticket_id))
73+ return amqp_utils.progress_failed, results
74+
75+ try:
76 test_bed.setup()
77+ except:
78+ log.exception(
79+ 'The testbed setup for {} failed'.format(ticket_id))
80+ if test_bed.instance is not None:
81+ self.save_testbed_console(log, test_bed, results)
82+ test_bed.teardown()
83+ return amqp_utils.progress_failed, results
84+
85+ status_cb('The test bed is ready')
86+ # The tests will succeed unless they fail ;)
87+ notify = amqp_utils.progress_completed
88+ try:
89 for package in package_list:
90 if params.get('cancelled'):
91- log.error('request has been cancelled, exiting')
92+ log.error('The request for {} has been cancelled,'
93+ ' exiting'.format(ticket_id))
94 return amqp_utils.progress_failed, results
95- status_cb('testing %s' % package)
96+ status_cb('Testing {}'.format(package))
97 # uci-vms shell adt-run ... --- adt-virt-null
98 return_code, subunit_stream = test_bed.run_test(package)
99 # 0 is success, 8 is skipped and considered a success
100@@ -91,11 +110,14 @@
101 # At least one test failed
102 notify = amqp_utils.progress_failed
103 self.save_subunit(log, package, subunit_stream, results)
104+ status_cb('Test completed for ticket {}'.format(ticket_id))
105 return notify, results
106+ except:
107+ log.exception(
108+ 'Exception while handling ticket {}'.format(ticket_id))
109+ raise
110 finally:
111- if test_bed:
112- self.save_testbed_console(log, test_bed, results)
113- test_bed.teardown()
114+ test_bed.teardown()
115
116
117 if __name__ == '__main__':
118
119=== modified file 'test_runner/tstrun/testbed.py'
120--- test_runner/tstrun/testbed.py 2014-03-14 10:37:28 +0000
121+++ test_runner/tstrun/testbed.py 2014-03-14 16:30:25 +0000
122@@ -189,8 +189,9 @@
123 self.instance = self.nova.servers.create(
124 name=self.name, flavor=flavor, image=image,
125 userdata=self.user_data, keypair=self.nova_ssh_key_name)
126- # FIXME: This times out for hpcloud because it requires a floating ip
127- # for the instance see http://pad.lv/1288622 -- vila 2014-03-06
128+ # FIXME: This times out for hpcloud (when used for testing from dev
129+ # host) because it requires a floating ip for the instance see
130+ # http://pad.lv/1288622 -- vila 2014-03-06
131 self.wait_for_ip()
132 self.wait_for_cloud_init()
133

Subscribers

People subscribed via source and target branches