From fa6e7a7430b3f4e4b534ac6d8f7d07b3319e0e39 Mon Sep 17 00:00:00 2001 From: Michael Auchter Date: Thu, 22 Oct 2020 10:34:56 -0500 Subject: mpm: filesystem_status: tolerate absence of mender If the mender utility is not installed or exits with a failure, return NULL for the artifact rather than raising an exception (and disrupting device initialization). --- mpm/python/usrp_mpm/sys_utils/filesystem_status.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'mpm/python/usrp_mpm/sys_utils') diff --git a/mpm/python/usrp_mpm/sys_utils/filesystem_status.py b/mpm/python/usrp_mpm/sys_utils/filesystem_status.py index 865741316..b9617cf0a 100644 --- a/mpm/python/usrp_mpm/sys_utils/filesystem_status.py +++ b/mpm/python/usrp_mpm/sys_utils/filesystem_status.py @@ -38,16 +38,18 @@ def get_mender_artifact(filesystem_root='/', parse_manually=False): # parse mender artifact manually file = pathlib.Path(filesystem_root, 'etc/mender/artifact_info') if not file.exists(): - return 'FILE NOT FOUND' + return None return parse_artifact(file.read_text()) - else: + try: output = subprocess.check_output(['/usr/bin/mender', '-show-artifact']).decode('utf-8') return output.splitlines()[0] + except: + return None def get_fs_version(filesystem_root='/'): file = pathlib.Path(filesystem_root, 'etc/version') if not file.exists(): - return 'FILE NOT FOUND' + return None return file.read_text().splitlines()[0] def get_opkg_status_date(date_only=False, filesystem_root='/'): @@ -57,11 +59,11 @@ def get_opkg_status_date(date_only=False, filesystem_root='/'): tformat = "%Y-%m-%d %H:%M:%S" file = pathlib.Path(filesystem_root, 'var/lib/opkg/status') if not file.exists(): - return 'FILE NOT FOUND' + return None return time.strftime(tformat, time.gmtime(file.stat().st_mtime)) def get_opkg_status_md5sum(filesystem_root='/'): file = pathlib.Path(filesystem_root, 'var/lib/opkg/status') if not file.exists(): - return 'FILE NOT FOUND' + return None return hashlib.md5sum(file.read_text()).hexdigest() -- cgit v1.2.3