summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-16 13:32:13 +0000
committerGerrit Code Review <review@openstack.org>2017-06-16 13:32:13 +0000
commit9669e0720d3cf87852cbb524e89237173c6f4b06 (patch)
tree84acbf54e06fa1c9247fd7642e6e72b5aa7a43f6
parent1585ed9766ff2ef69a9349e924c6df322c57bf8e (diff)
parent49a012e83c44d28ee533aace22c42b1781b8e5e2 (diff)
Merge "Fixes cached old WMI service objects issue"
-rw-r--r--os_win/tests/unit/utils/compute/test_migrationutils.py1
-rw-r--r--os_win/tests/unit/utils/test_baseutils.py2
-rw-r--r--os_win/utils/baseutils.py14
3 files changed, 12 insertions, 5 deletions
diff --git a/os_win/tests/unit/utils/compute/test_migrationutils.py b/os_win/tests/unit/utils/compute/test_migrationutils.py
index fcd10d8..43be847 100644
--- a/os_win/tests/unit/utils/compute/test_migrationutils.py
+++ b/os_win/tests/unit/utils/compute/test_migrationutils.py
@@ -33,7 +33,6 @@ class MigrationUtilsTestCase(test_base.OsWinBaseTestCase):
33 self._migrationutils = migrationutils.MigrationUtils() 33 self._migrationutils = migrationutils.MigrationUtils()
34 self._migrationutils._vmutils = mock.MagicMock() 34 self._migrationutils._vmutils = mock.MagicMock()
35 self._migrationutils._conn_attr = mock.MagicMock() 35 self._migrationutils._conn_attr = mock.MagicMock()
36 self._migrationutils._compat_conn_attr = mock.MagicMock()
37 self._migrationutils._jobutils = mock.MagicMock() 36 self._migrationutils._jobutils = mock.MagicMock()
38 37
39 def test_get_export_setting_data(self): 38 def test_get_export_setting_data(self):
diff --git a/os_win/tests/unit/utils/test_baseutils.py b/os_win/tests/unit/utils/test_baseutils.py
index 405a560..0e158ef 100644
--- a/os_win/tests/unit/utils/test_baseutils.py
+++ b/os_win/tests/unit/utils/test_baseutils.py
@@ -95,6 +95,7 @@ class BaseUtilsVirtTestCase(test_base.OsWinBaseTestCase):
95 mock_os] 95 mock_os]
96 expected = self.utils._conn.Msvm_VirtualSystemManagementService()[0] 96 expected = self.utils._conn.Msvm_VirtualSystemManagementService()[0]
97 self.assertEqual(expected, self.utils._vs_man_svc) 97 self.assertEqual(expected, self.utils._vs_man_svc)
98 self.assertEqual(expected, self.utils._vs_man_svc_attr)
98 99
99 @mock.patch.object(baseutils, 'imp') 100 @mock.patch.object(baseutils, 'imp')
100 @mock.patch.object(baseutils, 'wmi', create=True) 101 @mock.patch.object(baseutils, 'wmi', create=True)
@@ -108,6 +109,7 @@ class BaseUtilsVirtTestCase(test_base.OsWinBaseTestCase):
108 109
109 expected = old_conn.Msvm_VirtualSystemManagementService()[0] 110 expected = old_conn.Msvm_VirtualSystemManagementService()[0]
110 self.assertEqual(expected, self.utils._vs_man_svc) 111 self.assertEqual(expected, self.utils._vs_man_svc)
112 self.assertIsNone(self.utils._vs_man_svc_attr)
111 mock_imp.load_source.assert_called_once_with( 113 mock_imp.load_source.assert_called_once_with(
112 'old_wmi', '%s.py' % fake_module_path) 114 'old_wmi', '%s.py' % fake_module_path)
113 115
diff --git a/os_win/utils/baseutils.py b/os_win/utils/baseutils.py
index 8eee4cb..5aa304d 100644
--- a/os_win/utils/baseutils.py
+++ b/os_win/utils/baseutils.py
@@ -91,10 +91,16 @@ class BaseUtilsVirt(BaseUtils):
91 91
92 @property 92 @property
93 def _vs_man_svc(self): 93 def _vs_man_svc(self):
94 if not self._vs_man_svc_attr: 94 if self._vs_man_svc_attr:
95 self._vs_man_svc_attr = ( 95 return self._vs_man_svc_attr
96 self._compat_conn.Msvm_VirtualSystemManagementService()[0]) 96
97 return self._vs_man_svc_attr 97 vs_man_svc = self._compat_conn.Msvm_VirtualSystemManagementService()[0]
98 if BaseUtilsVirt._os_version >= [6, 3]:
99 # NOTE(claudiub): caching this property on Windows / Hyper-V Server
100 # 2012 (using the old WMI) can lead to memory leaks. PyMI doesn't
101 # have those issues, so we can safely cache it.
102 self._vs_man_svc_attr = vs_man_svc
103 return vs_man_svc
98 104
99 def _get_wmi_compat_conn(self, moniker, **kwargs): 105 def _get_wmi_compat_conn(self, moniker, **kwargs):
100 # old WMI should be used on Windows / Hyper-V Server 2012 whenever 106 # old WMI should be used on Windows / Hyper-V Server 2012 whenever