Merge lp:~cprov/adt-cloud-worker/basic-config into lp:adt-cloud-worker

Proposed by Celso Providelo
Status: Merged
Merged at revision: 4
Proposed branch: lp:~cprov/adt-cloud-worker/basic-config
Merge into: lp:adt-cloud-worker
Diff against target: 146 lines (+75/-17)
3 files modified
.adt-service.conf (+16/-0)
README.rst (+37/-7)
adt-cloud-worker.py (+22/-10)
To merge this branch: bzr merge lp:~cprov/adt-cloud-worker/basic-config
Reviewer Review Type Date Requested Status
Canonical CI Engineering Pending
Review via email: mp+251544@code.launchpad.net

Commit message

Basic configuration file support (INI-style with common sections across similar microservices). Also adding support for configuring nova OS_ environment.

Description of the change

Basic configuration file support (INI-style with common sections across similar microservices). Also adding support for configuring nova OS_ environment.

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
=== added file '.adt-service.conf'
--- .adt-service.conf 1970-01-01 00:00:00 +0000
+++ .adt-service.conf 2015-03-03 02:17:13 +0000
@@ -0,0 +1,16 @@
1# `adt-cloud-worker` configuration file.
2[adt]
3name = foo
4# <arch>.<platform>[ ...]
5tags = i386.nova amd64.nova
6
7[amqp]
8uris = amqp://guest:guest@localhost:5672//
9
10[nova]
11# Matching OS_ env_vars.
12os_username = foo
13os_tenant_name = foo_project
14os_password = <redacted>
15os_auth_url = https://keystone.canonistack.canonical.com:443/v2.0/
16os_region_name = lcy01
017
=== modified file 'README.rst'
--- README.rst 2015-03-03 00:30:40 +0000
+++ README.rst 2015-03-03 02:17:13 +0000
@@ -9,18 +9,48 @@
9Get the Source9Get the Source
10==============10==============
1111
12 $ bzr branch lp:adt-cloud-worker12Branch the code::
13
14 $ bzr branch lp:adt-cloud-worker
1315
14Install the dependencies16Install the dependencies
15========================17========================
1618
17 $ sudo apt-get install python3-kombu19Install dependencies::
20
21 $ sudo add-apt-repository ppa:canonical-ci-engineering/phase0
22 $ sudo apt-get update
23 $ sudo apt-get install python3-kombu
1824
19Run the Service25Run the Service
20===============26===============
2127
22Running the executable without arguments will print help:
23
24 $ ./adt-cloud-worker.py
25
26...you will need to specify some options in order for it to do anything sensible.
27\ No newline at end of file28\ No newline at end of file
29Creating/updating the sample configuration file in '.adt-service.conf'::
30
31 [adt]
32 name = foo
33 tags = i386.nova amd64.nova
34
35 [amqp]
36 uris = amqp://guest:guest@localhost:5672//
37
38 [nova]
39 os_username = foo
40 os_tenant_name = foo_project
41 os_password = xxx
42 os_auth_url = http://172.20.161.138:5000/v2.0/
43 os_region_name = bot_prototype
44
45Running the executable for help::
46
47 $ ./adt-cloud-worker.py -h
48 usage: adt-cloud-worker.py [-h] [-c CONF]
49
50 ADT worker ...
51
52 optional arguments:
53 -h, --help show this help message and exit
54 -c CONF, --conf CONF Configuration file path
55
56It's possible to run multiple instances of the worker in the same machine
57by providing diffent working directories of configuration file path.
2858
=== modified file 'adt-cloud-worker.py'
--- adt-cloud-worker.py 2015-03-03 01:21:54 +0000
+++ adt-cloud-worker.py 2015-03-03 02:17:13 +0000
@@ -23,6 +23,7 @@
23from __future__ import print_function23from __future__ import print_function
2424
25import argparse25import argparse
26import configparser
26import kombu27import kombu
27from kombu.log import get_logger28from kombu.log import get_logger
28from kombu.mixins import ConsumerMixin29from kombu.mixins import ConsumerMixin
@@ -121,6 +122,7 @@
121 subprocess.check_call(['adt-run'] + arguments)122 subprocess.check_call(['adt-run'] + arguments)
122 except subprocess.CalledProcessError as e:123 except subprocess.CalledProcessError as e:
123 # log?124 # log?
125 # TODO: filter log content to avoid leaking cloud credentials.
124 return e.returncode126 return e.returncode
125 return 0127 return 0
126128
@@ -128,24 +130,34 @@
128def main():130def main():
129 setup_logging(loglevel='DEBUG', loggers=[''])131 setup_logging(loglevel='DEBUG', loggers=[''])
130132
131 parser = argparse.ArgumentParser(description='ADT worker ...')133 parser = argparse.ArgumentParser(
132 parser.add_argument('name', help='Worker name')134 description='ADT cloud worker ...')
133 parser.add_argument('-t', '--tags', dest='tags',135 parser.add_argument('-c', '--conf', default='.adt-service.conf',
134 default=['i386.nova'], action='append',136 help='Configuration file path')
135 help='Target tag (<arch>.<platform>)')
136 args = parser.parse_args()137 args = parser.parse_args()
137138
139 # Load configuration options.
140 config = configparser.ConfigParser()
141 config.read(args.conf)
142 worker_name = config.get('adt', 'name')
143 routing_keys = config.get('adt', 'tags').split()
144 amqp_uris = config.get('amqp', 'uris').split()
145
146 # Setup nova environment variables based on the configuration file.
147 for k, v in config.items('nova'):
148 os.environ[k.upper()] = str(v)
149
138 adt_exchange = kombu.Exchange("adt.exchange", type="topic")150 adt_exchange = kombu.Exchange("adt.exchange", type="topic")
139 queues = []151 queues = []
140 for tag in set(args.tags):152 for routing_key in routing_keys:
141 queues.append(153 queues.append(
142 kombu.Queue('adt.requests.{}'.format(tag) ,154 kombu.Queue('adt.requests.{}'.format(routing_key) ,
143 adt_exchange, routing_key=tag)155 adt_exchange, routing_key=routing_key)
144 )156 )
145157
146 with kombu.Connection('amqp://guest:guest@localhost:5672//') as conn:158 with kombu.Connection(amqp_uris) as conn:
147 try:159 try:
148 worker = Worker(args.name, conn, queues)160 worker = Worker(worker_name, conn, queues)
149 worker.run()161 worker.run()
150 except KeyboardInterrupt:162 except KeyboardInterrupt:
151 print('Bye!')163 print('Bye!')

Subscribers

People subscribed via source and target branches