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

[Bugfix] [module_utils] [multiple modules] tmp_hlq use in utils whenever mvscmd gets called #1695

Merged
merged 32 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c8aef19
First iteration
AndreMarcel99 Aug 26, 2024
da36ff0
Merge branch 'dev' into enabler/1596/portability_zos_blockinfile
AndreMarcel99 Aug 28, 2024
0ecca18
Fix blockinfile test
AndreMarcel99 Aug 28, 2024
412bda5
Fix remove
AndreMarcel99 Aug 28, 2024
336f239
Add fragment
AndreMarcel99 Aug 28, 2024
9381219
Remove remaining
AndreMarcel99 Aug 29, 2024
5c435b7
Fix change
AndreMarcel99 Aug 29, 2024
a10e7da
Fix blockinfile
AndreMarcel99 Aug 29, 2024
411858d
Add use of tmphlq to dataset utils class
rexemin Sep 3, 2024
ee385c8
Merge branch 'dev' into enabler/1596/portability_zos_blockinfile
rexemin Sep 3, 2024
786a242
Update tmphlq in modules
rexemin Sep 3, 2024
230d0ed
Merge branch 'enabler/1596/portability_zos_blockinfile' into bugfix/9…
rexemin Sep 3, 2024
bcd7772
Remove all tmp occurrences
AndreMarcel99 Sep 3, 2024
40d3b90
Fix tmp
AndreMarcel99 Sep 3, 2024
f74e2f2
Fix tmp
AndreMarcel99 Sep 3, 2024
a52378e
Merge branch 'enabler/1596/portability_zos_blockinfile' into bugfix/9…
rexemin Sep 3, 2024
790b10d
Update tmphlq use in zos_encode
rexemin Sep 3, 2024
3c48ce0
Add tmphlq to data_set_exists
rexemin Sep 4, 2024
0aecda8
Update module utils
rexemin Sep 9, 2024
d62e34c
Update modules
rexemin Sep 11, 2024
32b08ac
Fix tmp_hlq in zos_copy
rexemin Sep 11, 2024
0460acf
Fix ensure_present for members
rexemin Sep 11, 2024
0ebbc2f
Fix wrong keyword arg in dataset util
rexemin Sep 13, 2024
5a0d0a8
Update zos_archive and zos_unarchive
rexemin Sep 13, 2024
466d443
Merge branch 'dev' into bugfix/912/tmp_hlq_in_data_set_exists
rexemin Sep 18, 2024
ac0ad93
Fix tmphlq error in zos_archive
rexemin Sep 18, 2024
ba56c4d
Add changelog fragment
rexemin Sep 20, 2024
ee48f20
Update changelog fragment
rexemin Sep 24, 2024
85b5e6b
Update dataset function calls
rexemin Sep 30, 2024
7a63b25
Merge branch 'dev' into bugfix/912/tmp_hlq_in_data_set_exists
rexemin Oct 2, 2024
d1ac0d6
Fix function calls in zos_data_set
rexemin Oct 2, 2024
3dc80f9
Fix missing import
rexemin Oct 2, 2024
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
31 changes: 31 additions & 0 deletions changelogs/fragments/1695-tmp_hlq_when_calling_mvscmd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bugfixes:
- zos_apf - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_archive - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_blockinfile - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_copy - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_data_set - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_encode - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_fetch - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_lineinfile - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_mount - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
- zos_unarchive - The ``tmp_hlq`` option was previously ignored and default
values were used instead. Fix now honors the value set in the module option.
(https://github.com/ansible-collections/ibm_zos_core/pull/1695).
29 changes: 22 additions & 7 deletions plugins/module_utils/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
It could be an MVS PS/PDS/PDSE/VSAM(KSDS), etc.
bk_dsn : str
The name of the backup data set.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand Down Expand Up @@ -128,14 +130,14 @@ def mvs_file_backup(dsn, bk_dsn=None, tmphlq=None):
if DataSet.is_gds_positive_relative_name(bk_dsn):
cp_rc = datasets.copy(dsn, bk_dsn)
else:
cp_rc = _copy_ds(dsn, bk_dsn)
cp_rc = _copy_ds(dsn, bk_dsn, tmphlq=tmphlq)

if cp_rc == 12: # The data set is probably a PDS or PDSE
# Delete allocated backup that was created when attempting to use _copy_ds()
# Safe to delete because _copy_ds() would have raised an exception if it did
# not successfully create the backup data set, so no risk of it predating module invocation
datasets.delete(bk_dsn)
_allocate_model(bk_dsn, dsn)
_allocate_model(bk_dsn, dsn, tmphlq=tmphlq)
rc, out, err = _copy_pds(dsn, bk_dsn)
if rc != 0:
raise BackupError(
Expand Down Expand Up @@ -222,7 +224,7 @@ def uss_file_backup(path, backup_name=None, compress=False):
return backup_name


def _copy_ds(ds, bk_ds):
def _copy_ds(ds, bk_ds, tmphlq=None):
"""Copy the contents of a data set to another.

Parameters
Expand All @@ -231,6 +233,8 @@ def _copy_ds(ds, bk_ds):
The source data set to be copied from. Should be SEQ or VSAM.
bk_dsn : str
The destination data set to copy to.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand All @@ -243,14 +247,19 @@ def _copy_ds(ds, bk_ds):
When copying data fails.
"""
module = AnsibleModuleHelper(argument_spec={})
_allocate_model(bk_ds, ds)
_allocate_model(bk_ds, ds, tmphlq=tmphlq)
repro_cmd = """ REPRO -
INDATASET('{0}') -
OUTDATASET('{1}')""".format(
ds, bk_ds
)

cmd = "mvscmdauth --pgm=idcams --sysprint=* --sysin=stdin"
if tmphlq:
cmd = "{0} -Q={1}".format(cmd, tmphlq)

rc, out, err = module.run_command(
"mvscmdauth --pgm=idcams --sysprint=* --sysin=stdin", data=repro_cmd, errors='replace'
cmd, data=repro_cmd, errors='replace'
)
if rc != 0 and rc != 12:
datasets.delete(bk_ds)
Expand All @@ -259,12 +268,12 @@ def _copy_ds(ds, bk_ds):
ds, out, err
)
)
if rc != 0 and DataSet.is_empty(ds):
if rc != 0 and DataSet.is_empty(ds, tmphlq=tmphlq):
rc = 0
return rc


