From 76969e91b4850c43a577bf88055a92e4140c55fc Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 5 Dec 2016 08:56:11 +0200 Subject: [PATCH] Remove NSGroup manager unit tests Those tests were moved to vmware-nsxlib in commit I9702da0b56fd03c6c09e1902ca167a01ccc730a7 Change-Id: I3567a81bd8e0e2ad029f8a22cb6e74c5ad28330a --- .../unit/extensions/test_securitygroup.py | 139 ------------------ 1 file changed, 139 deletions(-) diff --git a/vmware_nsx/tests/unit/extensions/test_securitygroup.py b/vmware_nsx/tests/unit/extensions/test_securitygroup.py index 9366b58f31..b978ea894d 100644 --- a/vmware_nsx/tests/unit/extensions/test_securitygroup.py +++ b/vmware_nsx/tests/unit/extensions/test_securitygroup.py @@ -19,9 +19,7 @@ from neutron.tests.unit.extensions import test_securitygroup as test_ext_sg from vmware_nsx.plugins.nsx_v3 import plugin as nsx_plugin from vmware_nsx.tests.unit.nsx_v3 import test_plugin as test_nsxv3 -from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase from vmware_nsxlib.v3 import exceptions as nsxlib_exc -from vmware_nsxlib.v3 import ns_group_manager from vmware_nsxlib.v3 import nsx_constants as consts @@ -179,140 +177,3 @@ class TestSecurityGroupsNoDynamicCriteria(test_nsxv3.NsxV3PluginTestCaseMixin, def test_create_security_group_rule_icmpv6_legacy_protocol_name(self): self.skipTest('not supported') - - -class TestNSGroupManager(nsxlib_testcase.NsxLibTestCase): - """ - This test suite is responsible for unittesting of class - vmware_nsxlib.v3.ns_group_manager.NSGroupManager. - """ - - @_mock_create_and_list_nsgroups - def test_first_initialization(self): - size = 5 - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - nested_groups = cont_manager.nested_groups - self.assertEqual({i: NSG_IDS[i] for i in range(size)}, - nested_groups) - - @_mock_create_and_list_nsgroups - def test_reconfigure_number_of_nested_groups(self): - # We need to test that when changing the number of nested groups then - # the NSGroupManager picks the ones which were previously created - # and create the ones which are missing, which also verifies that it - # also recognizes existing nested groups. - - size = 2 - # Creates 2 nested groups. - ns_group_manager.NSGroupManager(self.nsxlib, size) - - size = 5 - # Creates another 3 nested groups. - nested_groups = ns_group_manager.NSGroupManager( - self.nsxlib, size).nested_groups - self.assertEqual({i: NSG_IDS[i] for i in range(size)}, - nested_groups) - - @_mock_create_and_list_nsgroups - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.remove_member') - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.add_members') - def test_add_and_remove_nsgroups(self, - add_member_mock, - remove_member_mock): - # We verify that when adding a new nsgroup the properly placed - # according to its id and the number of nested groups. - - size = 5 - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - nsgroup_id = 'nsgroup_id' - - with mock.patch.object(cont_manager, '_hash_uuid', return_value=7): - cont_manager.add_nsgroup(nsgroup_id) - cont_manager.remove_nsgroup(nsgroup_id) - - # There are 5 nested groups, the hash function will return 7, therefore - # we expect that the nsgroup will be placed in the 3rd group. - add_member_mock.assert_called_once_with( - NSG_IDS[2], consts.NSGROUP, [nsgroup_id]) - remove_member_mock.assert_called_once_with( - NSG_IDS[2], consts.NSGROUP, nsgroup_id, - verify=True) - - @_mock_create_and_list_nsgroups - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.remove_member') - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.add_members') - def test_when_nested_group_is_full(self, - add_member_mock, - remove_member_mock): - - def _add_member_mock(nsgroup, target_type, target_id): - if nsgroup == NSG_IDS[2]: - raise nsxlib_exc.NSGroupIsFull(nsgroup_id=nsgroup) - - def _remove_member_mock(nsgroup, target_type, target_id, verify=False): - if nsgroup == NSG_IDS[2]: - raise nsxlib_exc.NSGroupMemberNotFound(nsgroup_id=nsgroup, - member_id=target_id) - - add_member_mock.side_effect = _add_member_mock - remove_member_mock.side_effect = _remove_member_mock - - size = 5 - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - nsgroup_id = 'nsgroup_id' - - with mock.patch.object(cont_manager, '_hash_uuid', return_value=7): - cont_manager.add_nsgroup(nsgroup_id) - cont_manager.remove_nsgroup(nsgroup_id) - - # Trying to add nsgroup to the nested group at index 2 will raise - # NSGroupIsFull exception, we expect that the nsgroup will be added to - # the nested group at index 3. - calls = [mock.call(NSG_IDS[2], - consts.NSGROUP, [nsgroup_id]), - mock.call(NSG_IDS[3], - consts.NSGROUP, [nsgroup_id])] - add_member_mock.assert_has_calls(calls) - - # Since the nsgroup was added to the nested group at index 3, it will - # fail to remove it from the group at index 2, and then will try to - # remove it from the group at index 3. - calls = [ - mock.call( - NSG_IDS[2], consts.NSGROUP, - nsgroup_id, verify=True), - mock.call( - NSG_IDS[3], consts.NSGROUP, - nsgroup_id, verify=True)] - remove_member_mock.assert_has_calls(calls) - - @_mock_create_and_list_nsgroups - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.remove_member') - @mock.patch('vmware_nsxlib.v3.security.NsxLibNsGroup.add_members') - def test_initialize_with_absent_nested_groups(self, - add_member_mock, - remove_member_mock): - size = 3 - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - # list_nsgroups will return nested group 1 and 3, but not group 2. - nsgroups = cont_manager.nsxlib_nsgroup.list() - with mock.patch("vmware_nsxlib.v3.security.NsxLibNsGroup.list", - side_effect=lambda: nsgroups[::2]): - # invoking the initialization process again, it should process - # groups 1 and 3 and create group 2. - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - self.assertEqual({0: NSG_IDS[0], - 1: NSG_IDS[3], - 2: NSG_IDS[2]}, - cont_manager.nested_groups) - - @_mock_create_and_list_nsgroups - def test_suggest_nested_group(self): - size = 5 - cont_manager = ns_group_manager.NSGroupManager(self.nsxlib, size) - # We expect that the first suggested index is 2 - expected_suggested_groups = NSG_IDS[2:5] + NSG_IDS[:2] - suggest_group = lambda: cont_manager._suggest_nested_group('fake-id') - with mock.patch.object(cont_manager, '_hash_uuid', return_value=7): - for i, suggested in enumerate(suggest_group()): - self.assertEqual(expected_suggested_groups[i], suggested)