diff options
author | Soren Hansen <soren.hansen@rackspace.com> | 2010-10-05 15:21:08 +0200 |
---|---|---|
committer | Soren Hansen <soren.hansen@rackspace.com> | 2010-10-05 15:21:08 +0200 |
commit | 394c5ae180ed25f7e617f6c43f9a88f003e5d2ea (patch) | |
tree | 8d52975aa9bc232d7060b76f2eb038414bb30668 | |
parent | 4b9be67025c3aff4b7f5f9b31a74eb14924885cb (diff) | |
download | nova-394c5ae180ed25f7e617f6c43f9a88f003e5d2ea.tar.gz nova-394c5ae180ed25f7e617f6c43f9a88f003e5d2ea.tar.xz nova-394c5ae180ed25f7e617f6c43f9a88f003e5d2ea.zip |
Make rpc calls work in unit tests by adding extra declare_consumer and consume methods on the FakeRabbit backend.
-rw-r--r-- | nova/fakerabbit.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/nova/fakerabbit.py b/nova/fakerabbit.py index 068025249..6679f8dab 100644 --- a/nova/fakerabbit.py +++ b/nova/fakerabbit.py @@ -38,6 +38,7 @@ class Exchange(object): def publish(self, message, routing_key=None): logging.debug('(%s) publish (key: %s) %s', self.name, routing_key, message) + routing_key = routing_key.split('.')[0] if routing_key in self._routes: for f in self._routes[routing_key]: logging.debug('Publishing to route %s', f) @@ -94,6 +95,20 @@ class Backend(object): self._exchanges[exchange].bind(self._queues[queue].push, routing_key) + def declare_consumer(self, queue, callback, *args, **kwargs): + print 'declare_consumer', queue, callback + self.current_queue = queue + self.current_callback = callback + + def consume(self, *args, **kwargs): + from eventlet import greenthread + while True: + item = self.get(self.current_queue) + if item: + self.current_callback(item) + raise StopIteration() + greenthread.sleep(0) + def get(self, queue, no_ack=False): if not queue in self._queues or not self._queues[queue].size(): return None @@ -102,6 +117,7 @@ class Backend(object): message = Message(backend=self, body=message_data, content_type=content_type, content_encoding=content_encoding) + message.result = True logging.debug('Getting from %s: %s', queue, message) return message |