~psivaa/snappy-proposed-selftest-agent/request-id-in-payload

« back to all changes in this revision

Viewing changes to snappy_proposed_selftest_agent/worker.py

  • Committer: Ubuntu CI Bot
  • Author(s): Paul Larson
  • Date: 2015-05-28 03:58:46 UTC
  • mfrom: (7.1.6 sandbox)
  • Revision ID: ubuntu_ci_bot-20150528035846-93r727ovh5oa6npb
Add example config file, and fill in more body information to send to the exchanges [r=Celso Providelo, Thomi Richards, Francis Ginther]

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#
17
17
 
18
18
import kombu
 
19
import urllib
19
20
 
20
21
from kombu.mixins import ConsumerMixin
21
22
 
 
23
from snappy_proposed_selftest_agent import constants
 
24
 
22
25
 
23
26
class CoreSelftestAgentWorker(ConsumerMixin):
24
27
 
28
31
        self.build_worker = build_worker
29
32
        self.result_worker = result_worker
30
33
 
31
 
        exchange = kombu.Exchange(self.config.INPUT_EXCHANGE,
 
34
        exchange = kombu.Exchange(constants.INPUT_EXCHANGE,
32
35
                                  type='fanout', durable=False)
33
 
        self.queue = kombu.Queue(self.config.INPUT_QUEUE, exchange)
 
36
        self.queue = kombu.Queue(constants.INPUT_QUEUE, exchange)
34
37
 
35
38
    def get_consumers(self, Consumer, channel):
36
39
        """Return consumers instances for all configured queues."""
48
51
        For now, just blindly post messages for these
49
52
        """
50
53
 
51
 
        self.build_worker(body)
52
 
        self.result_worker(body)
 
54
        request_id = kombu.uuid()
 
55
 
 
56
        # Build the message body to pass to the image builder
 
57
        image_build_body = body.copy()
 
58
        image_build_body['test_branch'] = constants.TEST_BRANCH
 
59
        image_build_body['channel'] = constants.CHANNEL
 
60
        image_build_body['device'] = constants.DEVICE
 
61
        image_build_body['test_name'] = constants.TEST_NAME
 
62
        self.build_worker(image_build_body)
 
63
 
 
64
        # Build the message body to pass to the results exchange
 
65
        results_body = body.copy()
 
66
        swift_url = self.config.get('swift', 'public_url')
 
67
        results_path = 'snappy-selftest-{}/results.tgz'.format(request_id)
 
68
        request_url = urllib.parse.urljoin(swift_url, results_path)
 
69
        results_body['request_url'] = request_url
 
70
        results_body['status'] = 'RUNNING'
 
71
        results_body['test_name'] = constants.TEST_NAME
 
72
        self.result_worker(results_body)