Merge "Convert HostState.limits['numa_topology'] to primitive"

This commit is contained in:
Jenkins 2017-07-19 17:34:27 +00:00 committed by Gerrit Code Review
commit 7d77eb4658
2 changed files with 43 additions and 1 deletions

View File

@ -44,10 +44,18 @@ QUOTAS = quota.QUOTAS
def _host_state_obj_to_dict(host_state):
limits = dict(host_state.limits)
# The NUMATopologyFilter can set 'numa_topology' in the limits dict
# to a NUMATopologyLimits object which we need to convert to a primitive
# before this hits jsonutils.to_primitive(). We only check for that known
# case specifically as we don't care about handling out of tree filters
# or drivers injecting non-serializable things in the limits dict.
if 'numa_topology' in limits:
limits['numa_topology'] = limits['numa_topology'].obj_to_primitive()
return {
'host': host_state.host,
'nodename': host_state.nodename,
'limits': host_state.limits,
'limits': limits
}

View File

@ -19,6 +19,7 @@ Tests For Scheduler
import mock
import nova.conf
from nova import context
from nova import objects
from nova.scheduler import caching_scheduler
@ -33,6 +34,8 @@ from nova.tests.unit import fake_server_actions
from nova.tests.unit.scheduler import fakes
from nova.tests import uuidsentinel as uuids
CONF = nova.conf.CONF
class SchedulerManagerInitTestCase(test.NoDBTestCase):
"""Test case for scheduler manager initiation."""
@ -238,6 +241,37 @@ class SchedulerManagerTestCase(test.NoDBTestCase):
cell_mapping=cm2)]
self.manager._discover_hosts_in_cells(mock.sentinel.context)
def test_host_state_obj_to_dict_numa_topology_limits_conversion(self):
"""Tests that _host_state_obj_to_dict properly converts a
NUMATopologyLimits object in the HostState.limits if found and
that other unexpected objects aren't converted.
"""
host_state = host_manager.HostState(
'fake-host', 'fake-node', uuids.cell_uuid)
# The NUMATopologyFilter sets host_state.limits['numa_topology'] to
# a NUMATopologyLimits object which is what we want to verify gets
# converted to a primitive in _host_state_obj_to_dict.
numa_limits = objects.NUMATopologyLimits(
cpu_allocation_ratio=CONF.cpu_allocation_ratio,
ram_allocation_ratio=CONF.ram_allocation_ratio)
host_state.limits['numa_topology'] = numa_limits
# Set some other unexpected object to assert we don't convert it.
ignored_limits = objects.SchedulerLimits()
host_state.limits['ignored'] = ignored_limits
result = manager._host_state_obj_to_dict(host_state)
expected = {
'host': 'fake-host',
'nodename': 'fake-node',
'limits': {
'numa_topology': numa_limits.obj_to_primitive(),
'ignored': ignored_limits
}
}
self.assertDictEqual(expected, result)
# Make sure the original limits weren't changed.
self.assertIsInstance(host_state.limits['numa_topology'],
objects.NUMATopologyLimits)
class SchedulerInitTestCase(test.NoDBTestCase):
"""Test case for base scheduler driver initiation."""