~vila/ubuntu-ci-services-itself/config

« back to all changes in this revision

Viewing changes to test_runner/run_worker

  • Committer: Chris Johnston
  • Author(s): Vincent Ladeuil
  • Date: 2014-02-06 17:41:49 UTC
  • mfrom: (208.2.7 upload-subunit)
  • Revision ID: chris_johnston-20140206174149-828h6sn7f6dxu678
[r=PS Jenkins bot, Parameswaran Sivatharman] Upload subunit streams for test results into the data store.  from Vincent Ladeuil

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from ci_utils import amqp_utils
30
30
 
31
31
 
 
32
from ci_utils import data_store
32
33
import tstrun
33
34
from tstrun import testbed
34
35
 
36
37
def on_message(msg):
37
38
    log.info('on_message: %s', msg.body)
38
39
    params = json.loads(msg.body)
 
40
    # We use the progress_trigger for both the progress queue and to define the
 
41
    # container in the data store.
39
42
    progress_queue = params['progress_trigger']
40
43
    image_id = params['image_id']
41
44
    package_list = params['package_list']
44
47
    def status_cb(msg):
45
48
        amqp_utils.progress_update(progress_queue, {'message': msg})
46
49
 
 
50
    # The tests will succeed unless they fail ;)
47
51
    notify = amqp_utils.progress_completed
48
52
    results = {}
49
53
    try:
 
54
        store = data_store.DataStore(
 
55
            'test-runner', tstrun.get_auth_config(),
 
56
            identifier=params['progress_trigger'], public=True)
50
57
        # FIXME: We need either a config option or a parameter for the instance
51
58
        # flavor -- vila 2014-01-29
52
59
        flavor = 'm1.small'
63
70
            status_cb('testing %s' % package)
64
71
            # uci-vms shell adt-run ...  --- adt-virt-null
65
72
            return_code, subunit_stream = test_bed.run_test(package)
66
 
            # uci-vms shell collect_artifacts and test results
67
 
            results[package] = (return_code, subunit_stream)
 
73
            # uci-vms shell collect test results
 
74
            subunit_url = store.put_file('{}-subunit-stream'.format(package),
 
75
                                         subunit_stream)
 
76
            results[package] = subunit_url
68
77
            # 0 is success, 8 is skipped and considered a success
69
78
            if return_code not in (0, 8):
 
79
                # At least one test failed
70
80
                notify = amqp_utils.progress_failed
71
 
        notify(progress_queue, results)
72
81
    except Exception as e:
 
82
        # FIXME: 'message' ??? Is the lander expecting that ? Needs testing --
 
83
        # vila 2014-02-06
73
84
        results['message'] = str(e)
74
85
        notify = amqp_utils.progress_failed
75
86
    finally:
76
 
        # remove from queue so request becomes completed
 
87
        # All tests have been run, report success or failure
 
88
        notify(progress_queue, results)
 
89
        # Request completed, remove from queue
 
90
 
 
91
        # FIXME: There is still a hole somewhere, the ack below won't happen if
 
92
        # an exception occurs while calling 'notify' just above, tricky testing
 
93
        # ahead... -- vila 2014-02-06
77
94
        msg.channel.basic_ack(msg.delivery_tag)
78
 
 
79
 
        notify(progress_queue, results)
80
95
        test_bed.teardown()
81
96
 
82
97