Merge "pci passthrough bug fix:hasattr dones not work for dict"

This commit is contained in:
Jenkins 2013-09-20 02:48:51 +00:00 committed by Gerrit Code Review
commit 2b056b3589
2 changed files with 14 additions and 1 deletions

View File

@ -168,7 +168,7 @@ class HostState(object):
self.vcpus_total = compute['vcpus']
self.vcpus_used = compute['vcpus_used']
self.updated = compute['updated_at']
if hasattr(compute, 'pci_stats'):
if 'pci_stats' in compute:
self.pci_stats = pci_stats.PciDeviceStats(compute['pci_stats'])
else:
self.pci_stats = None

View File

@ -1574,3 +1574,16 @@ class HostFiltersTestCase(test.NoDBTestCase):
filter_properties = {}
host = fakes.FakeHostState('h1', 'n1', {})
self.assertTrue(filt_cls.host_passes(host, filter_properties))
def test_pci_passthrough_comopute_stats(self):
filt_cls = self.class_map['PciPassthroughFilter']()
requests = [{'count': 1, 'spec': [{'vendor_id': '8086'}]}]
filter_properties = {'pci_requests': requests}
self.stubs.Set(pci_stats.PciDeviceStats, 'support_requests',
self._fake_pci_support_requests)
host = fakes.FakeHostState(
'host1', 'node1',
attribute_dict={})
self.pci_request_result = True
self.assertRaises(AttributeError, filt_cls.host_passes,
host, filter_properties)