From 2f2f384b4e7f9455631f9143dcb2c5f76817ed67 Mon Sep 17 00:00:00 2001 From: Tong He <68936428+unnecessary-username@users.noreply.github.com> Date: Wed, 16 Jun 2021 03:01:54 -0400 Subject: [PATCH] redhat_subscription: Add server_prefix and server_port as supported arguments (#2779) * Add server_prefix and server_port as supported arguments for the redhat_subscription module. * Adjust the argument sequence in the test case to be consistent with the original code in line 364 in redhat_subscription.py and add the changelog fragment. * Grammatical changes such as adding full stops and using 'an HTTP' instead of 'a HTTP'. * Commit the suggested changelog update. Co-authored-by: Amin Vakil * Fix typo. Co-authored-by: Amin Vakil Co-authored-by: Amin Vakil --- ...tion-add_server_prefix_and_server_port.yml | 2 + .../packaging/os/redhat_subscription.py | 20 +++++++-- .../packaging/os/test_redhat_subscription.py | 41 +++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/2779_redhat_subscription-add_server_prefix_and_server_port.yml diff --git a/changelogs/fragments/2779_redhat_subscription-add_server_prefix_and_server_port.yml b/changelogs/fragments/2779_redhat_subscription-add_server_prefix_and_server_port.yml new file mode 100644 index 0000000000..d484874ee9 --- /dev/null +++ b/changelogs/fragments/2779_redhat_subscription-add_server_prefix_and_server_port.yml @@ -0,0 +1,2 @@ +minor_changes: + - redhat_subscription - add ``server_prefix`` and ``server_port`` parameters (https://github.com/ansible-collections/community.general/pull/2779). diff --git a/plugins/modules/packaging/os/redhat_subscription.py b/plugins/modules/packaging/os/redhat_subscription.py index b62a7f391c..c8b5e991a0 100644 --- a/plugins/modules/packaging/os/redhat_subscription.py +++ b/plugins/modules/packaging/os/redhat_subscription.py @@ -32,7 +32,7 @@ options: type: str username: description: - - access.redhat.com or Sat6 username + - access.redhat.com or Sat6 username type: str password: description: @@ -46,6 +46,16 @@ options: description: - Enable or disable https server certificate verification when connecting to C(server_hostname) type: str + server_prefix: + description: + - Specify the prefix when registering to the Red Hat Subscription Management or Sat6 server. + type: str + version_added: 3.3.0 + server_port: + description: + - Specify the port when registering to the Red Hat Subscription Management or Sat6 server. + type: str + version_added: 3.3.0 rhsm_baseurl: description: - Specify CDN baseurl @@ -56,11 +66,11 @@ options: type: str server_proxy_hostname: description: - - Specify a HTTP proxy hostname + - Specify an HTTP proxy hostname. type: str server_proxy_port: description: - - Specify a HTTP proxy port + - Specify an HTTP proxy port. type: str server_proxy_user: description: @@ -782,6 +792,8 @@ def main(): 'password': {'no_log': True}, 'server_hostname': {}, 'server_insecure': {}, + 'server_prefix': {}, + 'server_port': {}, 'rhsm_baseurl': {}, 'rhsm_repo_ca_cert': {}, 'auto_attach': {'aliases': ['autosubscribe'], 'type': 'bool'}, @@ -827,6 +839,8 @@ def main(): password = module.params['password'] server_hostname = module.params['server_hostname'] server_insecure = module.params['server_insecure'] + server_prefix = module.params['server_prefix'] + server_port = module.params['server_port'] rhsm_baseurl = module.params['rhsm_baseurl'] rhsm_repo_ca_cert = module.params['rhsm_repo_ca_cert'] auto_attach = module.params['auto_attach'] diff --git a/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py b/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py index ef6f28b812..7f430ee72c 100644 --- a/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py +++ b/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py @@ -258,6 +258,47 @@ TEST_CASES = [ 'msg': "System successfully registered to 'None'." } ], + # Test of registration with arguments that are not part of register options but needs to be configured + [ + { + 'state': 'present', + 'username': 'admin', + 'password': 'admin', + 'org_id': 'admin', + 'force_register': 'true', + 'server_prefix': '/rhsm', + 'server_port': '443' + }, + { + 'id': 'test_arguments_not_in_register_options', + 'run_command.calls': [ + ( + ['/testbin/subscription-manager', 'identity'], + {'check_rc': False}, + (0, 'This system already registered.', '') + ), + ( + ['/testbin/subscription-manager', 'config', + '--server.port=443', + '--server.prefix=/rhsm' + ], + {'check_rc': True}, + (0, '', '') + ), + ( + ['/testbin/subscription-manager', 'register', + '--force', + '--org', 'admin', + '--username', 'admin', + '--password', 'admin'], + {'check_rc': True, 'expand_user_and_vars': False}, + (0, '', '') + ) + ], + 'changed': True, + 'msg': "System successfully registered to 'None'." + } + ], # Test of registration using username, password and proxy options [ {