rhsm_release: improve the execution of subscription-manager (#6669)

- pass the arguments to run_command() directly as list, rather than
  joining the arguments to string, which run_command() will need to
  split again
- disable the expansions of variables, as there are none

Adapt the unit test to the different way run_command() is called,
factorizing the kwargs for run_command() so there is less repetition.

There should be no behaviour changes.
This commit is contained in:
Pino Toscano 2023-06-11 10:34:25 +02:00 committed by GitHub
parent 2bd8469a92
commit 74ffb29573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View file

@ -14,6 +14,8 @@ from ansible_collections.community.general.tests.unit.plugins.modules.utils impo
class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase):
module = rhsm_release
SUBMAN_KWARGS = dict(check_rc=True, expand_user_and_vars=False)
def setUp(self):
super(RhsmRepositoryReleaseModuleTestCase, self).setUp()
@ -63,8 +65,8 @@ class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase):
self.assertTrue(result['changed'])
self.assertEqual('7.5', result['current_release'])
self.module_main_command.assert_has_calls([
call('/testbin/subscription-manager release --show', check_rc=True),
call('/testbin/subscription-manager release --set 7.5', check_rc=True),
call(['/testbin/subscription-manager', 'release', '--show'], **self.SUBMAN_KWARGS),
call(['/testbin/subscription-manager', 'release', '--set', '7.5'], **self.SUBMAN_KWARGS),
])
def test_release_set_idempotent(self):
@ -81,7 +83,7 @@ class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase):
self.assertFalse(result['changed'])
self.assertEqual('7.5', result['current_release'])
self.module_main_command.assert_has_calls([
call('/testbin/subscription-manager release --show', check_rc=True),
call(['/testbin/subscription-manager', 'release', '--show'], **self.SUBMAN_KWARGS),
])
def test_release_unset(self):
@ -100,8 +102,8 @@ class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase):
self.assertTrue(result['changed'])
self.assertIsNone(result['current_release'])
self.module_main_command.assert_has_calls([
call('/testbin/subscription-manager release --show', check_rc=True),
call('/testbin/subscription-manager release --unset', check_rc=True),
call(['/testbin/subscription-manager', 'release', '--show'], **self.SUBMAN_KWARGS),
call(['/testbin/subscription-manager', 'release', '--unset'], **self.SUBMAN_KWARGS),
])
def test_release_unset_idempotent(self):
@ -118,7 +120,7 @@ class RhsmRepositoryReleaseModuleTestCase(ModuleTestCase):
self.assertFalse(result['changed'])
self.assertIsNone(result['current_release'])
self.module_main_command.assert_has_calls([
call('/testbin/subscription-manager release --show', check_rc=True),
call(['/testbin/subscription-manager', 'release', '--show'], **self.SUBMAN_KWARGS),
])
def test_release_insane(self):