-
Notifications
You must be signed in to change notification settings - Fork 43
[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
mayankmani-sde
wants to merge
7
commits into
staging-v1.16.0-beta.1
Choose a base branch
from
Enhancement/1976/zos_data_set
base: staging-v1.16.0-beta.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
603894d
Enhance error messages
mayankmani-sde 99d8d4e
added fragments
mayankmani-sde cc61c66
FIXED SANITY
mayankmani-sde c77d3a9
FIXED SANITY
mayankmani-sde 95ed433
FIXED
mayankmani-sde 5a52b77
fixed
mayankmani-sde 8414baf
Merge branch 'staging-v1.16.0-beta.1' into Enhancement/1976/zos_data_set
mayankmani-sde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
(https://github.com/ansible-collections/ibm_zos_core/pull/2212) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
|
@@ -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. | ||
|
||
|
@@ -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, | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.