Merge lp:~thomir-deactivatedaccount/core-result-checker/trunk-add-worker into lp:core-result-checker

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 13
Merged at revision: 11
Proposed branch: lp:~thomir-deactivatedaccount/core-result-checker/trunk-add-worker
Merge into: lp:core-result-checker
Diff against target: 165 lines (+111/-8)
4 files modified
.bzrignore (+1/-0)
core-service.conf (+8/-0)
core_result_checker/__init__.py (+99/-7)
requirements.txt (+3/-1)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/core-result-checker/trunk-add-worker
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+255312@code.launchpad.net

Commit message

Basic implementation for the result-checker.

Description of the change

Basic implementation for the result-checker.

To post a comment you must log in.
13. By Thomi Richards

Check success of swift post operation, and log error as appropriate.

Revision history for this message
Celso Providelo (cprov) wrote :

Thomi,

Very cool, let's see it in action.

[]

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2015-03-25 04:59:12 +0000
+++ .bzrignore 2015-04-06 23:23:40 +0000
@@ -1,1 +1,2 @@
1core_result_checker.egg-info1core_result_checker.egg-info
2secret.conf
23
=== added file 'core-service.conf'
--- core-service.conf 1970-01-01 00:00:00 +0000
+++ core-service.conf 2015-04-06 23:23:40 +0000
@@ -0,0 +1,8 @@
1[amqp]
2uris = amqp://guest:guest@localhost:5672//
3
4[nova]
5os_username = foo
6os_password = <redacted>
7os_tenant_name = foo_project
8os_auth_url = http://172.20.161.138:5000/v2.0/
0\ No newline at end of file9\ No newline at end of file
110
=== modified file 'core_result_checker/__init__.py'
--- core_result_checker/__init__.py 2015-04-03 01:43:12 +0000
+++ core_result_checker/__init__.py 2015-04-06 23:23:40 +0000
@@ -19,14 +19,65 @@
19import configparser19import configparser
20import logging20import logging
21import os21import os
22import select
2322
24from uservice_utils.logging import configure_service_logging23import kombu
24from swiftclient.service import SwiftService
25from uservice_utils.logging import (
26 configure_service_logging,
27 ExtraLogger,
28)
29from uservice_utils.queue import (
30 DefaultRetryPolicy,
31 MessageActions,
32 SimpleRabbitQueueWorker,
33)
2534
26from core_result_checker import constants35from core_result_checker import constants
2736
2837
29logger = logging.getLogger(__name__)38class Worker(object):
39
40 def __init__(self, swift_publisher):
41 get_logger(__name__).info("Service Started.")
42 self.swift_publisher = swift_publisher
43
44 def __call__(self, message):
45 logger = get_logger(__name__, message)
46 logger.info("Got: %r", message)
47 try:
48 channel = message['channel']
49 device = message['device']
50 image_name = message['image_name']
51 except KeyError as e:
52 logger.error("Unable to unpack incoming message: %s", str(e))
53 return MessageActions.Retry
54
55 container_name = "core-{}-{}-{}".format(
56 channel,
57 device,
58 image_name,
59 )
60 try:
61 self.swift_publisher.make_container_public(container_name)
62 except RuntimeError as e:
63 logger.error(
64 "Unable to publish swift container '%s'. Error: %s.",
65 container_name,
66 e
67 )
68 return MessageActions.Retry
69 logger.info("Swift container made public OK.")
70 return MessageActions.Acknowledge
71
72
73def get_logger(name, extra={}):
74 if logging.getLoggerClass() != ExtraLogger:
75 logging.setLoggerClass(ExtraLogger)
76 logger = logging.getLogger(name)
77 e = constants.LOGGING_EXTRA.copy()
78 e.update(extra)
79 logger.set_extra_args(e)
80 return logger
3081
3182
32def read_config():83def read_config():
@@ -45,6 +96,33 @@
45 return config96 return config
4697
4798
99class SwiftPublisher(object):
100
101 """A class that knows how to make a swift container public."""
102
103 def __init__(self, nova_config):
104 self.config = nova_config
105
106 def make_container_public(self, container_name):
107 """Make a swift contianer public.
108
109 Raises RuntimeError on failure, returns None otherwise.
110
111 """
112 swift = SwiftService(self.config)
113 result = swift.post(
114 container=container_name,
115 options=dict(read_acl='.r:*')
116 )
117 if not result['success']:
118 raise RuntimeError(
119 "Unable to make swift container '%s' public: %s" % (
120 container_name,
121 result['error']
122 )
123 )
124
125
48def main():126def main():
49 config = read_config()127 config = read_config()
50 log_path = os.path.abspath(128 log_path = os.path.abspath(
@@ -54,7 +132,21 @@
54 config['logstash'] if 'logstash' in config else None132 config['logstash'] if 'logstash' in config else None
55 )133 )
56134
57 logger.info('Started!', extra=constants.LOGGING_EXTRA)135 amqp_uris = config.get('amqp', 'uris').split()
58136 swift_publisher = SwiftPublisher(config['nova'])
59 # for now, do nothing at all.137 worker = Worker(swift_publisher)
60 select.select([], [], [])138 retry_policy = DefaultRetryPolicy(
139 max_retries=3,
140 dead_queue='core.deadletters.{}'.format(constants.API_VERSION)
141 )
142 try:
143 with kombu.Connection(amqp_uris) as connection:
144 queue_monitor = SimpleRabbitQueueWorker(
145 connection,
146 "core.result.{}".format(constants.API_VERSION),
147 worker,
148 retry_policy,
149 )
150 queue_monitor.run()
151 except KeyboardInterrupt:
152 print("Bye")
61153
=== modified file 'requirements.txt'
--- requirements.txt 2015-04-03 01:41:47 +0000
+++ requirements.txt 2015-04-06 23:23:40 +0000
@@ -1,3 +1,5 @@
1kombu==3.0.241kombu==3.0.24
2python-keystoneclient==1.3.0
2python-logstash==0.4.23python-logstash==0.4.2
3uservice-utils==1.0.2.14python-swiftclient==2.4.0
5uservice-utils==1.0.2.1
4\ No newline at end of file6\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: