From e47fc0d6a88c60b05bce2e0915800906840ae3ad Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 26 Mar 2019 14:58:23 -0400 Subject: [PATCH] Fallback behavior on unparseable conditionals If firmware offers up an unparseable expression, prcoeed as if the expression were not there in the first place. The occurance observed was not viable. This hampers the improved error message, but the firmware will still enforce any rules. Change-Id: I2be9db12b9fa8da9d40bf6829b3cdc02bbdc946d --- pyghmi/ipmi/oem/lenovo/config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pyghmi/ipmi/oem/lenovo/config.py b/pyghmi/ipmi/oem/lenovo/config.py index b637a5fd..b638d83a 100644 --- a/pyghmi/ipmi/oem/lenovo/config.py +++ b/pyghmi/ipmi/oem/lenovo/config.py @@ -116,11 +116,14 @@ class _ExpEngine(object): def _eval_conditional(expression, cfg, setting): if not expression: return False, () - parsed = ast.parse(expression) - parsed = parsed.body[0].value - evaluator = _ExpEngine(cfg, setting) - result = evaluator.process(parsed) - return result, evaluator.relatedsettings + try: + parsed = ast.parse(expression) + parsed = parsed.body[0].value + evaluator = _ExpEngine(cfg, setting) + result = evaluator.process(parsed) + return result, evaluator.relatedsettings + except SyntaxError: + return False, () class LenovoFirmwareConfig(object):