Merge "PCI: Check pci_requests object is empty before passing to support_requests"
This commit is contained in:
commit
f9d7b383a7
@ -43,9 +43,10 @@ class PciPassthroughFilter(filters.BaseHostFilter):
|
||||
def host_passes(self, host_state, spec_obj):
|
||||
"""Return true if the host has the required PCI devices."""
|
||||
pci_requests = spec_obj.pci_requests
|
||||
if not pci_requests:
|
||||
if not pci_requests or not pci_requests.requests:
|
||||
return True
|
||||
if not host_state.pci_stats.support_requests(pci_requests.requests):
|
||||
if (not host_state.pci_stats or
|
||||
not host_state.pci_stats.support_requests(pci_requests.requests)):
|
||||
LOG.debug("%(host_state)s doesn't have the required PCI devices"
|
||||
" (%(requests)s)",
|
||||
{'host_state': host_state, 'requests': pci_requests})
|
||||
|
@ -58,16 +58,11 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
||||
host = fakes.FakeHostState('h1', 'n1', {})
|
||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_pci_passthrough_compute_stats(self):
|
||||
request = objects.InstancePCIRequest(count=1,
|
||||
spec=[{'vendor_id': '8086'}])
|
||||
requests = objects.InstancePCIRequests(requests=[request])
|
||||
def test_pci_passthrough_empty_pci_request_obj(self):
|
||||
requests = objects.InstancePCIRequests(requests=[])
|
||||
spec_obj = objects.RequestSpec(pci_requests=requests)
|
||||
host = fakes.FakeHostState(
|
||||
'host1', 'node1',
|
||||
attribute_dict={})
|
||||
self.assertRaises(AttributeError, self.filt_cls.host_passes,
|
||||
host, spec_obj)
|
||||
host = fakes.FakeHostState('h1', 'n1', {})
|
||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_pci_passthrough_no_pci_stats(self):
|
||||
request = objects.InstancePCIRequest(count=1,
|
||||
@ -77,3 +72,12 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
||||
host = fakes.FakeHostState('host1', 'node1',
|
||||
attribute_dict={'pci_stats': stats.PciDeviceStats()})
|
||||
self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_pci_passthrough_with_pci_stats_none(self):
|
||||
request = objects.InstancePCIRequest(count=1,
|
||||
spec=[{'vendor_id': '8086'}])
|
||||
requests = objects.InstancePCIRequests(requests=[request])
|
||||
spec_obj = objects.RequestSpec(pci_requests=requests)
|
||||
host = fakes.FakeHostState('host1', 'node1',
|
||||
attribute_dict={'pci_stats': None})
|
||||
self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
Loading…
x
Reference in New Issue
Block a user