Merge "Implement update_provider_tree"
This commit is contained in:
commit
6c7e4f812b
|
@ -460,3 +460,10 @@ class HyperVDriver(driver.ComputeDriver):
|
|||
|
||||
def check_instance_shared_storage_cleanup(self, context, data):
|
||||
return self._pathutils.check_instance_shared_storage_cleanup(data)
|
||||
|
||||
def update_provider_tree(self, provider_tree, nodename, allocations=None):
|
||||
inventory = provider_tree.data(nodename).inventory
|
||||
alloc_ratios = self._get_allocation_ratios(inventory)
|
||||
|
||||
self._hostops.update_provider_tree(
|
||||
provider_tree, nodename, alloc_ratios, allocations)
|
||||
|
|
|
@ -21,11 +21,13 @@ import platform
|
|||
import time
|
||||
|
||||
from nova.compute import api
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.objects import fields as obj_fields
|
||||
import os_resource_classes as orc
|
||||
from os_win import constants as os_win_const
|
||||
from os_win import utilsfactory
|
||||
from oslo_log import log as logging
|
||||
|
@ -346,3 +348,39 @@ class HostOps(object):
|
|||
'task_state': instance.task_state,
|
||||
'timeout': CONF.hyperv.evacuate_task_state_timeout})
|
||||
raise exception.InternalError(message=err)
|
||||
|
||||
def update_provider_tree(self, provider_tree, nodename,
|
||||
allocation_ratios, allocations=None):
|
||||
resources = self.get_available_resource()
|
||||
|
||||
inventory = {
|
||||
orc.VCPU: {
|
||||
'total': resources['vcpus'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['vcpus'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.VCPU],
|
||||
'reserved': CONF.reserved_host_cpus,
|
||||
},
|
||||
orc.MEMORY_MB: {
|
||||
'total': resources['memory_mb'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['memory_mb'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.MEMORY_MB],
|
||||
'reserved': CONF.reserved_host_memory_mb,
|
||||
},
|
||||
# TODO(lpetrut): once #1784020 is fixed, we can skip reporting
|
||||
# shared storage capacity
|
||||
orc.DISK_GB: {
|
||||
'total': resources['local_gb'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['local_gb'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.DISK_GB],
|
||||
'reserved': compute_utils.convert_mb_to_ceil_gb(
|
||||
CONF.reserved_host_disk_mb),
|
||||
},
|
||||
}
|
||||
|
||||
provider_tree.update_inventory(nodename, inventory)
|
||||
|
|
|
@ -630,3 +630,17 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase):
|
|||
|
||||
self.assertEqual(check_cleanup.return_value, ret_val)
|
||||
check_cleanup.assert_called_once_with(mock.sentinel.data)
|
||||
|
||||
@mock.patch.object(driver.HyperVDriver, '_get_allocation_ratios')
|
||||
def test_update_provider_tree(self, mock_get_alloc_ratios):
|
||||
mock_ptree = mock.Mock()
|
||||
mock_inventory = mock_ptree.data.return_value.inventory
|
||||
|
||||
self.driver.update_provider_tree(
|
||||
mock_ptree, mock.sentinel.nodename, mock.sentinel.allocations)
|
||||
|
||||
mock_get_alloc_ratios.assert_called_once_with(mock_inventory)
|
||||
self.driver._hostops.update_provider_tree.assert_called_once_with(
|
||||
mock_ptree, mock.sentinel.nodename,
|
||||
mock_get_alloc_ratios.return_value,
|
||||
mock.sentinel.allocations)
|
||||
|
|
|
@ -20,6 +20,7 @@ from nova import context as nova_context
|
|||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.objects import fields as obj_fields
|
||||
import os_resource_classes as orc
|
||||
from os_win import constants as os_win_const
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import units
|
||||
|
@ -388,3 +389,48 @@ class HostOpsTestCase(test_base.HyperVBaseTestCase):
|
|||
self._hostops._wait_for_instance_pending_task,
|
||||
context=mock.sentinel.CONTEXT,
|
||||
vm_uuid=mock.sentinel.VM_UUID)
|
||||
|
||||
@mock.patch.object(hostops.HostOps, 'get_available_resource')
|
||||
def test_update_provider_tree(self, mock_get_avail_res):
|
||||
resources = mock.MagicMock()
|
||||
allocation_ratios = mock.MagicMock()
|
||||
provider_tree = mock.Mock()
|
||||
|
||||
mock_get_avail_res.return_value = resources
|
||||
|
||||
self.flags(reserved_host_disk_mb=1)
|
||||
|
||||
exp_inventory = {
|
||||
orc.VCPU: {
|
||||
'total': resources['vcpus'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['vcpus'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.VCPU],
|
||||
'reserved': CONF.reserved_host_cpus,
|
||||
},
|
||||
orc.MEMORY_MB: {
|
||||
'total': resources['memory_mb'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['memory_mb'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.MEMORY_MB],
|
||||
'reserved': CONF.reserved_host_memory_mb,
|
||||
},
|
||||
orc.DISK_GB: {
|
||||
'total': resources['local_gb'],
|
||||
'min_unit': 1,
|
||||
'max_unit': resources['local_gb'],
|
||||
'step_size': 1,
|
||||
'allocation_ratio': allocation_ratios[orc.DISK_GB],
|
||||
'reserved': 1,
|
||||
},
|
||||
}
|
||||
|
||||
self._hostops.update_provider_tree(
|
||||
provider_tree, mock.sentinel.node_name, allocation_ratios,
|
||||
mock.sentinel.allocations)
|
||||
|
||||
provider_tree.update_inventory.assert_called_once_with(
|
||||
mock.sentinel.node_name,
|
||||
exp_inventory)
|
||||
|
|
Loading…
Reference in New Issue