From 2460e896128b07b3be81956ccf3e61b949c2b4b6 Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Mon, 21 Jul 2025 12:13:38 +0530 Subject: [PATCH 1/7] adding better error message hint --- plugins/modules/zos_copy.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 0a9c0d090..1d0d631f3 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -3963,8 +3963,12 @@ def run_module(module, arg_def): # Copy to a GDG # --------------------------------------------------------------------- elif dest_ds_type == "GDG": - copy_handler.copy_to_gdg(src, dest) - res_args["changed"] = True + try: + copy_handler.copy_to_gdg(src, dest) + res_args["changed"] = True + except Exception as e: + res_args["msg"] = f"Failure to copy might be because of source GDG in open state {e}" + # ------------------------------- o ----------------------------------- # Copy to VSAM data set From 482e665eee031f9af802e935c83005171b06fdee Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Mon, 4 Aug 2025 00:33:07 +0530 Subject: [PATCH 2/7] changing error from zoau for gdg copy --- plugins/modules/zos_copy.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 1d0d631f3..931fdbe50 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1205,9 +1205,20 @@ def copy_to_gdg(self, src, dest): # If identical_gdg_copy is False, use the default next generation dest_gen_name = f"{dest}(+1)" # Perform the copy operation - rc = datasets.copy(gds.name, dest_gen_name, **copy_args) - if rc != 0: - success = False + + try: + result = datasets.copy(gds.name, dest_gen_name, **copy_args) + rc = result.rc if hasattr(result, 'rc') else result + if rc != 0: + success = False + except zoau_exceptions.ZOAUException as e: + stderr = getattr(e.response, 'stderr_response', str(e)) + if "BGYSC6003E" in stderr : + raise GenerationDataGroupCreateError( + msg="BGYSC6003E Invalid generation relative name: This might be because the src GDG is in open state" + ) from e + else: + raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e return success def _copy_tree(self, entries, src, dest, dirs_exist_ok=False): @@ -3963,12 +3974,8 @@ def run_module(module, arg_def): # Copy to a GDG # --------------------------------------------------------------------- elif dest_ds_type == "GDG": - try: - copy_handler.copy_to_gdg(src, dest) - res_args["changed"] = True - except Exception as e: - res_args["msg"] = f"Failure to copy might be because of source GDG in open state {e}" - + copy_handler.copy_to_gdg(src, dest) + res_args["changed"] = True # ------------------------------- o ----------------------------------- # Copy to VSAM data set @@ -4347,5 +4354,11 @@ def __init__( super().__init__(msg) +class GenerationDataGroupCreateError(Exception): + def __init__(self, msg): + """Error during copy of a Generation Data Group.""" + self.msg = msg + super().__init__(self.msg) + if __name__ == "__main__": main() From aba3e8961fb3613a05e081ef9409ed794f34d337 Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Wed, 6 Aug 2025 01:19:08 +0530 Subject: [PATCH 3/7] adding chnagelog --- .../2220-zos_copy-better-error-message-GDG-copy-issue.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml diff --git a/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml new file mode 100644 index 000000000..a842548bc --- /dev/null +++ b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml @@ -0,0 +1,4 @@ +minor_changes: + - zos_copy - Adds a better error message that gives user a + hint that copy issue can be due to 'src' GDG in edit state. + (https://github.com/ansible-collections/ibm_zos_core/pull/2220) \ No newline at end of file From e92af20009e120ac4ee827a531437719349e00d1 Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Thu, 7 Aug 2025 04:10:11 +0530 Subject: [PATCH 4/7] Fixing sanity issue --- plugins/modules/zos_copy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 931fdbe50..ebf55fdd0 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1216,7 +1216,7 @@ def copy_to_gdg(self, src, dest): if "BGYSC6003E" in stderr : raise GenerationDataGroupCreateError( msg="BGYSC6003E Invalid generation relative name: This might be because the src GDG is in open state" - ) from e + ) from e else: raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e return success @@ -4360,5 +4360,6 @@ def __init__(self, msg): self.msg = msg super().__init__(self.msg) + if __name__ == "__main__": main() From 1cd6f20fa68748d58ad403e2b44089431144d8d9 Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Mon, 11 Aug 2025 10:08:06 +0530 Subject: [PATCH 5/7] adding review comments --- .../2220-zos_copy-better-error-message-GDG-copy-issue.yml | 3 ++- plugins/modules/zos_copy.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml index a842548bc..0188ff0b4 100644 --- a/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml +++ b/changelogs/fragments/2220-zos_copy-better-error-message-GDG-copy-issue.yml @@ -1,4 +1,5 @@ minor_changes: - zos_copy - Adds a better error message that gives user a - hint that copy issue can be due to 'src' GDG in edit state. + hint that copy issue can be due to a GDS part of ``src`` GDG is + being used by another process. (https://github.com/ansible-collections/ibm_zos_core/pull/2220) \ No newline at end of file diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index ebf55fdd0..735cc2980 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1215,7 +1215,7 @@ def copy_to_gdg(self, src, dest): stderr = getattr(e.response, 'stderr_response', str(e)) if "BGYSC6003E" in stderr : raise GenerationDataGroupCreateError( - msg="BGYSC6003E Invalid generation relative name: This might be because the src GDG is in open state" + msg="BGYSC6003E Invalid generation relative name: This might be because the GDS part of the src GDG is being used by another process." ) from e else: raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e From 11adf0f77ef490060a6a77ea0960e18004b5b6ae Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Mon, 11 Aug 2025 19:39:44 +0530 Subject: [PATCH 6/7] Error code mistake resolution --- plugins/modules/zos_copy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 735cc2980..ae44b6da7 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1213,9 +1213,10 @@ def copy_to_gdg(self, src, dest): success = False except zoau_exceptions.ZOAUException as e: stderr = getattr(e.response, 'stderr_response', str(e)) - if "BGYSC6003E" in stderr : + if "BGYSC0514E" in stderr : raise GenerationDataGroupCreateError( - msg="BGYSC6003E Invalid generation relative name: This might be because the GDS part of the src GDG is being used by another process." + msg="BGYSC0514E An error occurred while attempting to define the file." \ + " This might be because the GDS part of the src GDG is being used by another process." ) from e else: raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e From 2239bb4523e81aad8759dc5cb0604cd64222d6ab Mon Sep 17 00:00:00 2001 From: Rohitcodes28 Date: Mon, 11 Aug 2025 19:51:14 +0530 Subject: [PATCH 7/7] resolving sanity issue --- plugins/modules/zos_copy.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index ae44b6da7..0d2ac0213 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -1215,8 +1215,10 @@ def copy_to_gdg(self, src, dest): stderr = getattr(e.response, 'stderr_response', str(e)) if "BGYSC0514E" in stderr : raise GenerationDataGroupCreateError( - msg="BGYSC0514E An error occurred while attempting to define the file." \ - " This might be because the GDS part of the src GDG is being used by another process." + msg=( + "BGYSC0514E An error occurred while attempting to define the file." + " This might be because the GDS part of the src GDG is being used by another process." + ) ) from e else: raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}") from e