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):
|
def host_passes(self, host_state, spec_obj):
|
||||||
"""Return true if the host has the required PCI devices."""
|
"""Return true if the host has the required PCI devices."""
|
||||||
pci_requests = spec_obj.pci_requests
|
pci_requests = spec_obj.pci_requests
|
||||||
if not pci_requests:
|
if not pci_requests or not pci_requests.requests:
|
||||||
return True
|
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"
|
LOG.debug("%(host_state)s doesn't have the required PCI devices"
|
||||||
" (%(requests)s)",
|
" (%(requests)s)",
|
||||||
{'host_state': host_state, 'requests': pci_requests})
|
{'host_state': host_state, 'requests': pci_requests})
|
||||||
|
|
|
@ -58,16 +58,11 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
||||||
host = fakes.FakeHostState('h1', 'n1', {})
|
host = fakes.FakeHostState('h1', 'n1', {})
|
||||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||||
|
|
||||||
def test_pci_passthrough_compute_stats(self):
|
def test_pci_passthrough_empty_pci_request_obj(self):
|
||||||
request = objects.InstancePCIRequest(count=1,
|
requests = objects.InstancePCIRequests(requests=[])
|
||||||
spec=[{'vendor_id': '8086'}])
|
|
||||||
requests = objects.InstancePCIRequests(requests=[request])
|
|
||||||
spec_obj = objects.RequestSpec(pci_requests=requests)
|
spec_obj = objects.RequestSpec(pci_requests=requests)
|
||||||
host = fakes.FakeHostState(
|
host = fakes.FakeHostState('h1', 'n1', {})
|
||||||
'host1', 'node1',
|
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||||
attribute_dict={})
|
|
||||||
self.assertRaises(AttributeError, self.filt_cls.host_passes,
|
|
||||||
host, spec_obj)
|
|
||||||
|
|
||||||
def test_pci_passthrough_no_pci_stats(self):
|
def test_pci_passthrough_no_pci_stats(self):
|
||||||
request = objects.InstancePCIRequest(count=1,
|
request = objects.InstancePCIRequest(count=1,
|
||||||
|
@ -77,3 +72,12 @@ class TestPCIPassthroughFilter(test.NoDBTestCase):
|
||||||
host = fakes.FakeHostState('host1', 'node1',
|
host = fakes.FakeHostState('host1', 'node1',
|
||||||
attribute_dict={'pci_stats': stats.PciDeviceStats()})
|
attribute_dict={'pci_stats': stats.PciDeviceStats()})
|
||||||
self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
|
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…
Reference in New Issue