From 7fe8e3afb5e881c07861799232ce9a7355a9dbdd Mon Sep 17 00:00:00 2001 From: James Harmison Date: Wed, 18 Oct 2023 11:06:52 -0400 Subject: [PATCH] fix: return change status with all start_compose returns --- .../310-fix-start_compose-changed.yaml | 3 +++ plugins/modules/rhsm_repo_info.py | 2 +- plugins/modules/start_compose.py | 17 ++++++++++++----- .../unit/plugins/modules/test_start_compose.py | 6 ++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/310-fix-start_compose-changed.yaml diff --git a/changelogs/fragments/310-fix-start_compose-changed.yaml b/changelogs/fragments/310-fix-start_compose-changed.yaml new file mode 100644 index 00000000..d59d2dd6 --- /dev/null +++ b/changelogs/fragments/310-fix-start_compose-changed.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - return changed bool in response json from start_compose module diff --git a/plugins/modules/rhsm_repo_info.py b/plugins/modules/rhsm_repo_info.py index 5bc27569..3cd18dc6 100644 --- a/plugins/modules/rhsm_repo_info.py +++ b/plugins/modules/rhsm_repo_info.py @@ -36,7 +36,7 @@ - name: Add source for custom packages infra.osbuild.rhsm_repo_info: name: - - rhocp-ironic-4.12-for-rhel-8-x86_64-rpms + - rhocp-ironic-4.12-for-rhel-8-x86_64-rpms register: rhsm_repo_info_out - name: Debug rhsm_repo_info_out diff --git a/plugins/modules/start_compose.py b/plugins/modules/start_compose.py index 61432a8e..71e6ba06 100644 --- a/plugins/modules/start_compose.py +++ b/plugins/modules/start_compose.py @@ -174,13 +174,15 @@ def start_compose(module, weldr): if not is_supported: module.fail_json( msg="%s is not a valid image type, valid types are: %s" - % (module.params["compose_type"], [[v for k, v in t.items() if k == "name"] for t in supported_compose_type["types"]]) + % (module.params["compose_type"], [[v for k, v in t.items() if k == "name"] for t in supported_compose_type["types"]]), + changed=changed ) else: if not is_supported["enabled"]: module.fail_json( msg="%s is not a supported image type, supported image types are: %s" - % (module.params["compose_type"], [[v for k, v in t.items() if k == "enabled" and v is True] for t in supported_compose_type["types"]]) + % (module.params["compose_type"], [[v for k, v in t.items() if k == "enabled" and v is True] for t in supported_compose_type["types"]]), + changed=changed ) if not module.params["allow_duplicate"]: @@ -274,7 +276,8 @@ def start_compose(module, weldr): submitted_compose_uuid: str = submitted_compose_found_failed[0]["id"] else: module.fail_json( - msg="Unable to determine state of build, check osbuild-composer system logs. Also, consider increasing the request timeout" + msg="Unable to determine state of build, check osbuild-composer system logs. Also, consider increasing the request timeout", + changed=changed ) if submitted_compose_uuid: @@ -286,9 +289,13 @@ def start_compose(module, weldr): if "status_code" in result.keys(): if result["status_code"] >= 400: module.fail_json( - msg="Compose returned body: {0}, msg {1}, and status_code {2}".format(result["body"], result["error_msg"], result["status_code"]) + msg="Compose returned body: {0}, msg {1}, and status_code {2}".format(result["body"], result["error_msg"], result["status_code"]), + changed=changed ) + # Having received a non-400+ response, we know a compose has started + changed: bool = True + compose_output_types: dict[str, list[str]] = { "tar": ["tar", "edge-commit", "iot-commit", "edge-container", "iot-container", "container"], "iso": ["edge-installer", "edge-simplified-installer", "iot-installer", "image-installer"], @@ -305,7 +312,7 @@ def start_compose(module, weldr): output_type: str = compose_type result["output_type"] = output_type - module.exit_json(msg="Compose submitted to queue", result=result) + module.exit_json(msg="Compose submitted to queue", result=result, changed=changed) else: changed: bool = False diff --git a/tests/unit/plugins/modules/test_start_compose.py b/tests/unit/plugins/modules/test_start_compose.py index d7617c1c..95c0f7c0 100644 --- a/tests/unit/plugins/modules/test_start_compose.py +++ b/tests/unit/plugins/modules/test_start_compose.py @@ -40,6 +40,7 @@ def test_start_compose_not_valid_image_type(): with pytest.raises(AnsibleFailJson) as fail_json_obj: start_compose(module, weldr=weldr) assert "not a valid image type" in str(fail_json_obj) + assert not fail_json_obj.value.args[0]['changed'] def test_start_compose_not_supported_image_type(): @@ -49,6 +50,7 @@ def test_start_compose_not_supported_image_type(): with pytest.raises(AnsibleFailJson) as fail_json_obj: start_compose(module, weldr=weldr) assert "not a supported image type" in str(fail_json_obj) + assert not fail_json_obj.value.args[0]['changed'] def test_start_compose_unable_to_determine_build(): @@ -58,6 +60,7 @@ def test_start_compose_unable_to_determine_build(): with pytest.raises(AnsibleFailJson) as fail_json_obj: start_compose(module, weldr=weldr) assert "Unable to determine state of build" in str(fail_json_obj) + assert not fail_json_obj.value.args[0]['changed'] def test_start_compose_submitted_queue(): @@ -66,6 +69,7 @@ def test_start_compose_submitted_queue(): with pytest.raises(AnsibleExitJson) as exit_json_obj: start_compose(module, weldr=weldr) assert "Compose submitted to queue" in str(exit_json_obj) + assert exit_json_obj.value.args[0]['changed'] def test_start_compose_submitted_duplicate_allowed(): @@ -82,6 +86,7 @@ def test_start_compose_submitted_duplicate_allowed(): start_compose(module, weldr=weldr) # We expect this to work unless we set allow_duplicate to False assert "Compose submitted to queue" in str(exit_json_obj) + assert exit_json_obj.value.args[0]['changed'] def test_start_compose_submitted_duplicate(): @@ -98,3 +103,4 @@ def test_start_compose_submitted_duplicate(): with pytest.raises(AnsibleExitJson) as exit_json_obj: start_compose(module, weldr=weldr) assert "Not queuing a duplicate versioned" in str(exit_json_obj) + assert not exit_json_obj.value.args[0]['changed']