Skip to content

Commit

Permalink
Add HTTP status test when discovering CM endpoint (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Webster Mudge <[email protected]>
  • Loading branch information
wmudge authored Nov 22, 2024
1 parent f64ce9b commit fe3ea60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 7 additions & 1 deletion plugins/module_utils/cm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from time import sleep
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.dict_transformations import recursive_diff
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.common.text.converters import to_native, to_text
from time import sleep
from cm_client import (
ApiClient,
Expand Down Expand Up @@ -434,6 +434,12 @@ def discover_endpoint(self, config):
if not self.version:
pre_versioned = urljoin(rendered_url, "/api/version")
versioned = rest.pool_manager.request("GET", pre_versioned, headers=headers)
if versioned.status != 200:
self.module.fail_json(
"Unable to retrieve API version",
status=to_native(versioned.status),
reason=to_native(versioned.reason),
)
self.version = versioned.data.decode("utf-8")

# Construct the discovered API endpoint
Expand Down
5 changes: 1 addition & 4 deletions plugins/modules/cm_endpoint_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}

DOCUMENTATION = r"""
---
module: cm_endpoint_info
short_description: Discover the Cloudera Manager API endpoint
description:
Expand All @@ -38,7 +37,6 @@
"""

EXAMPLES = r"""
---
# This will first try 'http://example.cloudera.com:7180' and will
# follow any redirects
- name: Gather details using auto-discovery
Expand All @@ -50,9 +48,8 @@
"""

RETURN = r"""
---
endpoint:
description: The discovered Cloudera Manager API endpoint
description: The discovered Cloudera Manager API endpoint, i.e. the base URL.
type: str
returned: always
"""
Expand Down

0 comments on commit fe3ea60

Please sign in to comment.