Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix][1678]Add validation for maker begin end #1684

Merged
merged 11 commits into from
Sep 24, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- zos_blockinfile - User could set same values for marker begin and end generate issue on ZOAU python API.
Change now catch the error and throw to the user a message with the problem.
AndreMarcel99 marked this conversation as resolved.
Show resolved Hide resolved
(https://github.com/ansible-collections/ibm_zos_core/pull/1684).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Ansible user won't care particularly about bugs in ZOAU (or any other dependencies). Better to use this space to describe the bug as experienced by the Ansible user.

User could previously set the same values for module options 'marker_begin' and 'marker_end', which would result in <..whatever the issue was..>. Fix now introduces a requirement for 'marker_begin' and 'marker_end' to have different values.

Even better would be if you could bring the <..whatever the issue was..> to the beginning,

Previously <..issue..> happened when 'marker_begin' and 'marker_end' were set to the same value. Fix introduces a requirement for 'marker_begin' and 'marker_end' to have different values.

5 changes: 4 additions & 1 deletion plugins/modules/zos_blockinfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@
marker_begin:
description:
- This will be inserted at C({mark}) in the opening ansible block marker.
- Required unique value different from marker_end
AndreMarcel99 marked this conversation as resolved.
Show resolved Hide resolved
required: false
type: str
default: BEGIN
marker_end:
required: false
description:
- This will be inserted at C({mark}) in the closing ansible block marker.
- Required unique value different from marker_begin
AndreMarcel99 marked this conversation as resolved.
Show resolved Hide resolved
type: str
default: END
backup:
Expand Down Expand Up @@ -759,7 +761,8 @@ def main():
marker_begin = 'BEGIN'
if not marker_end:
marker_end = 'END'

if marker_begin == marker_end:
module.fail_json(msg='marker begin and fail required unique values')
AndreMarcel99 marked this conversation as resolved.
Show resolved Hide resolved
marker = "{0}\\n{1}\\n{2}".format(marker_begin, marker_end, marker)
block = transformBlock(block, ' ', indentation)
# analysis the file type
Expand Down
42 changes: 42 additions & 0 deletions tests/functional/modules/test_zos_blockinfile_func.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is need for this new test case, looks like is doing the same as test_uss_block_absent_custommarker

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@
PYTHON_HOME=/usr/lpp/izoda/v110/anaconda
export ZOAU_ROOT"""

TEST_CONTENT_NOT_DEFAULTMARKER = """if [ -z STEPLIB ] && tty -s;
then
export STEPLIB=none
exec -a 0 SHELL
fi
TZ=PST8PDT
export TZ
export MAIL
umask 022
*HELLO USER MANAGED BLOCK
ZOAU_ROOT=/usr/lpp/zoautil/v100
ZOAUTIL_DIR=/usr/lpp/zoautil/v100
*BYE USER MANAGED BLOCK
ZOAU_ROOT=/usr/lpp/zoautil/v100
PKG_CONFIG_PATH=/usr/lpp/izoda/v110/anaconda/lib/pkgconfig
PYTHON_HOME=/usr/lpp/izoda/v110/anaconda
export ZOAU_ROOT"""

TEST_CONTENT_CUSTOMMARKER = """if [ -z STEPLIB ] && tty -s;
then
export STEPLIB=none
Expand Down Expand Up @@ -696,6 +714,30 @@ def test_uss_block_absent_defaultmarker(ansible_zos_module):
remove_uss_environment(ansible_zos_module, full_path)


@pytest.mark.uss
def test_uss_block_absent_not_defaultmarker(ansible_zos_module):
hosts = ansible_zos_module
params = {
"state":"absent",
"marker_begin":"HELLO",
"marker_end":"BYE",
"marker":"*{mark} USER MANAGED BLOCK"
}
full_path = get_random_file_name(dir=TMP_DIRECTORY)
content = TEST_CONTENT_NOT_DEFAULTMARKER
try:
set_uss_environment(ansible_zos_module, content, full_path)
params["path"] = full_path
results = hosts.all.zos_blockinfile(**params)
for result in results.contacted.values():
assert result.get("changed") is True
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
for result in results.contacted.values():
assert result.get("stdout") == EXPECTED_ABSENT
finally:
remove_uss_environment(ansible_zos_module, full_path)


@pytest.mark.uss
def test_uss_block_absent_custommarker(ansible_zos_module):
hosts = ansible_zos_module
Expand Down