Skip to content

Commit

Permalink
Fixes #18999: when we install a plugin, if the dependency (package ma…
Browse files Browse the repository at this point in the history
…nager) is not met, it still tries to install it and fails
  • Loading branch information
ncharles authored and fanf committed Apr 16, 2021
1 parent 8bffc16 commit c99cd86
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion relay/sources/rudder-pkg/lib/rudder-pkg/rudderPkgUtils.py
Expand Up @@ -16,6 +16,17 @@

logger = logging.getLogger("rudder-pkg")

try:
import rpm
except:
logger.debug("No rpm python lib found")

try:
import apt
except:
logger.debug("No apt python lib found")


# See global variables at the end of the file
""" Get Terminal width """
def terminal_size():
Expand Down Expand Up @@ -307,7 +318,38 @@ def install_dependencies(metadata):
logger.warning("The binary " + executable + " was not found on the system, you must install it before installing " + metadata['name'])
return False
else:
has_depends = True
dependencyToCheck = False
packageManagerQueried = False
try:
if system == "rpm":
dependencyToCheck = True
if distutils.spawn.find_executable("rpm") is not None:
# this is an rpm system
ts = rpm.TransactionSet()
for package in metadata["depends"]["rpm"]:
mi = ts.dbMatch('name', package)
packageManagerQueried = True
try :
h = mi.next()
except StopIteration:
logger.warning("The rpm package " + package + " was not found on the system, you must install it before installing " + metadata['name'])
return False
if system == "apt":
dependencyToCheck = True
if distutils.spawn.find_executable("apt") is not None:
cache = apt.Cache()
packageManagerQueried = True
for package in metadata["depends"]["apt"]:
if not cache[package].is_installed:
logger.warning("The apt package " + package + " was not found on the system, you must install it before installing " + metadata['name'])
return False
except Exception:
logger.error("Could not query rpm or apt package repository to check dependencies for this plugin.")

# dependency check failed
if dependencyToCheck and not packageManagerQueried:
logger.warning("Neither rpm nor apt could be queried successfully - cannot check the dependencies for this plugin.")

if not depends_printed:
logger.info("This package depends on the following")
depends_printed = True
Expand Down

0 comments on commit c99cd86

Please sign in to comment.