Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting SDR repository should work when there is an unknown record #99

Closed
EmilioPeJu opened this issue Oct 1, 2021 · 2 comments
Closed

Comments

@EmilioPeJu
Copy link
Contributor

EmilioPeJu commented Oct 1, 2021

When iterating the SDR repository, if it contains an unknown record, an exception is raised and we can't continue iterating over the remaining records. A possible solution would be having a default unknown sensor record class for dealing with that case, for example:

     SdrManagementControllerDeviceLocator,
-                SDR_TYPE_OEM_SENSOR_RECORD:
-                    SdrOEMSensorRecord,
-            }[sdr_type]
-        except KeyError:
-            raise DecodingError('Unsupported SDR type(0x%02x)' % sdr_type)
+        cls = {
+            SDR_TYPE_FULL_SENSOR_RECORD:
+                SdrFullSensorRecord,
+            SDR_TYPE_COMPACT_SENSOR_RECORD:
+                SdrCompactSensorRecord,
+            SDR_TYPE_EVENT_ONLY_SENSOR_RECORD:
+                SdrEventOnlySensorRecord,
+            SDR_TYPE_FRU_DEVICE_LOCATOR_RECORD:
+                SdrFruDeviceLocator,
+            SDR_TYPE_MANAGEMENT_CONTROLLER_DEVICE_LOCATOR_RECORD:
+                SdrManagementControllerDeviceLocator,
+            SDR_TYPE_OEM_SENSOR_RECORD:
+                SdrOEMSensorRecord,
+        }.get(sdr_type, SdrUnknownSensorRecord)

         return cls(data, next_id)

@@ -627,3 +624,20 @@ class SdrOEMSensorRecord(SdrCommon):

         # record key bytes
         self._common_record_key(buffer.pop_slice(3))
+
+
+# Any SDR type not known or not implemented
+class SdrUnknownSensorRecord(SdrCommon):
+    def __init__(self, data=None, next_id=None):
+        super(SdrUnknownSensorRecord, self).__init__(data, next_id)
+        if data:
+            self._from_data(data)
+
+    def __str__(self):
+        return 'Not supported yet.'
+
+    def _from_data(self, data):
+        buffer = ByteBuffer(data[5:])
+
+        # record key bytes
+        self._common_record_key(buffer.pop_slice(3))

@hthiery
Copy link
Contributor

hthiery commented Oct 1, 2021

Seems to be a good idea. Pleas make a PR and add a test for that.

@EmilioPeJu EmilioPeJu changed the title Getting SDR repository should work when there is a unknown record Getting SDR repository should work when there is an unknown record Oct 3, 2021
@EmilioPeJu
Copy link
Contributor Author

Done! I simplified the new class a bit, given we cannot assume an unknown record will have the record key part

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants