Fix OEM required attribute parsing
During initialization vendor id is not known and it does not pick up Oem/Vendor section that triggers missing attribute error when at least one field is marked as required. Fix this by skipping parsing if vendor id is not known. Attributes are parsed again after setting parent resource with vendor id. It is expected that setting parent resource will always be done from `common.get_resource_extension_by_vendor` method. Change-Id: Ib6cd982cb5def522c1a24b9914f2135ba2aeae71
This commit is contained in:
parent
aed23871f7
commit
55d949cccc
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes OEM resource attribute parsing for OEM resources with required
|
||||
fields. Before the fix an error such as "The attribute <attribute name> is
|
||||
missing from the resource <resource path>" occurred.
|
@ -55,6 +55,11 @@ class OEMResourceBase(base.ResourceBase):
|
||||
|
||||
:param json_doc: parsed JSON document in form of Python types
|
||||
"""
|
||||
# Too early to parse, need to call set_parent_resource first that
|
||||
# assigns vendor_id and re-parses attributes
|
||||
if self._vendor_id is None:
|
||||
return
|
||||
|
||||
oem_json = json_doc.get(
|
||||
'Oem', {}).get(self._vendor_id, {})
|
||||
|
||||
|
@ -31,6 +31,7 @@ class ContosoActionsField(base.CompositeField):
|
||||
class FakeOEMSystemExtension(oem_base.OEMResourceBase):
|
||||
|
||||
data_type = base.Field('@odata.type')
|
||||
name = base.Field('Name', required=True)
|
||||
production_location = ProductionLocationField('ProductionLocation')
|
||||
_actions = ContosoActionsField('Actions')
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
"Oem": {
|
||||
"Contoso": {
|
||||
"@odata.type": "#Contoso.ComputerSystem",
|
||||
"Name": "Contoso OEM system",
|
||||
"ProductionLocation": {
|
||||
"FacilityName": "PacWest Production Facility",
|
||||
"Country": "USA"
|
||||
|
@ -37,6 +37,7 @@ class FakeOEMSystemExtensionTestCase(base.TestCase):
|
||||
self.sys_instance, 'Contoso')
|
||||
|
||||
def test__parse_oem_attributes(self):
|
||||
self.assertEqual('Contoso OEM system', self.fake_sys_oem_extn.name)
|
||||
self.assertEqual('#Contoso.ComputerSystem',
|
||||
self.fake_sys_oem_extn.data_type)
|
||||
self.assertEqual('PacWest Production Facility', (
|
||||
|
Loading…
Reference in New Issue
Block a user