Merge lp:~cprov/adt-cloud-worker/initial-tweaks into lp:adt-cloud-worker

Proposed by Celso Providelo
Status: Merged
Merged at revision: 3
Proposed branch: lp:~cprov/adt-cloud-worker/initial-tweaks
Merge into: lp:adt-cloud-worker
Diff against target: 108 lines (+30/-23)
1 file modified
adt-cloud-worker.py (+30/-23)
To merge this branch: bzr merge lp:~cprov/adt-cloud-worker/initial-tweaks
Reviewer Review Type Date Requested Status
Canonical CI Engineering Pending
Review via email: mp+251538@code.launchpad.net

Commit message

Fixing adt-run arguments builder, results stored in a temporary directory (properly removed when the result is passed over) and also replacing isolated arch + platform arguments by 'tag' one (combination of both is obscure)

Description of the change

Fixing adt-run arguments builder, results stored in a temporary directory (properly removed when the result is passed over) and also replacing isolated arch + platform arguments by 'tag' one (combination of both is obscure)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'adt-cloud-worker.py'
2--- adt-cloud-worker.py 2015-03-03 00:30:40 +0000
3+++ adt-cloud-worker.py 2015-03-03 01:23:21 +0000
4@@ -27,9 +27,10 @@
5 from kombu.log import get_logger
6 from kombu.mixins import ConsumerMixin
7 from kombu.utils.debug import setup_logging
8-import yaml
9+import os
10+import shutil
11 import subprocess
12-
13+import tempfile
14
15 logger = get_logger(__name__)
16
17@@ -45,12 +46,19 @@
18 return [Consumer(queues=self.queues, callbacks=[self.process])]
19
20 def process(self, body, message):
21- # TODO: is 'body' guaranteed to
22+ logger.info('Got: {}'.format(body))
23+ # TODO: body validation
24+ # Ack message once it's valid or message.reject()
25+ message.ack()
26+
27+ result_dir = tempfile.mkdtemp(
28+ prefix='adt-{}'.format(body['request_id']))
29+
30 try:
31 # what information do we need from the message?
32 adt_run_args = [
33 '--apt-source', body['package_name'],
34- '--output-dir', 'tmp/adt-cloud-worker', # TODO: replace me
35+ '--output-dir', result_dir, # TODO: replace me
36 ]
37 if 'apt_pocket' in body:
38 adt_run_args += [
39@@ -58,7 +66,8 @@
40 '--apt-upgrade',
41 ]
42 adt_ssh_nova_args = [
43- '--flavour', body['nova_flavour'],
44+ '--',
45+ '--flavor', body['nova_flavor'],
46 '--image', body['nova_image'],
47 ]
48
49@@ -82,22 +91,23 @@
50 # 16 testbed failure
51 # 20 other unexpected failures including bad usage
52
53- swift_container = body['swift_container']
54-
55 # TODO: tar/gzip the output directory.
56 # TODO: upload to swift instance at 'swift_container'
57
58- # we can ack the message now, build the result message, then
59- # we're done.
60- message.ack()
61+ except Exception as e:
62+ logger.error(e, exc_info=True)
63+ finally:
64+ # build the result message
65 body['worker'] = self.name
66+ body['exit_code'] = exit_code
67+ # TODO: send error logging to result-checker in the message
68+
69 queue = self.connection.SimpleQueue('adt.results')
70 queue.put(body)
71 queue.close()
72-
73- except Exception as e:
74- message.reject()
75- logger.error(e)
76+ # Drop the result directory
77+ # TODO: it could be possibly useful for clients.
78+ shutil.rmtree(result_dir)
79
80
81 def run_adt(arguments):
82@@ -120,20 +130,17 @@
83
84 parser = argparse.ArgumentParser(description='ADT worker ...')
85 parser.add_argument('name', help='Worker name')
86- parser.add_argument('-a', '--arch', dest='architectures',
87- default=['i386'], action='append',
88- help='Target architectures')
89- parser.add_argument('-p', '--platform', default='default',
90- help='Target platform')
91+ parser.add_argument('-t', '--tags', dest='tags',
92+ default=['i386.nova'], action='append',
93+ help='Target tag (<arch>.<platform>)')
94 args = parser.parse_args()
95
96 adt_exchange = kombu.Exchange("adt.exchange", type="topic")
97 queues = []
98- for arch in set(args.architectures):
99- routing_key = '{}.{}'.format(arch, args.platform)
100+ for tag in set(args.tags):
101 queues.append(
102- kombu.Queue('adt.requests.{}'.format(routing_key) ,
103- adt_exchange, routing_key=routing_key)
104+ kombu.Queue('adt.requests.{}'.format(tag) ,
105+ adt_exchange, routing_key=tag)
106 )
107
108 with kombu.Connection('amqp://guest:guest@localhost:5672//') as conn:

Subscribers

People subscribed via source and target branches