Hyper-V: Fixes disk overhead claim issue
For each started VM, Hyper-V creates a VM memory file on the local disk. The size of the file is the same as the size of the VM's memory amount. Implements the mentioned method in HyperVDriver. Change-Id: Id40219dae96c0f7e60a86c0ed76fa08cea608aec Closes-Bug: #1505681
This commit is contained in:
		@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user