Merge "Fixes cached old WMI service objects issue"

This commit is contained in:
Jenkins 2017-06-16 13:32:13 +00:00 committed by Gerrit Code Review
commit 9669e0720d
3 changed files with 12 additions and 5 deletions

View File

@ -33,7 +33,6 @@ class MigrationUtilsTestCase(test_base.OsWinBaseTestCase):
self._migrationutils = migrationutils.MigrationUtils()
self._migrationutils._vmutils = mock.MagicMock()
self._migrationutils._conn_attr = mock.MagicMock()
self._migrationutils._compat_conn_attr = mock.MagicMock()
self._migrationutils._jobutils = mock.MagicMock()
def test_get_export_setting_data(self):

View File

@ -95,6 +95,7 @@ class BaseUtilsVirtTestCase(test_base.OsWinBaseTestCase):
mock_os]
expected = self.utils._conn.Msvm_VirtualSystemManagementService()[0]
self.assertEqual(expected, self.utils._vs_man_svc)
self.assertEqual(expected, self.utils._vs_man_svc_attr)
@mock.patch.object(baseutils, 'imp')
@mock.patch.object(baseutils, 'wmi', create=True)
@ -108,6 +109,7 @@ class BaseUtilsVirtTestCase(test_base.OsWinBaseTestCase):
expected = old_conn.Msvm_VirtualSystemManagementService()[0]
self.assertEqual(expected, self.utils._vs_man_svc)
self.assertIsNone(self.utils._vs_man_svc_attr)
mock_imp.load_source.assert_called_once_with(
'old_wmi', '%s.py' % fake_module_path)

View File

@ -91,10 +91,16 @@ class BaseUtilsVirt(BaseUtils):
@property
def _vs_man_svc(self):
if not self._vs_man_svc_attr:
self._vs_man_svc_attr = (
self._compat_conn.Msvm_VirtualSystemManagementService()[0])
return self._vs_man_svc_attr
if self._vs_man_svc_attr:
return self._vs_man_svc_attr
vs_man_svc = self._compat_conn.Msvm_VirtualSystemManagementService()[0]
if BaseUtilsVirt._os_version >= [6, 3]:
# NOTE(claudiub): caching this property on Windows / Hyper-V Server
# 2012 (using the old WMI) can lead to memory leaks. PyMI doesn't
# have those issues, so we can safely cache it.
self._vs_man_svc_attr = vs_man_svc
return vs_man_svc
def _get_wmi_compat_conn(self, moniker, **kwargs):
# old WMI should be used on Windows / Hyper-V Server 2012 whenever