From 20c3bd1562a512819b5cdf09cbe095a09b1a01ea Mon Sep 17 00:00:00 2001 From: Eric Windisch Date: Fri, 13 Jul 2012 20:47:55 -0400 Subject: 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 --- tests/unit/rpc/test_zmq.py | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'tests/unit/rpc') 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: -- cgit