Skip to content

Commit 7d06bf6

Browse files
added test case
1 parent 6958310 commit 7d06bf6

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

tests/functional/modules/test_zos_data_set_func.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,3 +1161,162 @@ def test_gdg_deletion_when_absent(ansible_zos_module):
11611161
assert result.get("changed") is False
11621162
assert result.get("module_stderr") is None
11631163
assert result.get("failed") is None
1164+
1165+
def test_data_set_delete_with_noscratch(ansible_zos_module, volumes_on_systems):
1166+
"""
1167+
Tests that 'state: absent' with 'noscratch: true' correctly uncatalogs
1168+
a data set but leaves its physical entry in the VTOC.
1169+
"""
1170+
volumes = Volume_Handler(volumes_on_systems)
1171+
volume = volumes.get_available_vol()
1172+
hosts = ansible_zos_module
1173+
dataset = get_tmp_ds_name(2, 2)
1174+
1175+
try:
1176+
# Arrange: Create the test data set on the specific volume
1177+
hosts.all.zos_data_set(
1178+
name=dataset,
1179+
type='seq',
1180+
state='present',
1181+
volumes=[volume],
1182+
space_primary=1,
1183+
space_type='m'
1184+
)
1185+
1186+
# Act: Delete the dataset using the noscratch option
1187+
results = hosts.all.zos_data_set(
1188+
name=dataset,
1189+
state='absent',
1190+
noscratch=True
1191+
)
1192+
for result in results.contacted.values():
1193+
print(result)
1194+
assert result.get("changed") is True
1195+
assert result.get("module_stderr") is None
1196+
# Assert 1: Verify the data set is GONE from the catalog.
1197+
# This is the first part of the test, where we check that the data set
1198+
results = hosts.all.zos_data_set(
1199+
name=dataset,
1200+
state='absent',
1201+
)
1202+
for result in results.contacted.values():
1203+
print(result)
1204+
assert result.get("changed") is False
1205+
# catalog_check = hosts.all.command(f"dls '{dataset}'", failed_when=False)
1206+
# for result in catalog_check.contacted.values():
1207+
# # Assert that the command failed (non-zero return code)
1208+
# assert result.get("rc") != 0
1209+
# Assert 2: Verify the data set is STILL on the volume's VTOC.
1210+
# This is the crucial second half of the test.
1211+
# We can do this by trying to delete it again, but specifying the volume.
1212+
# If this delete reports "changed: true", it's proof that it found and
1213+
# deleted the uncataloged data set from the VTOC.
1214+
vtoc_check_and_delete = hosts.all.zos_data_set(
1215+
name=dataset,
1216+
state='absent',
1217+
volumes=volume
1218+
)
1219+
for result in vtoc_check_and_delete.contacted.values():
1220+
# This assertion proves the data set existed on the volume's VTOC
1221+
print(result)
1222+
assert result.get("changed") is True
1223+
finally:
1224+
# Cleanup: Perform a final, full delete from the volume since it's still there.
1225+
# We provide the volume to ensure it can be found and deleted.
1226+
hosts.all.zos_data_set(
1227+
name=dataset,
1228+
state='absent',
1229+
volumes=[volume]
1230+
)
1231+
1232+
def test_batch_uncatalog_with_noscratch_suboption(ansible_zos_module, volumes_on_systems):
1233+
"""
1234+
Tests that the 'noscratch: true' sub-option works correctly when used inside a
1235+
batch list to uncatalog multiple data sets.
1236+
"""
1237+
hosts = ansible_zos_module
1238+
volume = Volume_Handler(volumes_on_systems).get_available_vol()
1239+
1240+
# Define two separate data sets for the batch operation
1241+
dataset_1 = get_tmp_ds_name()
1242+
dataset_2 = get_tmp_ds_name()
1243+
1244+
try:
1245+
# --- Arrange ---
1246+
# Create both data sets in a preliminary batch operation so they exist
1247+
setup_results = hosts.all.zos_data_set(
1248+
batch=[
1249+
{'name': dataset_1, 'type': 'seq', 'state': 'present', 'volumes': volume},
1250+
{'name': dataset_2, 'type': 'seq', 'state': 'present', 'volumes': volume}
1251+
]
1252+
)
1253+
for result in setup_results.contacted.values():
1254+
assert result.get("changed") is True
1255+
1256+
# --- Act ---
1257+
# Run the main test: a batch uncatalog where both items use noscratch
1258+
act_results = hosts.all.zos_data_set(
1259+
batch=[
1260+
{'name': dataset_1, 'state': 'absent', 'noscratch': True},
1261+
{'name': dataset_2, 'state': 'absent', 'noscratch': True}
1262+
]
1263+
)
1264+
# # Assert on the main action results
1265+
for result in act_results.contacted.values():
1266+
print(result)
1267+
assert result.get("changed") is True
1268+
assert result.get("module_stderr") is None
1269+
results = hosts.all.zos_data_set(
1270+
name=dataset_1,
1271+
state='absent',
1272+
)
1273+
for result in results.contacted.values():
1274+
print(result)
1275+
assert result.get("changed") is False
1276+
for result in act_results.contacted.values():
1277+
print(result)
1278+
assert result.get("changed") is True
1279+
assert result.get("module_stderr") is None
1280+
results = hosts.all.zos_data_set(
1281+
name=dataset_2,
1282+
state='absent',
1283+
)
1284+
for result in results.contacted.values():
1285+
print(result)
1286+
assert result.get("changed") is False
1287+
1288+
# # --- Verification Assertions ---
1289+
# Assert 2: Verify the data set is STILL on the volume's VTOC.
1290+
# This is the crucial second half of the test.
1291+
# We can do this by trying to delete it again, but specifying the volume.
1292+
# If this delete reports "changed: true", it's proof that it found and
1293+
# deleted the uncataloged data set from the VTOC.
1294+
vtoc_check_and_delete = hosts.all.zos_data_set(
1295+
name=dataset_1,
1296+
state='absent',
1297+
volumes=volume
1298+
)
1299+
for result in vtoc_check_and_delete.contacted.values():
1300+
# This assertion proves the data set existed on the volume's VTOC
1301+
print(result)
1302+
assert result.get("changed") is True
1303+
1304+
vtoc_check_and_delete = hosts.all.zos_data_set(
1305+
name=dataset_2,
1306+
state='absent',
1307+
volumes=volume
1308+
)
1309+
for result in vtoc_check_and_delete.contacted.values():
1310+
# This assertion proves the data set existed on the volume's VTOC
1311+
print(result)
1312+
assert result.get("changed") is True
1313+
finally:
1314+
# --- Cleanup ---
1315+
# Ensure both data sets are fully deleted from the volume's VTOC.
1316+
# This is critical because the test's main action leaves them on disk.
1317+
hosts.all.zos_data_set(
1318+
batch=[
1319+
{'name': dataset_1, 'state': 'absent', 'volumes': [volume]},
1320+
{'name': dataset_2, 'state': 'absent', 'volumes': [volume]}
1321+
]
1322+
)

0 commit comments

Comments
 (0)