1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

redhat_subscription: use D-Bus registration on RHEL 7 only on 7.4+ (#7624)

subscription-manager does not provide a D-Bus interface in versions of
RHEL 7 older than 7.4.
This commit is contained in:
Pino Toscano 2023-11-30 05:58:07 +01:00 committed by GitHub
parent 1b9d437be8
commit af01b462d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View file

@ -0,0 +1,6 @@
bugfixes:
- |
redhat_subscription - use the D-Bus registration on RHEL 7 only on 7.4 and
greater; older versions of RHEL 7 do not have it
(https://github.com/ansible-collections/community.general/issues/7622,
https://github.com/ansible-collections/community.general/pull/7624).

View file

@ -28,7 +28,7 @@ notes:
process listing on the system. Due to limitations of the D-Bus interface of C(rhsm), process listing on the system. Due to limitations of the D-Bus interface of C(rhsm),
the module will I(not) use D-Bus for registration when trying either to register the module will I(not) use D-Bus for registration when trying either to register
using O(token), or when specifying O(environment), or when the system is old using O(token), or when specifying O(environment), or when the system is old
(typically RHEL 6 and older). (typically RHEL 7 older than 7.4, RHEL 6, and older).
- In order to register a system, subscription-manager requires either a username and password, or an activationkey and an Organization ID. - In order to register a system, subscription-manager requires either a username and password, or an activationkey and an Organization ID.
- Since 2.5 values for O(server_hostname), O(server_insecure), O(rhsm_baseurl), - Since 2.5 values for O(server_hostname), O(server_insecure), O(rhsm_baseurl),
O(server_proxy_hostname), O(server_proxy_port), O(server_proxy_user) and O(server_proxy_hostname), O(server_proxy_port), O(server_proxy_user) and
@ -414,6 +414,30 @@ class Rhsm(object):
else: else:
return False return False
def _has_dbus_interface(self):
"""
Checks whether subscription-manager has a D-Bus interface.
:returns: bool -- whether subscription-manager has a D-Bus interface.
"""
def str2int(s, default=0):
try:
return int(s)
except ValueError:
return default
distro_id = distro.id()
distro_version = tuple(str2int(p) for p in distro.version_parts())
# subscription-manager in any supported Fedora version has the interface.
if distro_id == 'fedora':
return True
# Any other distro: assume it is EL;
# the D-Bus interface was added to subscription-manager in RHEL 7.4.
return (distro_version[0] == 7 and distro_version[1] >= 4) or \
distro_version[0] >= 8
def _can_connect_to_dbus(self): def _can_connect_to_dbus(self):
""" """
Checks whether it is possible to connect to the system D-Bus bus. Checks whether it is possible to connect to the system D-Bus bus.
@ -457,7 +481,8 @@ class Rhsm(object):
# of rhsm, so always use the CLI in that case; # of rhsm, so always use the CLI in that case;
# also, since the specified environments are names, and the D-Bus APIs # also, since the specified environments are names, and the D-Bus APIs
# require IDs for the environments, use the CLI also in that case # require IDs for the environments, use the CLI also in that case
if not token and not environment and self._can_connect_to_dbus(): if (not token and not environment and self._has_dbus_interface() and
self._can_connect_to_dbus()):
self._register_using_dbus(was_registered, username, password, auto_attach, self._register_using_dbus(was_registered, username, password, auto_attach,
activationkey, org_id, consumer_type, activationkey, org_id, consumer_type,
consumer_name, consumer_id, consumer_name, consumer_id,

View file

@ -29,6 +29,8 @@ def patch_redhat_subscription(mocker):
return_value='/testbin/subscription-manager') return_value='/testbin/subscription-manager')
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.Rhsm._can_connect_to_dbus', mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.Rhsm._can_connect_to_dbus',
return_value=False) return_value=False)
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.Rhsm._has_dbus_interface',
return_value=False)
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.getuid', mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.getuid',
return_value=0) return_value=0)