Merge "Fix pci_alias that include white spaces" into stable/newton

This commit is contained in:
Jenkins 2016-12-09 18:25:29 +00:00 committed by Gerrit Code Review
commit cf20b24b56
2 changed files with 34 additions and 2 deletions

View File

@ -103,7 +103,9 @@ def _get_alias_from_config():
for jsonspecs in jaliases:
spec = jsonutils.loads(jsonspecs)
jsonschema.validate(spec, _ALIAS_SCHEMA)
name = spec.pop("name")
# It should keep consistent behaviour in configuration
# and extra specs to call strip() function.
name = spec.pop("name").strip()
dev_type = spec.pop('device_type', None)
if dev_type:
spec['dev_type'] = dev_type
@ -130,8 +132,8 @@ def _translate_alias_to_requests(alias_spec):
pci_aliases = _get_alias_from_config()
pci_requests = [] # list of a specs dict
alias_spec = alias_spec.replace(' ', '')
for name, count in [spec.split(':') for spec in alias_spec.split(',')]:
name = name.strip()
if name not in pci_aliases:
raise exception.PciRequestAliasNotDefined(alias=name)
else:

View File

@ -52,6 +52,14 @@ _fake_alias3 = """{
"device_type": "type-PF"
}"""
_fake_alias4 = """{
"name": " Cirrus Logic ",
"capability_type": "pci",
"product_id": "0ff2",
"vendor_id": "10de",
"device_type": "type-PCI"
}"""
class AliasTestCase(test.NoDBTestCase):
def test_good_alias(self):
@ -202,6 +210,28 @@ class AliasTestCase(test.NoDBTestCase):
set([p.count for p in requests.requests]))
self._verify_result(expect_request, requests.requests)
def test_get_pci_requests_from_flavor_including_space(self):
self.flags(pci_alias=[_fake_alias3, _fake_alias4])
expect_request = [
{'count': 4,
'spec': [{'vendor_id': '10de', 'product_id': '0ff2',
'dev_type': "type-PCI",
'capability_type': 'pci'}],
'alias_name': 'Cirrus Logic'},
{'count': 3,
'spec': [{'vendor_id': '8086', 'product_id': '1111',
'dev_type': "type-PF",
'capability_type': 'pci'}],
'alias_name': 'IntelNIC'}, ]
flavor = {'extra_specs': {"pci_passthrough:alias":
" Cirrus Logic : 4, IntelNIC: 3"}}
requests = request.get_pci_requests_from_flavor(flavor)
self.assertEqual(set([3, 4]),
set([p.count for p in requests.requests]))
self._verify_result(expect_request, requests.requests)
def test_get_pci_requests_from_flavor_no_extra_spec(self):
self.flags(pci_alias=[_fake_alias1, _fake_alias3])
flavor = {}