From e2b2f6806bcdd37d48761538aa722439c47d0975 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Fri, 17 Dec 2021 14:25:50 +0100 Subject: [PATCH] Refactor oemmap lookup Previously, looking up an unknown OEM resulted in an exception being logged: exception while get_oem_handler, oemid:{'device_id': 32, 'device_revision': 1, 'manufacturer_id': 10876, 'product_id': 2414, 'firmware_version': '1.73'} Traceback (most recent call last): File "/omd/sites/plutex/local/lib/python3/pyghmi/ipmi/oem/lookup.py", line 43, in get_oem_handler return (oemmap[oemid['manufacturer_id']].OEMHandler(oemid, KeyError: 10876 So while I was at it, I also reduced duplicate code. Signed-off-by: Jan-Philipp Litza Change-Id: Ib2483aeb3f92bcafbaa877eb1c0318a385f97474 --- pyghmi/ipmi/oem/lookup.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pyghmi/ipmi/oem/lookup.py b/pyghmi/ipmi/oem/lookup.py index 24740c51..ac05f2ad 100755 --- a/pyghmi/ipmi/oem/lookup.py +++ b/pyghmi/ipmi/oem/lookup.py @@ -33,18 +33,16 @@ oemmap = { def get_oem_handler(oemid, ipmicmd, *args): - try: - # first try to find with composite key manufacturer_id.product_id, - # if found return directly - # then try to find with manufacturer_id - item = '{}.{}'.format(oemid['manufacturer_id'], oemid['product_id']) + # first try to find with composite key manufacturer_id.product_id, + # if found return directly + # then try to find with manufacturer_id + for item in ( + '{}.{}'.format(oemid['manufacturer_id'], oemid['product_id']), + oemid['manufacturer_id'], + ): if item in oemmap: return (oemmap[item].OEMHandler(oemid, ipmicmd, *args), True) - return (oemmap[oemid['manufacturer_id']].OEMHandler(oemid, - ipmicmd, *args), True) - except KeyError: - logger.exception( - 'exception while get_oem_handler, oemid:{0}'.format(oemid)) + else: return generic.OEMHandler(oemid, ipmicmd, *args), False