From: Salvatore Orlando Date: Wed, 22 Aug 2012 23:29:24 +0000 (-0700) Subject: Run core unit tests for each plugin X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9548defc4f56ed40f2bea3a04b1a74cc8b7e89b2;p=openstack-build%2Fneutron-build.git Run core unit tests for each plugin Fixes bug 1040277 Execute the test cases in test_db_plugin.py for each plugin. Each plugin now get its own test__plugin test module. This commit excludes cisco and metaplugin plugins, which do not run the "core" unit tests at all. Change-Id: I137411f47d8cfcc753aa3a88359f5b1590ca8237 --- diff --git a/quantum/policy.py b/quantum/policy.py index 6d6db41cb..e2c1d9017 100644 --- a/quantum/policy.py +++ b/quantum/policy.py @@ -24,13 +24,13 @@ from quantum.openstack.common import cfg import quantum.common.utils as utils from quantum.openstack.common import policy - _POLICY_PATH = None _POLICY_CACHE = {} def reset(): global _POLICY_PATH + global _POLICY_CACHE _POLICY_PATH = None _POLICY_CACHE = {} policy.reset() @@ -188,5 +188,6 @@ def enforce(context, action, target, plugin=None): real_target = _build_target(action, target, plugin, context) match_list = _build_match_list(action, real_target) credentials = context.to_dict() + policy.enforce(match_list, real_target, credentials, exceptions.PolicyNotAuthorized, action=action) diff --git a/quantum/tests/unit/test_db_plugin.py b/quantum/tests/unit/test_db_plugin.py index 4f13f5ae9..2d1e1b826 100644 --- a/quantum/tests/unit/test_db_plugin.py +++ b/quantum/tests/unit/test_db_plugin.py @@ -71,7 +71,8 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase): 'application/json': json_deserializer, } - plugin = test_config.get('plugin_name_v2', DB_PLUGIN_KLASS) + if not plugin: + plugin = test_config.get('plugin_name_v2', DB_PLUGIN_KLASS) # Create the default configurations args = ['--config-file', etcdir('quantum.conf.test')] # If test_config specifies some config-file, use it, as well diff --git a/quantum/tests/unit/test_linuxbridge_plugin.py b/quantum/tests/unit/test_linuxbridge_plugin.py new file mode 100644 index 000000000..03d3546be --- /dev/null +++ b/quantum/tests/unit/test_linuxbridge_plugin.py @@ -0,0 +1,50 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# 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. + +from quantum.tests.unit import test_db_plugin as test_plugin + + +class LinuxBridgePluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase): + + _plugin_name = ('quantum.plugins.linuxbridge.' + 'lb_quantum_plugin.LinuxBridgePluginV2') + + def setUp(self): + super(LinuxBridgePluginV2TestCase, self).setUp(self._plugin_name) + + +class TestLinuxBridgeBasicGet(test_plugin.TestBasicGet, + LinuxBridgePluginV2TestCase): + pass + + +class TestLinuxBridgeV2HTTPResponse(test_plugin.TestV2HTTPResponse, + LinuxBridgePluginV2TestCase): + pass + + +class TestLinuxBridgePortsV2(test_plugin.TestPortsV2, + LinuxBridgePluginV2TestCase): + pass + + +class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2, + LinuxBridgePluginV2TestCase): + pass + + +class TestLinuxBridgeSubnetsV2(test_plugin.TestSubnetsV2, + LinuxBridgePluginV2TestCase): + pass diff --git a/quantum/tests/unit/test_nec_plugin.py b/quantum/tests/unit/test_nec_plugin.py new file mode 100644 index 000000000..ec7e19725 --- /dev/null +++ b/quantum/tests/unit/test_nec_plugin.py @@ -0,0 +1,45 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# 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. + +from quantum.tests.unit import test_db_plugin as test_plugin + + +class NecPluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase): + + _plugin_name = 'quantum.plugins.nec.nec_plugin.NECPluginV2' + + def setUp(self): + super(NecPluginV2TestCase, self).setUp(self._plugin_name) + + +class TestNecBasicGet(test_plugin.TestBasicGet, NecPluginV2TestCase): + pass + + +class TestNecV2HTTPResponse(test_plugin.TestV2HTTPResponse, + NecPluginV2TestCase): + pass + + +class TestNecPortsV2(test_plugin.TestPortsV2, NecPluginV2TestCase): + pass + + +class TestNecNetworksV2(test_plugin.TestNetworksV2, NecPluginV2TestCase): + pass + + +class TestNecSubnetsV2(test_plugin.TestSubnetsV2, NecPluginV2TestCase): + pass diff --git a/quantum/tests/unit/test_nicira_plugin.py b/quantum/tests/unit/test_nicira_plugin.py new file mode 100644 index 000000000..96677ddd3 --- /dev/null +++ b/quantum/tests/unit/test_nicira_plugin.py @@ -0,0 +1,74 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# 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 os + +import mock + +import quantum.common.test_lib as test_lib +from quantum.plugins.nicira.nicira_nvp_plugin.tests import fake_nvpapiclient +import quantum.tests.unit.test_db_plugin as test_plugin + +NICIRA_PATH = '../../plugins/nicira/nicira_nvp_plugin' +NICIRA_PKG_PATH = 'quantum.plugins.nicira.nicira_nvp_plugin' + + +class NiciraPluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase): + + _plugin_name = ('%s.QuantumPlugin.NvpPluginV2' % NICIRA_PKG_PATH) + + def setUp(self): + config_file_path = os.path.abspath('%s/tests/nvp.ini.test' + % NICIRA_PATH) + test_lib.test_config['config_files'] = [config_file_path] + # mock nvp api client + fc = fake_nvpapiclient.FakeClient(os.path.abspath('%s/tests' + % NICIRA_PATH)) + self.mock_nvpapi = mock.patch('%s.NvpApiClient.NVPApiHelper' + % NICIRA_PKG_PATH, autospec=True) + instance = self.mock_nvpapi.start() + instance.return_value.login.return_value = "the_cookie" + + def _fake_request(*args, **kwargs): + return fc.fake_request(*args, **kwargs) + + instance.return_value.request.side_effect = _fake_request + super(NiciraPluginV2TestCase, self).setUp(self._plugin_name) + + def tearDown(self): + super(NiciraPluginV2TestCase, self).tearDown() + self.mock_nvpapi.stop() + + +class TestNiciraBasicGet(test_plugin.TestBasicGet, NiciraPluginV2TestCase): + pass + + +class TestNiciraV2HTTPResponse(test_plugin.TestV2HTTPResponse, + NiciraPluginV2TestCase): + pass + + +class TestNiciraPortsV2(test_plugin.TestPortsV2, NiciraPluginV2TestCase): + pass + + +class TestNiciraNetworksV2(test_plugin.TestNetworksV2, + NiciraPluginV2TestCase): + pass + + +class TestNiciraSubnetsV2(test_plugin.TestSubnetsV2, NiciraPluginV2TestCase): + pass diff --git a/quantum/tests/unit/test_openvswitch_plugin.py b/quantum/tests/unit/test_openvswitch_plugin.py new file mode 100644 index 000000000..df65a209f --- /dev/null +++ b/quantum/tests/unit/test_openvswitch_plugin.py @@ -0,0 +1,50 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# 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. + +from quantum.tests.unit import test_db_plugin as test_plugin + + +class OpenvswitchPluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase): + + _plugin_name = ('quantum.plugins.openvswitch.' + 'ovs_quantum_plugin.OVSQuantumPluginV2') + + def setUp(self): + super(OpenvswitchPluginV2TestCase, self).setUp(self._plugin_name) + + +class TestOpenvswitchBasicGet(test_plugin.TestBasicGet, + OpenvswitchPluginV2TestCase): + pass + + +class TestOpenvswitchV2HTTPResponse(test_plugin.TestV2HTTPResponse, + OpenvswitchPluginV2TestCase): + pass + + +class TestOpenvswitchPortsV2(test_plugin.TestPortsV2, + OpenvswitchPluginV2TestCase): + pass + + +class TestOpenvswitchNetworksV2(test_plugin.TestNetworksV2, + OpenvswitchPluginV2TestCase): + pass + + +class TestOpenvswitchSubnetsV2(test_plugin.TestSubnetsV2, + OpenvswitchPluginV2TestCase): + pass diff --git a/quantum/tests/unit/test_policy.py b/quantum/tests/unit/test_policy.py index 14f43def3..989a6012c 100644 --- a/quantum/tests/unit/test_policy.py +++ b/quantum/tests/unit/test_policy.py @@ -250,6 +250,7 @@ class QuantumPolicyTestCase(unittest.TestCase): def tearDown(self): self.patcher.stop() + quantum.policy.reset() def test_nonadmin_write_on_private_returns_403(self): action = "update_network" diff --git a/quantum/tests/unit/test_ryu_plugin.py b/quantum/tests/unit/test_ryu_plugin.py new file mode 100644 index 000000000..f5e2c233a --- /dev/null +++ b/quantum/tests/unit/test_ryu_plugin.py @@ -0,0 +1,62 @@ +# Copyright (c) 2012 OpenStack, LLC. +# +# 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 quantum.tests.unit import test_db_plugin as test_plugin + + +class RyuPluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase): + + _plugin_name = 'quantum.plugins.ryu.ryu_quantum_plugin.RyuQuantumPluginV2' + + def _patch_fake_ryu_client(self): + ryu_mod = mock.Mock() + ryu_app_mod = ryu_mod.app + ryu_app_client = ryu_app_mod.client + rest_nw_id = ryu_app_mod.rest_nw_id + rest_nw_id.NW_ID_EXTERNAL = '__NW_ID_EXTERNAL__' + rest_nw_id.NW_ID_UNKNOWN = '__NW_ID_UNKNOWN__' + return mock.patch.dict('sys.modules', + {'ryu': ryu_mod, + 'ryu.app': ryu_app_mod, + 'ryu.app.client': ryu_app_client, + 'ryu.app.rest_nw_id': rest_nw_id}) + + def setUp(self): + self.ryu_patcher = self._patch_fake_ryu_client() + self.ryu_patcher.start() + super(RyuPluginV2TestCase, self).setUp(self._plugin_name) + + +class TestRyuBasicGet(test_plugin.TestBasicGet, RyuPluginV2TestCase): + pass + + +class TestRyuV2HTTPResponse(test_plugin.TestV2HTTPResponse, + RyuPluginV2TestCase): + pass + + +class TestRyuPortsV2(test_plugin.TestPortsV2, RyuPluginV2TestCase): + pass + + +class TestRyuNetworksV2(test_plugin.TestNetworksV2, RyuPluginV2TestCase): + pass + + +class TestRyuSubnetsV2(test_plugin.TestSubnetsV2, RyuPluginV2TestCase): + pass