mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
redhat_subscription: fix D-Bus option for environments on CentOS (#6275)
Factorize the current logic to determine whether use 'environments' as D-Bus registration option (rather than 'environment') in an own function, so it is easier to read it and maintain it. With the small helper function in place, extend the logic to support CentOS: it is in practice the same as the RHEL one, with an additional check to support CentOS Stream 8 (which is a rolling release, and not versioned).
This commit is contained in:
parent
9bb768ae62
commit
c280b793de
2 changed files with 30 additions and 5 deletions
|
@ -0,0 +1,4 @@
|
|||
bugfixes:
|
||||
- redhat_subscription - use the right D-Bus options for environments when registering
|
||||
a CentOS Stream 8 system and using ``environment``
|
||||
(https://github.com/ansible-collections/community.general/pull/6275).
|
|
@ -544,7 +544,8 @@ class Rhsm(RegistrationBase):
|
|||
return default
|
||||
|
||||
distro_id = distro.id()
|
||||
distro_version = tuple(str2int(p) for p in distro.version_parts())
|
||||
distro_version_parts = distro.version_parts()
|
||||
distro_version = tuple(str2int(p) for p in distro_version_parts)
|
||||
|
||||
# Stop the rhsm service when using systemd (which means Fedora or
|
||||
# RHEL 7+): this is because the service may not use new configuration bits
|
||||
|
@ -585,11 +586,31 @@ class Rhsm(RegistrationBase):
|
|||
# of RHEL before 8.6, and then it changed to 'environments'; since
|
||||
# the Register*() D-Bus functions reject unknown options, we have
|
||||
# to pass the right option depending on the version -- funky.
|
||||
environment_key = 'environment'
|
||||
if distro_id == 'fedora' or \
|
||||
(distro_id == 'rhel' and
|
||||
def supports_option_environments():
|
||||
# subscription-manager in any supported Fedora version
|
||||
# has the new option.
|
||||
if distro_id == 'fedora':
|
||||
return True
|
||||
# Check for RHEL 8 >= 8.6, or RHEL >= 9.
|
||||
if distro_id == 'rhel' and \
|
||||
((distro_version[0] == 8 and distro_version[1] >= 6) or
|
||||
distro_version[0] >= 9)):
|
||||
distro_version[0] >= 9):
|
||||
return True
|
||||
# CentOS: similar checks as for RHEL, with one extra bit:
|
||||
# if the 2nd part of the version is empty, it means it is
|
||||
# CentOS Stream, and thus we can assume it has the latest
|
||||
# version of subscription-manager.
|
||||
if distro_id == 'centos' and \
|
||||
((distro_version[0] == 8 and
|
||||
(distro_version[1] >= 6 or distro_version_parts[1] == '')) or
|
||||
distro_version[0] >= 9):
|
||||
return True
|
||||
# Unknown or old distro: assume it does not support
|
||||
# the new option.
|
||||
return False
|
||||
|
||||
environment_key = 'environment'
|
||||
if supports_option_environments():
|
||||
environment_key = 'environments'
|
||||
register_opts[environment_key] = environment
|
||||
if force_register and dbus_force_option_works and was_registered:
|
||||
|
|
Loading…
Reference in a new issue