diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py index ecfc19f13..ffaa051a1 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py @@ -80,12 +80,17 @@ class OpenBMCFlashTask(ParallelNodesCommand): def _get_firmware_version(self, target_file): - grep_cmd = '/usr/bin/grep -a' - version_cmd = grep_cmd + ' ^version= ' + target_file - purpose_cmd = grep_cmd + ' purpose= ' + target_file - firmware = os.popen(version_cmd).readlines()[0].split('=')[-1].strip() - purpose = os.popen(purpose_cmd).readlines()[0].split('=')[-1].strip().split('.')[-1] - return { firmware: {'purpose': purpose} } + version = purpose = None + with open(target_file, 'r') as fh: + for line in fh: + if 'version=' in line: + version = line.split('=')[-1].strip() + if 'purpose=' in line: + purpose = line.split('=')[-1].strip().split('.')[-1] + if version and purpose: + break + + return { version: {'purpose': purpose} } def pre_activate_firm(self, task, activate_arg, **kw): diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py index 6cd2ea871..8fdf93368 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py @@ -28,22 +28,18 @@ class OpenBMCInventoryTask(ParallelNodesCommand): target_file = utils.get_full_path(self.cwd, target_file) - grep_cmd = '/usr/bin/grep -a' - version_cmd = grep_cmd + ' ^version= ' + target_file - purpose_cmd = grep_cmd + ' purpose= ' + target_file - purpose_ver = os.popen(purpose_cmd).readlines() - firmware_ver = os.popen(version_cmd).readlines() - if purpose_ver: - purpose_ver = purpose_ver[0].split('=')[-1].strip() - else: - purpose_ver = '' - if firmware_ver: - firmware_ver = firmware_ver[0].split('=')[-1].strip() - else: - firmware_ver = '' + version = purpose = None + with open(target_file, 'r') as fh: + for line in fh: + if 'version=' in line: + version = line.split('=')[-1].strip() + if 'purpose=' in line: + purpose = line.split('=')[-1].strip().split('.')[-1] + if version and purpose: + break self.callback.info('TAR %s Firmware Product Version: %s' \ - % (purpose_ver,firmware_ver)) + % (purpose, version)) def _get_firm_info(self, firm_info_list): (has_functional, firm_obj_dict) = firm_info_list