From: armando-migliaccio Date: Wed, 24 Dec 2014 06:30:19 +0000 (-0800) Subject: Fix AttributeError when using DVRServerRpcApi X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=97f28d24450d27d3326334bce0dbba0dbbd28cbe;p=openstack-build%2Fneutron-build.git Fix AttributeError when using DVRServerRpcApi This time with tests for the joy of Maru and Assaf. More context on [1]. [1] https://review.openstack.org/#/c/143778/ Related-bug: #1394848 Closes-bug: #1414812 Change-Id: I8ad1f1ad6caaee1f18a44f06cea532f4aa9a82b6 --- diff --git a/neutron/api/rpc/handlers/dvr_rpc.py b/neutron/api/rpc/handlers/dvr_rpc.py index c6d76bc52..b15add273 100644 --- a/neutron/api/rpc/handlers/dvr_rpc.py +++ b/neutron/api/rpc/handlers/dvr_rpc.py @@ -33,23 +33,23 @@ class DVRServerRpcApi(object): @log.log def get_dvr_mac_address_by_host(self, context, host): - cctxt = self.client.prepare(version=self.DVR_RPC_VERSION) + cctxt = self.client.prepare() return cctxt.call(context, 'get_dvr_mac_address_by_host', host=host) @log.log def get_dvr_mac_address_list(self, context): - cctxt = self.client.prepare(version=self.DVR_RPC_VERSION) + cctxt = self.client.prepare() return cctxt.call(context, 'get_dvr_mac_address_list') @log.log def get_ports_on_host_by_subnet(self, context, host, subnet): - cctxt = self.client.prepare(version=self.DVR_RPC_VERSION) + cctxt = self.client.prepare() return cctxt.call(context, 'get_ports_on_host_by_subnet', host=host, subnet=subnet) @log.log def get_subnet_for_dvr(self, context, subnet): - cctxt = self.client.prepare(version=self.DVR_RPC_VERSION) + cctxt = self.client.prepare() return cctxt.call(context, 'get_subnet_for_dvr', subnet=subnet) diff --git a/neutron/tests/unit/api/rpc/handlers/__init__.py b/neutron/tests/unit/api/rpc/handlers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/neutron/tests/unit/api/rpc/handlers/test_dvr_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_dvr_rpc.py new file mode 100644 index 000000000..5be1121fc --- /dev/null +++ b/neutron/tests/unit/api/rpc/handlers/test_dvr_rpc.py @@ -0,0 +1,53 @@ +# Copyright (c) 2015 OpenStack Foundation. +# +# 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 neutron.api.rpc.handlers import dvr_rpc +from neutron.tests import base + + +class DVRServerRpcApiTestCase(base.BaseTestCase): + + def setUp(self): + self.client_p = mock.patch.object(dvr_rpc.n_rpc, "get_client") + self.client = self.client_p.start() + self.rpc = dvr_rpc.DVRServerRpcApi('fake_topic') + self.mock_cctxt = self.rpc.client.prepare.return_value + self.ctxt = mock.ANY + super(DVRServerRpcApiTestCase, self).setUp() + + def test_get_dvr_mac_address_by_host(self): + self.rpc.get_dvr_mac_address_by_host(self.ctxt, 'foo_host') + self.mock_cctxt.call.assert_called_with( + self.ctxt, 'get_dvr_mac_address_by_host', host='foo_host') + + def test_get_dvr_mac_address_list(self): + self.rpc.get_dvr_mac_address_list(self.ctxt) + self.mock_cctxt.call.assert_called_with( + self.ctxt, 'get_dvr_mac_address_list') + + def test_get_ports_on_host_by_subnet(self): + self.rpc.get_ports_on_host_by_subnet( + self.ctxt, 'foo_host', 'foo_subnet') + self.mock_cctxt.call.assert_called_with( + self.ctxt, 'get_ports_on_host_by_subnet', + host='foo_host', subnet='foo_subnet') + + def test_get_subnet_for_dvr(self): + self.rpc.get_subnet_for_dvr(self.ctxt, 'foo_subnet') + self.mock_cctxt.call.assert_called_with( + self.ctxt, 'get_subnet_for_dvr', + subnet='foo_subnet')