rhn_register fixes for username and password when unregistering

- Require username and password for unregistering and avoid "cannot marshal None unless allow_none is enabled" error when using an activation key and no channels specified.
- Update test fixtures and add changelog


Co-authored-by: WhyIsThisOpen <WhyIsThisOpen@users.noreply.github.com>
pull/49831/head
WhyIsThisOpen 6 years ago committed by Sam Doran
parent d8a690952e
commit 7bdca72713

@ -0,0 +1,2 @@
bugfixes:
- rhn_register - require username/password when unregistering and provide useful error message (https://github.com/ansible/ansible/issues/22300)

@ -295,11 +295,13 @@ class Rhn(redhat.RegistrationBase):
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]
new_channels.extend(channels)
return self.api('channel.software.setSystemChannels', self.systemid, list(new_channels))
else:
current_channels = self.api('channel.software.listSystemChannels', self.systemid)
current_channels = [item['label'] for item in current_channels]
@ -315,10 +317,13 @@ class Rhn(redhat.RegistrationBase):
new_childs.append(ch)
out_base = 0
out_childs = 0
if new_base:
out_base = self.api('system.setBaseChannel', self.systemid, new_base)
if new_childs:
out_childs = self.api('system.setChildChannels', self.systemid, new_childs)
return out_base and out_childs
def _is_hosted(self):
@ -344,7 +349,13 @@ def main():
enable_eus=dict(default=False, type='bool'),
nopackages=dict(default=False, type='bool'),
channels=dict(default=[], type='list'),
)
),
# username/password is required for state=absent, or if channels is not empty
# (basically anything that uses self.api requires username/password) but it doesnt
# look like we can express that with required_if/required_together/mutually_exclusive
# only username+password can be used for unregister
required_if=[['state', 'absent', ['username', 'password']]]
)
if not HAS_UP2DATE_CLIENT:
@ -404,6 +415,9 @@ def main():
if not rhn.is_registered:
module.exit_json(changed=False, msg="System already unregistered.")
if not (rhn.username and rhn.password):
module.fail_json(msg="Missing arguments, the system is currently registered and unregistration requires a username and password")
try:
rhn.unregister()
except Exception as exc:

@ -110,7 +110,7 @@ def test_without_required_parameters(capfd, patch_rhn):
TESTED_MODULE = rhn_register.__name__
TEST_CASES = [
[
# Registering an unregistered host and subscribing to one channel
# Registering an unregistered host with channels
{
'channels': 'rhel-x86_64-server-6',
'username': 'user',
@ -137,9 +137,11 @@ TEST_CASES = [
}
],
[
# Registering an unregistered host with only an activationkey and without subscribing any channels
# Registering an unregistered host without channels
{
'activationkey': 'key',
'username': 'user',
'password': 'pass',
},
{
'calls': [

Loading…
Cancel
Save