Merge lp:~thomir-deactivatedaccount/core-image-publisher/trunk-publish-messages into lp:core-image-publisher

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 23
Merged at revision: 15
Proposed branch: lp:~thomir-deactivatedaccount/core-image-publisher/trunk-publish-messages
Merge into: lp:core-image-publisher
Diff against target: 108 lines (+29/-11)
3 files modified
core_image_publisher/__init__.py (+3/-1)
core_image_publisher/queue.py (+21/-3)
core_image_publisher/worker.py (+5/-7)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/core-image-publisher/trunk-publish-messages
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Review via email: mp+254648@code.launchpad.net

Commit message

Publish result messages to the next micro-service.

Description of the change

Publish result messages to the next micro-service.

To post a comment you must log in.
Revision history for this message
Francis Ginther (fginther) wrote :

Approve.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core_image_publisher/__init__.py'
2--- core_image_publisher/__init__.py 2015-03-30 03:51:14 +0000
3+++ core_image_publisher/__init__.py 2015-03-30 20:35:37 +0000
4@@ -26,6 +26,7 @@
5 from core_image_publisher.queue import (
6 create_connection_from_config,
7 CoreImagePublisherQueueMonitor,
8+ CoreImageResultPublisher,
9 )
10 from core_image_publisher import worker
11
12@@ -93,9 +94,10 @@
13 connection = create_connection_from_config(config)
14 try:
15 with connection:
16+ publisher = CoreImageResultPublisher(connection)
17 monitor = CoreImagePublisherQueueMonitor(
18 connection,
19- worker.ImagePublisherWorker(config)
20+ worker.ImagePublisherWorker(config, publisher)
21 )
22 monitor.run()
23 except KeyboardInterrupt:
24
25=== modified file 'core_image_publisher/queue.py'
26--- core_image_publisher/queue.py 2015-03-30 20:05:16 +0000
27+++ core_image_publisher/queue.py 2015-03-30 20:35:37 +0000
28@@ -28,8 +28,8 @@
29
30 __all__ = [
31 'CoreImagePublisherQueueMonitor',
32+ 'CoreImageResultPublisher',
33 'create_connection_from_config',
34- 'enqueue_message',
35 ]
36
37
38@@ -153,5 +153,23 @@
39 return kombu.Connection(amqp_uris)
40
41
42-def enqueue_message(payload):
43- """Enqueue 'payload' for the core-image-tester."""
44+class CoreImageResultPublisher(object):
45+
46+ """A callable that knows how to publish results from this service.
47+
48+ For now we're using a simple queue, but this can easily be extended to use
49+ a full-blown topic exchange in the future.
50+
51+ """
52+
53+ def __init__(self, connection):
54+ self.connection = connection
55+
56+ def __call__(self, payload):
57+ """Take 'payload' and enqueue it on the rabbit queue."""
58+ queue = self.connection.SimpleQueue(
59+ "core.tests.{}".format(constants.API_VERSION)
60+ )
61+ queue.put(payload)
62+ queue.close()
63+
64
65=== modified file 'core_image_publisher/worker.py'
66--- core_image_publisher/worker.py 2015-03-30 04:04:49 +0000
67+++ core_image_publisher/worker.py 2015-03-30 20:35:37 +0000
68@@ -22,10 +22,7 @@
69 import subprocess
70 import tempfile
71
72-from core_image_publisher.queue import (
73- enqueue_message,
74- MessageActions,
75-)
76+from core_image_publisher.queue import MessageActions
77 from core_image_publisher.cloud import get_glance_client
78 from core_image_publisher.utils import check_call
79
80@@ -36,8 +33,9 @@
81
82 """A worker callable that contains all our main logic."""
83
84- def __init__(self, config):
85+ def __init__(self, config, publisher):
86 self._config = config
87+ self.publish_results = publisher
88
89 def __call__(self, payload):
90 logger.info("Got %r", payload, extra=payload)
91@@ -83,7 +81,7 @@
92 logger.info("Image uploaded to glance OK.", extra=payload)
93
94 payload['nova_image'] = glance_image_name
95- enqueue_message(payload)
96+ self.publish_results(payload)
97 logger.info("Processing completed.", extra=payload)
98 return MessageActions.Acknowledge
99
100@@ -126,7 +124,7 @@
101 """
102 glance = get_glance_client(config)
103 image_name = os.path.basename(nova_image_path)
104- image = glance.images.create(
105+ glance.images.create(
106 name=image_name,
107 data=open(nova_image_path, 'rb'),
108 disk_format='qcow2',

Subscribers

People subscribed via source and target branches

to all changes: