Cleanups for pci stats in preparation for RT using ComputeNode
While converting the resource tracker to use the ComputeNode object it became apparent that there was a trivial bug in the way tags were assigned in PciDevicePool.from_dict() and that the format for pci stats in the examples is wrong. The bug was that a dict was assigned to the tags field and then items were added to it as follows: pool.tags = {} pool.tags.update(pool_dict) The setter for objects is over ridden to perform type checking and coercion for fields. In the above case the tags field is a dict of strings, so the coercion converts all values in the dict to be strings (if it can). In the above snippet the values of pool_dict are not type checked or coerced because they are added directly to the dict. The correct way to do this is (it just so happens that pool_dict again here): pool.tags = pool_dict The format of the pci stats does not include an extra_info field as was originally planned by the author. Instead tags that would have been in extra_info are included as additional fields. The phys_function tag was intended to have particular meaning but has now been dropped. The api samples and related tests for hypervisors-pci-detail-resp and hypervisors-pci-show-resp do include extra_info, so the samples and tests are incorrect. This patch corrects them. The change in the samples is not an API change, only a correction, so there is no change to the API version. However, the api samples are included in documentation so this patch is marked with with a document impact. DocImpact Change-Id: I8730f18d660777e23637b4846e06af1c3e14238e
This commit is contained in:
parent
71b719c26b
commit
f1a0d852c8
|
@ -20,13 +20,11 @@
|
|||
"os-pci:pci_stats": [
|
||||
{
|
||||
"count": 5,
|
||||
"extra_info": {
|
||||
"key1": "value1",
|
||||
"phys_function": "[[\"0x0000\", \"0x04\", \"0x00\", \"0x1\"]]"
|
||||
},
|
||||
"key1": "value1",
|
||||
"keya": "valuea",
|
||||
"product_id": "1520",
|
||||
"vendor_id": "8086"
|
||||
"vendor_id": "8086",
|
||||
"numa_node": 1
|
||||
}
|
||||
],
|
||||
"running_vms": 0,
|
||||
|
|
|
@ -19,13 +19,11 @@
|
|||
"os-pci:pci_stats": [
|
||||
{
|
||||
"count": 5,
|
||||
"extra_info": {
|
||||
"key1": "value1",
|
||||
"phys_function": "[[\"0x0000\", \"0x04\", \"0x00\", \"0x1\"]]"
|
||||
},
|
||||
"key1": "value1",
|
||||
"keya": "valuea",
|
||||
"product_id": "1520",
|
||||
"vendor_id": "8086"
|
||||
"vendor_id": "8086",
|
||||
"numa_node": 1
|
||||
}
|
||||
],
|
||||
"running_vms": 0,
|
||||
|
|
|
@ -53,8 +53,7 @@ class PciDevicePool(base.NovaObject):
|
|||
pool.product_id = pool_dict.pop("product_id")
|
||||
pool.numa_node = pool_dict.pop("numa_node", None)
|
||||
pool.count = pool_dict.pop("count")
|
||||
pool.tags = {}
|
||||
pool.tags.update(pool_dict)
|
||||
pool.tags = pool_dict
|
||||
return pool
|
||||
|
||||
# NOTE(sbauza): Before using objects, pci stats was a list of
|
||||
|
|
|
@ -20,6 +20,7 @@ from oslo_log import log as logging
|
|||
|
||||
from nova import exception
|
||||
from nova.i18n import _LE
|
||||
from nova.objects import pci_device_pool
|
||||
from nova.pci import utils
|
||||
from nova.pci import whitelist
|
||||
|
||||
|
@ -254,3 +255,8 @@ class PciDeviceStats(object):
|
|||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
def to_device_pools_obj(self):
|
||||
"""Return the contents of the pools as a PciDevicePoolList object."""
|
||||
stats = [x for x in self]
|
||||
return pci_device_pool.from_pci_stats(stats)
|
||||
|
|
|
@ -20,13 +20,11 @@
|
|||
"os-pci:pci_stats": [
|
||||
{
|
||||
"count": 5,
|
||||
"extra_info": {
|
||||
"key1": "value1",
|
||||
"phys_function": "[[\"0x0000\", \"0x04\", \"0x00\", \"0x1\"]]"
|
||||
},
|
||||
"key1": "value1",
|
||||
"keya": "valuea",
|
||||
"product_id": "1520",
|
||||
"vendor_id": "8086"
|
||||
"vendor_id": "8086",
|
||||
"numa_node": 1
|
||||
}
|
||||
],
|
||||
"running_vms": 0,
|
||||
|
|
|
@ -19,13 +19,11 @@
|
|||
"os-pci:pci_stats": [
|
||||
{
|
||||
"count": 5,
|
||||
"extra_info": {
|
||||
"key1": "value1",
|
||||
"phys_function": "[[\"0x0000\", \"0x04\", \"0x00\", \"0x1\"]]"
|
||||
},
|
||||
"key1": "value1",
|
||||
"keya": "valuea",
|
||||
"product_id": "1520",
|
||||
"vendor_id": "8086"
|
||||
"vendor_id": "8086",
|
||||
"numa_node": 1
|
||||
}
|
||||
],
|
||||
"running_vms": 0,
|
||||
|
|
|
@ -134,11 +134,8 @@ class ExtendedHyervisorPciSampleJsonTest(api_sample_base.ApiSampleTestBaseV3):
|
|||
"vendor_id": "8086",
|
||||
"product_id": "1520",
|
||||
"keya": "valuea",
|
||||
"extra_info": {
|
||||
"phys_function": '[["0x0000", '
|
||||
'"0x04", "0x00",'
|
||||
' "0x1"]]',
|
||||
"key1": "value1"}}),)
|
||||
"key1": "value1",
|
||||
"numa_node": 1}),)
|
||||
self.fake_service = objects.Service(
|
||||
id=2,
|
||||
host='043b3cacf6f34c90a7245151fc8ebcda',
|
||||
|
|
|
@ -31,9 +31,8 @@ from nova.tests.unit.objects import test_pci_device
|
|||
pci_stats = [{"count": 3,
|
||||
"vendor_id": "8086",
|
||||
"product_id": "1520",
|
||||
"numa_node": 1,
|
||||
"extra_info": {"phys_function": '[["0x0000", "0x04", '
|
||||
'"0x00", "0x1"]]'}}]
|
||||
"numa_node": 1}]
|
||||
|
||||
fake_compute_node = objects.ComputeNode(
|
||||
pci_device_pools=pci_device_pool.from_pci_stats(pci_stats))
|
||||
|
||||
|
|
|
@ -37,6 +37,13 @@ class _TestPciDevicePoolObject(object):
|
|||
self.assertEqual(pool_obj.tags, {'t1': 'v1', 't2': 'v2'})
|
||||
self.assertEqual(pool_obj.count, 2)
|
||||
|
||||
def test_pci_pool_from_dict_bad_tags(self):
|
||||
bad_dict = copy.deepcopy(fake_pci.fake_pool_dict)
|
||||
bad_dict['bad'] = {'foo': 'bar'}
|
||||
self.assertRaises(ValueError,
|
||||
objects.PciDevicePool.from_dict,
|
||||
value=bad_dict)
|
||||
|
||||
def test_pci_pool_from_dict_no_tags(self):
|
||||
dict_notag = copy.copy(fake_pci.fake_pool_dict)
|
||||
dict_notag.pop('t1')
|
||||
|
|
|
@ -112,7 +112,7 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
|||
self.assertNotEqual(self.pci_stats, pci_stats2)
|
||||
|
||||
def test_object_create(self):
|
||||
m = objects.pci_device_pool.from_pci_stats(self.pci_stats.pools)
|
||||
m = self.pci_stats.to_device_pools_obj()
|
||||
new_stats = stats.PciDeviceStats(m)
|
||||
|
||||
self.assertEqual(len(new_stats.pools), 3)
|
||||
|
|
Loading…
Reference in New Issue