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_name>_plugin test module. This commit excludes cisco and metaplugin plugins, which do not run the "core" unit tests at all. Change-Id: I137411f47d8cfcc753aa3a88359f5b1590ca8237
This commit is contained in:
parent
59b78892b0
commit
54fc3c2cb9
@ -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)
|
||||
|
@ -71,6 +71,7 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
||||
'application/json': json_deserializer,
|
||||
}
|
||||
|
||||
if not plugin:
|
||||
plugin = test_config.get('plugin_name_v2', DB_PLUGIN_KLASS)
|
||||
# Create the default configurations
|
||||
args = ['--config-file', etcdir('quantum.conf.test')]
|
||||
|
50
quantum/tests/unit/test_linuxbridge_plugin.py
Normal file
50
quantum/tests/unit/test_linuxbridge_plugin.py
Normal file
@ -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
|
45
quantum/tests/unit/test_nec_plugin.py
Normal file
45
quantum/tests/unit/test_nec_plugin.py
Normal file
@ -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
|
74
quantum/tests/unit/test_nicira_plugin.py
Normal file
74
quantum/tests/unit/test_nicira_plugin.py
Normal file
@ -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
|
50
quantum/tests/unit/test_openvswitch_plugin.py
Normal file
50
quantum/tests/unit/test_openvswitch_plugin.py
Normal file
@ -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
|
@ -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"
|
||||
|
62
quantum/tests/unit/test_ryu_plugin.py
Normal file
62
quantum/tests/unit/test_ryu_plugin.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user