243 Commits

Author SHA1 Message Date
Zhongyue Luo
c59e04fbfa Replace assertEquals with assertEqual
The method assertEquals has been deprecated since python 2.7.
http://docs.python.org/2/library/unittest.html#deprecated-aliases

Also in Python 3, a deprecated warning is raised when using assertEquals.

Change-Id: Iba0ae72e72470cdf5b122defcd68effc5434f948
2013-10-23 16:23:01 +08:00
Jenkins
0b8f688efd Merge "Make rpc_backend default to 'rabbit'" 2013-10-21 17:16:30 +00:00
OpenStack Jenkins
b2cef24603 Updated from global requirements
Change-Id: I076e205d326c8da4e72032d81e46be21cba8ebe5
2013-10-20 00:00:50 +00:00
Mark McLoughlin
3a2a4d9831 Make rpc_backend default to 'rabbit'
'rabbit' is the canonical name for the driver and 'kombu' is just an
alias, so let's set the default to the canonical.

Change-Id: If163ece6793d2a7d6e99d0c8df1745bbcf9a36e6
2013-10-18 14:54:26 +01:00
Jenkins
14310fa45f Merge "Add third element to RPC versions for backports" 2013-10-15 11:41:57 +00:00
Davanum Srinivas
5f760096d6 Apply six for metaclass
__metaclass__ cannot be used in python3.six be used in general
for python 3 compatibility.

Porting Change-Id I9fc7a59df3af29b4cc1287c40fa4e883d994a961
from oslo-incubator

Change-Id: Icdacdcf5556b6d3b8450d1350c6f62b4f5a9690b
2013-10-14 14:10:31 -04:00
Davanum Srinivas
5af4478fb2 Add third element to RPC versions for backports
This makes the RPC version support three elements, adding a "revision"
in addition to the major and minor version. The revision would always
be zero for the master branch of a service, but could be incremented
for stable versions. This provides us some room to backport fixes
that affect RPC versions in such a way that would avoid breaking
the version lineage for systems running stable versions that may
some day be involved in a rolling upgrade to a version from master.

I didn't find any tests for version_is_compatible(), so I added
some for existing version scenarios, as well as new ones with
revisions. They also serve to validate that this doesn't break
anything for code using two-element versions (the expectation is that
two-element versions will still be used everywhere until a third
is needed).

Porting chages from Change-Id I239c17a3e305f572493498c4b96ee3c7514c5881
to oslo-incubator

Change-Id: I4fa7b0be14a7afba36136a746b76036355f119b2
2013-10-14 11:24:57 +00:00
Mark McLoughlin
91f74d8df0 Fix rpc client docs
Missing a colon before the example code, see:

  http://docs.openstack.org/developer/oslo.messaging/rpcclient.html

Change-Id: Icd875e509b0057c2c739d43c11cd37ab923b59ee
2013-10-13 08:13:43 +01:00
OpenStack Jenkins
f0ad97b344 Updated from global requirements
Change-Id: I4f26d3a8790c799e5c1f7f81031406e0c57545f9

Change-Id: Ica7315effe308bd739e90f885849fac27a3c542b
2013-10-10 20:26:31 +00:00
Monty Taylor
a1b57a5452 Remove cruft from setup.cfg
packages is recursive, so there is no need to list subpackages
versions are set by tags, so the version in the file is not needed
non-d2to1-based pbr does not need the hook specification

Change-Id: Id5e6c19dfe81c630862e9b87b7f9e5f67a965945
2013-10-04 10:07:58 -04:00
OpenStack Jenkins
2aa1dc6ca3 Updated from global requirements
Change-Id: I81e3d4bf4eef833b0b55d17e2a55028972ea4b55
2013-10-01 16:14:29 +00:00
Kenneth Giusti
86f2e74e13 Fixes a typo in the address string syntax
Closes-Bug: #1211338
Change-Id: I49ffc4f70cfa54a03c47537c16c35646d38f84c6
2013-09-18 13:11:51 -05:00
Mark McLoughlin
b6d8087746 Implement the server side of ZmqDriver
This implements the server side of the driver without modifying the
existing code by allowing the driver to spawn off multiple greenthreads
as before, but queueing any dispatched messages so that the executor
can still do listener.poll() to dispatch messages itself.

This is a hack, but it's a starting point.

Change-Id: Ie299c2695d81d0473cea81d40114326b89de0011
2013-08-28 14:06:36 +01:00
Mark McLoughlin
a2d113198c Add zmq-receiver
This is the ZeroMQ server which acts as a proxy for all messages
destined to a particular host. Again, there are a bunch of FIXMEs
here. This still needs work.

