From a76a4dd227a3b097b8df3a944dd0ace3ef01744c Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Tue, 19 Nov 2019 11:54:48 +0800 Subject: [PATCH] ZVM: Implement update_provider_tree This patch implements update_provider_tree() in the ZVMDriver As in Train [1] nova deprecated support for compute drivers that did not implement the update_provider_tree method. And the compat code is now removed in [2]. [1] I1eae47bce08f6292d38e893a2122289bcd6f4b58 [2] Ib62ac0b692eb92a2ed364ec9f486ded05def39ad Change-Id: I76192a4c8adb192b12c0ceb71bf5f5a318018b87 --- nova/tests/unit/virt/zvm/test_driver.py | 41 +++++++++++++++++++++++++ nova/virt/zvm/driver.py | 36 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/nova/tests/unit/virt/zvm/test_driver.py b/nova/tests/unit/virt/zvm/test_driver.py index 359e8c330ef0..022816df7d1e 100644 --- a/nova/tests/unit/virt/zvm/test_driver.py +++ b/nova/tests/unit/virt/zvm/test_driver.py @@ -18,6 +18,7 @@ import os from oslo_utils.fixture import uuidsentinel import six +from nova.compute import provider_tree from nova import conf from nova import context from nova import exception @@ -504,3 +505,43 @@ class TestZVMDriver(test.NoDBTestCase): outputs = self._driver.get_console_output(None, self._instance) call.assert_called_once_with('guest_get_console_output', 'abc00001') self.assertEqual('console output', outputs) + + @mock.patch('nova.virt.zvm.utils.ConnectorClient.call') + def test_update_provider_tree(self, call): + host_info = {'vcpus': 84, + 'disk_total': 2000, + 'memory_mb': 78192} + call.return_value = host_info + expected_inv = { + 'VCPU': { + 'total': 84, + 'min_unit': 1, + 'max_unit': 84, + 'step_size': 1, + 'allocation_ratio': CONF.initial_cpu_allocation_ratio, + 'reserved': CONF.reserved_host_cpus, + }, + 'MEMORY_MB': { + 'total': 78192, + 'min_unit': 1, + 'max_unit': 78192, + 'step_size': 1, + 'allocation_ratio': CONF.initial_ram_allocation_ratio, + 'reserved': CONF.reserved_host_memory_mb, + }, + 'DISK_GB': { + 'total': 2000, + 'min_unit': 1, + 'max_unit': 2000, + 'step_size': 1, + 'allocation_ratio': CONF.initial_disk_allocation_ratio, + 'reserved': CONF.reserved_host_disk_mb, + }, + } + + pt = provider_tree.ProviderTree() + nodename = 'fake-node' + pt.new_root(nodename, uuidsentinel.rp_uuid) + self._driver.update_provider_tree(pt, nodename) + inv = pt.data(nodename).inventory + self.assertEqual(expected_inv, inv) diff --git a/nova/virt/zvm/driver.py b/nova/virt/zvm/driver.py index 0ed5f98dae01..1dfa42a4ec02 100644 --- a/nova/virt/zvm/driver.py +++ b/nova/virt/zvm/driver.py @@ -17,6 +17,7 @@ import os import six import time +import os_resource_classes as orc from oslo_concurrency import lockutils from oslo_log import log as logging from oslo_serialization import jsonutils @@ -413,3 +414,38 @@ class ZVMDriver(driver.ComputeDriver): def get_console_output(self, context, instance): return self._hypervisor.guest_get_console_output(instance.name) + + def update_provider_tree(self, provider_tree, nodename, allocations=None): + resources = self._hypervisor.get_available_resource() + + inventory = provider_tree.data(nodename).inventory + allocation_ratios = self._get_allocation_ratios(inventory) + + 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['disk_total'], + 'min_unit': 1, + 'max_unit': resources['disk_total'], + 'step_size': 1, + 'allocation_ratio': allocation_ratios[orc.DISK_GB], + 'reserved': self._get_reserved_host_disk_gb_from_config(), + }, + } + + provider_tree.update_inventory(nodename, inventory)