Use the same pci_requests field for all filters and HostManager
Since filter_properties and the instance object were having the same pci_requests field, remove the key from filter_props and make sure that all filters are using the instance object. Partially-Implements: blueprint request-spec-object Change-Id: I6a9d5ea4204109c0e1eb29b1704ec3a1fb50c96b
This commit is contained in:
parent
bd3b5a62b4
commit
875594ad26
|
@ -966,15 +966,13 @@ class API(base.Base):
|
|||
return base_options, max_network_count
|
||||
|
||||
def _build_filter_properties(self, context, scheduler_hints, forced_host,
|
||||
forced_node, instance_type, pci_request_info):
|
||||
forced_node, instance_type):
|
||||
filter_properties = dict(scheduler_hints=scheduler_hints)
|
||||
filter_properties['instance_type'] = instance_type
|
||||
if forced_host:
|
||||
filter_properties['force_hosts'] = [forced_host]
|
||||
if forced_node:
|
||||
filter_properties['force_nodes'] = [forced_node]
|
||||
if pci_request_info and pci_request_info.requests:
|
||||
filter_properties['pci_requests'] = pci_request_info
|
||||
return filter_properties
|
||||
|
||||
def _provision_instances(self, context, instance_type, min_count,
|
||||
|
@ -1185,8 +1183,7 @@ class API(base.Base):
|
|||
|
||||
filter_properties = self._build_filter_properties(context,
|
||||
scheduler_hints, forced_host,
|
||||
forced_node, instance_type,
|
||||
base_options.get('pci_requests'))
|
||||
forced_node, instance_type)
|
||||
|
||||
for instance in instances:
|
||||
self._record_action_start(context, instance,
|
||||
|
|
|
@ -27,6 +27,7 @@ from six.moves import range
|
|||
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import objects
|
||||
from nova import rpc
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import scheduler_options
|
||||
|
@ -105,6 +106,18 @@ class FilterScheduler(driver.Scheduler):
|
|||
"""
|
||||
elevated = context.elevated()
|
||||
instance_properties = request_spec['instance_properties']
|
||||
|
||||
# NOTE(danms): Instance here is still a dict, which is converted from
|
||||
# an object. The pci_requests are a dict as well. Convert this when
|
||||
# we get an object all the way to this path.
|
||||
# TODO(sbauza): Will be fixed later by the RequestSpec object
|
||||
pci_requests = instance_properties.get('pci_requests')
|
||||
if pci_requests:
|
||||
pci_requests = (
|
||||
objects.InstancePCIRequests.from_request_spec_instance_props(
|
||||
pci_requests))
|
||||
instance_properties['pci_requests'] = pci_requests
|
||||
|
||||
instance_type = request_spec.get("instance_type", None)
|
||||
|
||||
update_group_hosts = filter_properties.get('group_updated', False)
|
||||
|
|
|
@ -26,7 +26,7 @@ class NUMATopologyFilter(filters.BaseHostFilter):
|
|||
requested_topology = hardware.instance_topology_from_instance(instance)
|
||||
host_topology, _fmt = hardware.host_topology_and_format_from_host(
|
||||
host_state)
|
||||
pci_requests = filter_properties.get('pci_requests')
|
||||
pci_requests = instance.get('pci_requests')
|
||||
if pci_requests:
|
||||
pci_requests = pci_requests.requests
|
||||
if requested_topology and host_topology:
|
||||
|
|
|
@ -42,7 +42,9 @@ class PciPassthroughFilter(filters.BaseHostFilter):
|
|||
|
||||
def host_passes(self, host_state, filter_properties):
|
||||
"""Return true if the host has the required PCI devices."""
|
||||
pci_requests = filter_properties.get('pci_requests')
|
||||
request_spec = filter_properties.get('request_spec', {})
|
||||
instance = request_spec.get('instance_properties', {})
|
||||
pci_requests = instance.get('pci_requests')
|
||||
if not pci_requests:
|
||||
return True
|
||||
if not host_state.pci_stats.support_requests(pci_requests.requests):
|
||||
|
|
|
@ -271,12 +271,7 @@ class HostState(object):
|
|||
self.num_instances += 1
|
||||
|
||||
pci_requests = instance.get('pci_requests')
|
||||
# NOTE(danms): Instance here is still a dict, which is converted from
|
||||
# an object. The pci_requests are a dict as well. Convert this when
|
||||
# we get an object all the way to this path.
|
||||
if pci_requests and pci_requests['requests'] and self.pci_stats:
|
||||
pci_requests = objects.InstancePCIRequests \
|
||||
.from_request_spec_instance_props(pci_requests)
|
||||
if pci_requests and self.pci_stats:
|
||||
pci_requests = pci_requests.requests
|
||||
else:
|
||||
pci_requests = None
|
||||
|
|
|
@ -31,7 +31,9 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
|||
request = objects.InstancePCIRequest(count=1,
|
||||
spec=[{'vendor_id': '8086'}])
|
||||
requests = objects.InstancePCIRequests(requests=[request])
|
||||
filter_properties = {'pci_requests': requests}
|
||||
filter_properties = {
|
||||
'request_spec': {
|
||||
'instance_properties': {'pci_requests': requests}}}
|
||||
host = fakes.FakeHostState(
|
||||
'host1', 'node1',
|
||||
attribute_dict={'pci_stats': pci_stats_mock})
|
||||
|
@ -45,7 +47,9 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
|||
request = objects.InstancePCIRequest(count=1,
|
||||
spec=[{'vendor_id': '8086'}])
|
||||
requests = objects.InstancePCIRequests(requests=[request])
|
||||
filter_properties = {'pci_requests': requests}
|
||||
filter_properties = {
|
||||
'request_spec': {
|
||||
'instance_properties': {'pci_requests': requests}}}
|
||||
host = fakes.FakeHostState(
|
||||
'host1', 'node1',
|
||||
attribute_dict={'pci_stats': pci_stats_mock})
|
||||
|
@ -60,7 +64,9 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
|||
|
||||
def test_pci_passthrough_compute_stats(self):
|
||||
requests = [{'count': 1, 'spec': [{'vendor_id': '8086'}]}]
|
||||
filter_properties = {'pci_requests': requests}
|
||||
filter_properties = {
|
||||
'request_spec': {
|
||||
'instance_properties': {'pci_requests': requests}}}
|
||||
host = fakes.FakeHostState(
|
||||
'host1', 'node1',
|
||||
attribute_dict={})
|
||||
|
@ -71,7 +77,9 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
|||
request = objects.InstancePCIRequest(count=1,
|
||||
spec=[{'vendor_id': '8086'}])
|
||||
requests = objects.InstancePCIRequests(requests=[request])
|
||||
filter_properties = {'pci_requests': requests}
|
||||
filter_properties = {
|
||||
'request_spec': {
|
||||
'instance_properties': {'pci_requests': requests}}}
|
||||
host = fakes.FakeHostState('host1', 'node1',
|
||||
attribute_dict={'pci_stats': stats.PciDeviceStats()})
|
||||
self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
|
||||
|
|
|
@ -19,6 +19,7 @@ Tests For Filter Scheduler.
|
|||
import mock
|
||||
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.scheduler import filter_scheduler
|
||||
from nova.scheduler import host_manager
|
||||
from nova.scheduler import utils as scheduler_utils
|
||||
|
@ -236,6 +237,24 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
|
|||
|
||||
self.assertEqual(50, hosts[0].weight)
|
||||
|
||||
@mock.patch.object(objects.InstancePCIRequests,
|
||||
'from_request_spec_instance_props')
|
||||
@mock.patch.object(host_manager.HostManager, 'get_filtered_hosts')
|
||||
def test_schedule_with_pci_requests(self, get_filtered_hosts, from_rs_ip):
|
||||
self.driver._get_all_host_states = mock.Mock()
|
||||
get_filtered_hosts.return_value = None
|
||||
|
||||
fake_requests = objects.InstancePCIRequests()
|
||||
from_rs_ip.return_value = fake_requests
|
||||
|
||||
instance_properties = {'pci_requests': 'anything_as_it_is_mocked'}
|
||||
request_spec = dict(instance_properties=instance_properties,
|
||||
instance_type={})
|
||||
|
||||
self.driver._schedule(self.context, request_spec, {})
|
||||
from_rs_ip.assert_called_once_with('anything_as_it_is_mocked')
|
||||
self.assertEqual(fake_requests, instance_properties['pci_requests'])
|
||||
|
||||
@mock.patch('nova.objects.ServiceList.get_by_binary',
|
||||
return_value=fakes.SERVICES)
|
||||
@mock.patch('nova.objects.InstanceList.get_by_host')
|
||||
|
|
|
@ -947,6 +947,8 @@ class HostStateTestCase(test.NoDBTestCase):
|
|||
ephemeral_gb=0,
|
||||
memory_mb=1024,
|
||||
vcpus=1))
|
||||
# NOTE(sbauza): FilterSchedule._schedule() rehydrates pci_requests
|
||||
req_spec['instance_properties']['pci_requests'] = fake_requests_obj
|
||||
host = host_manager.HostState("fakehost", "fakenode")
|
||||
self.assertIsNone(host.updated)
|
||||
host.pci_stats = pci_stats.PciDeviceStats(
|
||||
|
|
Loading…
Reference in New Issue