def _allocate_model(ds, model):
def _allocate_model(ds, model, tmphlq=None):
"""Allocate a data set using allocation information of a model data set.

Parameters
Expand All @@ -273,6 +282,8 @@ def _allocate_model(ds, model):
The name of the data set to be allocated.
model : str
The name of the data set whose allocation parameters should be used.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand All @@ -290,7 +301,11 @@ def _allocate_model(ds, model):
LIKE('{1}')""".format(
ds, model
)

cmd = "mvscmdauth --pgm=ikjeft01 --systsprt=* --systsin=stdin"
if tmphlq:
cmd = "{0} -Q={1}".format(cmd, tmphlq)

rc, out, err = module.run_command(cmd, data=alloc_cmd, errors='replace')
if rc != 0:
raise BackupError(
Expand Down
26 changes: 19 additions & 7 deletions plugins/module_utils/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def copy_mvs2mvs(src, dest, is_binary=False):
return rc, out, err


def copy_vsam_ps(src, dest):
def copy_vsam_ps(src, dest, tmphlq=None):
"""Copy a VSAM(KSDS) data set to a PS data set vise versa.

Parameters
Expand All @@ -348,6 +348,8 @@ def copy_vsam_ps(src, dest):
The VSAM(KSDS) or PS data set to be copied.
dest : str
The PS or VSAM(KSDS) data set.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand All @@ -367,14 +369,18 @@ def copy_vsam_ps(src, dest):
src = _validate_data_set_name(src)
dest = _validate_data_set_name(dest)
repro_cmd = REPRO.format(src, dest)

cmd = "mvscmdauth --pgm=idcams --sysprint=stdout --sysin=stdin"
if tmphlq:
cmd = "{0} -Q={1}".format(cmd, tmphlq)

rc, out, err = module.run_command(cmd, data=repro_cmd, errors='replace')
if rc:
raise USSCmdExecError(cmd, rc, out, err)
return rc, out, err


def copy_asa_uss2mvs(src, dest):
def copy_asa_uss2mvs(src, dest, tmphlq=None):
"""Copy a file from USS to an ASA sequential data set or PDS/E member.

Parameters
Expand All @@ -383,6 +389,8 @@ def copy_asa_uss2mvs(src, dest):
Path of the USS file.
dest : str
The MVS destination data set or member.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand All @@ -394,12 +402,12 @@ def copy_asa_uss2mvs(src, dest):
The stderr after the copy command executed successfully.
"""
oget_cmd = "OGET '{0}' '{1}'".format(src, dest)
rc, out, err = ikjeft01(oget_cmd, authorized=True)
rc, out, err = ikjeft01(oget_cmd, authorized=True, tmphlq=tmphlq)

return TSOCmdResponse(rc, out, err)


def copy_asa_mvs2uss(src, dest):
def copy_asa_mvs2uss(src, dest, tmphlq=None):
"""Copy an ASA sequential data set or member to USS.

Parameters
Expand All @@ -408,6 +416,8 @@ def copy_asa_mvs2uss(src, dest):
The MVS data set to be copied.
dest : str
Destination path in USS.
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand All @@ -422,12 +432,12 @@ def copy_asa_mvs2uss(src, dest):
dest = _validate_path(dest)

oput_cmd = "OPUT '{0}' '{1}'".format(src, dest)
rc, out, err = ikjeft01(oput_cmd, authorized=True)
rc, out, err = ikjeft01(oput_cmd, authorized=True, tmphlq=tmphlq)

return TSOCmdResponse(rc, out, err)


def copy_asa_pds2uss(src, dest):
def copy_asa_pds2uss(src, dest, tmphlq=None):
"""Copy all members from an ASA PDS/E to USS.

Parameters
Expand All @@ -436,6 +446,8 @@ def copy_asa_pds2uss(src, dest):
The MVS data set to be copied.
dest : str
Destination path in USS (must be a directory).
tmphlq : str
High Level Qualifier for temporary datasets.

Returns
-------
Expand Down Expand Up @@ -465,7 +477,7 @@ def copy_asa_pds2uss(src, dest):
dest_path = path.join(dest, member)

oput_cmd = "OPUT '{0}' '{1}'".format(src_member, dest_path)
rc, out, err = ikjeft01(oput_cmd, authorized=True)
rc, out, err = ikjeft01(oput_cmd, authorized=True, tmphlq=tmphlq)

if rc != 0:
return TSOCmdResponse(rc, out, err)
Expand Down
Loading