From fed74dfcb63395347b6689511c30b7c6d9a1cab1 Mon Sep 17 00:00:00 2001 From: Roey Chen Date: Wed, 4 Nov 2015 08:38:31 -0800 Subject: [PATCH] Fix unittests for port-security and security-groups Both test classes were not testing the actual plugin due to wrong inheritance hierarchy. Change-Id: Idf8057f0e43fc7b10c4f50800f1477ed61ce01d2 --- vmware_nsx/plugins/nsx_v3/plugin.py | 2 ++ .../tests/unit/extensions/test_portsecurity.py | 16 +++++----------- vmware_nsx/tests/unit/nsx_mh/test_plugin.py | 4 ++-- vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 6 +++--- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index c147beb356..d8ddb2f640 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -395,6 +395,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, created_net = super(NsxV3Plugin, self).create_network(context, network) + if psec.PORTSECURITY not in net_data: + net_data[psec.PORTSECURITY] = True self._process_network_port_security_create( context, net_data, created_net) self._process_l3_create(context, created_net, net_data) diff --git a/vmware_nsx/tests/unit/extensions/test_portsecurity.py b/vmware_nsx/tests/unit/extensions/test_portsecurity.py index 9865a38274..68060a5b6b 100644 --- a/vmware_nsx/tests/unit/extensions/test_portsecurity.py +++ b/vmware_nsx/tests/unit/extensions/test_portsecurity.py @@ -20,7 +20,7 @@ from vmware_nsx.common import sync from vmware_nsx.tests import unit as vmware from vmware_nsx.tests.unit.nsx_mh.apiclient import fake from vmware_nsx.tests.unit.nsx_v3 import test_constants as v3_constants -from vmware_nsx.tests.unit.nsxlib.v3 import nsxlib_testcase +from vmware_nsx.tests.unit.nsx_v3 import test_plugin as test_nsxv3 from vmware_nsx.tests.unit import test_utils @@ -48,13 +48,7 @@ class TestPortSecurityNSXv2(PortSecurityTestCaseNSXv2, psec.TestPortSecurity): pass -class PortSecurityTestCaseNSXv3(nsxlib_testcase.NsxClientTestCase, - psec.PortSecurityDBTestCase): - def setUp(self, *args, **kwargs): - super(PortSecurityTestCaseNSXv3, self).setUp( - plugin=v3_constants.PLUGIN_NAME) - - -class TestPortSecurityNSXv3(PortSecurityTestCaseNSXv3, - psec.TestPortSecurity): - pass +class TestPortSecurityNSXv3(psec.TestPortSecurity, + test_nsxv3.NsxV3PluginTestCaseMixin): + def setUp(self, plugin=v3_constants.PLUGIN_NAME): + super(TestPortSecurityNSXv3, self).setUp(plugin=plugin) diff --git a/vmware_nsx/tests/unit/nsx_mh/test_plugin.py b/vmware_nsx/tests/unit/nsx_mh/test_plugin.py index b5747bf359..91decb0966 100644 --- a/vmware_nsx/tests/unit/nsx_mh/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_mh/test_plugin.py @@ -77,8 +77,8 @@ class NsxPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): attrs.update(providernet_args) for arg in (('admin_state_up', 'tenant_id', 'shared') + (arg_list or ())): - # Arg must be present and not empty - if arg in kwargs and kwargs[arg]: + # Arg must be present + if arg in kwargs: data['network'][arg] = kwargs[arg] network_req = self.new_create_request('networks', data, fmt) if (kwargs.get('set_context') and 'tenant_id' in kwargs): diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index 40dc70972e..fb652870fa 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -97,8 +97,8 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase, attrs.update(providernet_args) for arg in (('admin_state_up', 'tenant_id', 'shared') + (arg_list or ())): - # Arg must be present and not empty - if arg in kwargs and kwargs[arg]: + # Arg must be present + if arg in kwargs: data['network'][arg] = kwargs[arg] network_req = self.new_create_request('networks', data, fmt) if (kwargs.get('set_context') and 'tenant_id' in kwargs): @@ -133,7 +133,7 @@ class TestPortsV2(test_plugin.TestPortsV2, NsxV3PluginTestCaseMixin): data['port']['fixed_ips']) -class TestSecurityGroups(ext_sg.TestSecurityGroups, NsxV3PluginTestCaseMixin): +class TestSecurityGroups(NsxV3PluginTestCaseMixin, ext_sg.TestSecurityGroups): pass