Update driver interface

finish_revert_migration() now accepts a migration object and
estimate_instance_overhead() has been dropped.

Change-Id: Iddd6c2cad1e6f94b1904e1f1196f6c7dee1b2f99
This commit is contained in:
Lucian Petrut 2019-08-07 22:41:35 +03:00
parent 6c7e4f812b
commit 20ee0665c5
6 changed files with 11 additions and 43 deletions

View File

@ -72,9 +72,11 @@ class HyperVClusterDriver(driver.HyperVDriver):
self._clops.add_to_cluster(instance)
def finish_revert_migration(self, context, instance, network_info,
block_device_info=None, power_on=True):
migration, block_device_info=None,
power_on=True):
super(HyperVClusterDriver, self).finish_revert_migration(
context, instance, network_info, block_device_info, power_on)
context, instance, network_info, migration,
block_device_info, power_on)
self._clops.add_to_cluster(instance)
def rollback_live_migration_at_destination(self, context, instance,

View File

@ -181,9 +181,6 @@ class HyperVDriver(driver.ComputeDriver):
def list_instances(self):
return self._vmops.list_instances()
def estimate_instance_overhead(self, instance_info):
return self._vmops.estimate_instance_overhead(instance_info)
def spawn(self, context, instance, image_meta, injected_files,
admin_password, allocations, network_info=None,
block_device_info=None):
@ -374,7 +371,8 @@ class HyperVDriver(driver.ComputeDriver):
instance, network_info)
def finish_revert_migration(self, context, instance, network_info,
block_device_info=None, power_on=True):
migration, block_device_info=None,
power_on=True):
self._migrationops.finish_revert_migration(context, instance,
network_info,
block_device_info, power_on)

View File

@ -118,19 +118,6 @@ class VMOps(object):
def list_instances(self):
return self._vmutils.list_instances()
def estimate_instance_overhead(self, instance_info):
# NOTE(claudiub): When an instance starts, Hyper-V creates a VM memory
# file on the local disk. The file size is the same as the VM's amount
# of memory. Since disk_gb must be an integer, and memory is MB, round
# up from X512 MB.
# This applies only when the host is configured to save the instances
# when turning off.
disk_overhead = ((instance_info['memory_mb'] + 512) // units.Ki
if not CONF.hyperv.instance_automatic_shutdown
else 0)
return {'memory_mb': 0,
'disk_gb': disk_overhead}
def get_info(self, instance):
"""Get information about the VM."""
LOG.debug("get_info called for instance", instance=instance)

View File

@ -141,12 +141,13 @@ class HyperVClusterTestCase(test_base.HyperVBaseTestCase):
self.driver.finish_revert_migration(self.context,
mock.sentinel.fake_instance,
mock.sentinel.network_info,
mock.sentinel.migration,
mock.sentinel.block_dev_info,
mock.sentinel.power_on)
mock_superclass_finish_rev_migr.assert_called_once_with(
self.context, mock.sentinel.fake_instance,
mock.sentinel.network_info, mock.sentinel.block_dev_info,
mock.sentinel.power_on)
mock.sentinel.network_info, mock.sentinel.migration,
mock.sentinel.block_dev_info, mock.sentinel.power_on)
self.driver._clops.add_to_cluster.assert_called_once_with(
mock.sentinel.fake_instance)

View File

@ -151,11 +151,6 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase):
self.driver.list_instances()
self.driver._vmops.list_instances.assert_called_once_with()
def test_estimate_instance_overhead(self):
self.driver.estimate_instance_overhead(mock.sentinel.instance)
self.driver._vmops.estimate_instance_overhead.assert_called_once_with(
mock.sentinel.instance)
@mock.patch.object(driver.HyperVDriver, '_recreate_image_meta')
def test_spawn(self, mock_recreate_img_meta):
self.driver.spawn(
@ -486,8 +481,8 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase):
def test_finish_revert_migration(self):
self.driver.finish_revert_migration(
mock.sentinel.context, mock.sentinel.instance,
mock.sentinel.network_info, mock.sentinel.block_device_info,
mock.sentinel.power_on)
mock.sentinel.network_info, mock.sentinel.migration,
mock.sentinel.block_device_info, mock.sentinel.power_on)
finish_revert_migr = self.driver._migrationops.finish_revert_migration
finish_revert_migr.assert_called_once_with(

View File

@ -91,21 +91,6 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
self._vmops._vmutils.list_instances.assert_called_once_with()
self.assertEqual(response, [mock_instance])
@ddt.data(True, False)
def test_estimate_instance_overhead(self, instance_automatic_shutdown):
self.flags(instance_automatic_shutdown=instance_automatic_shutdown,
group='hyperv')
instance_info = {'memory_mb': 512}
expected_disk_overhead = 0 if instance_automatic_shutdown else 1
overhead = self._vmops.estimate_instance_overhead(instance_info)
self.assertEqual(0, overhead['memory_mb'])
self.assertEqual(expected_disk_overhead, overhead['disk_gb'])
instance_info = {'memory_mb': 500}
overhead = self._vmops.estimate_instance_overhead(instance_info)
self.assertEqual(0, overhead['disk_gb'])
def _test_get_info(self, vm_exists):
mock_instance = fake_instance.fake_instance_obj(self.context)
mock_info = mock.MagicMock(spec_set=dict)