Browse Source

Merge "ZVM: Implement update_provider_tree"

changes/00/670000/4
Zuul 2 weeks ago
parent
commit
9a2f45173a
2 changed files with 77 additions and 0 deletions
  1. +41
    -0
      nova/tests/unit/virt/zvm/test_driver.py
  2. +36
    -0
      nova/virt/zvm/driver.py

+ 41
- 0
nova/tests/unit/virt/zvm/test_driver.py View File

@@ -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)

+ 36
- 0
nova/virt/zvm/driver.py View File

@@ -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)

Loading…
Cancel
Save