Merge "Add support to expose oem_vendors from resource links"

This commit is contained in:
Zuul 2020-11-08 21:48:26 +00:00 committed by Gerrit Code Review
commit 7016cc0f31
2 changed files with 32 additions and 3 deletions

View File

@ -218,6 +218,11 @@ class ListField(Field):
return getattr(self, key)
class LinksField(CompositeField):
"""Reference to linked resources."""
oem_vendors = Field('Oem', adapter=list)
class DictionaryField(Field):
"""Base class for fields consisting of dictionary of several sub-fields."""
@ -483,9 +488,11 @@ class ResourceBase(object, metaclass=abc.ABCMeta):
redfish_version = None
"""The Redfish version"""
oem_vendors = Field('Oem', adapter=list)
_oem_vendors = Field('Oem', adapter=list)
"""The list of OEM extension names for this resource."""
links = LinksField('Links')
def __init__(self,
connector,
path='',
@ -638,6 +645,12 @@ class ResourceBase(object, metaclass=abc.ABCMeta):
if force_refresh:
self.refresh()
@property
def oem_vendors(self):
return list(
set((self._oem_vendors or []) + (self.links.oem_vendors or []))
)
@property
def json(self):
return self._json

View File

@ -40,7 +40,21 @@ BASE_RESOURCE_JSON = {
"@odata.type": "http://AnotherStandardsBody/schemas.v1_0_1#styleInfoExt", # noqa
"Style": "Executive"
}
},
"Links": {
"Oem": {
"Contoso": {
"@odata.type": "http://contoso.com/schemas/extensions.v1_2_1#contoso.AnvilTypes1", # noqa
"slogan": "Contoso never fail",
"disclaimer": "* Most of the time"
},
"EID_420_ASB_345": {
"@odata.type": "http://AnotherStandardsBody/schemas.v1_0_1#styleInfoExt", # noqa
"Style": "Executive"
}
}
}
}
@ -139,8 +153,10 @@ class ResourceBaseTestCase(base.TestCase):
self.assertIsNot(resource_a._reader, resource_b._reader)
def test__parse_attributes(self):
for oem_vendor in self.base_resource2.oem_vendors:
self.assertTrue(oem_vendor in ('Contoso', 'EID_412_ASB_123'))
expected_oem_vendors = ['Contoso', 'EID_412_ASB_123',
'EID_420_ASB_345']
actual_oem_vendors = sorted(self.base_resource2.oem_vendors)
self.assertEqual(expected_oem_vendors, actual_oem_vendors)
self.assertEqual('base_resource2', self.base_resource2.resource_name)
def test_refresh_local(self):