resync and cleanup
Solve some minor differences between nova and compute-hyperv, and cleanup some unit tests. Change-Id: Id2971cdf582d9681d6e40d27940e0a145a325d91
This commit is contained in:
parent
c2e8cc605c
commit
588b84cade
|
@ -110,8 +110,3 @@ OPTIONAL = "optional"
|
|||
|
||||
IMAGE_PROP_VTPM = "os_vtpm"
|
||||
IMAGE_PROP_VTPM_SHIELDED = "os_shielded_vm"
|
||||
|
||||
BOOT_DEVICE_FLOPPY = 0
|
||||
BOOT_DEVICE_CDROM = 1
|
||||
BOOT_DEVICE_HARDDISK = 2
|
||||
BOOT_DEVICE_NETWORK = 3
|
||||
|
|
|
@ -320,8 +320,8 @@ class HyperVDriver(driver.ComputeDriver):
|
|||
retry_interval)
|
||||
|
||||
def confirm_migration(self, context, migration, instance, network_info):
|
||||
self._migrationops.confirm_migration(context, migration, instance,
|
||||
network_info)
|
||||
self._migrationops.confirm_migration(context, migration,
|
||||
instance, network_info)
|
||||
|
||||
def finish_revert_migration(self, context, instance, network_info,
|
||||
block_device_info=None, power_on=True):
|
||||
|
|
|
@ -185,13 +185,13 @@ class HostOps(object):
|
|||
'hypervisor_hostname': platform.node(),
|
||||
'vcpus_used': 0,
|
||||
'cpu_info': jsonutils.dumps(cpu_info),
|
||||
'supported_instances':
|
||||
[(obj_fields.Architecture.I686,
|
||||
obj_fields.HVType.HYPERV,
|
||||
obj_fields.VMMode.HVM),
|
||||
(obj_fields.Architecture.X86_64,
|
||||
obj_fields.HVType.HYPERV,
|
||||
obj_fields.VMMode.HVM)],
|
||||
'supported_instances': [
|
||||
(obj_fields.Architecture.I686,
|
||||
obj_fields.HVType.HYPERV,
|
||||
obj_fields.VMMode.HVM),
|
||||
(obj_fields.Architecture.X86_64,
|
||||
obj_fields.HVType.HYPERV,
|
||||
obj_fields.VMMode.HVM)],
|
||||
'numa_topology': self._get_host_numa_topology()._to_json(),
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ class PathUtils(pathutils.PathUtils):
|
|||
|
||||
def __init__(self):
|
||||
super(PathUtils, self).__init__()
|
||||
self._smbutils = utilsfactory.get_smbutils()
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
|
||||
def get_instances_dir(self, remote_server=None):
|
||||
|
|
|
@ -40,9 +40,6 @@ class VolumeOps(object):
|
|||
"""Management class for Volume-related tasks
|
||||
"""
|
||||
|
||||
_SUPPORTED_QOS_SPECS = ['total_bytes_sec', 'min_bytes_sec',
|
||||
'total_iops_sec', 'min_iops_sec']
|
||||
|
||||
def __init__(self):
|
||||
self._vmutils = utilsfactory.get_vmutils()
|
||||
self._default_root_device = 'vda'
|
||||
|
|
|
@ -184,9 +184,6 @@ class HostOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
mock_gpu_info = self._get_mock_gpu_info()
|
||||
mock_get_gpu_info.return_value = mock_gpu_info
|
||||
|
||||
self._hostops._hostutils.get_supported_vm_types.return_value = [
|
||||
constants.IMAGE_PROP_VM_GEN_1]
|
||||
|
||||
response = self._hostops.get_available_resource()
|
||||
|
||||
mock_get_memory_info.assert_called_once_with()
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
|
@ -34,7 +35,6 @@ CONF = cfg.CONF
|
|||
class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
||||
"""Unit tests for the Hyper-V ImageCache class."""
|
||||
|
||||
FAKE_BASE_DIR = 'fake/base/dir'
|
||||
FAKE_FORMAT = 'fake_format'
|
||||
FAKE_IMAGE_REF = 'fake_image_ref'
|
||||
FAKE_VHD_SIZE_GB = 1
|
||||
|
@ -49,6 +49,8 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
self.imagecache._pathutils = mock.MagicMock()
|
||||
self.imagecache._vhdutils = mock.MagicMock()
|
||||
|
||||
self.tmpdir = self.useFixture(fixtures.TempDir()).path
|
||||
|
||||
def _test_get_root_vhd_size_gb(self, old_flavor=True):
|
||||
if old_flavor:
|
||||
mock_flavor = objects.Flavor(**test_flavor.fake_flavor)
|
||||
|
@ -92,7 +94,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
self.instance.image_ref = self.FAKE_IMAGE_REF
|
||||
self.instance.system_metadata = {'image_disk_format': image_format}
|
||||
self.imagecache._pathutils.get_base_vhd_dir.return_value = (
|
||||
self.FAKE_BASE_DIR)
|
||||
self.tmpdir)
|
||||
self.imagecache._pathutils.exists.return_value = path_exists
|
||||
self.imagecache._vhdutils.get_vhd_format.return_value = (
|
||||
constants.DISK_FORMAT_VHD)
|
||||
|
@ -100,7 +102,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
CONF.set_override('use_cow_images', use_cow)
|
||||
|
||||
image_file_name = rescue_image_id or self.FAKE_IMAGE_REF
|
||||
expected_path = os.path.join(self.FAKE_BASE_DIR,
|
||||
expected_path = os.path.join(self.tmpdir,
|
||||
image_file_name)
|
||||
expected_vhd_path = "%s.%s" % (expected_path,
|
||||
constants.DISK_FORMAT_VHD.lower())
|
||||
|
@ -190,7 +192,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
self.imagecache._age_and_verify_cached_images(
|
||||
mock.sentinel.FAKE_CONTEXT,
|
||||
mock.sentinel.all_instances,
|
||||
mock.sentinel.FAKE_BASE_DIR)
|
||||
self.tmpdir)
|
||||
|
||||
self.imagecache._update_image_timestamp.assert_called_once_with(
|
||||
mock.sentinel.FAKE_IMG1)
|
||||
|
@ -238,7 +240,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
|
|||
mock_get_backing_files.assert_called_once_with(mock.sentinel.image)
|
||||
|
||||
def test_remove_old_image(self):
|
||||
fake_img_path = os.path.join(self.FAKE_BASE_DIR,
|
||||
fake_img_path = os.path.join(self.tmpdir,
|
||||
self.FAKE_IMAGE_REF)
|
||||
self.imagecache._remove_old_image(fake_img_path)
|
||||
self.imagecache._pathutils.remove.assert_called_once_with(
|
||||
|
|
|
@ -255,18 +255,17 @@ class PathUtilsTestCase(test_base.HyperVBaseTestCase):
|
|||
fake_image_name = 'fake_image_name'
|
||||
if found:
|
||||
mock_exists.side_effect = [False, True]
|
||||
expected_path = os.path.join('fake_base_dir',
|
||||
'fake_image_name.vhdx')
|
||||
else:
|
||||
mock_exists.return_value = False
|
||||
expected_path = None
|
||||
mock_get_base_vhd_dir.return_value = 'fake_base_dir'
|
||||
|
||||
res = self._pathutils.get_image_path(fake_image_name)
|
||||
|
||||
mock_get_base_vhd_dir.assert_called_once_with()
|
||||
if found:
|
||||
self.assertEqual(
|
||||
res, os.path.join('fake_base_dir', 'fake_image_name.vhdx'))
|
||||
else:
|
||||
self.assertIsNone(res)
|
||||
self.assertEqual(expected_path, res)
|
||||
|
||||
def test_get_image_path(self):
|
||||
self._test_get_image_path()
|
||||
|
|
|
@ -603,6 +603,9 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
instance_path = os.path.join(CONF.instances_path, mock_instance.name)
|
||||
mock_requires_secure_boot.return_value = True
|
||||
|
||||
flavor = flavor_obj.Flavor(**test_flavor.fake_flavor)
|
||||
mock_instance.flavor = flavor
|
||||
|
||||
if vnuma_enabled:
|
||||
mock_get_vnuma_config.return_value = (
|
||||
mock.sentinel.mem_per_numa, mock.sentinel.cpus_per_numa)
|
||||
|
@ -614,16 +617,12 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
mem_per_numa, cpus_per_numa = (None, None)
|
||||
dynamic_memory_ratio = CONF.hyperv.dynamic_memory_ratio
|
||||
|
||||
flavor = flavor_obj.Flavor(**test_flavor.fake_flavor)
|
||||
mock_instance.flavor = flavor
|
||||
|
||||
self._vmops.create_instance(
|
||||
context=self.context,
|
||||
instance=mock_instance,
|
||||
network_info=[fake_network_info],
|
||||
block_device_info=block_device_info,
|
||||
vm_gen=vm_gen,
|
||||
image_meta=mock.sentinel.image_meta)
|
||||
self._vmops.create_instance(context=self.context,
|
||||
instance=mock_instance,
|
||||
network_info=[fake_network_info],
|
||||
block_device_info=block_device_info,
|
||||
vm_gen=vm_gen,
|
||||
image_meta=mock.sentinel.image_meta)
|
||||
|
||||
mock_get_vnuma_config.assert_called_once_with(mock_instance,
|
||||
mock.sentinel.image_meta)
|
||||
|
@ -810,16 +809,6 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
mock.sentinel.FAKE_DRIVE_ADDR, mock.sentinel.FAKE_CTRL_DISK_ADDR,
|
||||
constants.DISK)
|
||||
|
||||
def _check_get_image_vm_gen_except(self, image_prop):
|
||||
image_meta = {"properties": {constants.IMAGE_PROP_VM_GEN: image_prop}}
|
||||
self._vmops._hostutils.get_supported_vm_types.return_value = [
|
||||
constants.IMAGE_PROP_VM_GEN_1, constants.IMAGE_PROP_VM_GEN_2]
|
||||
|
||||
self.assertRaises(exception.InstanceUnacceptable,
|
||||
self._vmops.get_image_vm_generation,
|
||||
mock.sentinel.instance_id,
|
||||
image_meta)
|
||||
|
||||
def test_get_image_vm_generation_default(self):
|
||||
image_meta = {"properties": {}}
|
||||
self._vmops._hostutils.get_default_vm_generation.return_value = (
|
||||
|
@ -844,7 +833,15 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self.assertEqual(constants.VM_GEN_2, response)
|
||||
|
||||
def test_get_image_vm_generation_bad_prop(self):
|
||||
self._check_get_image_vm_gen_except(mock.sentinel.FAKE_IMAGE_PROP)
|
||||
image_meta = {"properties":
|
||||
{constants.IMAGE_PROP_VM_GEN: mock.sentinel.bad_prop}}
|
||||
self._vmops._hostutils.get_supported_vm_types.return_value = [
|
||||
constants.IMAGE_PROP_VM_GEN_1, constants.IMAGE_PROP_VM_GEN_2]
|
||||
|
||||
self.assertRaises(exception.InstanceUnacceptable,
|
||||
self._vmops.get_image_vm_generation,
|
||||
mock.sentinel.instance_id,
|
||||
image_meta)
|
||||
|
||||
def test_check_vm_image_type_exception(self):
|
||||
self._vmops._vhdutils.get_vhd_format.return_value = (
|
||||
|
|
Loading…
Reference in New Issue