Skip to content
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

[v1.10.0] [module_utils/backup.py] Implement ZOAU 1.3 migration changes into module_utils/backup.py #1188

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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/1188-migrate-module_utils-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trivial:
- module_utils/backup.py - migrate code to use ZOAU v1.3.0.
(https://github.com/ansible-collections/ibm_zos_core/pull/1188).
31 changes: 18 additions & 13 deletions plugins/module_utils/backup.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

copyright dates!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added them, thanks !!

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) IBM Corporation 2020, 2022
# Copyright (c) IBM Corporation 2020 - 2024
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -22,8 +22,9 @@

import time
from shutil import copy2, copytree, rmtree
import traceback
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.import_handler import (
MissingZOAUImport,
ZOAUImportError,
)
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import (
BetterArgParser,
Expand All @@ -39,9 +40,10 @@
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.mvs_cmd import iebcopy

try:
from zoautil_py import datasets
from zoautil_py import datasets, exceptions
except Exception:
datasets = MissingZOAUImport()
datasets = ZOAUImportError(traceback.format_exc())
exceptions = ZOAUImportError(traceback.format_exc())
if PY3:
from shlex import quote
else:
Expand Down Expand Up @@ -76,29 +78,32 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
bk_dsn = extract_dsname(dsn) + "({0})".format(temp_member_name())

bk_dsn = _validate_data_set_name(bk_dsn).upper()
response = datasets._copy(dsn, bk_dsn)
if response.rc != 0:
try:
rc = datasets.copy(dsn, bk_dsn)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This variable rc which is the ZOU response object is not used anyplace, not sure if linters will complain about an unused variable, otherwise its not really an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops! removed it now, actually linters didn't showed a problem, maybe because is populated again down below, but is assigned value was never used so I removed it.

except exceptions.ZOAUException as copy_exception:
raise BackupError(
"Unable to backup {0} to {1}".format(dsn, bk_dsn),
rc=response.rc,
stdout=response.stdout_response,
stderr=response.stderr_response
rc=copy_exception.response.rc,
stdout=copy_exception.response.stdout_response,
stderr=copy_exception.response.stderr_response
)
else:
if not bk_dsn:
if tmphlq:
hlq = tmphlq
else:
hlq = datasets.hlq()
bk_dsn = datasets.tmp_name(hlq)
hlq = datasets.get_hlq()
bk_dsn = datasets.tmp_name(high_level_qualifier=hlq)
bk_dsn = _validate_data_set_name(bk_dsn).upper()

# In case the backup ds is a member we trust that the PDS attributes are ok to fit the src content.
# This should not delete a PDS just to create a backup member.
# Otherwise, we allocate the appropiate space for the backup ds based on src.
if is_member(bk_dsn):
cp_response = datasets._copy(dsn, bk_dsn)
cp_rc = cp_response.rc
try:
cp_rc = datasets.copy(dsn, bk_dsn)
except exceptions.ZOAUException as copy_exception:
cp_rc = copy_exception.response.rc
else:
cp_rc = _copy_ds(dsn, bk_dsn)

Expand Down