-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Fix pkg_mgr_name fact finding for Fedora #40922
Conversation
b961850
to
0699fc9
Compare
The test
|
incorrect assumption as i can |
pkg_mgr_name = 'apt_rpm' | ||
if pkg_mgr_name == 'apt': | ||
if os.path.exists('/etc/fedora-release'): | ||
pkg_mgr_name = 'dnf' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this break 'old' fedora that are 'pre dnf'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcoca to the best of my knowledge, Fedora that's pre-dnf
don't have a version of python new enough to fall within the support matrix of current Ansible versions. Fedora has been dnf
since Fedora 15 which was released 2011-05-24 .... so, yes? technically, but outside the scope of practical support (IMO anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, just wanted to make sure someone had looked it up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcoca I'm incorrect, I just checked. Fedora 14 was the first release to ship with python 2.7. So my new question is: How far back in the history of EOL'd distros do we want to maintain compat for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the word 'reasonable' but too many people make it unreasonable ....
fine with the change, the problem hits ancient version and this is mainly a desktop distro or 'cutting edge' so i expect almost no one will be hit by this.
/me now waits for thousands of users complaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bcoca actually, I'll go ahead and add a check for version range that way we don't accidentally break anyone who happens to still have an old Fedora machine in their environment. (I'm sure that number is non-zero)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be non-zero, but i suspect it is infinitely close to 0
4d06427
to
103f107
Compare
3098978
to
2c50add
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error handling for a string 'major version' rest should be ok
# are reported/requested | ||
if pkg_mgr_name == 'apt': | ||
if collected_facts["ansible_distribution"] == "Fedora": | ||
if int(collected_facts["ansible_distribution_major_version"]) < 15: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, ansible_distribution_major_version can be a string[1] that wont cast to int, so may need a try/except here.
1: For ex, if all else fails, it can end up as the string 'NA'
pkg_mgr_name = 'yum' | ||
else: | ||
pkg_mgr_name = 'dnf' | ||
elif collected_facts["ansible_distribution"] == 'ALT Linux': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nitpick... mixed use of single and double quote for keys.
@maxamillion You may want to tackle this as well in this PR - #27300 |
The test
The test
|
CI failure in unit tests: https://app.shippable.com/github/ansible/ansible/runs/71044/3/tests |
# that are debian based, this handles some of those scenarios as they | ||
# are reported/requested | ||
if pkg_mgr_name == 'apt': | ||
import q; q(collected_facts['ansible_distribution']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we look at 'os_family' and any RH based and assume yum/dnf instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ansible_os_family": "RedHat"
.. though we might want to include Suse and other rpm based that would appear as 'family' value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going off of apt
purely because of the precedence model, but I could pivot and focus on distro families.
The test
The test
The test
The test
The test
The test
The test
The test
The test
The test
The test
The test
|
Signed-off-by: Adam Miller <admiller@redhat.com>
… when needed Signed-off-by: Adam Miller <admiller@redhat.com>
Signed-off-by: Adam Miller <admiller@redhat.com>
133673a
to
6dcaa50
Compare
} | ||
|
||
import ansible.module_utils.facts.system.pkg_mgr | ||
ansible.module_utils.facts.system.pkg_mgr.os = Mock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be using mock.patch?
iirc, this can leave ansible.module_utils.facts.system.pkg_mgr monkeypatched to be a mock for the rest of the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like:
--- test/units/module_utils/facts/test_collectors.py
+++ test/units/module_utils/facts/test_collectors.py
@@ -258,12 +258,8 @@ class TestPkgMgrFactsAptFedora(BaseFactsTest):
"ansible_pkg_mgr": "apt"
}
- import ansible.module_utils.facts.system.pkg_mgr
- ansible.module_utils.facts.system.pkg_mgr.os = Mock()
- ansible.module_utils.facts.system.pkg_mgr.os.path = Mock()
- ansible.module_utils.facts.system.pkg_mgr.os.path.exists = Mock(side_effect=_sanitize_os_path_apt_get)
-
- def test_collect(self):
+ @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)
Signed-off-by: Adam Miller <admiller@redhat.com>
rebuild_merge |
Marking this here for posterity, @alikins +1'd in slack. |
rebuild_merge |
rebuild_merge |
1 similar comment
rebuild_merge |
rebuild_merge |
1 similar comment
rebuild_merge |
Thank you! I believe this will fix my bug with Independent from that (at least for now), I notice Fedora has |
required_facts = set(['distribution']) | ||
|
||
def _check_rh_versions(self, collected_facts): | ||
if collected_facts['ansible_distribution'] == 'Fedora': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also check whether yum or dnf exists in the PATH before setting it in this function?
# based by virtue of a dependency to the systemd mkosi project, this | ||
# handles some of those scenarios as they are reported/requested | ||
if pkg_mgr_name == 'pacman' and collected_facts['ansible_os_family'] in ["RedHat"]: | ||
pkg_mgr_name = self._check_rh_versions(collected_facts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe organizing this with one conditional per ansible_os_family will be better for the future (and allow handling a distro being able to install more package managers in the future)
if collected_facts['ansible_os_family'] == "RedHat":
if pkg_mgr_name not in ('yum', 'dnf'):
pkg_mgr_name = self._check_rh_versions(collected_facts)
elif collected_facts['ansible_os_family'] == 'Altlinux':
if pkg_mgr_name == 'apt':
pkg_mgr_name = 'apt_rpm'
* 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 ansible#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>
* 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> * fix fedora version dnf fact, default pkg_mgr detection per distro family (#43261) * fix fedora version dnf fact, default pkg_mgr detection per distro family * loop over possible dnf/yum paths in case there are multiple canonical sources later in life Signed-off-by: Adam Miller <admiller@redhat.com> * pkg_mgr: fixed apt_rpm detection (#43769) Instead of checking the distribution name (which apparently is tricky to find out) check if /usr/bin/apt-get is managed by RPM. Fixes #43539 * Ensure that apt is always chosen on debian/ubuntu One can install alternate packages managers on debuntu machines. However, doing so doesn't mean you want to suddenly start using them. Add in a check similar to the fedora yum/dnf check that sets apt as the pkg_mgr if the ansible_os_family is Debian.
Signed-off-by: Adam Miller admiller@redhat.com
SUMMARY
Raises priority of
dnf
overapt
because it's possible to installapt
on Fedora from the official distro repositories but not the other way around.Add integration tests to ensure this doesn't break in the future.
Fixes #34014
Fixes #27300
ISSUE TYPE
COMPONENT NAME
lib/ansible/module_utils/facts/system/pkg_mgr.py
ANSIBLE VERSION