[PR #6658/42f7531f backport][stable-7] redhat_subscription: refactor of internal Rhsm class (#6667)

redhat_subscription: refactor of internal Rhsm class (#6658)

The two RegistrationBase & Rhsm classes were copied from the ones in the
shared module_utils.redhat module; that said:
- the versions here got improvements over the years
- the RegistrationBase in module_utils.redhat is used only by the RHN
  modules, which are deprecated and slated for removal

Hence, the classes here can be kept and simplified a bit:
- fold the non-dummy content of RegistrationBase into Rhsm: there is no
  more need for the separate RegistrationBase base class
- drop the init arguments "username", "password", and "token": the
  instance variables of them are not used anywhere, as the needed
  credentials (together with other variables) are passed to the
  register() method
- create the Rhsm object later in main(), after the AnsibleModule
  creation and the uid check: this avoids the creation of Rhsm with a
  null module variable, changing it later

There should be no behaviour change.

(cherry picked from commit 42f7531f21)

Co-authored-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
patchback[bot] 2023-06-10 21:10:56 +02:00 committed by GitHub
parent 88b5e7ec0b
commit 396b94183d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 37 deletions

View file

@ -22,7 +22,7 @@ def patch_redhat_subscription(mocker):
"""
Function used for mocking some parts of redhat_subscription module
"""
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.RegistrationBase.REDHAT_REPO')
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.Rhsm.REDHAT_REPO')
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.isfile', return_value=False)
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.unlink', return_value=True)
mocker.patch('ansible_collections.community.general.plugins.modules.redhat_subscription.AnsibleModule.get_bin_path',