Merge "Read the ReadOnly attribute property in any case"
This commit is contained in:
commit
fcd6dc98a5
3 files changed
+53
-1
No files matched your search
@@ -0,0 +1,8 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
The ``ReadOnly`` property of an attribute registry entry is now read
|
||||
whatever case a vendor uses for it. Dell's manager and BIOS attribute
|
||||
registries spell it ``Readonly``, so every entry from an iDRAC previously
|
||||
reported ``read_only`` as ``None`` rather than saying whether the
|
||||
attribute could be changed.
|
||||
@@ -20,6 +20,20 @@ from sushy.resources import base
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _read_only_key(key, value=None, **context):
|
||||
"""Match the ReadOnly property regardless of how a vendor cases it.
|
||||
|
||||
The schema spells it ``ReadOnly``, but Dell's manager and BIOS attribute
|
||||
registries spell it ``Readonly``, which would otherwise be missed and
|
||||
leave every attribute reporting no read-only state at all.
|
||||
|
||||
:param key: candidate JSON key.
|
||||
:param value: value of the candidate key, unused.
|
||||
:returns: True if the key is the ReadOnly property.
|
||||
"""
|
||||
return key.lower() == 'readonly'
|
||||
|
||||
|
||||
class AttributeListField(base.ListField):
|
||||
|
||||
name = base.Field('AttributeName', required=True)
|
||||
@@ -40,7 +54,7 @@ class AttributeListField(base.ListField):
|
||||
immutable = base.Field('Immutable', adapter=bool)
|
||||
"""An indication of whether this attribute is immutable"""
|
||||
|
||||
read_only = base.Field('ReadOnly', adapter=bool)
|
||||
read_only = base.Field(_read_only_key, adapter=bool)
|
||||
"""An indication of whether this attribute is read-only"""
|
||||
|
||||
reset_required = base.Field('ResetRequired', adapter=bool)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import copy
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
@@ -105,3 +106,32 @@ class AttributeRegistryTestCase(base.TestCase):
|
||||
{'ValueDisplayName': 'Enable',
|
||||
'ValueName': 'Enable'}],
|
||||
attributes.allowable_values)
|
||||
|
||||
def test__parse_attributes_vendor_cased_read_only(self):
|
||||
# Dell's registries spell the property "Readonly".
|
||||
doc = copy.deepcopy(self.json_doc)
|
||||
for attribute in doc['RegistryEntries']['Attributes']:
|
||||
attribute['Readonly'] = attribute.pop('ReadOnly')
|
||||
self.conn.get.return_value.json.return_value = doc
|
||||
|
||||
registry = attribute_registry.AttributeRegistry(
|
||||
self.conn, '/redfish/v1/Test/Bios/BiosRegistry',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
attributes = registry.registry_entries.attributes[0]
|
||||
self.assertEqual('SystemModelName', attributes.name)
|
||||
self.assertEqual(True, attributes.read_only)
|
||||
self.assertEqual(False,
|
||||
registry.registry_entries.attributes[1].read_only)
|
||||
|
||||
def test__parse_attributes_no_read_only(self):
|
||||
doc = copy.deepcopy(self.json_doc)
|
||||
for attribute in doc['RegistryEntries']['Attributes']:
|
||||
del attribute['ReadOnly']
|
||||
self.conn.get.return_value.json.return_value = doc
|
||||
|
||||
registry = attribute_registry.AttributeRegistry(
|
||||
self.conn, '/redfish/v1/Test/Bios/BiosRegistry',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
self.assertIsNone(registry.registry_entries.attributes[0].read_only)
|
||||
Reference in new issue
Block a user