Skip to content

Commit fe3ea60

Browse files
authored
Add HTTP status test when discovering CM endpoint (#253)
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent f64ce9b commit fe3ea60

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

plugins/module_utils/cm_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from time import sleep
3030
from ansible.module_utils.basic import AnsibleModule
3131
from ansible.module_utils.common.dict_transformations import recursive_diff
32-
from ansible.module_utils.common.text.converters import to_text
32+
from ansible.module_utils.common.text.converters import to_native, to_text
3333
from time import sleep
3434
from cm_client import (
3535
ApiClient,
@@ -434,6 +434,12 @@ def discover_endpoint(self, config):
434434
if not self.version:
435435
pre_versioned = urljoin(rendered_url, "/api/version")
436436
versioned = rest.pool_manager.request("GET", pre_versioned, headers=headers)
437+
if versioned.status != 200:
438+
self.module.fail_json(
439+
"Unable to retrieve API version",
440+
status=to_native(versioned.status),
441+
reason=to_native(versioned.reason),
442+
)
437443
self.version = versioned.data.decode("utf-8")
438444

439445
# Construct the discovered API endpoint

plugins/modules/cm_endpoint_info.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
}
2424

2525
DOCUMENTATION = r"""
26-
---
2726
module: cm_endpoint_info
2827
short_description: Discover the Cloudera Manager API endpoint
2928
description:
@@ -38,7 +37,6 @@
3837
"""
3938

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

5250
RETURN = r"""
53-
---
5451
endpoint:
55-
description: The discovered Cloudera Manager API endpoint
52+
description: The discovered Cloudera Manager API endpoint, i.e. the base URL.
5653
type: str
5754
returned: always
5855
"""

0 commit comments

Comments
 (0)