Skip to content

Commit

Permalink
Update tests for CMS service-wide configurations
Browse files Browse the repository at this point in the history
Signed-off-by: Webster Mudge <[email protected]>
  • Loading branch information
wmudge committed Dec 16, 2024
1 parent 6fa3890 commit 5dcb396
Showing 1 changed file with 62 additions and 70 deletions.
132 changes: 62 additions & 70 deletions tests/unit/plugins/modules/cm_service_config/test_cm_service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
__metaclass__ = type

import logging
import os
import pytest

from ansible_collections.cloudera.cluster.plugins.modules import cm_service_config
Expand All @@ -31,29 +30,6 @@
LOG = logging.getLogger(__name__)


@pytest.fixture
def conn():
conn = dict(username=os.getenv("CM_USERNAME"), password=os.getenv("CM_PASSWORD"))

if os.getenv("CM_HOST", None):
conn.update(host=os.getenv("CM_HOST"))

if os.getenv("CM_PORT", None):
conn.update(port=os.getenv("CM_PORT"))

if os.getenv("CM_ENDPOINT", None):
conn.update(url=os.getenv("CM_ENDPOINT"))

if os.getenv("CM_PROXY", None):
conn.update(proxy=os.getenv("CM_PROXY"))

return {
**conn,
"verify_tls": "no",
"debug": "no",
}


def test_missing_required(conn, module_args):
module_args(conn)

Expand All @@ -73,93 +49,109 @@ def test_present_invalid_parameter(conn, module_args):
cm_service_config.main()


def test_set_parameters(conn, module_args):
conn.update(
parameters=dict(mgmt_emit_sensitive_data_in_stderr=True),
# _ansible_check_mode=True,
# _ansible_diff=True,
message="test_cm_service_config::test_set_parameters",
@pytest.mark.service_config(dict(log_event_retry_frequency=10))
def test_set_parameters(conn, module_args, cms_service_config):
module_args(
{
**conn,
"parameters": dict(mgmt_emit_sensitive_data_in_stderr=True),
"message": "test_cm_service_config::test_set_parameters",
# _ansible_check_mode=True,
# _ansible_diff=True,
}
)

expected = dict(
mgmt_emit_sensitive_data_in_stderr="True", log_event_retry_frequency="10"
)
module_args(conn)

with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

assert e.value.changed == True
assert {c["name"]: c["value"] for c in e.value.config}[
"mgmt_emit_sensitive_data_in_stderr"
] == "true"
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()

# Idempotency
with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

assert e.value.changed == False
assert {c["name"]: c["value"] for c in e.value.config}[
"mgmt_emit_sensitive_data_in_stderr"
] == "true"
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()


def test_unset_parameters(conn, module_args):
conn.update(
parameters=dict(mgmt_emit_sensitive_data_in_stderr=None),
message="test_cm_service_config::test_unset_parameters",
@pytest.mark.service_config(
dict(mgmt_emit_sensitive_data_in_stderr=True, log_event_retry_frequency=10)
)
def test_unset_parameters(conn, module_args, cms_service_config):
module_args(
{
**conn,
"parameters": dict(mgmt_emit_sensitive_data_in_stderr=None),
"message": "test_cm_service_config::test_unset_parameters",
}
)
module_args(conn)

expected = dict(log_event_retry_frequency="10")

with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

assert e.value.changed == True
results = {c["name"]: c["value"] for c in e.value.config}
assert "mgmt_emit_sensitive_data_in_stderr" not in results
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()

# Idempotency
with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

# Idempotency
assert e.value.changed == False
results = {c["name"]: c["value"] for c in e.value.config}
assert "mgmt_emit_sensitive_data_in_stderr" not in results
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()


def test_set_parameters_with_purge(conn, module_args):
conn.update(
parameters=dict(mgmt_emit_sensitive_data_in_stderr=True),
purge=True,
message="test_cm_service_config::test_set_parameters_with_purge",
# _ansible_check_mode=True,
# _ansible_diff=True,
@pytest.mark.service_config(
dict(mgmt_emit_sensitive_data_in_stderr=True, log_event_retry_frequency=10)
)
def test_set_parameters_with_purge(conn, module_args, cms_service_config):
module_args(
{
**conn,
"parameters": dict(mgmt_emit_sensitive_data_in_stderr=True),
"purge": True,
"message": "test_cm_service_config::test_set_parameters_with_purge",
# _ansible_check_mode=True,
# _ansible_diff=True,
}
)
module_args(conn)

expected = dict(mgmt_emit_sensitive_data_in_stderr="True")

with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

assert e.value.changed == True
assert {c["name"]: c["value"] for c in e.value.config}[
"mgmt_emit_sensitive_data_in_stderr"
] == "true"
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()

# Idempotency
with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()

# Idempotency
assert e.value.changed == False
assert {c["name"]: c["value"] for c in e.value.config}[
"mgmt_emit_sensitive_data_in_stderr"
] == "true"
assert expected.items() <= {c["name"]: c["value"] for c in e.value.config}.items()


def test_purge_all_parameters(conn, module_args):
conn.update(
parameters=dict(),
purge=True,
message="test_cm_service_config::test_purge_all_parameters",
# _ansible_check_mode=True,
# _ansible_diff=True,
@pytest.mark.service_config(
dict(mgmt_emit_sensitive_data_in_stderr=True, log_event_retry_frequency=10)
)
def test_purge_all_parameters(conn, module_args, cms_service_config):
module_args(
{
**conn,
"parameters": dict(),
"purge": True,
"message": "test_cm_service_config::test_purge_all_parameters",
# _ansible_check_mode=True,
# _ansible_diff=True,
}
)
module_args(conn)

with pytest.raises(AnsibleExitJson) as e:
cm_service_config.main()
Expand Down

0 comments on commit 5dcb396

Please sign in to comment.