Change-Id: I9384f486e44b0b0cbca028e219ad66f1990d5181
2013-08-28 12:25:10 +01:00
Mark McLoughlin
5d3fc9c18c Implement the client side of ZmqDriver
Get sending working with an initial version of the driver. There's a
bunch of FIXMEs inline reflecting that even the client side needs a
tonne of work yet.

Change-Id: I6d69ebc9ae3b3999832209e0c4100ffe26e35919
2013-08-28 12:08:18 +01:00
Mark McLoughlin
ff3a4155bf Import zmq driver code with minimal modifications
Modifications are:

  - use stdlib logging; no huge need for oslo logging here

  - stub out the _() function; we don't have any l10n infrastructure in
    the project and may never have

  - change imports to oslo.messaging.openstack.common and
    oslo.messaging._drivers as appropriate

Change-Id: I87b85b79a33dec65e51ed95fff90cc56042240c5
2013-08-28 09:44:59 +01:00
Jenkins
868c085c83 Merge "Remove check_for_lock support in RPCClient" 2013-08-26 13:17:49 +00:00
Jenkins
5c2c32010c Merge "Don't include msg_id or reply_q in casts" 2013-08-26 13:16:42 +00:00
Jenkins
fd98ebadbb Merge "Fix race-condition in rabbit reply processing" 2013-08-26 13:16:06 +00:00
Mark McLoughlin
aebe53f242 Fix race-condition in rabbit reply processing
Concurrency. Sigh.

A sequence of events like this is possible:

  - We send a request from thread A
  - Thread B, who is waiting for a response gets scheduled
  - Thread B receives our response and queues it up
  - Thread B receives its own response and drops the connection lock
  - Thread A grabs the connection lock and wait for a response to arrive

The obvious solution is that when we grab the connection lock, we should
check whether a previous lock-holding thread had already received our
response and queued it up.

Change-Id: I88b0d55d5a40814a84d82ed4f42d5ba85d2ef7e0
2013-08-26 12:47:04 +01:00
Mark McLoughlin
59299dc202 Fix error message if message handler fails
There are a number of situations in which we log a message if an
exception occurs during the handling of a message:

  1) Something goes wrong pulling the message from the queue and
     de-serializing it - here we print "Failed to process message"

  2) An RPC endpoint method raises an expected exception - here we
     print an 'Expected exception during message handling' debug
     message

  3) An RPC endpoint method raises any other exception - here we
     should print an 'Exception during message handling' error message

However, in the latter case, we are currently printing out the 'Failed
to process' error message.

Change-Id: I4f7042b8ec978aaff8f4e20e62ba1ac765fe6ba5
2013-08-26 10:38:35 +01:00
Mark McLoughlin
f7cf85333c Don't include msg_id or reply_q in casts
On the server side, we only send replies if the request included a
_msg_id key. Also, the _reply_q key is only used when we wish to send a
reply.

So, in order to retain the exact same on-the-wire behaviour and ensure
servers aren't sending replies where none is needed, only include these
keys if we're doing a call (i.e. wait_for_reply=True).

Change-Id: Iac329493252be7d94b1ebe24f00e4d3f5c61d269
2013-08-26 10:23:06 +01:00
Mark McLoughlin
1806c0724a Remove check_for_lock support in RPCClient
I added check_for_lock because I assumed it was enabled by default and
actively in use by Nova. However, it actually isn't used by Nova yet and
enabling spews a tonne of warnings.

It's a rather clunky API and there's a good chance we can design a
better API for it, so let's leave it out until we're ready to actually
start using it in Nova.

Related-Bug: #1063222
Change-Id: Ib890978398059f360cd0f3352f4755262b8111c6
2013-08-26 09:31:12 +01:00
Mark McLoughlin
361092a488 Add a Notifier.prepare() method
Nova sends notifications with a bunch of different publisher_ids, so we
instantiate quite a lot of Notifier objects. Loading the noification
drivers for each of these is a substantial amount of overhead.

One obvious answer would be to make publisher_id an argument to the
error(), info(), etc. methods, but I think it's nice to encapsulate the
publisher_id in a notifier instance.

Instead, add a prepare() method which mirrors the approach in RPCClient.
You use this method to create a specialized notifier instance with a new
publisher_id.

Change-Id: Ia45fda3164086bb7a9ef6dee0587f726ab8b1a97
2013-08-21 07:30:49 +01:00
Davanum Srinivas
0555e939be Fix dictionary changed size during iteration
Make a copy of the keys before we operate on it

Fixes LP# : 1212854

