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
1=== added file '.adt-service.conf'
2--- .adt-service.conf 1970-01-01 00:00:00 +0000
3+++ .adt-service.conf 2015-03-03 02:17:13 +0000
4@@ -0,0 +1,16 @@
5+# `adt-cloud-worker` configuration file.
6+[adt]
7+name = foo
8+# <arch>.<platform>[ ...]
9+tags = i386.nova amd64.nova
10+
11+[amqp]
12+uris = amqp://guest:guest@localhost:5672//
13+
14+[nova]
15+# Matching OS_ env_vars.
16+os_username = foo
17+os_tenant_name = foo_project
18+os_password = <redacted>
19+os_auth_url = https://keystone.canonistack.canonical.com:443/v2.0/
20+os_region_name = lcy01
21
22=== modified file 'README.rst'
23--- README.rst 2015-03-03 00:30:40 +0000
24+++ README.rst 2015-03-03 02:17:13 +0000
25@@ -9,18 +9,48 @@
26 Get the Source
27 ==============
28
29- $ bzr branch lp:adt-cloud-worker
30+Branch the code::
31+
32+ $ bzr branch lp:adt-cloud-worker
33
34 Install the dependencies
35 ========================
36
37- $ sudo apt-get install python3-kombu
38+Install dependencies::
39+
40+ $ sudo add-apt-repository ppa:canonical-ci-engineering/phase0
41+ $ sudo apt-get update
42+ $ sudo apt-get install python3-kombu
43
44 Run the Service
45 ===============
46
47-Running the executable without arguments will print help:
48-
49- $ ./adt-cloud-worker.py
50-
51-...you will need to specify some options in order for it to do anything sensible.
52\ No newline at end of file
53+Creating/updating the sample configuration file in '.adt-service.conf'::
54+
55+ [adt]
56+ name = foo
57+ tags = i386.nova amd64.nova
58+
59+ [amqp]
60+ uris = amqp://guest:guest@localhost:5672//
61+
62+ [nova]
63+ os_username = foo
64+ os_tenant_name = foo_project
65+ os_password = xxx
66+ os_auth_url = http://172.20.161.138:5000/v2.0/
67+ os_region_name = bot_prototype
68+
69+Running the executable for help::
70+
71+ $ ./adt-cloud-worker.py -h
72+ usage: adt-cloud-worker.py [-h] [-c CONF]
73+
74+ ADT worker ...
75+
76+ optional arguments:
77+ -h, --help show this help message and exit
78+ -c CONF, --conf CONF Configuration file path
79+
80+It's possible to run multiple instances of the worker in the same machine
81+by providing diffent working directories of configuration file path.
82
83=== modified file 'adt-cloud-worker.py'
84--- adt-cloud-worker.py 2015-03-03 01:21:54 +0000
85+++ adt-cloud-worker.py 2015-03-03 02:17:13 +0000
86@@ -23,6 +23,7 @@
87 from __future__ import print_function
88
89 import argparse
90+import configparser
91 import kombu
92 from kombu.log import get_logger
93 from kombu.mixins import ConsumerMixin
94@@ -121,6 +122,7 @@
95 subprocess.check_call(['adt-run'] + arguments)
96 except subprocess.CalledProcessError as e:
97 # log?
98+ # TODO: filter log content to avoid leaking cloud credentials.
99 return e.returncode
100 return 0
101
102@@ -128,24 +130,34 @@
103 def main():
104 setup_logging(loglevel='DEBUG', loggers=[''])
105
106- parser = argparse.ArgumentParser(description='ADT worker ...')
107- parser.add_argument('name', help='Worker name')
108- parser.add_argument('-t', '--tags', dest='tags',
109- default=['i386.nova'], action='append',
110- help='Target tag (<arch>.<platform>)')
111+ parser = argparse.ArgumentParser(
112+ description='ADT cloud worker ...')
113+ parser.add_argument('-c', '--conf', default='.adt-service.conf',
114+ help='Configuration file path')
115 args = parser.parse_args()
116
117+ # Load configuration options.
118+ config = configparser.ConfigParser()
119+ config.read(args.conf)
120+ worker_name = config.get('adt', 'name')
121+ routing_keys = config.get('adt', 'tags').split()
122+ amqp_uris = config.get('amqp', 'uris').split()
123+
124+ # Setup nova environment variables based on the configuration file.
125+ for k, v in config.items('nova'):
126+ os.environ[k.upper()] = str(v)
127+
128 adt_exchange = kombu.Exchange("adt.exchange", type="topic")
129 queues = []
130- for tag in set(args.tags):
131+ for routing_key in routing_keys:
132 queues.append(
133- kombu.Queue('adt.requests.{}'.format(tag) ,
134- adt_exchange, routing_key=tag)
135+ kombu.Queue('adt.requests.{}'.format(routing_key) ,
136+ adt_exchange, routing_key=routing_key)
137 )
138
139- with kombu.Connection('amqp://guest:guest@localhost:5672//') as conn:
140+ with kombu.Connection(amqp_uris) as conn:
141 try:
142- worker = Worker(args.name, conn, queues)
143+ worker = Worker(worker_name, conn, queues)
144 worker.run()
145 except KeyboardInterrupt:
146 print('Bye!')

Subscribers

People subscribed via source and target branches