From d68c734ae203b11bed0c3341dad5968ec8a812d3 Mon Sep 17 00:00:00 2001 From: photoninger Date: Wed, 22 Aug 2018 18:25:58 +0200 Subject: [PATCH] Fix for "cannot marshal None unless.." (#33660) when using only an activation key without any channels. As already suggested by mattclay in https://github.com/ansible/ansible/pull/25079 and also patch unit test for rhn_register and add test case for activationkey only --- .../modules/packaging/os/rhn_register.py | 2 ++ .../modules/packaging/os/test_rhn_register.py | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/os/rhn_register.py b/lib/ansible/modules/packaging/os/rhn_register.py index 44267c39b9e..3bb07132b83 100644 --- a/lib/ansible/modules/packaging/os/rhn_register.py +++ b/lib/ansible/modules/packaging/os/rhn_register.py @@ -292,6 +292,8 @@ class Rhn(redhat.RegistrationBase): os.unlink(self.config['systemIdPath']) def subscribe(self, channels): + if not channels: + return if self._is_hosted(): current_channels = self.api('channel.software.listSystemChannels', self.systemid) new_channels = [item['channel_label'] for item in current_channels] diff --git a/test/units/modules/packaging/os/test_rhn_register.py b/test/units/modules/packaging/os/test_rhn_register.py index 7900115e74f..0cf4548a164 100644 --- a/test/units/modules/packaging/os/test_rhn_register.py +++ b/test/units/modules/packaging/os/test_rhn_register.py @@ -110,9 +110,9 @@ def test_without_required_parameters(capfd, patch_rhn): TESTED_MODULE = rhn_register.__name__ TEST_CASES = [ [ - # Registering an unregistered host + # Registering an unregistered host and subscribing to one channel { - 'activationkey': 'key', + 'channels': 'rhel-x86_64-server-6', 'username': 'user', 'password': 'pass', }, @@ -136,6 +136,26 @@ TEST_CASES = [ 'unlink.call_count': 0, } ], + [ + # Registering an unregistered host with only an activationkey and without subscribing any channels + { + 'activationkey': 'key', + }, + { + 'calls': [ + ], + 'is_registered': False, + 'is_registered.call_count': 1, + 'enable.call_count': 1, + 'systemid.call_count': 0, + 'changed': True, + 'msg': "System successfully registered to 'rhn.redhat.com'.", + 'run_command.call_count': 1, + 'run_command.call_args': '/usr/sbin/rhnreg_ks', + 'request_called': False, + 'unlink.call_count': 0, + } + ], [ # Register an host already registered, check that result is unchanged {