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
This commit is contained in:
Claudiu Belu 2018-01-19 16:22:59 +02:00
parent bbaa712277
commit 776270c4b3
2 changed files with 14 additions and 11 deletions

View File

@ -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()

View File

@ -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