From bc79e5c3093c23ba16f79421ff53ed0c7a22a14a Mon Sep 17 00:00:00 2001 From: Jakub Hadvig Date: Tue, 5 Sep 2017 11:03:03 +0200 Subject: Import dnf only if importing yum fails --- roles/openshift_health_checker/library/aos_version.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/roles/openshift_health_checker/library/aos_version.py b/roles/openshift_health_checker/library/aos_version.py index c8769b511..34d8f71e7 100644 --- a/roles/openshift_health_checker/library/aos_version.py +++ b/roles/openshift_health_checker/library/aos_version.py @@ -32,11 +32,14 @@ try: PKG_MGR = "yum" except ImportError as err: YUM_IMPORT_EXCEPTION = err -try: - import dnf # pylint: disable=import-error - PKG_MGR = "dnf" -except ImportError as err: - DNF_IMPORT_EXCEPTION = err + +# Import and use dnf only if yum is missing +if YUM_IMPORT_EXCEPTION: + try: + import dnf # pylint: disable=import-error + PKG_MGR = "dnf" + except ImportError as err: + DNF_IMPORT_EXCEPTION = err class AosVersionException(Exception): @@ -127,8 +130,11 @@ def _retrieve_available_packages(expected_pkgs): dquery = dbase.sack.query() aquery = dquery.available() + iquery = dquery.installed() - pkgs = list(aquery.filter(name=expected_pkgs)) + available_pkgs = list(aquery.filter(name=expected_pkgs)) + installed_pkgs = list(iquery.filter(name=expected_pkgs)) + pkgs = available_pkgs + installed_pkgs if not pkgs: # pkgs list is empty, raise because no expected packages found -- cgit v1.2.3