mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fix pkg_mgr_name fact finding for Fedora (#40922)
* Properly handle default package manager vs apt For distros where apt might be installed but is not the default package manager for the distro, properly identify the default distro package manager during fact finding and re-use fact finding from DistributionFactCollector and instead of reimplementing small portions of it in PkgMgrFactCollector Add unit test to always check the apt + Fedora combination to test the new code. Fixes #34014 Signed-off-by: Adam Miller <admiller@redhat.com> * remove q debugging output I accidentally left behind Signed-off-by: Adam Miller <admiller@redhat.com> * add os_family to the conditional so we're only hitting that code path when needed Signed-off-by: Adam Miller <admiller@redhat.com> * setup for a _check* pattern for general os_family group pkg_mgr checking Signed-off-by: Adam Miller <admiller@redhat.com> * use Mock.patch decorator for os.path.exists in TestPkgMgrFactsAptFedora Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
ab3475e3f9
commit
562ff66a98
4 changed files with 96 additions and 7 deletions
|
@ -202,6 +202,8 @@ class TestCollectedFacts(unittest.TestCase):
|
|||
'env']
|
||||
not_expected_facts = ['facter', 'ohai']
|
||||
|
||||
collected_facts = {}
|
||||
|
||||
def _mock_module(self, gather_subset=None):
|
||||
return mock_module(gather_subset=self.gather_subset)
|
||||
|
||||
|
@ -212,7 +214,8 @@ class TestCollectedFacts(unittest.TestCase):
|
|||
fact_collector = \
|
||||
ansible_collector.AnsibleFactCollector(collectors=collectors,
|
||||
namespace=ns)
|
||||
self.facts = fact_collector.collect(module=mock_module)
|
||||
self.facts = fact_collector.collect(module=mock_module,
|
||||
collected_facts=self.collected_facts)
|
||||
|
||||
def _collectors(self, module,
|
||||
all_collector_classes=None,
|
||||
|
@ -466,10 +469,15 @@ class TestOhaiCollectedFacts(TestCollectedFacts):
|
|||
class TestPkgMgrFacts(TestCollectedFacts):
|
||||
gather_subset = ['pkg_mgr']
|
||||
min_fact_count = 1
|
||||
max_fact_count = 10
|
||||
max_fact_count = 20
|
||||
expected_facts = ['gather_subset',
|
||||
'module_setup',
|
||||
'pkg_mgr']
|
||||
collected_facts = {
|
||||
"ansible_distribution": "Fedora",
|
||||
"ansible_distribution_major_version": "28",
|
||||
"ansible_os_family": "RedHat"
|
||||
}
|
||||
|
||||
|
||||
class TestOpenBSDPkgMgrFacts(TestPkgMgrFacts):
|
||||
|
|
|
@ -224,6 +224,11 @@ class TestPkgMgrFacts(BaseFactsTest):
|
|||
valid_subsets = ['pkg_mgr']
|
||||
fact_namespace = 'ansible_pkgmgr'
|
||||
collector_class = PkgMgrFactCollector
|
||||
collected_facts = {
|
||||
"ansible_distribution": "Fedora",
|
||||
"ansible_distribution_major_version": "28",
|
||||
"ansible_os_family": "RedHat"
|
||||
}
|
||||
|
||||
def test_collect(self):
|
||||
module = self._mock_module()
|
||||
|
@ -233,6 +238,35 @@ class TestPkgMgrFacts(BaseFactsTest):
|
|||
self.assertIn('pkg_mgr', facts_dict)
|
||||
|
||||
|
||||
def _sanitize_os_path_apt_get(path):
|
||||
if path == '/usr/bin/apt-get':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class TestPkgMgrFactsAptFedora(BaseFactsTest):
|
||||
__test__ = True
|
||||
gather_subset = ['!all', 'pkg_mgr']
|
||||
valid_subsets = ['pkg_mgr']
|
||||
fact_namespace = 'ansible_pkgmgr'
|
||||
collector_class = PkgMgrFactCollector
|
||||
collected_facts = {
|
||||
"ansible_distribution": "Fedora",
|
||||
"ansible_distribution_major_version": "28",
|
||||
"ansible_os_family": "RedHat",
|
||||
"ansible_pkg_mgr": "apt"
|
||||
}
|
||||
|
||||
@patch('ansible.module_utils.facts.system.pkg_mgr.os.path.exists', side_effect=_sanitize_os_path_apt_get)
|
||||
def test_collect(self, mock_os_path_exists):
|
||||
module = self._mock_module()
|
||||
fact_collector = self.collector_class()
|
||||
facts_dict = fact_collector.collect(module=module, collected_facts=self.collected_facts)
|
||||
self.assertIsInstance(facts_dict, dict)
|
||||
self.assertIn('pkg_mgr', facts_dict)
|
||||
|
||||
|
||||
class TestOpenBSDPkgMgrFacts(BaseFactsTest):
|
||||
__test__ = True
|
||||
gather_subset = ['!all', 'pkg_mgr']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue