Make hyperv driver use flavor fields instead of legacy ones

This makes the hyperv driver use instance.flavor.root_gb instead
of the legacy instance.root_gb field (and friends).

Also note I believe I found a bug in the
test_cache_rescue_image_bigger_than_flavor test, which was not
properly returning an image size in bytes. This was passing only
because the fake_instance object had a root_gb of 0, which made
the unit disparity moot.

Change-Id: I03207a267f1ffb21ea464165c1910f66962caab6
This commit is contained in:
Dan Smith
2016-07-12 10:02:57 -07:00
parent 7a4356c287
commit a25e0b3f39
6 changed files with 18 additions and 18 deletions

View File

@@ -75,7 +75,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
def test_get_root_vhd_size_gb(self):
ret_val = self._test_get_root_vhd_size_gb(old_flavor=False)
self.assertEqual(self.instance.root_gb, ret_val)
self.assertEqual(self.instance.flavor.root_gb, ret_val)
@mock.patch.object(imagecache.ImageCache, '_get_root_vhd_size_gb')
def test_resize_and_cache_vhd_smaller(self, mock_get_vhd_size_gb):
@@ -166,7 +166,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
fake_rescue_image_id = 'fake_rescue_image_id'
self.imagecache._vhdutils.get_vhd_info.return_value = {
'VirtualSize': self.instance.root_gb + 1}
'VirtualSize': (self.instance.flavor.root_gb + 1) * units.Gi}
(expected_path,
expected_vhd_path) = self._prepare_get_cached_image(
rescue_image_id=fake_rescue_image_id)

View File

@@ -140,7 +140,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase):
def test_check_target_flavor(self):
mock_instance = fake_instance.fake_instance_obj(self.context)
mock_instance.root_gb = 1
mock_instance.flavor.root_gb = 1
mock_flavor = mock.MagicMock(root_gb=0)
self.assertRaises(exception.InstanceFaultRollback,
self._migrationops._check_target_flavor,
@@ -376,7 +376,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase):
mock_check_attach_config_drive,
disk_type=constants.DISK):
mock_instance = fake_instance.fake_instance_obj(self.context)
mock_instance.ephemeral_gb = 1
mock_instance.flavor.ephemeral_gb = 1
root_device = {'type': disk_type}
block_device_info = {'root_disk': root_device, 'ephemerals': []}
@@ -404,7 +404,7 @@ class MigrationOpsTestCase(test_base.HyperVBaseTestCase):
mock_vhd_info.get.return_value)
expected_check_resize.append(
mock.call(root_device_path, mock_vhd_info,
mock_instance.root_gb * units.Gi))
mock_instance.flavor.root_gb * units.Gi))
ephemerals = block_device_info['ephemerals']
mock_check_eph_disks.assert_called_once_with(

View File

@@ -172,12 +172,12 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
def _prepare_create_root_device_mocks(self, use_cow_images, vhd_format,
vhd_size):
mock_instance = fake_instance.fake_instance_obj(self.context)
mock_instance.root_gb = self.FAKE_SIZE
mock_instance.flavor.root_gb = self.FAKE_SIZE
self.flags(use_cow_images=use_cow_images)
self._vmops._vhdutils.get_vhd_info.return_value = {'VirtualSize':
vhd_size * units.Gi}
self._vmops._vhdutils.get_vhd_format.return_value = vhd_format
root_vhd_internal_size = mock_instance.root_gb * units.Gi
root_vhd_internal_size = mock_instance.flavor.root_gb * units.Gi
get_size = self._vmops._vhdutils.get_internal_vhd_size_by_file_size
get_size.return_value = root_vhd_internal_size
self._vmops._pathutils.exists.return_value = True
@@ -213,7 +213,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
mock_get_cached_image.return_value = fake_vhd_path
fake_root_path = self._vmops._pathutils.get_root_vhd_path.return_value
root_vhd_internal_size = mock_instance.root_gb * units.Gi
root_vhd_internal_size = mock_instance.flavor.root_gb * units.Gi
get_size = self._vmops._vhdutils.get_internal_vhd_size_by_file_size
response = self._vmops._create_root_vhd(context=self.context,
@@ -248,7 +248,7 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
mock.sentinel.rescue_image_id if is_rescue_vhd else None)
fake_root_path = self._vmops._pathutils.get_root_vhd_path.return_value
root_vhd_internal_size = mock_instance.root_gb * units.Gi
root_vhd_internal_size = mock_instance.flavor.root_gb * units.Gi
get_size = self._vmops._vhdutils.get_internal_vhd_size_by_file_size
response = self._vmops._create_root_vhd(
@@ -466,8 +466,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
block_device_info=block_device_info,
vm_gen=vm_gen)
self._vmops._vmutils.create_vm.assert_called_once_with(
mock_instance.name, mock_instance.memory_mb,
mock_instance.vcpus, CONF.hyperv.limit_cpu_features,
mock_instance.name, mock_instance.flavor.memory_mb,
mock_instance.flavor.vcpus, CONF.hyperv.limit_cpu_features,
CONF.hyperv.dynamic_memory_ratio, vm_gen, instance_path,
[mock_instance.uuid])

View File

@@ -58,7 +58,7 @@ class ImageCache(imagecache.ImageCacheManager):
if instance.old_flavor:
return instance.old_flavor.root_gb
else:
return instance.root_gb
return instance.flavor.root_gb
def _resize_and_cache_vhd(self, instance, vhd_path):
vhd_size = self._vhdutils.get_vhd_size(vhd_path)['VirtualSize']
@@ -153,7 +153,7 @@ class ImageCache(imagecache.ImageCacheManager):
rescue_image_path):
rescue_image_info = self._vhdutils.get_vhd_info(rescue_image_path)
rescue_image_size = rescue_image_info['VirtualSize']
flavor_disk_size = instance.root_gb * units.Gi
flavor_disk_size = instance.flavor.root_gb * units.Gi
if rescue_image_size > flavor_disk_size:
err_msg = _('Using a rescue image bigger than the instance '

View File

@@ -106,7 +106,7 @@ class MigrationOps(object):
def _check_target_flavor(self, instance, flavor):
new_root_gb = flavor.root_gb
curr_root_gb = instance.root_gb
curr_root_gb = instance.flavor.root_gb
if new_root_gb < curr_root_gb:
raise exception.InstanceFaultRollback(
@@ -290,7 +290,7 @@ class MigrationOps(object):
src_base_disk_path)
if resize_instance:
new_size = instance.root_gb * units.Gi
new_size = instance.flavor.root_gb * units.Gi
self._check_resize_vhd(root_vhd_path, root_vhd_info, new_size)
ephemerals = block_device_info['ephemerals']

View File

@@ -178,7 +178,7 @@ class VMOps(object):
root_vhd_path = self._pathutils.get_root_vhd_path(instance.name,
format_ext,
is_rescue_vhd)
root_vhd_size = instance.root_gb * units.Gi
root_vhd_size = instance.flavor.root_gb * units.Gi
try:
if CONF.use_cow_images:
@@ -289,8 +289,8 @@ class VMOps(object):
instance_path = os.path.join(CONF.instances_path, instance_name)
self._vmutils.create_vm(instance_name,
instance.memory_mb,
instance.vcpus,
instance.flavor.memory_mb,
instance.flavor.vcpus,
CONF.hyperv.limit_cpu_features,
CONF.hyperv.dynamic_memory_ratio,
vm_gen,