Merge "Hyper-V: Fixes disk overhead claim issue"
This commit is contained in:
@@ -150,6 +150,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):
|
||||
image_meta = self._recreate_image_meta(context, instance, image_meta)
|
||||
|
||||
@@ -114,6 +114,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)
|
||||
|
||||
@@ -144,6 +144,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)
|
||||
|
||||
@mock.patch.object(driver.HyperVDriver, '_recreate_image_meta')
|
||||
def test_spawn(self, mock_recreate_img_meta):
|
||||
self.driver.spawn(
|
||||
|
||||
@@ -96,6 +96,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)
|
||||
|
||||
Reference in New Issue
Block a user