diff --git a/nova/tests/unit/virt/hyperv/test_driver.py b/nova/tests/unit/virt/hyperv/test_driver.py index 4b124e7610..44d97a2d81 100644 --- a/nova/tests/unit/virt/hyperv/test_driver.py +++ b/nova/tests/unit/virt/hyperv/test_driver.py @@ -127,6 +127,11 @@ 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) + def test_spawn(self): self.driver.spawn( mock.sentinel.context, mock.sentinel.instance, diff --git a/nova/tests/unit/virt/hyperv/test_vmops.py b/nova/tests/unit/virt/hyperv/test_vmops.py index 82323a578d..b3c88d73a4 100644 --- a/nova/tests/unit/virt/hyperv/test_vmops.py +++ b/nova/tests/unit/virt/hyperv/test_vmops.py @@ -100,6 +100,16 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase): self._vmops._vmutils.list_instances.assert_called_once_with() self.assertEqual(response, [mock_instance]) + def test_estimate_instance_overhead(self): + instance_info = {'memory_mb': 512} + overhead = self._vmops.estimate_instance_overhead(instance_info) + self.assertEqual(0, overhead['memory_mb']) + self.assertEqual(1, 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) diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py index 29e4ac3379..0009313ad1 100644 --- a/nova/virt/hyperv/driver.py +++ b/nova/virt/hyperv/driver.py @@ -137,6 +137,9 @@ 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, network_info=None, block_device_info=None): self._vmops.spawn(context, instance, image_meta, injected_files, diff --git a/nova/virt/hyperv/vmops.py b/nova/virt/hyperv/vmops.py index 49f39b1723..4187a0a4fc 100644 --- a/nova/virt/hyperv/vmops.py +++ b/nova/virt/hyperv/vmops.py @@ -131,6 +131,14 @@ 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. + return {'memory_mb': 0, + 'disk_gb': (instance_info['memory_mb'] + 512) // units.Ki} + def get_info(self, instance): """Get information about the VM.""" LOG.debug("get_info called for instance", instance=instance)