]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix AttributeError when using DVRServerRpcApi
authorarmando-migliaccio <armamig@gmail.com>
Wed, 24 Dec 2014 06:30:19 +0000 (22:30 -0800)
committerarmando-migliaccio <armamig@gmail.com>
Tue, 27 Jan 2015 21:59:00 +0000 (13:59 -0800)
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

neutron/api/rpc/handlers/dvr_rpc.py
neutron/tests/unit/api/rpc/handlers/__init__.py [new file with mode: 0644]
neutron/tests/unit/api/rpc/handlers/test_dvr_rpc.py [new file with mode: 0644]

index c6d76bc520606dd4b13637109eb270caeec37784..b15add2734e8d6721dc68cc2f771f9a93c32c66c 100644 (file)
@@ -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 (file)
index 0000000..e69de29
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 (file)
index 0000000..5be1121
--- /dev/null
@@ -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')