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

Pkg facts apt fix #56008

Open
wants to merge 2 commits into
base: stable-2.8
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,2 @@
bugfixes:
- For package_facts, correct information about apt being missing and fix missing attribute.
@@ -18,6 +18,8 @@ def get_all_pkg_managers():

class PkgMgr(with_metaclass(ABCMeta, object)):

warnings = []

This comment has been minimized.

Copy link
@samdoran

samdoran May 20, 2019

Member

I'm not sure it makes sense to add this is as a class attribute. Warnings aren't inherently something related to a PkgMgr object.

Should we create a global value to hold warning state, then process the warning state in fail_json() or exit_json()?

This comment has been minimized.

Copy link
@bcoca

bcoca May 20, 2019

Author Member

so module.warn?

This comment has been minimized.

Copy link
@samdoran

samdoran May 20, 2019

Member

Pretty much. But without the need for a module instance. This would give us a better place to keep warnings than adding a new attribute here.

This comment has been minimized.

Copy link
@bcoca

bcoca May 20, 2019

Author Member

w/o module it cannot be processed in fail_json/exit_json automatically, that is why i did it this way, still works in similar fashion

This comment has been minimized.

Copy link
@abadger

abadger Jun 3, 2019

Member

Issue outstanding.


@abstractmethod
def is_available(self):
# This method is supposed to return True/False if the package manager is currently installed/usable
@@ -155,6 +155,7 @@

from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.process import get_bin_path
from ansible.module_utils.facts.packages import LibMgr, CLIMgr, get_all_pkg_managers


@@ -177,6 +178,10 @@ class APT(LibMgr):

LIB = 'apt'

def __init__(self):
self._cache = None
super(APT, self).__init__()

@property
def pkg_cache(self):
if self._cache:
@@ -185,6 +190,16 @@ def pkg_cache(self):
self._cache = self._lib.Cache()
return self._cache

def is_available(self):
''' we expect the python bindings installed, but if there is apt/apt-get give warning about missing bindings'''
we_have_lib = super(APT, self).is_available()
if not we_have_lib:
for exe in ('apt', 'apt-get'):
if get_bin_path(exe):
self.warnings.append('Found "%s" but python bindings are missing, so we cannot get package information.' % exe)
break
return we_have_lib

def list_installed(self):
return [pk for pk in self.pkg_cache.keys() if self.pkg_cache[pk].is_installed]

@@ -295,11 +310,15 @@ def main():
if manager.is_available():
found += 1
packages.update(manager.get_packages())

except Exception as e:
if pkgmgr in module.params['manager']:
module.warn('Requested package manager %s was not usable by this module: %s' % (pkgmgr, to_text(e)))
continue

for warning in getattr(manager, 'warnings', []):
module.warn(warning)

except Exception as e:
if pkgmgr in module.params['manager']:
module.warn('Failed to retrieve packages with %s: %s' % (pkgmgr, to_text(e)))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.