diff --git a/plugins/modules/cm_trial.py b/plugins/modules/cm_trial_license.py similarity index 80% rename from plugins/modules/cm_trial.py rename to plugins/modules/cm_trial_license.py index 84ea9427..e686e794 100644 --- a/plugins/modules/cm_trial.py +++ b/plugins/modules/cm_trial_license.py @@ -26,7 +26,7 @@ DOCUMENTATION = r""" --- -module: cm_trial +module: cm_trial_license short_description: Activate the trial license of Cloudera Manager description: - Checking if the trial license is already activated. @@ -41,7 +41,7 @@ EXAMPLES = r""" --- - name: Activate the trial license of Cloudera Manager - cloudera.cluster.cm_trial: + cloudera.cluster.cm_trial_license: host: example.cloudera.com port: "7180" username: "jane_smith" @@ -88,22 +88,22 @@ def __init__(self, module): @ClouderaManagerModule.handle_process def process(self): - - api_instance = ClouderaManagerResourceApi(self.api_client) - - try: - get_trial_state_request = api_instance.read_license().to_dict() - - if get_trial_state_request: - self.cm_trial_output = get_trial_state_request - self.changed = False - - except ApiException as e: - if e.status == 404: - api_instance.begin_trial() - get_trial_state_request = api_instance.read_license().to_dict() - self.cm_trial_output = get_trial_state_request - self.changed = True + if not self.module.check_mode: + api_instance = ClouderaManagerResourceApi(self.api_client) + + try: + get_trial_state_request = api_instance.read_license().to_dict() + + if get_trial_state_request: + self.cm_trial_output = get_trial_state_request + self.changed = False + + except ApiException as e: + if e.status == 404: + api_instance.begin_trial() + get_trial_state_request = api_instance.read_license().to_dict() + self.cm_trial_output = get_trial_state_request + self.changed = True def main(): module = ClouderaManagerModule.ansible_module( diff --git a/tests/unit/plugins/modules/cm_trial/test_cm_trial.py b/tests/unit/plugins/modules/cm_trial/test_cm_trial_license.py similarity index 87% rename from tests/unit/plugins/modules/cm_trial/test_cm_trial.py rename to tests/unit/plugins/modules/cm_trial/test_cm_trial_license.py index 5dd22d92..afb1a6ba 100644 --- a/tests/unit/plugins/modules/cm_trial/test_cm_trial.py +++ b/tests/unit/plugins/modules/cm_trial/test_cm_trial_license.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2024 Cloudera, Inc. All Rights Reserved. +# Copyright 2023 Cloudera, Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,25 +21,25 @@ import logging import pytest -from ansible_collections.cloudera.cluster.plugins.modules import cm_trial +from ansible_collections.cloudera.cluster.plugins.modules import cm_trial_license from ansible_collections.cloudera.cluster.tests.unit import AnsibleExitJson, AnsibleFailJson LOG = logging.getLogger(__name__) -def test_pytest_cm_trial(module_args): +def test_pytest_cm_trial_license(module_args): module_args( { "username": os.getenv('CM_USERNAME'), "password": os.getenv('CM_PASSWORD'), "host": os.getenv('CM_HOST'), - "port": os.getenv('CM_PORT'), + "port": "7180", "verify_tls": "no", "debug": "no", } ) with pytest.raises(AnsibleExitJson) as e: - cm_trial.main() + cm_trial_license.main() # LOG.info(str(e.value)) LOG.info(str(e.value.cloudera_manager))