Improve startup performance of nova-compute Hyper-V driver

During the nova-compute driver startup, a lot of calls are made to
get_windows_version slowing down startup.
This patch speeds up the startup by caching the windows version to
be used for later calls of get_windows_version.

Change-Id: I5b2eadc0bce79cd261a5dcaac7712c23c49dfcc2
This commit is contained in:
Alin Balutoiu 2015-12-07 18:28:24 +02:00
parent 343788b005
commit 24d7079ad5
2 changed files with 15 additions and 2 deletions

View File

@ -26,6 +26,8 @@ from hyperv.nova import constants
class HostUtils(object):
_windows_version = None
_HOST_FORCED_REBOOT = 6
_HOST_FORCED_SHUTDOWN = 12
_DEFAULT_VM_GENERATION = constants.IMAGE_PROP_VM_GEN_1
@ -79,8 +81,10 @@ class HostUtils(object):
return list(map(int, version_str.split('.'))) >= [major, minor, build]
def get_windows_version(self):
if self._conn_cimv2:
return self._conn_cimv2.Win32_OperatingSystem()[0].Version
if not HostUtils._windows_version and self._conn_cimv2:
Win32_OperatingSystem = self._conn_cimv2.Win32_OperatingSystem()[0]
HostUtils._windows_version = Win32_OperatingSystem.Version
return HostUtils._windows_version
def get_local_ips(self):
addr_info = socket.getaddrinfo(socket.gethostname(), None, 0, 0, 0)

View File

@ -94,9 +94,18 @@ class HostUtilsTestCase(test.NoDBTestCase):
os = mock.MagicMock()
os.Version = version
self._hostutils._conn_cimv2.Win32_OperatingSystem.return_value = [os]
hostutils.HostUtils._windows_version = None
self.assertEqual(expected,
self._hostutils.check_min_windows_version(6, 2))
def test_get_windows_version(self):
os = mock.MagicMock()
os.Version = self._FAKE_VERSION_GOOD
self._hostutils._conn_cimv2.Win32_OperatingSystem.return_value = [os]
hostutils.HostUtils._windows_version = None
self.assertEqual(self._FAKE_VERSION_GOOD,
self._hostutils.get_windows_version())
def _test_host_power_action(self, action):
fake_win32 = mock.MagicMock()
fake_win32.Win32Shutdown = mock.MagicMock()