summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEric Windisch <eric@cloudscaling.com>2012-07-13 20:47:55 -0400
committerEric Windisch <eric@cloudscaling.com>2012-08-01 12:10:02 -0400
commit20c3bd1562a512819b5cdf09cbe095a09b1a01ea (patch)
tree4e99e04a11a9e25524a7b728b0f733378058146e /tests
parent7b5412ffc874c6ff89f61b286a69c88080b65f42 (diff)
downloadoslo-20c3bd1562a512819b5cdf09cbe095a09b1a01ea.tar.gz
oslo-20c3bd1562a512819b5cdf09cbe095a09b1a01ea.tar.xz
oslo-20c3bd1562a512819b5cdf09cbe095a09b1a01ea.zip
Make receiver spawning in impl_zmq more robust/clean.
The receiver spawning had some faulty and complex logic which this patch improves. The old logic was logging detection of a zmq-receiver socket, although the code was also launching a receiver daemon. It was also doing dirty things such as intentionally doing a return to trigger a finally block. Change-Id: Ic044710679c43753240a2b9d909088af5317cbf4
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/rpc/test_zmq.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/tests/unit/rpc/test_zmq.py b/tests/unit/rpc/test_zmq.py
index e27fff1..459a9e3 100644
--- a/tests/unit/rpc/test_zmq.py
+++ b/tests/unit/rpc/test_zmq.py
@@ -61,27 +61,38 @@ class _RpcZmqBaseTestCase(common.BaseRpcTestCase):
# We'll change this if we detect no daemon running.
ipc_dir = FLAGS.rpc_zmq_ipc_dir
- # Only launch the router if it isn't running independently.
+ # Our IPC dir, if no nova-rpc-zmq_receiver is running system-wide.
+ internal_ipc_dir = '/tmp/openstack-zmq.ipc.test'
+
+ # Only launch the router if it isn't running.
if not os.path.exists(os.path.join(ipc_dir, "zmq_topic_zmq_replies")):
LOG.info(_("Running internal zmq receiver."))
# The normal ipc_dir default needs to run as root,
# /tmp is easier within a testing environment.
- FLAGS.set_default('rpc_zmq_ipc_dir', '/tmp/openstack-zmq.ipc.test')
+ FLAGS.set_default('rpc_zmq_ipc_dir', internal_ipc_dir)
# Value has changed.
ipc_dir = FLAGS.rpc_zmq_ipc_dir
- try:
- # Only launch the receiver if it isn't running independently.
- # This is checked again, with the (possibly) new ipc_dir.
- if os.path.exists(os.path.join(ipc_dir, "zmq_topic_zmq_replies")):
- LOG.warning(_("Detected zmq-receiver socket. "
- "Assuming nova-rpc-zmq-receiver is running."))
- return
-
- if not os.path.isdir(ipc_dir):
- os.mkdir(ipc_dir)
+ self.setup_receiver(ipc_dir)
+ elif ipc_dir != internal_ipc_dir:
+ LOG.warning(_("Detected zmq-receiver socket."))
+ LOG.warning(_("Assuming nova-rpc-zmq-receiver is running."))
+ LOG.warning(_("Using system zmq receiver deamon."))
+
+ super(_RpcZmqBaseTestCase, self).setUp(
+ topic=topic, topic_nested=topic_nested)
+ def setup_receiver(self, ipc_dir):
+ # Only launch the receiver if it isn't running independently.
+ # This is checked again, with the (possibly) new ipc_dir.
+ if not os.path.isdir(ipc_dir):
+ try:
+ os.mkdir(ipc_dir)
+ except OSError:
+ LOG.error(_("Could not create IPC directory %s") % (ipc_dir, ))
+ raise
+ try:
self.reactor = impl_zmq.ZmqProxy(FLAGS)
consume_in = "tcp://%s:%s" % \
(FLAGS.rpc_zmq_bind_address,
@@ -94,13 +105,9 @@ class _RpcZmqBaseTestCase(common.BaseRpcTestCase):
out_bind=True)
self.reactor.consume_in_thread()
except zmq.ZMQError:
- assert False, _("Could not create ZeroMQ receiver daemon. "
- "Socket may already be in use.")
- except OSError:
- assert False, _("Could not create IPC directory %s") % (ipc_dir, )
- finally:
- super(_RpcZmqBaseTestCase, self).setUp(
- topic=topic, topic_nested=topic_nested)
+ LOG.error(_("Could not create ZeroMQ receiver daemon. "
+ "Socket may already be in use."))
+ raise
def tearDown(self):
if not impl_zmq: