diff options
author | Adelina Tuvenie <atuvenie@cloudbasesolutions.com> | 2015-06-04 09:40:45 -0700 |
---|---|---|
committer | Adelina Tuvenie <atuvenie@cloudbasesolutions.com> | 2015-06-05 05:16:16 -0700 |
commit | 7eb617580384f9e077eca0d8a01683ce943ee89e (patch) | |
tree | dced82d56612dd9282e2b619a052a75d34c13713 | |
parent | 65d6eb01b979acba40c9a8bb5e7c18e3716ae867 (diff) | |
download | nova-7eb617580384f9e077eca0d8a01683ce943ee89e.tar.gz |
Adds hostutilsv2 to HyperV
Since RemoteFX works on Windows 2012 R2 it needs the "root\virtualization\v2"
WMI namespace.
This patch adds hostutilsv2 to Hyperv and the corresponding unit tests.
Partially implements blueprint: hyper-v-remotefx
Change-Id: I72e26df03b47d47c478635df39cb5baad6a3b596
-rw-r--r-- | nova/tests/unit/virt/hyperv/test_base.py | 6 | ||||
-rw-r--r-- | nova/tests/unit/virt/hyperv/test_hostutilsv2.py | 30 | ||||
-rw-r--r-- | nova/tests/unit/virt/hyperv/test_imagecache.py | 13 | ||||
-rw-r--r-- | nova/virt/hyperv/hostutils.py | 4 | ||||
-rw-r--r-- | nova/virt/hyperv/hostutilsv2.py | 34 | ||||
-rw-r--r-- | nova/virt/hyperv/utilsfactory.py | 10 |
6 files changed, 90 insertions, 7 deletions
diff --git a/nova/tests/unit/virt/hyperv/test_base.py b/nova/tests/unit/virt/hyperv/test_base.py index 9a5caaeca7..3677bada2b 100644 --- a/nova/tests/unit/virt/hyperv/test_base.py +++ b/nova/tests/unit/virt/hyperv/test_base.py @@ -17,6 +17,7 @@ import mock from nova import test +from nova.virt.hyperv import utilsfactory class HyperVBaseTestCase(test.NoDBTestCase): @@ -25,9 +26,14 @@ class HyperVBaseTestCase(test.NoDBTestCase): wmi_patcher = mock.patch('__builtin__.wmi', create=True) platform_patcher = mock.patch('sys.platform', 'win32') + hostutils_patcher = mock.patch.object(utilsfactory, 'utils') platform_patcher.start() wmi_patcher.start() + patched_hostutils = hostutils_patcher.start() + + patched_hostutils.check_min_windows_version.return_value = False self.addCleanup(wmi_patcher.stop) self.addCleanup(platform_patcher.stop) + self.addCleanup(hostutils_patcher.stop) diff --git a/nova/tests/unit/virt/hyperv/test_hostutilsv2.py b/nova/tests/unit/virt/hyperv/test_hostutilsv2.py new file mode 100644 index 0000000000..b2e426bf71 --- /dev/null +++ b/nova/tests/unit/virt/hyperv/test_hostutilsv2.py @@ -0,0 +1,30 @@ +# Copyright 2015 Cloudbase Solutions Srl +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from nova import test +from nova.virt.hyperv import hostutilsv2 + + +class HostUtilsV2TestCase(test.NoDBTestCase): + """Unit tests for the Hyper-V hostutilsv2 class.""" + + def setUp(self): + self._hostutils = hostutilsv2.HostUtilsV2() + self._hostutils._conn_cimv2 = mock.MagicMock() + self._hostutils._conn_virt = mock.MagicMock() + + super(HostUtilsV2TestCase, self).setUp() diff --git a/nova/tests/unit/virt/hyperv/test_imagecache.py b/nova/tests/unit/virt/hyperv/test_imagecache.py index 401dd5ccfe..7478469205 100644 --- a/nova/tests/unit/virt/hyperv/test_imagecache.py +++ b/nova/tests/unit/virt/hyperv/test_imagecache.py @@ -44,14 +44,19 @@ class ImageCacheTestCase(test.NoDBTestCase): # utilsfactory will check the host OS version via get_hostutils, # in order to return the proper Utils Class, so it must be mocked. - patched_func = mock.patch.object(imagecache.utilsfactory, - "get_hostutils") + patched_get_hostutils = mock.patch.object(imagecache.utilsfactory, + "get_hostutils") patched_get_pathutils = mock.patch.object(imagecache.utilsfactory, "get_pathutils") - patched_func.start() + patched_get_vhdutils = mock.patch.object(imagecache.utilsfactory, + "get_vhdutils") + patched_get_hostutils.start() patched_get_pathutils.start() - self.addCleanup(patched_func.stop) + patched_get_vhdutils.start() + + self.addCleanup(patched_get_hostutils.stop) self.addCleanup(patched_get_pathutils.stop) + self.addCleanup(patched_get_vhdutils.stop) self.imagecache = imagecache.ImageCache() self.imagecache._pathutils = mock.MagicMock() diff --git a/nova/virt/hyperv/hostutils.py b/nova/virt/hyperv/hostutils.py index 1f56ed403d..7f073e6a9c 100644 --- a/nova/virt/hyperv/hostutils.py +++ b/nova/virt/hyperv/hostutils.py @@ -33,6 +33,10 @@ class HostUtils(object): def __init__(self): if sys.platform == 'win32': self._conn_cimv2 = wmi.WMI(privileges=["Shutdown"]) + self._init_wmi_virt_conn() + + def _init_wmi_virt_conn(self): + self._conn_virt = None def get_cpus_info(self): cpus = self._conn_cimv2.query("SELECT * FROM Win32_Processor " diff --git a/nova/virt/hyperv/hostutilsv2.py b/nova/virt/hyperv/hostutilsv2.py new file mode 100644 index 0000000000..7bed7a5797 --- /dev/null +++ b/nova/virt/hyperv/hostutilsv2.py @@ -0,0 +1,34 @@ +# Copyright 2015 Cloudbase Solutions Srl +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import sys + +if sys.platform == 'win32': + import wmi + +from nova.virt.hyperv import hostutils + + +class HostUtilsV2(hostutils.HostUtils): + + FEATURE_RDS_VIRTUALIZATION = 322 + + def __init__(self): + super(HostUtilsV2, self).__init__() + self._init_wmi_virt_conn() + + def _init_wmi_virt_conn(self): + if sys.platform == 'win32': + self._conn_virt = wmi.WMI(moniker='//./root/virtualization/v2') diff --git a/nova/virt/hyperv/utilsfactory.py b/nova/virt/hyperv/utilsfactory.py index 9ff0216450..453993bde3 100644 --- a/nova/virt/hyperv/utilsfactory.py +++ b/nova/virt/hyperv/utilsfactory.py @@ -18,6 +18,7 @@ from oslo_log import log as logging from nova.i18n import _ from nova.virt.hyperv import hostutils +from nova.virt.hyperv import hostutilsv2 from nova.virt.hyperv import livemigrationutils from nova.virt.hyperv import networkutils from nova.virt.hyperv import networkutilsv2 @@ -45,11 +46,13 @@ CONF.register_opts(hyper_opts, 'hyperv') LOG = logging.getLogger(__name__) +utils = hostutils.HostUtils() + def _get_class(v1_class, v2_class, force_v1_flag): # V2 classes are supported starting from Hyper-V Server 2012 and # Windows Server 2012 (kernel version 6.2) - if not force_v1_flag and get_hostutils().check_min_windows_version(6, 2): + if not force_v1_flag and utils.check_min_windows_version(6, 2): cls = v2_class else: cls = v1_class @@ -63,7 +66,7 @@ def _get_virt_utils_class(v1_class, v2_class): # Windows Server / Hyper-V Server 2012 R2 / Windows 8.1 # (kernel version 6.3) or above. if (CONF.hyperv.force_hyperv_utils_v1 and - get_hostutils().check_min_windows_version(6, 3)): + utils.check_min_windows_version(6, 3)): raise vmutils.HyperVException( _('The "force_hyperv_utils_v1" option cannot be set to "True" ' 'on Windows Server / Hyper-V Server 2012 R2 or above as the WMI ' @@ -85,7 +88,8 @@ def get_networkutils(): def get_hostutils(): - return hostutils.HostUtils() + return _get_virt_utils_class(hostutils.HostUtils, + hostutilsv2.HostUtilsV2)() def get_pathutils(): |