Change-Id: I431ffb3878863e9be6d1a35078f7d7c3edf4b133
2013-08-17 22:04:05 -04:00
Mark McLoughlin
2564795108 Fix transport URL parsing bug
Handle e.g. foo://u:p@/bar. Right now we get:

 IndexError: string index out of range

from:

     if hostname[0] == '[':

Change-Id: I0bccebb14ad1d37862955e8988d160240bd1cf6d
2013-08-18 01:49:25 +01:00
Mark McLoughlin
c79bd1f24c Fix rabbit driver handling of None, etc. replies
Just like the bug in the fake driver, we have a similar rather
embarassing and obvious bug - we're currently not allowing endpoint
methods to send replies of None, '', False, [], {}, etc.

Change-Id: Icf0abdfcf122c5757dd3737f66130b3a53769ef6
2013-08-17 21:40:02 +01:00
Jenkins
f0bb1dac2e Merge "Bumps hacking to 0.7.0" 2013-08-17 17:10:26 +00:00
Jenkins
26722f92d9 Merge "Remove ConfFixture from toplevel public API" 2013-08-17 16:59:51 +00:00
Jenkins
42c324293d Merge "Fix fake driver handling of failure replies" 2013-08-17 16:58:33 +00:00
Mark McLoughlin
a2f99ad35e Remove ConfFixture from toplevel public API
There's no need to make the fixtures, testtools, etc. libraries a
runtime requirement, so let's move it from the toplevel oslo.messaging
API so you need to explicitly import it.

Change-Id: I9e2f32a898d78489f2d8d9c218c81f35cda14e34
2013-08-17 17:49:23 +01:00
Mark McLoughlin
001d66e6e5 Fix fake driver handling of failure replies
The driver reply() method is actually passed a full sys.exc_info()
tuple.

This was masked in the unit tests because the driver ended up basically
doing:

  raise (ValueError, ValueError, ...)

which caused a new ValueError to be instantiated and the test was
satisified. However, if an exception type has some required arguments,
you'll get a TypeError when this statement attempts to instantiate it
with no arguments.

Change-Id: I4af9c5084954d7b9c5f02cdae3387d17c206985b
2013-08-16 11:08:50 +01:00
Zhongyue Luo
f4e4f45433 Bumps hacking to 0.7.0
Change-Id: Ife77d8c6a2a479fce0a7879fb72c0b44e1287324
2013-08-16 14:36:42 +08:00
Mark McLoughlin
a3ffdd1b16 Fix transport URL ipv6 parsing support
Just copies code from Nova's cells code.

See I6b18f7643ab694f5ff34206b80865c40b1ec2680 for where this code was
first introduced.

Change-Id: If9b1503ed47f5910c0ab44edfbe3f42fcce9bf18
2013-08-16 06:31:03 +01:00
Mark McLoughlin
747e1a4099 Fix handling of None, etc. replies
A rather embarassing and obvious bug - we're currently not allowing
endpoint methods to send replies of None, '', False, [], {}, etc.

Change-Id: Ifc5ff8f308f526197559a4df7bed244cff6ed3c1
2013-08-15 21:11:38 +01:00
Jenkins
f95c5bb6ed Merge "Add a unit testing configuration fixture" 2013-08-13 14:02:29 +00:00
Mark McLoughlin
fbe3192d9a Add a unit testing configuration fixture
The configuration options registered by oslo.messaging should not be
directly relied upon by users of the library, since those config option
names could change in future.

Add an API which allows API users to override specific configuration
options e.g.

    self.messaging_conf = self.useFixture(messaging.ConfFixture(cfg.CONF))
    self.messaging_conf.transport_driver = 'fake'

Change-Id: If0d837e1b86e3b04237fde522551cfb81505a543
2013-08-13 13:52:42 +01:00
Mark McLoughlin
c846cf35b8 Add a TransportURL class to the public API
Nova's cells/rpc_driver.py has some code which allows user of the REST
API to update elements of a cell's transport URL (say, the host name of
the message broker) stored in the database. To achieve this, it has
a parse_transport_url() method which breaks the URL into its constituent
parts and an unparse_transport_url() which re-forms it again after
updating some of its parts.

This is all fine and, since it's fairly specialized, it wouldn't be a
big deal to leave this code in Nova for now ... except the unparse
method looks at CONF.rpc_backend to know what scheme to use in the
returned URL if now backend was specified.

oslo.messaging registers the rpc_backend option, but the ability to
reference any option registered by the library should not be relied upon
by users of the library. Imagine, for instance, if we renamed the option
in future (with backwards compat for old configurations), then this
would mean API breakage.

So, long story short - an API along these lines makes some sense, but
especially since not having it would mean we'd need to add some way to
query the name of the transport driver.

