]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add missing Connection.close() method
authorIlya Shakhat <ishakhat@mirantis.com>
Thu, 22 Jan 2015 15:30:06 +0000 (18:30 +0300)
committerIlya Shakhat <ishakhat@mirantis.com>
Tue, 27 Jan 2015 15:12:59 +0000 (18:12 +0300)
This patch adds missing Connection.close() which is referred from
Service.stop().

Closes bug 1413998

Change-Id: I76e825463012384f98a473dfda62665392e533f3

neutron/common/rpc.py
neutron/tests/unit/test_rpc_service.py [new file with mode: 0644]

index aeb4cb4d37be2e0b9e81f6490a42c0943f5a27ef..0da9e9cac4a01734de614024ef72a2ae1e56ac27 100644 (file)
@@ -195,6 +195,12 @@ class Connection(object):
             server.start()
         return self.servers
 
+    def close(self):
+        for server in self.servers:
+            server.stop()
+        for server in self.servers:
+            server.wait()
+
 
 # functions
 def create_connection(new=True):
diff --git a/neutron/tests/unit/test_rpc_service.py b/neutron/tests/unit/test_rpc_service.py
new file mode 100644 (file)
index 0000000..9c6ecb6
--- /dev/null
@@ -0,0 +1,57 @@
+# Copyright 2015 OpenStack Foundation.
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import mock
+from oslo.config import cfg
+from oslo.messaging import conffixture as messaging_conffixture
+
+from neutron.common import rpc
+from neutron.tests import sub_base
+
+
+CONF = cfg.CONF
+CONF.import_opt('state_path', 'neutron.common.config')
+
+
+class ServiceTestCase(sub_base.SubBaseTestCase):
+    # the class cannot be based on BaseTestCase since it mocks rpc.Connection
+
+    def setUp(self):
+        super(ServiceTestCase, self).setUp()
+        self.host = 'foo'
+        self.topic = 'neutron-agent'
+
+        self.target_mock = mock.patch('oslo.messaging.Target')
+        self.target_mock.start()
+
+        self.messaging_conf = messaging_conffixture.ConfFixture(CONF)
+        self.messaging_conf.transport_driver = 'fake'
+        self.messaging_conf.response_timeout = 0
+        self.useFixture(self.messaging_conf)
+
+        self.addCleanup(rpc.cleanup)
+        rpc.init(CONF)
+
+    def test_operations(self):
+        with mock.patch('oslo.messaging.get_rpc_server') as get_rpc_server:
+            rpc_server = get_rpc_server.return_value
+
+            service = rpc.Service(self.host, self.topic)
+            service.start()
+            rpc_server.start.assert_called_once_with()
+
+            service.stop()
+            rpc_server.stop.assert_called_once_with()
+            rpc_server.wait.assert_called_once_with()