Skip to content

[Enhancement][data_set]Enhance error messages when not able to create GDGs #2212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: staging-v1.16.0-beta.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/2212-data_set-Enhance-error-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- data_set - Enhances error message for GDG creation failure.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- data_set - Enhances error message for GDG creation failure.
- zos_data_set - Enhances error messages when creating a Generation Data Group fails.

(https://github.com/ansible-collections/ibm_zos_core/pull/2212)
46 changes: 44 additions & 2 deletions plugins/module_utils/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@

try:
from zoautil_py import datasets, exceptions, gdgs, mvscmd, ztypes
from zoautil_py.exceptions import GenerationDataGroupCreateException
except ImportError:
datasets = ZOAUImportError(traceback.format_exc())
exceptions = ZOAUImportError(traceback.format_exc())
gdgs = ZOAUImportError(traceback.format_exc())
mvscmd = ZOAUImportError(traceback.format_exc())
ztypes = ZOAUImportError(traceback.format_exc())
GenerationDataGroupCreateException = ZOAUImportError(traceback.format_exc())


class DataSet(object):
Expand Down Expand Up @@ -2948,6 +2950,14 @@ def __init__(
# Removed escaping since is not needed by the GDG python api.
# self.name = DataSet.escape_data_set_name(self.name)

@staticmethod
def _validate_gdg_name(name):
"""Validates the length of a GDG name."""
if name and len(name) > 35:
raise GenerationDataGroupCreateError(
msg="GDG creation failed: dataset name exceeds 35 characters."
)

def create(self):
"""Creates the GDG.

Expand All @@ -2956,6 +2966,7 @@ def create(self):
int
Indicates if changes were made.
"""
GenerationDataGroup._validate_gdg_name(self.name)
gdg = gdgs.create(
name=self.name,
limit=self.limit,
Expand Down Expand Up @@ -2984,16 +2995,40 @@ def ensure_present(self, replace):
changed = False
present = False
gdg = None
name = arguments.get("name")

# Add this line to validate the name length before any operation
GenerationDataGroup._validate_gdg_name(name)

def _create_gdg(args):
try:
return gdgs.create(**args)
except exceptions._ZOAUExtendableException as e:
# Now, check if it's the specific exception we want to handle.
if isinstance(e, GenerationDataGroupCreateException):
stderr = getattr(e.response, 'stderr_response', '')
if "BGYSC5906E" in stderr :
raise GenerationDataGroupCreateError(msg="FIFO creation failed: the system may not support FIFO datasets or is not configured for it.")
elif "BGYSC6104E" in stderr :
raise GenerationDataGroupCreateError(msg="GDG creation failed: 'purge=true' requires 'scratch=true'.")
else:
raise GenerationDataGroupCreateError(msg=f"GDG creation failed. Raw error: {stderr}")
else:
# If it's a different ZOAU error, re-raise it.
raise e
if gdgs.exists(arguments.get("name")):
present = True

if not present:
gdg = gdgs.create(**arguments)
# gdg = gdgs.create(**arguments)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the code works fine with your changes, I would remove the commented lines with the calls that were previously used.

gdg = _create_gdg(arguments)

else:
if not replace:
return changed
changed = self.ensure_absent(True)
gdg = gdgs.create(**arguments)
gdg = _create_gdg(arguments)
# gdg = gdgs.create(**arguments)
if isinstance(gdg, gdgs.GenerationDataGroupView):
changed = True
return changed
Expand Down Expand Up @@ -3465,3 +3500,10 @@ def __init__(self, data_set):
"Make sure the generation exists and is active.".format(data_set)
)
super().__init__(self.msg)


class GenerationDataGroupCreateError(Exception):
def __init__(self, msg):
"""Error during creation of a Generation Data Group."""
self.msg = msg
super().__init__(self.msg)