diff --git a/.secrets.baseline b/.secrets.baseline index 3486173fbe..79630764dd 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -1,9 +1,9 @@ { "exclude": { - "files": "zos_mvs_raw.rst|^.secrets.baseline$", + "files": "zos_mvs_raw.rst|test_zos_apf_func.py|^.secrets.baseline$", "lines": null }, - "generated_at": "2025-09-01T16:59:39Z", + "generated_at": "2025-10-23T20:47:32Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -77,7 +77,7 @@ } ], "results": {}, - "version": "0.13.1+ibm.62.dss", + "version": "0.13.1+ibm.64.dss", "word_list": { "file": null, "hash": null diff --git a/changelogs/fragments/2365-Adopt_generation_data_group_generations.yml b/changelogs/fragments/2365-Adopt_generation_data_group_generations.yml new file mode 100644 index 0000000000..5a03beb1cd --- /dev/null +++ b/changelogs/fragments/2365-Adopt_generation_data_group_generations.yml @@ -0,0 +1,13 @@ +trivial: + - module_utils/data_set - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) + - module_utils/copy - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) + - modules/zos_copy - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) + - modules/zos_fetch - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) + - modules/zos_mvs_raw - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) + - modules/zos_stat - Adopt new GenerationDataGroupView generations property for ZOAU 1.4.0. + (https://github.com/ansible-collections/ibm_zos_core/pull/2365) diff --git a/plugins/module_utils/copy.py b/plugins/module_utils/copy.py index 63f6bbdd62..60189d02f4 100644 --- a/plugins/module_utils/copy.py +++ b/plugins/module_utils/copy.py @@ -149,7 +149,7 @@ def copy_gdg2uss(src, dest, binary=False, asa_text=False): True if all copies were successful, False otherwise. """ src_view = gdgs.GenerationDataGroupView(src) - generations = src_view.generations() + generations = src_view.generations copy_args = { "options": "" diff --git a/plugins/module_utils/data_set.py b/plugins/module_utils/data_set.py index 325d5c6c6b..6892b5550f 100644 --- a/plugins/module_utils/data_set.py +++ b/plugins/module_utils/data_set.py @@ -1859,8 +1859,9 @@ def resolve_gds_absolute_name(relative_name): # Fail if we are trying to resolve a future generation. raise Exception gdg = gdgs.GenerationDataGroupView(name=gdg_base) - generations = gdg.generations() - gds = generations[rel_generation - 1] + generations = gdg.generations + # From ZOAU 1.4 version relative notation 0 or -1 is on automatic give + gds = generations[rel_generation] except Exception: raise GDSNameResolveError(relative_name) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index c1afe37dd9..1195efea03 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1187,7 +1187,7 @@ def copy_to_gdg(self, src, dest): True if every copy operation was successful, False otherwise. """ src_view = gdgs.GenerationDataGroupView(src) - generations = src_view.generations() + generations = src_view.generations copy_args = { "options": "" } @@ -2756,8 +2756,8 @@ def does_destination_allow_copy( src_view = gdgs.GenerationDataGroupView(src) dest_view = gdgs.GenerationDataGroupView(dest) - src_allocated_gens = len(src_view.generations()) - dest_allocated_gens = len(dest_view.generations()) + src_allocated_gens = len(src_view.generations) + dest_allocated_gens = len(dest_view.generations) if src_allocated_gens > (dest_view.limit - dest_allocated_gens): return False diff --git a/plugins/modules/zos_fetch.py b/plugins/modules/zos_fetch.py index e0cf45186a..ca09f77dc4 100644 --- a/plugins/modules/zos_fetch.py +++ b/plugins/modules/zos_fetch.py @@ -719,7 +719,7 @@ def _fetch_gdg(self, src, binary, encoding=None): dir_path = tempfile.mkdtemp() data_group = gdgs.GenerationDataGroupView(src) - for current_gds in data_group.generations(): + for current_gds in data_group.generations: if current_gds.organization in data_set.DataSet.MVS_SEQ: self._fetch_mvs_data( current_gds.name, diff --git a/plugins/modules/zos_mvs_raw.py b/plugins/modules/zos_mvs_raw.py index 9e87a0ecc7..4c356e276b 100644 --- a/plugins/modules/zos_mvs_raw.py +++ b/plugins/modules/zos_mvs_raw.py @@ -2802,8 +2802,6 @@ def resolve_data_set_names(dataset, disposition, type): Data set name to determine if is a GDS relative name or regular name. disposition : str Disposition of data set for it creation. - type : str - Type of dataset Returns ------- str @@ -2820,9 +2818,11 @@ def resolve_data_set_names(dataset, disposition, type): if data_set.DataSet.is_gds_positive_relative_name(dataset): if disp == "new": if type: - return str(datasets.create(dataset, type).name), "shr" + new_generation = datasets.create(name=dataset, dataset_type=type) + return new_generation.name, "shr" else: - return str(datasets.create(dataset, "seq").name), "shr" + new_generation = datasets.create(name=dataset, dataset_type="seq") + return new_generation.name, "shr" else: raise ("To generate a new GDS as {0} disposition 'new' is required.".format(dataset)) else: diff --git a/plugins/modules/zos_stat.py b/plugins/modules/zos_stat.py index 1f29c52ead..bd15accc4c 100644 --- a/plugins/modules/zos_stat.py +++ b/plugins/modules/zos_stat.py @@ -2232,7 +2232,7 @@ def query(self): 'order': self.gdg_view.order, 'purge': self.gdg_view.purge, 'extended': self.gdg_view.extended, - 'active_gens': [generation.name for generation in self.gdg_view.generations()] + 'active_gens': [generation.name for generation in self.gdg_view.generations] } # Now we call LISTCAT to get the creation time. diff --git a/tests/functional/modules/test_zos_archive_func.py b/tests/functional/modules/test_zos_archive_func.py index fa40df375c..a41f70a72e 100644 --- a/tests/functional/modules/test_zos_archive_func.py +++ b/tests/functional/modules/test_zos_archive_func.py @@ -727,7 +727,7 @@ def test_mvs_archive_single_data_set_remove_target(ansible_zos_module, ds_format # Assert src_data_set is removed cmd_result = hosts.all.shell(cmd = f"dls '{src_data_set}'") for c_result in cmd_result.contacted.values(): - assert f"BGYSC1103E No datasets match pattern: {src_data_set}." in c_result.get("stderr") + assert f"BGYSC1103E No datasets match pattern: {src_data_set}" in c_result.get("stderr") finally: hosts.all.zos_data_set(name=src_data_set, state="absent") hosts.all.zos_data_set(name=archive_data_set, state="absent") diff --git a/tests/functional/modules/test_zos_copy_func.py b/tests/functional/modules/test_zos_copy_func.py index 8d1a0e1826..3aa749a70b 100644 --- a/tests/functional/modules/test_zos_copy_func.py +++ b/tests/functional/modules/test_zos_copy_func.py @@ -4412,7 +4412,6 @@ def test_copy_pds_loadlib_to_uss_to_pds_loadlib(ansible_zos_module): assert result.get("src") is not None for result in copy_res_aliases.contacted.values(): - print(result) assert result.get("msg") is None assert result.get("changed") is True assert result.get("dest") == "{0}".format(dest_lib_aliases) @@ -5442,671 +5441,671 @@ def test_display_verbosity_in_zos_copy_plugin(ansible_zos_module, options): finally: hosts.all.file(path=dest_path, state="absent") -# All gds test cases is commented out due to issues with GDS will be fixed in #2280 -# @pytest.mark.parametrize("generation", ["0", "+1"]) -# def test_copy_seq_gds_inexistent_src(ansible_zos_module, generation): -# hosts = ansible_zos_module -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() +@pytest.mark.parametrize("generation", ["0", "+1"]) +def test_copy_seq_gds_inexistent_src(ansible_zos_module, generation): + hosts = ansible_zos_module -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() -# copy_results = hosts.all.zos_copy( -# src=f"{src_data_set}({generation})", -# dest=dest_data_set, -# remote_src=True -# ) + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is not None -# assert cp_res.get("changed") is False -# assert cp_res.get("failed") is True -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") + copy_results = hosts.all.zos_copy( + src=f"{src_data_set}({generation})", + dest=dest_data_set, + remote_src=True + ) + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is not None + assert cp_res.get("changed") is False + assert cp_res.get("failed") is True + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") -# def test_copy_seq_gds_to_data_set(ansible_zos_module): -# hosts = ansible_zos_module -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=f"{src_data_set}(0)", -# dest=dest_data_set, -# remote_src=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}" """) - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert cp_res.get("dest") == dest_data_set -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"drm {dest_data_set}") +def test_copy_seq_gds_to_data_set(ansible_zos_module): + hosts = ansible_zos_module + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() -# def test_copy_data_set_to_new_gds(ansible_zos_module): -# hosts = ansible_zos_module + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=f"{dest_data_set}(+1)", -# remote_src=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) - -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" - -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") - -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + copy_results = hosts.all.zos_copy( + src=f"{src_data_set}(0)", + dest=dest_data_set, + remote_src=True + ) + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}" """) -# def test_copy_uss_file_to_new_gds(ansible_zos_module): -# hosts = ansible_zos_module + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert cp_res.get("dest") == dest_data_set + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"drm {dest_data_set}") -# try: -# src_file = "/etc/profile" -# dest_data_set = get_tmp_ds_name() -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") +def test_copy_data_set_to_new_gds(ansible_zos_module): + hosts = ansible_zos_module -# copy_results = hosts.all.zos_copy( -# src=src_file, -# dest=f"{dest_data_set}(+1)", -# remote_src=True -# ) + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=f"{dest_data_set}(+1)", + remote_src=True + ) -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") -# def test_copy_pds_to_new_gds(ansible_zos_module): -# hosts = ansible_zos_module + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") -# try: -# src_data_set = get_tmp_ds_name() -# member_src = f"{src_data_set}(MEMBER)" -# dest_data_set = get_tmp_ds_name() -# hosts.all.shell(cmd=f"dtouch -tPDS {src_data_set}") -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) +def test_copy_uss_file_to_new_gds(ansible_zos_module): + hosts = ansible_zos_module -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + try: + src_file = "/etc/profile" + dest_data_set = get_tmp_ds_name() -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=f"{dest_data_set}(+1)", -# remote_src=True -# ) + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# verify_copy = hosts.all.shell(cmd=f"""mls "{dest_data_set}(0)" """) + copy_results = hosts.all.zos_copy( + src=src_file, + dest=f"{dest_data_set}(+1)", + remote_src=True + ) -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") -# def test_copy_data_set_to_previous_gds(ansible_zos_module): -# hosts = ansible_zos_module -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) - -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) -# hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=f"{dest_data_set}(0)", -# remote_src=True, -# replace=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) - -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" - -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") - -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") +def test_copy_pds_to_new_gds(ansible_zos_module): + hosts = ansible_zos_module + try: + src_data_set = get_tmp_ds_name() + member_src = f"{src_data_set}(MEMBER)" + dest_data_set = get_tmp_ds_name() -# def test_copy_uss_file_to_previous_gds(ansible_zos_module): -# hosts = ansible_zos_module + hosts.all.shell(cmd=f"dtouch -tPDS {src_data_set}") + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) -# try: -# src_file = "/etc/profile" -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_file, -# dest=f"{dest_data_set}(0)", -# remote_src=True, -# replace=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) - -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" - -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") - -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=f"{dest_data_set}(+1)", + remote_src=True + ) -# def test_copy_pds_member_to_previous_gds(ansible_zos_module): -# hosts = ansible_zos_module + verify_copy = hosts.all.shell(cmd=f"""mls "{dest_data_set}(0)" """) -# try: -# src_data_set = get_tmp_ds_name() -# member_src = f"{src_data_set}(MEMBER)" -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tPDS {src_data_set}") -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=member_src, -# dest=f"{dest_data_set}(0)", -# remote_src=True, -# replace=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) - -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" - -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") - -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") -# def test_copy_pds_to_previous_gds(ansible_zos_module): -# hosts = ansible_zos_module + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") -# try: -# src_data_set = get_tmp_ds_name() -# member_src = f"{src_data_set}(MEMBER)" -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tPDSE {src_data_set}") -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tPDS "{dest_data_set}(+1)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=f"{dest_data_set}(0)", -# remote_src=True, -# replace=True -# ) - -# verify_copy = hosts.all.shell(cmd=f"""mls "{dest_data_set}(0)" """) - -# # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. -# gds_pattern = r"G[0-9]+V[0-9]+" - -# for cp_res in copy_results.contacted.values(): -# dest = cp_res.get("dest", "") - -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert re.fullmatch(gds_pattern, dest.split(".")[-1]) -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_cp in verify_copy.contacted.values(): -# assert v_cp.get("rc") == 0 -# assert v_cp.get("stdout") != "" -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") +def test_copy_data_set_to_previous_gds(ansible_zos_module): + hosts = ansible_zos_module -# def test_copy_data_set_to_previous_gds_no_force(ansible_zos_module): -# hosts = ansible_zos_module + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) - -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) -# hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=f"{dest_data_set}(0)", -# remote_src=True, -# replace=False -# ) - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is not None -# assert cp_res.get("changed") is False -# assert cp_res.get("failed") is True -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) + hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) -# @pytest.mark.parametrize("generation", [0, -1]) -# def test_copy_data_set_to_previous_non_existent_gds(ansible_zos_module, generation): -# hosts = ansible_zos_module + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=f"{dest_data_set}(0)", + remote_src=True, + replace=True + ) -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# if generation < 0: -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) - -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# # Copying to a previous generation that doesn't exist. -# dest=f"{dest_data_set}({generation})", -# remote_src=True, -# replace=True -# ) - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is not None -# assert "generation data set is not allocated" in cp_res.get("msg") -# assert cp_res.get("changed") is False -# assert cp_res.get("failed") is True -# finally: -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" -# def test_copy_gdg_to_uss_dir(ansible_zos_module): -# hosts = ansible_zos_module + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") -# try: -# src_data_set = get_tmp_ds_name() -# dest = get_random_file_name(dir=TMP_DIRECTORY) - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) - -# hosts.all.file(path=dest, state="directory") - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest, -# remote_src=True -# ) - -# verify_dest = hosts.all.shell(cmd=f"ls {dest}/{src_data_set}") - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert cp_res.get("dest") is not None -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# for v_res in verify_dest.contacted.values(): -# assert v_res.get("rc") == 0 -# assert len(v_res.get("stdout_lines", [])) > 0 -# finally: -# hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {src_data_set}") -# hosts.all.file(path=dest, state="absent") + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") -# @pytest.mark.parametrize("new_gdg", [True, False]) -# def test_copy_gdg_to_gdg(ansible_zos_module, new_gdg): -# hosts = ansible_zos_module +def test_copy_uss_file_to_previous_gds(ansible_zos_module): + hosts = ansible_zos_module -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) - -# if not new_gdg: -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest_data_set, -# remote_src=True -# ) - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert cp_res.get("dest") is not None -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# finally: -# hosts.all.shell(cmd=f"""drm "{src_data_set}(-1)" """) -# hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {src_data_set}") - -# if not new_gdg: -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(-2)" """) -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(-1)" """) -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") - -# def test_identical_gdg_copy(ansible_zos_module): -# hosts = ansible_zos_module -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() -# # Create source GDG base -# hosts.all.shell(cmd=f"dtouch -tGDG -L5 {src_data_set}") -# # Create 5 generations in source GDG -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) - -# # Delete first two generations: (-4) and (-3) -# hosts.all.shell(cmd=f"""drm "{src_data_set}(-4)" """) -# hosts.all.shell(cmd=f"""drm "{src_data_set}(-3)" """) -# # Copy with identical_gdg_copy: true -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest_data_set, -# remote_src=True, -# identical_gdg_copy=True -# ) -# for result in copy_results.contacted.values(): -# assert result.get("msg") is None -# assert result.get("changed") is True -# assert result.get("dest") is not None -# assert result.get("dest_created") is not None -# assert result.get("src") is not None -# finally: -# src_gdg_result = hosts.all.shell(cmd=f"dls {src_data_set}.*") -# src_gdgs = [] -# for result in src_gdg_result.contacted.values(): -# src_gdgs.extend(result.get("stdout_lines", [])) -# # List destination generations -# dest_gdg_result = hosts.all.shell(cmd=f"dls {dest_data_set}.*") -# dest_gdgs = [] -# for result in dest_gdg_result.contacted.values(): -# dest_gdgs.extend(result.get("stdout_lines", [])) -# expected_dest_gdgs = [ -# ds_name.replace(src_data_set,dest_data_set) for ds_name in src_gdgs -# ] -# assert sorted(dest_gdgs) == sorted(expected_dest_gdgs), f"Absolute names mismatch.\nExpected: {expected_dest_gdgs}\nFound: {dest_gdgs}" -# print("Abssolute GDG names copied correctly.") -# for name in dest_gdgs: -# print(name) -# # Clean up both source and destination -# hosts.all.shell(cmd=f"drm {src_data_set}*") -# hosts.all.shell(cmd=f"drm {dest_data_set}*") - - -# def test_copy_gdg_to_gdg_dest_attributes(ansible_zos_module): -# hosts = ansible_zos_module + try: + src_file = "/etc/profile" + dest_data_set = get_tmp_ds_name() -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) -# hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) - -# copy_results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest_data_set, -# remote_src=True, -# dest_data_set={ -# "type": "gdg", -# "limit": 5, -# "empty": False, -# "scratch": True, -# "purge": True, -# "extended": False, -# "fifo": False -# } -# ) - -# for cp_res in copy_results.contacted.values(): -# assert cp_res.get("msg") is None -# assert cp_res.get("changed") is True -# assert cp_res.get("dest") is not None -# assert cp_res.get("dest_created") is not None -# assert cp_res.get("src") is not None -# finally: -# hosts.all.shell(cmd=f"""drm "{src_data_set}(-1)" """) -# hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) + + copy_results = hosts.all.zos_copy( + src=src_file, + dest=f"{dest_data_set}(0)", + remote_src=True, + replace=True + ) -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(-1)" """) -# hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {dest_data_set}") + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" -# def test_backup_gds(ansible_zos_module): -# hosts = ansible_zos_module + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() -# backup_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tSEQ {dest_data_set}") -# hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{src_data_set}\"") -# hosts.all.shell(cmd=f"decho \"A record\" \"{dest_data_set}\"") - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {backup_data_set}") - -# results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest_data_set, -# remote_src=True, -# replace=True, -# backup=True, -# backup_name=f"{backup_data_set}(+1)", -# ) - -# backup_check = hosts.all.shell( -# cmd=f"""dcat "{backup_data_set}(0)" | wc -l """ -# ) - -# for result in results.contacted.values(): -# assert result.get("changed") is True -# assert result.get("msg") is None -# assert result.get("dest") is not None -# assert result.get("dest_created") is not None -# assert result.get("src") is not None - -# for result in backup_check.contacted.values(): -# assert result.get("rc") == 0 -# assert int(result.get("stdout")) > 0 + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") -# finally: -# hosts.all.shell(cmd=f"""drm "{backup_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {backup_data_set}") -# hosts.all.shell(cmd=f"drm {dest_data_set}") -# hosts.all.shell(cmd=f"drm {src_data_set}") +def test_copy_pds_member_to_previous_gds(ansible_zos_module): + hosts = ansible_zos_module -# def test_backup_gds_invalid_generation(ansible_zos_module): -# hosts = ansible_zos_module + try: + src_data_set = get_tmp_ds_name() + member_src = f"{src_data_set}(MEMBER)" + dest_data_set = get_tmp_ds_name() -# try: -# src_data_set = get_tmp_ds_name() -# dest_data_set = get_tmp_ds_name() -# backup_data_set = get_tmp_ds_name() - -# hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") -# hosts.all.shell(cmd=f"dtouch -tSEQ {dest_data_set}") - -# hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{src_data_set}\"") -# hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{dest_data_set}\"") - -# hosts.all.shell(cmd=f"dtouch -tGDG -L3 {backup_data_set}") -# hosts.all.shell(cmd=f"""dtouch -tSEQ "{backup_data_set}(+1)" """) - -# results = hosts.all.zos_copy( -# src=src_data_set, -# dest=dest_data_set, -# remote_src=True, -# replace=True, -# backup=True, -# backup_name=f"{backup_data_set}(0)", -# ) - -# for result in results.contacted.values(): -# assert result.get("failed") is True -# assert result.get("changed") is False -# assert result.get("msg") is not None -# assert "cannot be used" in result.get("msg") + hosts.all.shell(cmd=f"dtouch -tPDS {src_data_set}") + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) -# finally: -# hosts.all.shell(cmd=f"""drm "{backup_data_set}(0)" """) -# hosts.all.shell(cmd=f"drm {backup_data_set}") -# hosts.all.shell(cmd=f"drm {dest_data_set}") -# hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) + + copy_results = hosts.all.zos_copy( + src=member_src, + dest=f"{dest_data_set}(0)", + remote_src=True, + replace=True + ) + + verify_copy = hosts.all.shell(cmd=f"""dcat "{dest_data_set}(0)" """) + + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" + + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") + + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + + +def test_copy_pds_to_previous_gds(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + member_src = f"{src_data_set}(MEMBER)" + dest_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tPDSE {src_data_set}") + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{member_src}" """) + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tPDS "{dest_data_set}(+1)" """) + + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=f"{dest_data_set}(0)", + remote_src=True, + replace=True + ) + + verify_copy = hosts.all.shell(cmd=f"""mls "{dest_data_set}(0)" """) + + # Checking that we got a source of the form: ANSIBLE.DATA.SET.G0001V01. + gds_pattern = r"G[0-9]+V[0-9]+" + + for cp_res in copy_results.contacted.values(): + dest = cp_res.get("dest", "") + + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert re.fullmatch(gds_pattern, dest.split(".")[-1]) + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_cp in verify_copy.contacted.values(): + assert v_cp.get("rc") == 0 + assert v_cp.get("stdout") != "" + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + + +def test_copy_data_set_to_previous_gds_no_force(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) + hosts.all.shell(cmd=f"""decho "A record." "{dest_data_set}(0)" """) + + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=f"{dest_data_set}(0)", + remote_src=True, + replace=False + ) + + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is not None + assert cp_res.get("changed") is False + assert cp_res.get("failed") is True + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + + +@pytest.mark.parametrize("generation", [0, -1]) +def test_copy_data_set_to_previous_non_existent_gds(ansible_zos_module, generation): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + if generation < 0: + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}" """) + + copy_results = hosts.all.zos_copy( + src=src_data_set, + # Copying to a previous generation that doesn't exist. + dest=f"{dest_data_set}({generation})", + remote_src=True, + replace=True + ) + + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is not None + assert "generation data set is not allocated" in cp_res.get("msg") + assert cp_res.get("changed") is False + assert cp_res.get("failed") is True + finally: + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + + +def test_copy_gdg_to_uss_dir(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest = get_random_file_name(dir=TMP_DIRECTORY) + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) + + hosts.all.file(path=dest, state="directory") + + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=dest, + remote_src=True + ) + + verify_dest = hosts.all.shell(cmd=f"ls {dest}/{src_data_set}") + + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert cp_res.get("dest") is not None + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + for v_res in verify_dest.contacted.values(): + assert v_res.get("rc") == 0 + assert len(v_res.get("stdout_lines", [])) > 0 + finally: + hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {src_data_set}") + hosts.all.file(path=dest, state="absent") + + +@pytest.mark.parametrize("new_gdg", [True, False]) +def test_copy_gdg_to_gdg(ansible_zos_module, new_gdg): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) + + if not new_gdg: + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {dest_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{dest_data_set}(+1)" """) + + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=dest_data_set, + remote_src=True + ) + + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert cp_res.get("dest") is not None + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + finally: + hosts.all.shell(cmd=f"""drm "{src_data_set}(-1)" """) + hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {src_data_set}") + + if not new_gdg: + hosts.all.shell(cmd=f"""drm "{dest_data_set}(-2)" """) + hosts.all.shell(cmd=f"""drm "{dest_data_set}(-1)" """) + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + +def test_identical_gdg_copy(ansible_zos_module): + hosts = ansible_zos_module + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + # Create source GDG base + hosts.all.shell(cmd=f"dtouch -tGDG -L5 {src_data_set}") + # Create 5 generations in source GDG + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + + # Delete first two generations: (-4) and (-3) + hosts.all.shell(cmd=f"""drm "{src_data_set}(-4)" """) + hosts.all.shell(cmd=f"""drm "{src_data_set}(-3)" """) + # Copy with identical_gdg_copy: true + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=dest_data_set, + remote_src=True, + identical_gdg_copy=True + ) + for result in copy_results.contacted.values(): + assert result.get("msg") is None + assert result.get("changed") is True + assert result.get("dest") is not None + assert result.get("dest_created") is not None + assert result.get("src") is not None + finally: + src_gdg_result = hosts.all.shell(cmd=f"dls {src_data_set}.*") + src_gdgs = [] + for result in src_gdg_result.contacted.values(): + src_gdgs.extend(result.get("stdout_lines", [])) + # List destination generations + dest_gdg_result = hosts.all.shell(cmd=f"dls {dest_data_set}.*") + dest_gdgs = [] + for result in dest_gdg_result.contacted.values(): + dest_gdgs.extend(result.get("stdout_lines", [])) + expected_dest_gdgs = [ + ds_name.replace(src_data_set,dest_data_set) for ds_name in src_gdgs + ] + assert sorted(dest_gdgs) == sorted(expected_dest_gdgs), f"Absolute names mismatch.\nExpected: {expected_dest_gdgs}\nFound: {dest_gdgs}" + print("Abssolute GDG names copied correctly.") + for name in dest_gdgs: + print(name) + # Clean up both source and destination + hosts.all.shell(cmd=f"drm {src_data_set}*") + hosts.all.shell(cmd=f"drm {dest_data_set}*") + + +def test_copy_gdg_to_gdg_dest_attributes(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {src_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"""dtouch -tSEQ "{src_data_set}(+1)" """) + hosts.all.shell(cmd=f"""decho "{DUMMY_DATA}" "{src_data_set}(0)" """) + + copy_results = hosts.all.zos_copy( + src=src_data_set, + dest=dest_data_set, + remote_src=True, + dest_data_set={ + "type": "gdg", + "limit": 5, + "empty": False, + "scratch": True, + "purge": True, + "extended": False, + "fifo": False + } + ) + + for cp_res in copy_results.contacted.values(): + assert cp_res.get("msg") is None + assert cp_res.get("changed") is True + assert cp_res.get("dest") is not None + assert cp_res.get("dest_created") is not None + assert cp_res.get("src") is not None + finally: + hosts.all.shell(cmd=f"""drm "{src_data_set}(-1)" """) + hosts.all.shell(cmd=f"""drm "{src_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {src_data_set}") + + hosts.all.shell(cmd=f"""drm "{dest_data_set}(-1)" """) + hosts.all.shell(cmd=f"""drm "{dest_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {dest_data_set}") + + +def test_backup_gds(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + backup_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tSEQ {dest_data_set}") + hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{src_data_set}\"") + hosts.all.shell(cmd=f"decho \"A record\" \"{dest_data_set}\"") + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {backup_data_set}") + + results = hosts.all.zos_copy( + src=src_data_set, + dest=dest_data_set, + remote_src=True, + replace=True, + backup=True, + backup_name=f"{backup_data_set}(+1)", + ) + + backup_check = hosts.all.shell( + cmd=f"""dcat "{backup_data_set}(0)" | wc -l """ + ) + + for result in results.contacted.values(): + assert result.get("changed") is True + assert result.get("msg") is None + assert result.get("dest") is not None + assert result.get("dest_created") is not None + assert result.get("src") is not None + + for result in backup_check.contacted.values(): + assert result.get("rc") == 0 + assert int(result.get("stdout")) > 0 + + finally: + hosts.all.shell(cmd=f"""drm "{backup_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {backup_data_set}") + hosts.all.shell(cmd=f"drm {dest_data_set}") + hosts.all.shell(cmd=f"drm {src_data_set}") + + +def test_backup_gds_invalid_generation(ansible_zos_module): + hosts = ansible_zos_module + + try: + src_data_set = get_tmp_ds_name() + dest_data_set = get_tmp_ds_name() + backup_data_set = get_tmp_ds_name() + + hosts.all.shell(cmd=f"dtouch -tSEQ {src_data_set}") + hosts.all.shell(cmd=f"dtouch -tSEQ {dest_data_set}") + + hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{src_data_set}\"") + hosts.all.shell(cmd=f"decho \"{DUMMY_DATA}\" \"{dest_data_set}\"") + + hosts.all.shell(cmd=f"dtouch -tGDG -L3 {backup_data_set}") + hosts.all.shell(cmd=f"""dtouch -tSEQ "{backup_data_set}(+1)" """) + + results = hosts.all.zos_copy( + src=src_data_set, + dest=dest_data_set, + remote_src=True, + replace=True, + backup=True, + backup_name=f"{backup_data_set}(0)", + ) + + for result in results.contacted.values(): + assert result.get("failed") is True + assert result.get("changed") is False + assert result.get("msg") is not None + assert "cannot be used" in result.get("msg") + + finally: + hosts.all.shell(cmd=f"""drm "{backup_data_set}(0)" """) + hosts.all.shell(cmd=f"drm {backup_data_set}") + hosts.all.shell(cmd=f"drm {dest_data_set}") + hosts.all.shell(cmd=f"drm {src_data_set}") def test_copy_to_dataset_with_special_symbols(ansible_zos_module): diff --git a/tests/functional/modules/test_zos_replace_func.py b/tests/functional/modules/test_zos_replace_func.py index 59e4182ef5..12e2a34666 100644 --- a/tests/functional/modules/test_zos_replace_func.py +++ b/tests/functional/modules/test_zos_replace_func.py @@ -1598,76 +1598,75 @@ def test_ds_backup_name(ansible_zos_module, dstype, backup_name): ds_backup_file = ds_backup_file[:position] remove_ds_environment(ansible_zos_module, ds_backup_file) -# Commenting GDS as currently failing in 1.4.0 -# @pytest.mark.ds -# def test_gdg_ds(ansible_zos_module): -# hosts = ansible_zos_module -# params = { -# "regexp":"ZOAU_ROOT", -# "after":"export PATH", -# } -# ds_name = get_tmp_ds_name(3, 2) -# try: -# # Set environment -# temp_file = get_random_file_name(dir=TMP_DIRECTORY) -# hosts.all.shell(cmd="dtouch -tGDG -L3 {0}".format(ds_name)) -# hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(ds_name)) -# hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(ds_name)) -# hosts.all.shell(cmd=f"echo \"{TEST_CONTENT}\" > {temp_file}") -# ds_full_name = ds_name + "(0)" -# cmd_str = f"cp -CM {quote(temp_file)} \"//'{ds_full_name}'\"" -# hosts.all.shell(cmd=cmd_str) -# ds_full_name = ds_name + "(-1)" -# cmd_str = f"cp -CM {quote(temp_file)} \"//'{ds_full_name}'\"" -# hosts.all.shell(cmd=cmd_str) -# hosts.all.shell(cmd="rm -rf " + temp_file) - -# params["target"] = ds_name + "(0)" -# results = hosts.all.zos_replace(**params) -# for result in results.contacted.values(): -# assert result.get("changed") == True -# assert result.get("target") == ds_name + "(0)" -# assert result.get("found") == 2 -# results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["target"])) -# for result in results.contacted.values(): -# assert result.get("stdout") == TEST_AFTER +@pytest.mark.ds +def test_gdg_ds(ansible_zos_module): + hosts = ansible_zos_module + params = { + "regexp":"ZOAU_ROOT", + "after":"export PATH", + } + ds_name = get_tmp_ds_name(3, 2) + try: + # Set environment + temp_file = get_random_file_name(dir=TMP_DIRECTORY) + hosts.all.shell(cmd="dtouch -tGDG -L3 {0}".format(ds_name)) + hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(ds_name)) + hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(ds_name)) + hosts.all.shell(cmd=f"echo \"{TEST_CONTENT}\" > {temp_file}") + ds_full_name = ds_name + "(0)" + cmd_str = f"cp -CM {quote(temp_file)} \"//'{ds_full_name}'\"" + hosts.all.shell(cmd=cmd_str) + ds_full_name = ds_name + "(-1)" + cmd_str = f"cp -CM {quote(temp_file)} \"//'{ds_full_name}'\"" + hosts.all.shell(cmd=cmd_str) + hosts.all.shell(cmd="rm -rf " + temp_file) -# params["target"] = ds_name + "(-1)" -# results = hosts.all.zos_replace(**params) -# for result in results.contacted.values(): -# assert result.get("changed") == True -# assert result.get("target") == ds_name + "(-1)" -# assert result.get("found") == 2 -# results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["target"])) -# for result in results.contacted.values(): -# assert result.get("stdout") == TEST_AFTER + params["target"] = ds_name + "(0)" + results = hosts.all.zos_replace(**params) + for result in results.contacted.values(): + assert result.get("changed") == True + assert result.get("target") == ds_name + "(0)" + assert result.get("found") == 2 + results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["target"])) + for result in results.contacted.values(): + assert result.get("stdout") == TEST_AFTER -# params_w_bck = { -# "regexp":"ZOAU_ROOT", -# "after":"export PATH", -# "backup":True, -# "backup_name": ds_name + "(+1)", -# } -# params_w_bck["target"] = ds_name + "(-1)" -# backup = ds_name + "(0)" -# results = hosts.all.zos_replace(**params_w_bck) -# for result in results.contacted.values(): -# assert result.get("found") == 0 -# assert result.get("changed") == False -# assert result.get("target") == ds_name + "(-1)" -# assert result.get("backup_name") is not None -# backup = ds_name + "(0)" -# results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(backup)) -# for result in results.contacted.values(): -# assert result.get("stdout") == TEST_AFTER + params["target"] = ds_name + "(-1)" + results = hosts.all.zos_replace(**params) + for result in results.contacted.values(): + assert result.get("changed") == True + assert result.get("target") == ds_name + "(-1)" + assert result.get("found") == 2 + results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["target"])) + for result in results.contacted.values(): + assert result.get("stdout") == TEST_AFTER -# params["target"] = ds_name + "(-3)" -# results = hosts.all.zos_replace(**params) -# for result in results.contacted.values(): -# assert result.get("failed") == True -# assert result.get("changed") == False -# finally: -# hosts.all.shell(cmd="""drm "ANSIBLE.*" """) + params_w_bck = { + "regexp":"ZOAU_ROOT", + "after":"export PATH", + "backup":True, + "backup_name": ds_name + "(+1)", + } + params_w_bck["target"] = ds_name + "(-1)" + backup = ds_name + "(0)" + results = hosts.all.zos_replace(**params_w_bck) + for result in results.contacted.values(): + assert result.get("found") == 0 + assert result.get("changed") == False + assert result.get("target") == ds_name + "(-1)" + assert result.get("backup_name") is not None + backup = ds_name + "(0)" + results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(backup)) + for result in results.contacted.values(): + assert result.get("stdout") == TEST_AFTER + + params["target"] = ds_name + "(-3)" + results = hosts.all.zos_replace(**params) + for result in results.contacted.values(): + assert result.get("failed") == True + assert result.get("changed") == False + finally: + hosts.all.shell(cmd="""drm "ANSIBLE.*" """) ######################### # No UTF-8 Characters