Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #18999: when we install a plugin, if the dependency (package manager) is not met, it still tries to install it and fails #3551

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a case in the same way that the "binary" type was defined. I am pretty sure we want to have typed dependencies and so, an "apt" and a "rpm" type of dependencies..

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