From: Ilya Shakhat Date: Thu, 22 Jan 2015 15:30:06 +0000 (+0300) Subject: Add missing Connection.close() method X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0d417a7e570fc670f49d13ebb3ade67dc2211029;p=openstack-build%2Fneutron-build.git Add missing Connection.close() method This patch adds missing Connection.close() which is referred from Service.stop(). Closes bug 1413998 Change-Id: I76e825463012384f98a473dfda62665392e533f3 --- diff --git a/neutron/common/rpc.py b/neutron/common/rpc.py index aeb4cb4d3..0da9e9cac 100644 --- a/neutron/common/rpc.py +++ b/neutron/common/rpc.py @@ -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 index 000000000..9c6ecb658 --- /dev/null +++ b/neutron/tests/unit/test_rpc_service.py @@ -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()