From 776270c4b3be0523f2ee2a73792b4a41bb52d6f5 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Fri, 19 Jan 2018 16:22:59 +0200 Subject: [PATCH] Fixes port security settings caching issue When updating the MAC spoofing for a given vswitch port, its Msvm_EthernetSwitchPortSecuritySettingData object is removed and a new one is created, but the original object is not cleared from the cache. Because of this, the next update will fail with a Not Found exception. This patch addresses this issue. Closes-Bug: #1744755 Change-Id: I91b9000c64d269b7d5b1db9e0c6344bbd70e37b2 --- .../tests/unit/utils/network/test_networkutils.py | 12 +++++++----- os_win/utils/network/networkutils.py | 13 +++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/os_win/tests/unit/utils/network/test_networkutils.py b/os_win/tests/unit/utils/network/test_networkutils.py index 3c252f69..32c608d3 100644 --- a/os_win/tests/unit/utils/network/test_networkutils.py +++ b/os_win/tests/unit/utils/network/test_networkutils.py @@ -603,14 +603,16 @@ class NetworkUtilsTestCase(test_base.OsWinBaseTestCase): self.netutils._set_switch_port_security_settings( mock.sentinel.switch_port_name, VirtualSubnetId=mock.sentinel.vsid) - mock_remove_feature = self.netutils._jobutils.remove_virt_feature - mock_remove_feature.assert_called_once_with(mock_sec_settings) self.assertEqual(mock.sentinel.vsid, mock_sec_settings.VirtualSubnetId) - mock_add_feature = self.netutils._jobutils.add_virt_feature - mock_add_feature.assert_called_once_with(mock_sec_settings, - mock_port_alloc) + if missing_sec: + mock_add_feature = self.netutils._jobutils.add_virt_feature + mock_add_feature.assert_called_once_with(mock_sec_settings, + mock_port_alloc) + else: + mock_modify_feature = self.netutils._jobutils.modify_virt_feature + mock_modify_feature.assert_called_once_with(mock_sec_settings) def test_set_switch_port_security_settings(self): self._check_set_switch_port_security_settings() diff --git a/os_win/utils/network/networkutils.py b/os_win/utils/network/networkutils.py index 03238eaa..6eaae0c0 100644 --- a/os_win/utils/network/networkutils.py +++ b/os_win/utils/network/networkutils.py @@ -547,14 +547,12 @@ class NetworkUtils(baseutils.BaseUtilsVirt): sec_settings = self._get_security_setting_data_from_port_alloc( port_alloc) - if sec_settings: + exists = sec_settings is not None + + if exists: if all(getattr(sec_settings, k) == v for k, v in kwargs.items()): # All desired properties already properly set. Nothing to do. return - - # Removing the feature because it cannot be modified - # due to a wmi exception. - self._jobutils.remove_virt_feature(sec_settings) else: sec_settings = self._create_default_setting_data( self._PORT_SECURITY_SET_DATA) @@ -562,7 +560,10 @@ class NetworkUtils(baseutils.BaseUtilsVirt): for k, v in kwargs.items(): setattr(sec_settings, k, v) - self._jobutils.add_virt_feature(sec_settings, port_alloc) + if exists: + self._jobutils.modify_virt_feature(sec_settings) + else: + self._jobutils.add_virt_feature(sec_settings, port_alloc) # TODO(claudiub): This will help solve the missing VSID issue, but it # comes with a performance cost. The root cause of the problem must