Skip to content

Commit d340e17

Browse files
authored
Adding test case to test working of tmp_hlq in zos_backup_restore (#2135)
* adding test case for tmp_hlq * changelog addition and testing * test changes * testing with 2.16 * testing with managed user * checking with updated users.py * adding changes for to check test failure. * modifying the ret condition
1 parent 78e1839 commit d340e17

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- test_zos_backup_restore - Added a test case to ensure tmphlq is tested in the module.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/2135).

tests/functional/modules/test_zos_backup_restore.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
__metaclass__ = type
1717

18+
from ibm_zos_core.tests.helpers.users import ManagedUserType, ManagedUser
1819
from ibm_zos_core.tests.helpers.dataset import (
1920
get_tmp_ds_name,
2021
get_random_q,
@@ -1019,3 +1020,121 @@ def test_backup_tolerate_enqueue(ansible_zos_module):
10191020
hosts.all.shell(cmd=f"kill 9 {pid.strip()}")
10201021
hosts.all.shell(cmd='rm -r {0}'.format(temp_file))
10211022
hosts.all.shell(cmd=f"drm ANSIBLE.* ")
1023+
1024+
1025+
@pytest.mark.parametrize(
1026+
"backup_name,overwrite,recover",
1027+
[
1028+
("DATA_SET", True, True)
1029+
],
1030+
)
1031+
def test_backup_and_restore_of_data_set_tmphlq(
1032+
ansible_zos_module, backup_name, overwrite, recover
1033+
):
1034+
hlqs = []
1035+
hosts = ansible_zos_module
1036+
data_set_name = get_tmp_ds_name()
1037+
new_hlq = "N" + get_random_q(4)
1038+
hlqs.append(new_hlq)
1039+
if backup_name == "DATA_SET":
1040+
backup_name = get_tmp_ds_name(1,1)
1041+
else:
1042+
backup_name = get_random_file_name(dir=TMP_DIRECTORY, prefix='.dzp')
1043+
try:
1044+
delete_data_set_or_file(hosts, data_set_name)
1045+
delete_data_set_or_file(hosts, backup_name)
1046+
create_sequential_data_set_with_contents(
1047+
hosts, data_set_name, DATA_SET_CONTENTS
1048+
)
1049+
results = hosts.all.zos_backup_restore(
1050+
operation="backup",
1051+
data_sets=dict(include=data_set_name),
1052+
backup_name=backup_name,
1053+
overwrite=overwrite,
1054+
tmp_hlq="TMPHLQ",
1055+
recover=recover,
1056+
)
1057+
assert_module_did_not_fail(results)
1058+
# NEW: Assert backup_name appears in output
1059+
for result in results.contacted.values():
1060+
assert result.get("backup_name") == backup_name, \
1061+
f"Backup name '{backup_name}' not found in output"
1062+
# Verify backup file/dataset exists
1063+
assert_data_set_or_file_exists(hosts, backup_name)
1064+
if not overwrite:
1065+
new_hlq = "N" + get_random_q(4)
1066+
hlqs.append(new_hlq)
1067+
assert_module_did_not_fail(results)
1068+
assert_data_set_or_file_exists(hosts, backup_name)
1069+
results = hosts.all.zos_backup_restore(
1070+
operation="restore",
1071+
backup_name=backup_name,
1072+
hlq=new_hlq,
1073+
overwrite=overwrite,
1074+
tmp_hlq="TMPHLQ",
1075+
)
1076+
assert_module_did_not_fail(results)
1077+
for result in results.contacted.values():
1078+
assert result.get("backup_name") == backup_name, \
1079+
"Backup name '{backup_name}' not found in restore output"
1080+
finally:
1081+
delete_data_set_or_file(hosts, data_set_name)
1082+
delete_data_set_or_file(hosts, backup_name)
1083+
delete_remnants(hosts, hlqs)
1084+
1085+
def test_list_cat_for_existing_data_set_with_tmp_hlq_option_restricted_user(ansible_zos_module, z_python_interpreter):
1086+
"""
1087+
This tests the error message when a user cannot create data sets with a given HLQ.
1088+
"""
1089+
managed_user = None
1090+
managed_user_test_case_name = "managed_user_backup_of_data_set_tmphlq_restricted_user"
1091+
try:
1092+
# Initialize the Managed user API from the pytest fixture.
1093+
managed_user = ManagedUser.from_fixture(ansible_zos_module, z_python_interpreter)
1094+
1095+
# Important: Execute the test case with the managed users execution utility.
1096+
managed_user.execute_managed_user_test(
1097+
managed_user_test_case = managed_user_test_case_name, debug = True,
1098+
verbose = True, managed_user_type=ManagedUserType.ZOS_LIMITED_HLQ)
1099+
1100+
finally:
1101+
# Delete the managed user on the remote host to avoid proliferation of users.
1102+
managed_user.delete_managed_user()
1103+
1104+
def managed_user_backup_of_data_set_tmphlq_restricted_user(ansible_zos_module):
1105+
backup_name = "DATA_SET"
1106+
overwrite = True
1107+
recover = True
1108+
hlqs = []
1109+
hosts = ansible_zos_module
1110+
data_set_name = get_tmp_ds_name()
1111+
new_hlq = "N" + get_random_q(4)
1112+
hlqs.append(new_hlq)
1113+
tmphlq = "NOPERMIT"
1114+
if backup_name == "DATA_SET":
1115+
backup_name = get_tmp_ds_name(1,1)
1116+
try:
1117+
delete_data_set_or_file(hosts, data_set_name)
1118+
delete_data_set_or_file(hosts, backup_name)
1119+
create_sequential_data_set_with_contents(
1120+
hosts, data_set_name, DATA_SET_CONTENTS
1121+
)
1122+
results = hosts.all.zos_backup_restore(
1123+
operation="backup",
1124+
data_sets=dict(include=data_set_name),
1125+
backup_name=backup_name,
1126+
overwrite=overwrite,
1127+
tmp_hlq=tmphlq,
1128+
recover=recover,
1129+
)
1130+
# NEW: Assert backup_name appears in output
1131+
for result in results.contacted.values():
1132+
assert result.get("backup_name") == '', \
1133+
f"Backup name '{backup_name}' is there in output so tmphlq failed."
1134+
print(result)
1135+
assert result.get("changed", False) is False
1136+
1137+
finally:
1138+
delete_data_set_or_file(hosts, data_set_name)
1139+
delete_data_set_or_file(hosts, backup_name)
1140+
delete_remnants(hosts, hlqs)

0 commit comments

Comments
 (0)