@@ -442,6 +442,7 @@ def test_uss_archive_encode_skip_encoding(ansible_zos_module, ds_format):
442
442
# - test_mvs_archive_single_dataset_encoding
443
443
# - test_mvs_archive_multiple_dataset_pattern_encoding
444
444
# - test_mvs_archive_multiple_dataset_pattern_encoding_skip_encoding
445
+ # - test_mvs_archive_multiple_dataset_pattern_encoding_revert_src_encoding
445
446
446
447
447
448
@pytest .mark .ds
@@ -1464,6 +1465,126 @@ def test_mvs_archive_multiple_dataset_pattern_encoding_skip_encoding(ansible_zos
1464
1465
1465
1466
archived_datasets .append (archive_data_set )
1466
1467
1468
+ finally :
1469
+ for ds_name in matched_datasets :
1470
+ hosts .all .zos_data_set (name = ds_name , state = "absent" )
1471
+ for archive_ds in archived_datasets :
1472
+ hosts .all .zos_data_set (name = archive_ds , state = "absent" )
1473
+
1474
+ @pytest .mark .ds
1475
+ @pytest .mark .parametrize (
1476
+ "ds_format" , [
1477
+ "terse"
1478
+ ])
1479
+ @pytest .mark .parametrize (
1480
+ "data_set" , [
1481
+ {
1482
+ "dstype" : "seq" ,
1483
+ "members" : ["" ]
1484
+ }
1485
+ ])
1486
+ @pytest .mark .parametrize (
1487
+ "encoding" , [
1488
+ {"from" : "IBM-1047" , "to" : "ISO8859-1" },
1489
+ ])
1490
+ def test_mvs_archive_multiple_dataset_pattern_encoding_revert_src_encoding (ansible_zos_module , ds_format , data_set , encoding ):
1491
+ try :
1492
+ hosts = ansible_zos_module
1493
+ hlq_prefix = "OMVSADM.ABC"
1494
+ matched_datasets = [f"{ hlq_prefix } .A" , f"{ hlq_prefix } .B" ]
1495
+ archived_datasets = []
1496
+ copy_src_datasets = [f"{ hlq_prefix } .C" , f"{ hlq_prefix } .D" ]
1497
+ all_datasets_to_process = matched_datasets + copy_src_datasets
1498
+
1499
+ for ds_name in all_datasets_to_process :
1500
+ hosts .all .zos_data_set (name = ds_name , state = "absent" )
1501
+ hosts .all .zos_data_set (
1502
+ name = ds_name ,
1503
+ type = data_set .get ("dstype" ),
1504
+ state = "present" ,
1505
+ replace = True ,
1506
+ )
1507
+ if data_set .get ("dstype" ) in ["pds" , "pdse" ]:
1508
+ for member in data_set .get ("members" ):
1509
+ hosts .all .zos_data_set (
1510
+ name = f"{ ds_name } ({ member } )" ,
1511
+ type = "member" ,
1512
+ state = "present"
1513
+ )
1514
+
1515
+ test_line = "pattern match"
1516
+ for ds_name in all_datasets_to_process :
1517
+ for member in data_set .get ("members" ):
1518
+ ds_target = f"{ ds_name } ({ member } )" if member else ds_name
1519
+ hosts .all .shell (cmd = f"decho '{ test_line } ' \" { ds_target } \" " )
1520
+
1521
+ format_dict = {"name" : ds_format }
1522
+ if ds_format == "terse" :
1523
+ format_dict ["format_options" ] = {"terse_pack" : "spack" }
1524
+ for ds_name in matched_datasets :
1525
+
1526
+ original_hex_result = hosts .all .shell (cmd = f"dcat '{ ds_name } ' | od -x" )
1527
+ host_original_result = None
1528
+ if original_hex_result .contacted :
1529
+ host_original_result = next (iter (original_hex_result .contacted .values ()))
1530
+
1531
+ original_hex_output_lines = [line .strip () for line in host_original_result .get ("stdout" , "" ).splitlines () if line .strip ()]
1532
+ archive_data_set = get_tmp_ds_name ()
1533
+ archive_result = hosts .all .zos_archive (
1534
+ src = ds_name ,
1535
+ dest = archive_data_set ,
1536
+ format = format_dict ,
1537
+ encoding = encoding ,
1538
+ )
1539
+ reverted_hex_result = hosts .all .shell (cmd = f"dcat '{ ds_name } ' | od -x" )
1540
+ host_reverted_result = None
1541
+ if reverted_hex_result .contacted :
1542
+ host_reverted_result = next (iter (reverted_hex_result .contacted .values ()))
1543
+ reverted_hex_output_lines = [line .strip () for line in host_reverted_result .get ("stdout" , "" ).splitlines () if line .strip ()]
1544
+
1545
+ original_hex = []
1546
+ for line in original_hex_output_lines :
1547
+ if line == '*' :
1548
+ original_hex .append ('*' )
1549
+ else :
1550
+ parts = line .split ()
1551
+ if len (parts ) > 1 :
1552
+ original_hex .extend (parts [1 :])
1553
+
1554
+ reverted_hex = []
1555
+ for line in reverted_hex_output_lines :
1556
+ if line == '*' :
1557
+ reverted_hex .append ('*' )
1558
+ else :
1559
+ parts = line .split ()
1560
+ if len (parts ) > 1 :
1561
+ reverted_hex .extend (parts [1 :])
1562
+
1563
+ for result in archive_result .contacted .values ():
1564
+ try :
1565
+ original_first_star_idx = original_hex .index ('*' )
1566
+ except ValueError :
1567
+ original_first_star_idx = len (original_hex )
1568
+
1569
+ try :
1570
+ reverted_first_star_idx = reverted_hex .index ('*' )
1571
+ except ValueError :
1572
+ reverted_first_star_idx = len (reverted_hex )
1573
+
1574
+ original_hex_to_compare = original_hex [:original_first_star_idx ]
1575
+ reverted_hex_to_compare = reverted_hex [:reverted_first_star_idx ]
1576
+
1577
+ is_identical = (original_hex_to_compare == reverted_hex_to_compare )
1578
+ assert is_identical is True
1579
+ assert result .get ("changed" ) is True
1580
+ assert result .get ("dest" ) == archive_data_set
1581
+ assert ds_name in result .get ("archived" )
1582
+ cmd_result = hosts .all .shell (cmd = f"dls { archive_data_set } " )
1583
+ for c_result in cmd_result .contacted .values ():
1584
+ assert archive_data_set in c_result .get ("stdout" )
1585
+
1586
+ archived_datasets .append (archive_data_set )
1587
+
1467
1588
finally :
1468
1589
for ds_name in matched_datasets :
1469
1590
hosts .all .zos_data_set (name = ds_name , state = "absent" )
0 commit comments