In this commit, we add a simple new TransportURL class:

  >>> url = messaging.TransportURL.parse(cfg.CONF, 'foo:///')
  >>> str(url), url
  ('foo:///', <TransportURL transport='foo'>)
  >>> url.hosts.append(messaging.TransportHost(hostname='localhost'))
  >>> str(url), url
  ('foo://localhost/', <TransportURL transport='foo', hosts=[<TransportHost hostname='localhost'>]>)
  >>> url.transport = None
  >>> str(url), url
  ('kombu://localhost/', <TransportURL transport='kombu', hosts=[<TransportHost hostname='localhost'>]>)
  >>> cfg.CONF.set_override('rpc_backend', 'bar')
  >>> str(url), url
  ('bar://localhost/', <TransportURL transport='bar', hosts=[<TransportHost hostname='localhost'>]>)

The TransportURL.parse() method equates to parse_transport_url() and
TransportURL.__str__() equates to unparse_transport().

The transport drivers are also updated to take a TransportURL as a
required argument, which simplifies the handling of transport URLs in
the drivers.

Change-Id: Ic04173476329858e4a2c2d2707e9d4aeb212d127
2013-08-12 23:30:43 +01:00
Mark McLoughlin
5aa7c37144 Ensure namespace package is installed
This is apparently fixed in pbr since I3972b3132619e8e2dd7e362ca5fe9d1e3add43b8
but I'm seeing the issue with pbr 0.5.21 on Fedora.

Related-Bug: #1194742
Change-Id: I136b8493c8d8d48a0116facf5f23c2a1479c070f
2013-08-12 14:35:33 +01:00
Jenkins
514e91cc95 Merge "Add transport URL support to rabbit driver" 2013-08-12 09:24:42 +00:00
Jenkins
3a7dde4fe8 Merge "Kill ability to specify exchange in transport URL" 2013-08-12 09:24:08 +00:00
Jenkins
f3b30fde49 Merge "Add thread-local store of request context" 2013-08-12 09:23:42 +00:00
Jenkins
c7236958d0 Merge "Add a context serialization hook" 2013-08-12 09:23:29 +00:00
Mark McLoughlin
9c110a4c94 Add transport URL support to rabbit driver
If a transport URL is supplied, transform it into the server_params
format which was previously used for cast_to_server() etc.

Change-Id: I453734a71748dc8d3ffc02ead7bfb92ffb0a6c7c
2013-08-12 07:50:30 +01:00
Mark McLoughlin
9cc66e1e01 Kill ability to specify exchange in transport URL
My original thinking was that if you're using the exchange name to
separate two instances of the applications (so their queues don't
collide) then the exchange name is pretty key to transport
configuration. In fact, it's really a virtual host that you'd use for
this (at least in the case of rabbit and qpid).

Also, Nova's cells code has already moved ahead with the assumption that
the path specifies a virtual host, so it'd only make sense to deviate
from that if there was a really good reason to.

Change-Id: Ic8b5dc3538b6b17afec524047acc2efa76366377
2013-08-12 06:09:48 +01:00
Jenkins
a7d7eb660e Merge "Fix handling expected exceptions in rabbit driver" 2013-08-12 01:14:12 +00:00
Andreas Jaeger
8cb17b8041 Fix capitalization, it's OpenStack
I'm fixing all other occurences of this string, incl. oslo-incubator.

Change-Id: If607379d4d1d4bc99084db4b01ada5dfd5c9fa3f
2013-08-11 20:14:39 +02:00
Mark McLoughlin
5fa7f93d09 Fix handling expected exceptions in rabbit driver
We shouldn't be logging expected exceptions. Add a failing rabbit driver
test to check this and fix it.

Change-Id: I78b758957117be7c11c5826a27dd6d1d4fffe9cb
2013-08-11 14:10:18 +01:00
Mark McLoughlin
f1612f2895 Add thread-local store of request context
Oslo's logging code has some useful support for including bits of the
request context in log messages. While this isn't exclusively about the
request context in a dispatching RPC method, it seems useful for
oslo.messaging to support the concept for at least this use case simply
by recording the context in a thread local store before dispatching an
endpoint method and immediately clearing it when the method returns.

Note, we don't need to store weak refs in our store because we will
clear the reference in all cases rather than ever leaving a stale
reference around in the store.

Change-Id: I70ac06ed3a2a891a7a7b388b1823a0f3b08f2dd1
2013-08-09 11:21:27 +01:00
Jenkins
6ec2c8bdbf Merge "Removes a redundant version_is_compatible function" 2013-08-09 07:49:37 +00:00