diff --git a/changelogs/fragments/1633-zos_mvs_raw_tests_portability.yml b/changelogs/fragments/1633-zos_mvs_raw_tests_portability.yml new file mode 100644 index 000000000..b6ecfca69 --- /dev/null +++ b/changelogs/fragments/1633-zos_mvs_raw_tests_portability.yml @@ -0,0 +1,4 @@ +trivial: + - test_zos_mvs_raw_func.py - Remove the use of hard coded dataset + names. + (https://github.com/ansible-collections/ibm_zos_core/pull/1633). \ No newline at end of file diff --git a/changelogs/fragments/1635-backup_restore_portability.yml b/changelogs/fragments/1635-backup_restore_portability.yml new file mode 100644 index 000000000..dd5bf061a --- /dev/null +++ b/changelogs/fragments/1635-backup_restore_portability.yml @@ -0,0 +1,3 @@ +trivial: + - test_zos_backup_restore - Remove the use of hard coded hlq and files names. + (https://github.com/ansible-collections/ibm_zos_core/pull/1635). \ No newline at end of file diff --git a/changelogs/fragments/1640-quick-fix-ansible-core:2.17-verbosity-issue b/changelogs/fragments/1640-quick-fix-ansible-core:2.17-verbosity-issue new file mode 100644 index 000000000..0b8ffe9a6 --- /dev/null +++ b/changelogs/fragments/1640-quick-fix-ansible-core:2.17-verbosity-issue @@ -0,0 +1,7 @@ +bugfixes: + - zos_copy - module would fail when an internal SFTP command wrote output to + stderr. Fix sets default value of existing module option `ignore_sftp_error` to True + (https://github.com/ansible-collections/ibm_zos_core/pull/1640). + - zos_fetch - module would fail when an internal SFTP command wrote output to + stderr. Fix sets default value of existing module option `ignore_sftp_error` to True + (https://github.com/ansible-collections/ibm_zos_core/pull/1640). \ No newline at end of file diff --git a/plugins/action/zos_copy.py b/plugins/action/zos_copy.py index 62bde96bf..8561045e5 100644 --- a/plugins/action/zos_copy.py +++ b/plugins/action/zos_copy.py @@ -61,7 +61,7 @@ def run(self, tmp=None, task_vars=None): force_lock = _process_boolean(task_args.get('force_lock'), default=False) executable = _process_boolean(task_args.get('executable'), default=False) asa_text = _process_boolean(task_args.get('asa_text'), default=False) - ignore_sftp_stderr = _process_boolean(task_args.get("ignore_sftp_stderr"), default=False) + ignore_sftp_stderr = _process_boolean(task_args.get("ignore_sftp_stderr"), default=True) backup_name = task_args.get("backup_name", None) encoding = task_args.get("encoding", None) mode = task_args.get("mode", None) diff --git a/plugins/action/zos_fetch.py b/plugins/action/zos_fetch.py index 192b9ce6f..c3e4ec1ee 100644 --- a/plugins/action/zos_fetch.py +++ b/plugins/action/zos_fetch.py @@ -123,7 +123,7 @@ def run(self, tmp=None, task_vars=None): flat = _process_boolean(self._task.args.get('flat'), default=False) is_binary = _process_boolean(self._task.args.get('is_binary')) ignore_sftp_stderr = _process_boolean( - self._task.args.get("ignore_sftp_stderr"), default=False + self._task.args.get("ignore_sftp_stderr"), default=True ) validate_checksum = _process_boolean( self._task.args.get("validate_checksum"), default=True diff --git a/plugins/modules/zos_copy.py b/plugins/modules/zos_copy.py index 6da0232a2..80a9a034f 100644 --- a/plugins/modules/zos_copy.py +++ b/plugins/modules/zos_copy.py @@ -201,18 +201,19 @@ required: false ignore_sftp_stderr: description: - - During data transfer through SFTP, the module fails if the SFTP command - directs any content to stderr. The user is able to override this - behavior by setting this parameter to C(true). By doing so, the module - would essentially ignore the stderr stream produced by SFTP and continue - execution. + - During data transfer through SFTP, the SFTP command directs content to + stderr. By default, the module essentially ignores the stderr stream + produced by SFTP and continues execution. The user is able to override + this behavior by setting this parameter to C(false). By doing so, any + content written to stderr is considered an error by Ansible and will + have module fail. - When Ansible verbosity is set to greater than 3, either through the command line interface (CLI) using B(-vvvv) or through environment variables such as B(verbosity = 4), then this parameter will automatically be set to C(true). type: bool required: false - default: false + default: true version_added: "1.4.0" is_binary: description: @@ -3822,7 +3823,7 @@ def main(): backup_name=dict(type='str'), local_follow=dict(type='bool', default=True), remote_src=dict(type='bool', default=False), - ignore_sftp_stderr=dict(type='bool', default=False), + ignore_sftp_stderr=dict(type='bool', default=True), validate=dict(type='bool', default=False), volume=dict(type='str', required=False), dest_data_set=dict( diff --git a/plugins/modules/zos_fetch.py b/plugins/modules/zos_fetch.py index 574c5923c..9d22b58b6 100644 --- a/plugins/modules/zos_fetch.py +++ b/plugins/modules/zos_fetch.py @@ -122,18 +122,19 @@ type: str ignore_sftp_stderr: description: - - During data transfer through sftp, the module fails if the sftp command - directs any content to stderr. The user is able to override this - behavior by setting this parameter to C(true). By doing so, the module - would essentially ignore the stderr stream produced by sftp and continue - execution. + - During data transfer through SFTP, the SFTP command directs content to + stderr. By default, the module essentially ignores the stderr stream + produced by SFTP and continues execution. The user is able to override + this behavior by setting this parameter to C(false). By doing so, any + content written to stderr is considered an error by Ansible and will + have module fail. - When Ansible verbosity is set to greater than 3, either through the command line interface (CLI) using B(-vvvv) or through environment variables such as B(verbosity = 4), then this parameter will automatically be set to C(true). type: bool required: false - default: false + default: true notes: - When fetching PDSE and VSAM data sets, temporary storage will be used on the remote z/OS system. After the PDSE or VSAM data set is @@ -821,7 +822,7 @@ def run_module(): use_qualifier=dict(required=False, default=False, type="bool"), validate_checksum=dict(required=False, default=True, type="bool"), encoding=dict(required=False, type="dict"), - ignore_sftp_stderr=dict(type="bool", default=False, required=False), + ignore_sftp_stderr=dict(type="bool", default=True, required=False), tmp_hlq=dict(required=False, type="str", default=None), ) ) diff --git a/tests/functional/modules/test_zos_backup_restore.py b/tests/functional/modules/test_zos_backup_restore.py index c42d8c49c..41ec94241 100644 --- a/tests/functional/modules/test_zos_backup_restore.py +++ b/tests/functional/modules/test_zos_backup_restore.py @@ -15,21 +15,23 @@ __metaclass__ = type -from ibm_zos_core.tests.helpers.dataset import get_tmp_ds_name +from ibm_zos_core.tests.helpers.dataset import ( + get_tmp_ds_name, + get_random_q, +) import pytest from re import search, IGNORECASE, MULTILINE import string import random import time -DATA_SET_CONTENTS = "HELLO world" -DATA_SET_QUALIFIER = "{0}.PRIVATE.TESTDS" -DATA_SET_QUALIFIER2 = "{0}.PRIVATE.TESTDS2" -DATA_SET_BACKUP_LOCATION = "MY.BACKUP" -UNIX_BACKUP_LOCATION = "/tmp/mybackup.dzp" -NEW_HLQ = "TMPHLQ" -DATA_SET_RESTORE_LOCATION = DATA_SET_QUALIFIER.format(NEW_HLQ) -DATA_SET_RESTORE_LOCATION2 = DATA_SET_QUALIFIER2.format(NEW_HLQ) +from datetime import datetime + +DATA_SET_CONTENTS = "HELLO WORLD" + +def get_unique_uss_file_name(): + unique_str = "n" + datetime.now().strftime("%H:%M:%S").replace("-", "").replace(":", "") + ".dzp" + return "/tmp/{0}".format(unique_str) c_pgm="""#include @@ -99,10 +101,13 @@ def delete_data_set(hosts, data_set_name): def delete_file(hosts, path): hosts.all.file(path=path, state="absent") -def delete_remnants(hosts): +def delete_remnants(hosts, list=None): hosts.all.shell(cmd="drm 'ANSIBLE.*'") hosts.all.shell(cmd="drm 'TEST.*'") hosts.all.shell(cmd="drm 'TMPHLQ.*'") + if list: + for object in list: + hosts.all.shell(cmd="drm '{0}.*'".format(object)) def get_unused_volume_serial(hosts): found = False @@ -209,19 +214,23 @@ def assert_file_does_not_exist(hosts, path): @pytest.mark.parametrize( "backup_name,overwrite,recover", [ - (DATA_SET_BACKUP_LOCATION, False, False), - (DATA_SET_BACKUP_LOCATION, True, True), - (DATA_SET_BACKUP_LOCATION, False, True), - (DATA_SET_BACKUP_LOCATION, True, False), - (UNIX_BACKUP_LOCATION, False, False), - (UNIX_BACKUP_LOCATION, True, True), - (UNIX_BACKUP_LOCATION, False, True), - (UNIX_BACKUP_LOCATION, True, False), + ("DATA_SET", False, False), + ("DATA_SET", True, True), + ("DATA_SET", False, True), + ("DATA_SET", True, False), + ("UNIX", False, False), + ("UNIX", True, True), + ("UNIX", False, True), + ("UNIX", True, False), ], ) def test_backup_of_data_set(ansible_zos_module, backup_name, overwrite, recover): hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() try: if not overwrite: delete_data_set_or_file(hosts, backup_name) @@ -247,10 +256,10 @@ def test_backup_of_data_set(ansible_zos_module, backup_name, overwrite, recover) @pytest.mark.parametrize( "backup_name,overwrite", [ - (DATA_SET_BACKUP_LOCATION, False), - (DATA_SET_BACKUP_LOCATION, True), - (UNIX_BACKUP_LOCATION, False), - (UNIX_BACKUP_LOCATION, True), + ("DATA_SET", False), + ("DATA_SET", True), + ("UNIX", False), + ("UNIX", True), ], ) def test_backup_of_data_set_when_backup_dest_exists( @@ -258,6 +267,10 @@ def test_backup_of_data_set_when_backup_dest_exists( ): hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() try: create_data_set_or_file_with_contents(hosts, backup_name, DATA_SET_CONTENTS) assert_data_set_or_file_exists(hosts, backup_name) @@ -284,22 +297,28 @@ def test_backup_of_data_set_when_backup_dest_exists( @pytest.mark.parametrize( "backup_name,overwrite,recover", [ - (DATA_SET_BACKUP_LOCATION, False, False), - (DATA_SET_BACKUP_LOCATION, True, True), - (DATA_SET_BACKUP_LOCATION, False, True), - (DATA_SET_BACKUP_LOCATION, True, False), - (UNIX_BACKUP_LOCATION, False, False), - (UNIX_BACKUP_LOCATION, True, True), - (UNIX_BACKUP_LOCATION, False, True), - (UNIX_BACKUP_LOCATION, True, False), + ("DATA_SET", False, False), + ("DATA_SET", True, True), + ("DATA_SET", False, True), + ("DATA_SET", True, False), + ("UNIX", False, False), + ("UNIX", True, True), + ("UNIX", False, True), + ("UNIX", True, False), ], ) def test_backup_and_restore_of_data_set( ansible_zos_module, backup_name, overwrite, recover ): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() - new_hlq = NEW_HLQ + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, backup_name) @@ -314,7 +333,8 @@ def test_backup_and_restore_of_data_set( recover=recover, ) if not overwrite: - new_hlq = "TEST" + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) assert_module_did_not_fail(results) assert_data_set_or_file_exists(hosts, backup_name) results = hosts.all.zos_backup_restore( @@ -327,29 +347,36 @@ def test_backup_and_restore_of_data_set( finally: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, backup_name) - delete_remnants(hosts) + delete_remnants(hosts, hlqs) @pytest.mark.parametrize( "backup_name,space,space_type", [ - (DATA_SET_BACKUP_LOCATION, 10, "m"), - (DATA_SET_BACKUP_LOCATION, 10000, "k"), - (DATA_SET_BACKUP_LOCATION, 10, None), - (DATA_SET_BACKUP_LOCATION, 2, "cyl"), - (DATA_SET_BACKUP_LOCATION, 10, "trk"), - (UNIX_BACKUP_LOCATION, 10, "m"), - (UNIX_BACKUP_LOCATION, 10000, "k"), - (UNIX_BACKUP_LOCATION, 10, None), - (UNIX_BACKUP_LOCATION, 2, "cyl"), - (UNIX_BACKUP_LOCATION, 10, "trk"), + ("DATA_SET", 10, "m"), + ("DATA_SET", 10000, "k"), + ("DATA_SET", 10, None), + ("DATA_SET", 2, "cyl"), + ("DATA_SET", 10, "trk"), + ("UNIX", 10, "m"), + ("UNIX", 10000, "k"), + ("UNIX", 10, None), + ("UNIX", 2, "cyl"), + ("UNIX", 10, "trk"), ], ) def test_backup_and_restore_of_data_set_various_space_measurements( ansible_zos_module, backup_name, space, space_type ): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, backup_name) @@ -371,7 +398,7 @@ def test_backup_and_restore_of_data_set_various_space_measurements( args = dict( operation="restore", backup_name=backup_name, - hlq=NEW_HLQ, + hlq=new_hlq, overwrite=True, space=space, ) @@ -388,17 +415,24 @@ def test_backup_and_restore_of_data_set_various_space_measurements( @pytest.mark.parametrize( "backup_name,overwrite", [ - (DATA_SET_BACKUP_LOCATION, False), - (DATA_SET_BACKUP_LOCATION, True), - (UNIX_BACKUP_LOCATION, False), - (UNIX_BACKUP_LOCATION, True), + ("DATA_SET", False), + ("DATA_SET", True), + ("UNIX", False), + ("UNIX", True), ], ) def test_backup_and_restore_of_data_set_when_restore_location_exists( ansible_zos_module, backup_name, overwrite ): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, backup_name) @@ -415,13 +449,13 @@ def test_backup_and_restore_of_data_set_when_restore_location_exists( results = hosts.all.zos_backup_restore( operation="restore", backup_name=backup_name, - hlq=NEW_HLQ, + hlq=new_hlq, ) assert_module_did_not_fail(results) results = hosts.all.zos_backup_restore( operation="restore", backup_name=backup_name, - hlq=NEW_HLQ, + hlq=new_hlq, overwrite=overwrite, ) if overwrite: @@ -431,7 +465,7 @@ def test_backup_and_restore_of_data_set_when_restore_location_exists( finally: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, backup_name) - delete_remnants(hosts) + delete_remnants(hosts, hlqs) def test_backup_and_restore_of_multiple_data_sets(ansible_zos_module): @@ -439,10 +473,11 @@ def test_backup_and_restore_of_multiple_data_sets(ansible_zos_module): data_set_name = get_tmp_ds_name() data_set_name2 = get_tmp_ds_name() data_set_include = [data_set_name, data_set_name2] + data_set_backup_location = get_tmp_ds_name(1, 1) try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_backup_location) create_sequential_data_set_with_contents( hosts, data_set_name, DATA_SET_CONTENTS ) @@ -452,13 +487,13 @@ def test_backup_and_restore_of_multiple_data_sets(ansible_zos_module): results = hosts.all.zos_backup_restore( operation="backup", data_sets=dict(include=data_set_include), - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, ) assert_module_did_not_fail(results) - assert_data_set_or_file_exists(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_or_file_exists(hosts, data_set_backup_location) results = hosts.all.zos_backup_restore( operation="restore", - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, overwrite=True, recover=True, ) @@ -466,19 +501,23 @@ def test_backup_and_restore_of_multiple_data_sets(ansible_zos_module): finally: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_backup_location) delete_remnants(hosts) def test_backup_and_restore_of_multiple_data_sets_by_hlq(ansible_zos_module): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() data_set_name2 = get_tmp_ds_name() data_sets_hlq = "ANSIBLE.**" + data_set_backup_location = get_tmp_ds_name(1, 1) + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_backup_location) create_sequential_data_set_with_contents( hosts, data_set_name, DATA_SET_CONTENTS ) @@ -488,35 +527,40 @@ def test_backup_and_restore_of_multiple_data_sets_by_hlq(ansible_zos_module): results = hosts.all.zos_backup_restore( operation="backup", data_sets=dict(include=data_sets_hlq), - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, ) assert_module_did_not_fail(results) - assert_data_set_or_file_exists(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_or_file_exists(hosts, data_set_backup_location) results = hosts.all.zos_backup_restore( operation="restore", - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, overwrite=True, recover=True, - hlq=NEW_HLQ, + hlq=new_hlq, ) assert_module_did_not_fail(results) - assert_data_set_exists(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_exists(hosts, data_set_backup_location) finally: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) - delete_remnants(hosts) + delete_data_set_or_file(hosts, data_set_backup_location) + delete_remnants(hosts, hlqs) def test_backup_and_restore_exclude_from_pattern(ansible_zos_module): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() data_set_name2 = get_tmp_ds_name() + data_set_restore_location2 = get_tmp_ds_name(1, 1) + data_set_backup_location = get_tmp_ds_name(1, 1) + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) try: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_restore_location2) + delete_data_set_or_file(hosts, data_set_backup_location) create_sequential_data_set_with_contents( hosts, data_set_name, DATA_SET_CONTENTS ) @@ -526,63 +570,72 @@ def test_backup_and_restore_exclude_from_pattern(ansible_zos_module): results = hosts.all.zos_backup_restore( operation="backup", data_sets=dict(include="ANSIBLE.**", exclude=data_set_name2), - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, ) assert_module_did_not_fail(results) - assert_data_set_or_file_exists(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_or_file_exists(hosts, data_set_backup_location) results = hosts.all.zos_backup_restore( operation="restore", - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, overwrite=True, recover=True, - hlq=NEW_HLQ, + hlq=new_hlq, ) assert_module_did_not_fail(results) - assert_data_set_exists(hosts, DATA_SET_BACKUP_LOCATION) - assert_data_set_does_not_exist(hosts, DATA_SET_RESTORE_LOCATION2) + assert_data_set_exists(hosts, data_set_backup_location) + assert_data_set_does_not_exist(hosts, data_set_restore_location2) finally: delete_data_set_or_file(hosts, data_set_name) delete_data_set_or_file(hosts, data_set_name2) - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION2) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) - delete_remnants(hosts) + delete_data_set_or_file(hosts, data_set_restore_location2) + delete_data_set_or_file(hosts, data_set_backup_location) + delete_remnants(hosts, hlqs) @pytest.mark.parametrize( "backup_name", [ - DATA_SET_BACKUP_LOCATION, - DATA_SET_BACKUP_LOCATION, - UNIX_BACKUP_LOCATION, - UNIX_BACKUP_LOCATION, + "DATA_SET", + "DATA_SET", + "UNIX", + "UNIX", ], ) def test_restore_of_data_set_when_backup_does_not_exist( ansible_zos_module, backup_name ): + hlqs = [] hosts = ansible_zos_module + data_set_restore_location = get_tmp_ds_name(2, 2) + if backup_name == "DATA_SET": + backup_name = get_tmp_ds_name(1,1) + else: + backup_name = get_unique_uss_file_name() + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) try: - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION) + delete_data_set_or_file(hosts, data_set_restore_location) delete_data_set_or_file(hosts, backup_name) results = hosts.all.zos_backup_restore( operation="restore", backup_name=backup_name, - hlq=NEW_HLQ, + hlq=new_hlq, ) assert_module_failed(results) finally: - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION) + delete_data_set_or_file(hosts, data_set_restore_location) delete_data_set_or_file(hosts, backup_name) - delete_remnants(hosts) + delete_remnants(hosts, hlqs) + @pytest.mark.parametrize( "backup_name", [ - DATA_SET_BACKUP_LOCATION, - DATA_SET_BACKUP_LOCATION, - UNIX_BACKUP_LOCATION, - UNIX_BACKUP_LOCATION, + "DATA_SET", + "DATA_SET", + "UNIX", + "UNIX", ], ) def test_backup_of_data_set_when_data_set_does_not_exist( @@ -605,12 +658,14 @@ def test_backup_of_data_set_when_data_set_does_not_exist( delete_data_set_or_file(hosts, backup_name) delete_remnants(hosts) + def test_backup_of_data_set_when_volume_does_not_exist(ansible_zos_module): hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + data_set_backup_location = get_tmp_ds_name(1, 1) try: delete_data_set_or_file(hosts, data_set_name) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_backup_location) create_sequential_data_set_with_contents( hosts, data_set_name, DATA_SET_CONTENTS ) @@ -619,47 +674,52 @@ def test_backup_of_data_set_when_volume_does_not_exist(ansible_zos_module): data_sets=dict(include=data_set_name), # volume=get_unused_volume_serial(hosts), volume="@@@@", - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, ) assert_module_failed(results) - assert_data_set_does_not_exist(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_does_not_exist(hosts, data_set_backup_location) finally: delete_data_set_or_file(hosts, data_set_name) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_backup_location) delete_remnants(hosts) def test_restore_of_data_set_when_volume_does_not_exist(ansible_zos_module): + hlqs = [] hosts = ansible_zos_module data_set_name = get_tmp_ds_name() + data_set_restore_location = get_tmp_ds_name() + data_set_backup_location = get_tmp_ds_name(1, 1) + new_hlq = "N" + get_random_q(4) + hlqs.append(new_hlq) try: delete_data_set_or_file(hosts, data_set_name) - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) + delete_data_set_or_file(hosts, data_set_restore_location) + delete_data_set_or_file(hosts, data_set_backup_location) create_sequential_data_set_with_contents( hosts, data_set_name, DATA_SET_CONTENTS ) results = hosts.all.zos_backup_restore( operation="backup", data_sets=dict(include=data_set_name), - backup_name=DATA_SET_BACKUP_LOCATION, + backup_name=data_set_backup_location, ) assert_module_did_not_fail(results) - assert_data_set_or_file_exists(hosts, DATA_SET_BACKUP_LOCATION) + assert_data_set_or_file_exists(hosts, data_set_backup_location) results = hosts.all.zos_backup_restore( operation="restore", - backup_name=DATA_SET_BACKUP_LOCATION, - hlq=NEW_HLQ, + backup_name=data_set_backup_location, + hlq=new_hlq, # volume=get_unused_volume_serial(hosts), volume="@@@@", ) assert_module_failed(results) - assert_data_set_does_not_exist(hosts, DATA_SET_RESTORE_LOCATION) + assert_data_set_does_not_exist(hosts, data_set_restore_location) finally: delete_data_set_or_file(hosts, data_set_name) - delete_data_set_or_file(hosts, DATA_SET_RESTORE_LOCATION) - delete_data_set_or_file(hosts, DATA_SET_BACKUP_LOCATION) - delete_remnants(hosts) + delete_data_set_or_file(hosts, data_set_restore_location) + delete_data_set_or_file(hosts, data_set_backup_location) + delete_remnants(hosts, hlqs) # def test_backup_and_restore_of_data_set_from_volume_to_new_volume(ansible_zos_module): diff --git a/tests/functional/modules/test_zos_mvs_raw_func.py b/tests/functional/modules/test_zos_mvs_raw_func.py index a7a5667f5..00dd56e31 100644 --- a/tests/functional/modules/test_zos_mvs_raw_func.py +++ b/tests/functional/modules/test_zos_mvs_raw_func.py @@ -27,10 +27,19 @@ DEFAULT_DD = "MYDD" SYSIN_DD = "SYSIN" SYSPRINT_DD = "SYSPRINT" -IDCAMS_STDIN = f" LISTCAT ENTRIES('{EXISTING_DATA_SET.upper()}')" IDCAMS_INVALID_STDIN = " hello world #$!@%!#$!@``~~^$*%" +def get_temp_idcams_dataset(hosts): + """Returns IDCAMS args that use a newly created PDS. + """ + dataset_name = get_tmp_ds_name() + + hosts.all.shell(f"""dtouch -tPDS -l80 -rFB '{dataset_name}' """) + hosts.all.shell(f"""decho 'A record' '{dataset_name}(MEMBER)' """) + + return dataset_name, f" LISTCAT ENTRIES('{dataset_name.upper()}')" + # ---------------------------------------------------------------------------- # # Data set DD tests # # ---------------------------------------------------------------------------- # @@ -52,9 +61,12 @@ def test_failing_name_format(ansible_zos_module): def test_disposition_new(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + hosts.all.zos_data_set(name=default_data_set, state="absent") results = hosts.all.zos_mvs_raw( program_name="idcams", @@ -74,7 +86,7 @@ def test_disposition_new(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -83,7 +95,9 @@ def test_disposition_new(ansible_zos_module): assert result.get("ret_code", {}).get("code", -1) == 0 assert len(result.get("dd_names", [])) > 0 finally: - results = hosts.all.zos_data_set(name=default_data_set, state="absent") + hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -91,12 +105,15 @@ def test_disposition_new(ansible_zos_module): ["shr", "mod", "old"], ) def test_dispositions_for_existing_data_set(ansible_zos_module, disposition): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set( name=default_data_set, type="seq", state="present", replace=True ) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -114,7 +131,7 @@ def test_dispositions_for_existing_data_set(ansible_zos_module, disposition): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -123,66 +140,78 @@ def test_dispositions_for_existing_data_set(ansible_zos_module, disposition): assert result.get("ret_code", {}).get("code", -1) == 0 assert len(result.get("dd_names", [])) > 0 finally: - results = hosts.all.zos_data_set(name=default_data_set, state="absent") + hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_list_cat_for_existing_data_set_with_tmp_hlq_option(ansible_zos_module, volumes_on_systems): - hosts = ansible_zos_module - tmphlq = "TMPHLQ" - volumes = Volume_Handler(volumes_on_systems) - default_volume = volumes.get_available_vol() - default_data_set = get_tmp_ds_name()[:25] - hosts.all.zos_data_set( - name=default_data_set, type="seq", state="present", replace=True - ) - results = hosts.all.zos_mvs_raw( - program_name="idcams", - auth=True, - tmp_hlq=tmphlq, - dds=[ - { - "dd_data_set":{ - "dd_name":SYSPRINT_DD, - "data_set_name":default_data_set, - "disposition":"new", - "return_content":{ - "type":"text" + idcams_dataset = None + try: + hosts = ansible_zos_module + tmphlq = "TMPHLQ" + volumes = Volume_Handler(volumes_on_systems) + default_volume = volumes.get_available_vol() + default_data_set = get_tmp_ds_name()[:25] + hosts.all.zos_data_set( + name=default_data_set, type="seq", state="present", replace=True + ) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + + results = hosts.all.zos_mvs_raw( + program_name="idcams", + auth=True, + tmp_hlq=tmphlq, + dds=[ + { + "dd_data_set":{ + "dd_name":SYSPRINT_DD, + "data_set_name":default_data_set, + "disposition":"new", + "return_content":{ + "type":"text" + }, + "replace":True, + "backup":True, + "type":"seq", + "space_primary":5, + "space_secondary":1, + "space_type":"m", + "volumes":default_volume, + "record_format":"fb" }, - "replace":True, - "backup":True, - "type":"seq", - "space_primary":5, - "space_secondary":1, - "space_type":"m", - "volumes":default_volume, - "record_format":"fb" - }, - }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN - } - }, - ], - ) - for result in results.contacted.values(): - assert result.get("ret_code", {}).get("code", -1) == 0 - assert len(result.get("dd_names", [])) > 0 - for backup in result.get("backups"): - backup.get("backup_name")[:6] == tmphlq - results = hosts.all.zos_data_set(name=default_data_set, state="absent") - for result in results.contacted.values(): - assert result.get("changed", False) is True + }, + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd + } + }, + ], + ) + for result in results.contacted.values(): + assert result.get("ret_code", {}).get("code", -1) == 0 + assert len(result.get("dd_names", [])) > 0 + for backup in result.get("backups"): + backup.get("backup_name")[:6] == tmphlq + for result in results.contacted.values(): + assert result.get("changed", False) is True + finally: + results = hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # * new data set and append to member in one step not currently supported def test_new_disposition_for_data_set_members(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() default_data_set_with_member = default_data_set + '(MEM)' hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -202,7 +231,7 @@ def test_new_disposition_for_data_set_members(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -211,6 +240,8 @@ def test_new_disposition_for_data_set_members(ansible_zos_module): assert result.get("ret_code", {}).get("code", -1) == 8 finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -218,6 +249,7 @@ def test_new_disposition_for_data_set_members(ansible_zos_module): ["shr", "mod", "old"], ) def test_dispositions_for_existing_data_set_members(ansible_zos_module, disposition): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() @@ -225,6 +257,8 @@ def test_dispositions_for_existing_data_set_members(ansible_zos_module, disposit hosts.all.zos_data_set( name=default_data_set, type="pds", state="present", replace=True ) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -242,7 +276,7 @@ def test_dispositions_for_existing_data_set_members(ansible_zos_module, disposit { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -252,6 +286,8 @@ def test_dispositions_for_existing_data_set_members(ansible_zos_module, disposit assert len(result.get("dd_names", [])) > 0 finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -264,11 +300,14 @@ def test_normal_dispositions_data_set( changed, volumes_on_systems ): + idcams_dataset = None try: hosts = ansible_zos_module volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() default_data_set = get_tmp_ds_name() + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_data_set( name=default_data_set, type="seq", @@ -295,7 +334,7 @@ def test_normal_dispositions_data_set( { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -304,7 +343,9 @@ def test_normal_dispositions_data_set( assert result.get("ret_code", {}).get("code", -1) == 0 assert len(result.get("dd_names", [])) > 0 finally: - results = hosts.all.zos_data_set(name=default_data_set, state="absent") + hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -318,10 +359,13 @@ def test_normal_dispositions_data_set( ], ) def test_space_types(ansible_zos_module, space_type, primary, secondary, expected): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -343,7 +387,7 @@ def test_space_types(ansible_zos_module, space_type, primary, secondary, expecte { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -359,6 +403,8 @@ def test_space_types(ansible_zos_module, space_type, primary, secondary, expecte assert str(expected) in result.get("stdout", "") finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -366,12 +412,15 @@ def test_space_types(ansible_zos_module, space_type, primary, secondary, expecte ["pds", "pdse", "large", "basic", "seq"], ) def test_data_set_types_non_vsam(ansible_zos_module, data_set_type, volumes_on_systems): + idcams_dataset = None try: hosts = ansible_zos_module volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -388,7 +437,7 @@ def test_data_set_types_non_vsam(ansible_zos_module, data_set_type, volumes_on_s { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -399,6 +448,8 @@ def test_data_set_types_non_vsam(ansible_zos_module, data_set_type, volumes_on_s assert "BGYSC1103E" not in result.get("stderr", "") finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -406,12 +457,15 @@ def test_data_set_types_non_vsam(ansible_zos_module, data_set_type, volumes_on_s ["ksds", "rrds", "lds", "esds"], ) def test_data_set_types_vsam(ansible_zos_module, data_set_type, volumes_on_systems): + idcams_dataset = None try: hosts = ansible_zos_module volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -441,7 +495,7 @@ def test_data_set_types_vsam(ansible_zos_module, data_set_type, volumes_on_syste { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -450,9 +504,11 @@ def test_data_set_types_vsam(ansible_zos_module, data_set_type, volumes_on_syste # * because that means data set exists and is VSAM so we can't read it results = hosts.all.command(cmd=f"head \"//'{default_data_set}'\"") for result in results.contacted.values(): - assert "EDC5041I" or "EDC5049I" in result.get("stderr", "") + assert "EDC5041I" in result.get("stderr", "") or "EDC5049I" in result.get("stderr", "") finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -460,12 +516,15 @@ def test_data_set_types_vsam(ansible_zos_module, data_set_type, volumes_on_syste ["u", "vb", "vba", "fb", "fba"], ) def test_record_formats(ansible_zos_module, record_format, volumes_on_systems): + idcams_dataset = None try: hosts = ansible_zos_module volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -482,7 +541,7 @@ def test_record_formats(ansible_zos_module, record_format, volumes_on_systems): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -494,6 +553,8 @@ def test_record_formats(ansible_zos_module, record_format, volumes_on_systems): assert str(f" {record_format.upper()} ") in result.get("stdout", "") finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -507,11 +568,13 @@ def test_record_formats(ansible_zos_module, record_format, volumes_on_systems): ], ) def test_return_content_type(ansible_zos_module, return_content_type, expected, volumes_on_systems): + idcams_dataset = None try: hosts = ansible_zos_module volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() default_data_set = get_tmp_ds_name() + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) results = hosts.all.zos_data_set( name=default_data_set, type="seq", @@ -519,6 +582,7 @@ def test_return_content_type(ansible_zos_module, return_content_type, expected, replace=True, volumes=[volume_1], ) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -537,7 +601,7 @@ def test_return_content_type(ansible_zos_module, return_content_type, expected, { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -549,6 +613,8 @@ def test_return_content_type(ansible_zos_module, return_content_type, expected, assert expected in "\n".join(result.get("dd_names")[0].get("content", [])) finally: hosts.all.zos_data_set(name=default_data_set, state="absent", volumes=[volume_1]) + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -565,11 +631,13 @@ def test_return_content_type(ansible_zos_module, return_content_type, expected, def test_return_text_content_encodings( ansible_zos_module, src_encoding, response_encoding, expected, volumes_on_systems ): + idcams_dataset = None try: volumes = Volume_Handler(volumes_on_systems) volume_1 = volumes.get_available_vol() hosts = ansible_zos_module default_data_set = get_tmp_ds_name() + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) results = hosts.all.zos_data_set( name=default_data_set, type="seq", @@ -597,7 +665,7 @@ def test_return_text_content_encodings( { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -608,15 +676,20 @@ def test_return_text_content_encodings( assert expected in "\n".join(result.get("dd_names")[0].get("content", [])) finally: hosts.all.zos_data_set(name=default_data_set, state="absent", volumes=[volume_1]) + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_reuse_existing_data_set(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set( name=default_data_set, type="seq", state="present", replace=True ) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="IDCAMS", auth=True, @@ -636,7 +709,7 @@ def test_reuse_existing_data_set(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -647,15 +720,20 @@ def test_reuse_existing_data_set(ansible_zos_module): assert len(result.get("dd_names", [])) > 0 finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_replace_existing_data_set(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set( name=default_data_set, type="seq", state="present", replace=True ) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="IDCAMS", auth=True, @@ -675,7 +753,7 @@ def test_replace_existing_data_set(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -686,13 +764,18 @@ def test_replace_existing_data_set(ansible_zos_module): assert len(result.get("dd_names", [])) > 0 finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_replace_existing_data_set_make_backup(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + hosts.all.zos_mvs_raw( program_name="IDCAMS", auth=True, @@ -712,7 +795,7 @@ def test_replace_existing_data_set_make_backup(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -737,7 +820,7 @@ def test_replace_existing_data_set_make_backup(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -748,7 +831,7 @@ def test_replace_existing_data_set_make_backup(ansible_zos_module): assert len(result.get("backups", [])) > 0 assert result.get("backups")[0].get("backup_name") is not None results2 = hosts.all.command( - cmd="head \"//'{0}'\"".format(result.get("backups")[0].get("backup_name")) + cmd=f"head \"//'{result.get('backups')[0].get('backup_name')}'\""#.format() ) hosts.all.zos_data_set( name=result.get("backups")[0].get("backup_name"), state="absent" @@ -761,15 +844,20 @@ def test_replace_existing_data_set_make_backup(ansible_zos_module): assert "IDCAMS" in result.get("stdout", "") finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_data_set_name_gdgs(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name(3, 3) hosts.all.shell(cmd="dtouch -tGDG -L4 {0}".format(default_data_set)) hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(default_data_set)) hosts.all.shell(cmd="""dtouch -tseq "{0}(+1)" """.format(default_data_set)) + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -781,7 +869,7 @@ def test_data_set_name_gdgs(ansible_zos_module): return_content=dict(type="text"), ), ), - dict(dd_input=dict(dd_name=SYSIN_DD, content=IDCAMS_STDIN)), + dict(dd_input=dict(dd_name=SYSIN_DD, content=idcams_listcat_dataset_cmd)), ], ) for result in results.contacted.values(): @@ -799,7 +887,7 @@ def test_data_set_name_gdgs(ansible_zos_module): return_content=dict(type="text"), ), ), - dict(dd_input=dict(dd_name=SYSIN_DD, content=IDCAMS_STDIN)), + dict(dd_input=dict(dd_name=SYSIN_DD, content=idcams_listcat_dataset_cmd)), ], ) for result in results.contacted.values(): @@ -818,7 +906,7 @@ def test_data_set_name_gdgs(ansible_zos_module): return_content=dict(type="text"), ), ), - dict(dd_input=dict(dd_name=SYSIN_DD, content=IDCAMS_STDIN)), + dict(dd_input=dict(dd_name=SYSIN_DD, content=idcams_listcat_dataset_cmd)), ], ) for result in results.contacted.values(): @@ -837,20 +925,25 @@ def test_data_set_name_gdgs(ansible_zos_module): return_content=dict(type="text"), ), ), - dict(dd_input=dict(dd_name=SYSIN_DD, content=IDCAMS_STDIN)), + dict(dd_input=dict(dd_name=SYSIN_DD, content=idcams_listcat_dataset_cmd)), ], ) for result in results.contacted.values(): assert result.get("ret_code", {}).get("code", -1) == 8 finally: hosts.all.shell(cmd="""drm "ANSIBLE.*" """) + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_data_set_name_special_characters(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name(5, 6, symbols=True) hosts.all.zos_data_set(name=default_data_set, type="seq", state="present") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -862,7 +955,7 @@ def test_data_set_name_special_characters(ansible_zos_module): return_content=dict(type="text"), ), ), - dict(dd_input=dict(dd_name=SYSIN_DD, content=IDCAMS_STDIN)), + dict(dd_input=dict(dd_name=SYSIN_DD, content=idcams_listcat_dataset_cmd)), ], ) for result in results.contacted.values(): @@ -870,6 +963,9 @@ def test_data_set_name_special_characters(ansible_zos_module): assert len(result.get("dd_names", [])) > 0 finally: hosts.all.shell(cmd="""drm "ANSIBLE.*" """) + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") + # ---------------------------------------------------------------------------- # # Input DD Tests # # ---------------------------------------------------------------------------- # @@ -950,13 +1046,17 @@ def test_input_large(ansible_zos_module): def test_input_provided_as_list(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + contents = [] for i in range(10): - contents.append(IDCAMS_STDIN) + contents.append(idcams_listcat_dataset_cmd) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -986,6 +1086,8 @@ def test_input_provided_as_list(ansible_zos_module): assert len(result.get("dd_names", [{}])[0].get("content")) > 100 finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -999,10 +1101,13 @@ def test_input_provided_as_list(ansible_zos_module): ], ) def test_input_return_content_types(ansible_zos_module, return_content_type, expected): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1018,7 +1123,7 @@ def test_input_return_content_types(ansible_zos_module, return_content_type, exp { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, "return_content":{ "type":return_content_type }, @@ -1032,6 +1137,8 @@ def test_input_return_content_types(ansible_zos_module, return_content_type, exp assert expected in "\n".join(result.get("dd_names", [{}])[0].get("content")) finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1040,7 +1147,7 @@ def test_input_return_content_types(ansible_zos_module, return_content_type, exp ( "iso8859-1", "ibm-1047", - "|\udceeqBFfeF|g\udcefF\udcfdqgB\udcd4\udcd0CBg\udcfdҿ\udcfdqGeFgҿ\udcfd", + "|\udceeqBFfeF|g\udcefF\udcfdqgB\udcd4\udcd0", ), ( "ibm-1047", @@ -1052,10 +1159,13 @@ def test_input_return_content_types(ansible_zos_module, return_content_type, exp def test_input_return_text_content_encodings( ansible_zos_module, src_encoding, response_encoding, expected ): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1071,7 +1181,7 @@ def test_input_return_text_content_encodings( { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, "return_content":{ "type":"text", "src_encoding":src_encoding, @@ -1087,6 +1197,8 @@ def test_input_return_text_content_encodings( assert expected in "\n".join(result.get("dd_names", [{}])[0].get("content")) finally: hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -1095,35 +1207,44 @@ def test_input_return_text_content_encodings( def test_failing_path_name(ansible_zos_module): - hosts = ansible_zos_module - results = hosts.all.zos_mvs_raw( - program_name="idcams", - auth=True, - dds=[ - { - "dd_unix":{ - "dd_name":SYSPRINT_DD, - "path":"1dfa3f4rafwer/f2rfsd", + idcams_dataset = None + try: + hosts = ansible_zos_module + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( + program_name="idcams", + auth=True, + dds=[ + { + "dd_unix":{ + "dd_name":SYSPRINT_DD, + "path":"1dfa3f4rafwer/f2rfsd", + }, }, - }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, - } - }, - ], - ) - for result in results.contacted.values(): - assert result.get("ret_code", {}).get("code", -1) == 8 - assert "ValueError" in result.get("msg", "") + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd, + } + }, + ], + ) + for result in results.contacted.values(): + assert result.get("ret_code", {}).get("code", -1) == 8 + assert "ValueError" in result.get("msg", "") + finally: + if idcams_dataset: + results = hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_create_new_file(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1137,7 +1258,7 @@ def test_create_new_file(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1149,13 +1270,18 @@ def test_create_new_file(ansible_zos_module): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_write_to_existing_file(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="present") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1169,7 +1295,7 @@ def test_write_to_existing_file(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1181,16 +1307,21 @@ def test_write_to_existing_file(ansible_zos_module): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( "normal_disposition,expected", [("keep", True), ("delete", False)] ) def test_file_normal_disposition(ansible_zos_module, normal_disposition, expected): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="present") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1205,7 +1336,7 @@ def test_file_normal_disposition(ansible_zos_module, normal_disposition, expecte { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1217,13 +1348,18 @@ def test_file_normal_disposition(ansible_zos_module, normal_disposition, expecte assert result.get("stat", {}).get("exists", not expected) is expected finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize("mode,expected", [(644, "0644"), (755, "0755")]) def test_file_modes(ansible_zos_module, mode, expected): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1238,7 +1374,7 @@ def test_file_modes(ansible_zos_module, mode, expected): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1250,6 +1386,8 @@ def test_file_modes(ansible_zos_module, mode, expected): assert result.get("stat", {}).get("mode", "") == expected finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1261,9 +1399,12 @@ def test_file_modes(ansible_zos_module, mode, expected): ], ) def test_file_path_options(ansible_zos_module, access_group, status_group): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1279,7 +1420,7 @@ def test_file_path_options(ansible_zos_module, access_group, status_group): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1291,6 +1432,8 @@ def test_file_path_options(ansible_zos_module, access_group, status_group): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1298,10 +1441,13 @@ def test_file_path_options(ansible_zos_module, access_group, status_group): [10, 20, 50, 80, 120], ) def test_file_block_size(ansible_zos_module, block_size): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1316,7 +1462,7 @@ def test_file_block_size(ansible_zos_module, block_size): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1328,6 +1474,8 @@ def test_file_block_size(ansible_zos_module, block_size): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1335,10 +1483,13 @@ def test_file_block_size(ansible_zos_module, block_size): [10, 20, 50, 80, 120], ) def test_file_record_length(ansible_zos_module, record_length): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1353,7 +1504,7 @@ def test_file_record_length(ansible_zos_module, record_length): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1365,6 +1516,8 @@ def test_file_record_length(ansible_zos_module, record_length): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1372,10 +1525,13 @@ def test_file_record_length(ansible_zos_module, record_length): ["u", "vb", "vba", "fb", "fba"], ) def test_file_record_format(ansible_zos_module, record_format): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1390,7 +1546,7 @@ def test_file_record_format(ansible_zos_module, record_format): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1402,6 +1558,8 @@ def test_file_record_format(ansible_zos_module, record_format): assert "IDCAMS SYSTEM" in result.get("stdout", "") finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1415,10 +1573,13 @@ def test_file_record_format(ansible_zos_module, record_format): ], ) def test_file_return_content(ansible_zos_module, return_content_type, expected): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1435,7 +1596,7 @@ def test_file_return_content(ansible_zos_module, return_content_type, expected): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1446,6 +1607,8 @@ def test_file_return_content(ansible_zos_module, return_content_type, expected): assert expected in "\n".join(result.get("dd_names")[0].get("content", [])) finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1462,10 +1625,13 @@ def test_file_return_content(ansible_zos_module, return_content_type, expected): def test_file_return_text_content_encodings( ansible_zos_module, src_encoding, response_encoding, expected ): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1484,7 +1650,7 @@ def test_file_return_text_content_encodings( { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1495,6 +1661,8 @@ def test_file_return_text_content_encodings( assert expected in "\n".join(result.get("dd_names")[0].get("content", [])) finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -1503,10 +1671,13 @@ def test_file_return_text_content_encodings( def test_dummy(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1519,7 +1690,7 @@ def test_dummy(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1529,6 +1700,8 @@ def test_dummy(ansible_zos_module): assert len(result.get("dd_names", [])) == 0 finally: hosts.all.file(path=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -1537,12 +1710,15 @@ def test_dummy(ansible_zos_module): def test_concatenation_with_data_set_dd_and_response(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() default_data_set_2 = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1574,7 +1750,7 @@ def test_concatenation_with_data_set_dd_and_response(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1587,15 +1763,20 @@ def test_concatenation_with_data_set_dd_and_response(ansible_zos_module): finally: hosts.all.zos_data_set(name=default_data_set, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_concatenation_with_data_set_dd_with_replace_and_backup(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() default_data_set_2 = get_tmp_ds_name() hosts.all.zos_data_set(name=default_data_set, state="present", type="seq") hosts.all.zos_data_set(name=default_data_set_2, state="present", type="seq") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1631,7 +1812,7 @@ def test_concatenation_with_data_set_dd_with_replace_and_backup(ansible_zos_modu { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1658,9 +1839,12 @@ def test_concatenation_with_data_set_dd_with_replace_and_backup(ansible_zos_modu finally: hosts.all.zos_data_set(name=default_data_set, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_concatenation_with_data_set_member(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set = get_tmp_ds_name() @@ -1668,6 +1852,8 @@ def test_concatenation_with_data_set_member(ansible_zos_module): default_data_set_with_member = default_data_set + '(MEM)' hosts.all.zos_data_set(name=default_data_set, state="present", type="pds") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1697,7 +1883,7 @@ def test_concatenation_with_data_set_member(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1715,15 +1901,20 @@ def test_concatenation_with_data_set_member(ansible_zos_module): finally: hosts.all.zos_data_set(name=default_data_set, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_concatenation_with_unix_dd_and_response_datasets(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module default_data_set_2 = get_tmp_ds_name() hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1753,7 +1944,7 @@ def test_concatenation_with_unix_dd_and_response_datasets(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1766,13 +1957,18 @@ def test_concatenation_with_unix_dd_and_response_datasets(ansible_zos_module): finally: hosts.all.file(name=DEFAULT_PATH, state="absent") hosts.all.zos_data_set(name=default_data_set_2, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_concatenation_with_unix_dd_and_response_uss(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( program_name="idcams", auth=True, @@ -1803,7 +1999,7 @@ def test_concatenation_with_unix_dd_and_response_uss(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, + "content":idcams_listcat_dataset_cmd, } }, ], @@ -1815,41 +2011,49 @@ def test_concatenation_with_unix_dd_and_response_uss(ansible_zos_module): assert "Hello world!" in "\n".join(result.get("dd_names")[1].get("content", [])) finally: hosts.all.file(name=DEFAULT_PATH, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") def test_concatenation_fail_with_unsupported_dd_type(ansible_zos_module): - hosts = ansible_zos_module - results = hosts.all.zos_mvs_raw( - program_name="idcams", - auth=True, - dds=[ - { - "dd_concat":{ - "dd_name":SYSPRINT_DD, - "dds":[ - { - "dd_dummy":{ - "path":DEFAULT_PATH_WITH_FILE, - "return_content":{ - "type":"text" + idcams_dataset = None + try: + hosts = ansible_zos_module + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( + program_name="idcams", + auth=True, + dds=[ + { + "dd_concat":{ + "dd_name":SYSPRINT_DD, + "dds":[ + { + "dd_dummy":{ + "path":DEFAULT_PATH_WITH_FILE, + "return_content":{ + "type":"text" + }, }, + "dd_concat":{}, }, - "dd_concat":{}, - }, - ], + ], + }, }, - }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, - } - }, - ], - ) - for result in results.contacted.values(): - assert result.get("ret_code", {}).get("code", -1) == -1 - assert "Unsupported parameters" in result.get("msg", "") + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd, + } + }, + ], + ) + for result in results.contacted.values(): + assert result.get("ret_code", {}).get("code", -1) == -1 + assert "Unsupported parameters" in result.get("msg", "") + finally: + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") @pytest.mark.parametrize( @@ -1889,12 +2093,6 @@ def test_concatenation_fail_with_unsupported_dd_type(ansible_zos_module): ], }, }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, - } - }, ], 2, "Hello world!", @@ -1933,12 +2131,6 @@ def test_concatenation_fail_with_unsupported_dd_type(ansible_zos_module): ], }, }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, - } - }, ], 2, "Hello world!", @@ -1977,12 +2169,6 @@ def test_concatenation_fail_with_unsupported_dd_type(ansible_zos_module): ], }, }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN, - } - }, ], 0, "IDCAMS", @@ -1990,12 +2176,26 @@ def test_concatenation_fail_with_unsupported_dd_type(ansible_zos_module): ], ) def test_concatenation_all_dd_types(ansible_zos_module, dds, input_pos, input_content): + idcams_dataset = None try: hosts = ansible_zos_module + default_data_set = "ANSIBLE.USER.PRIVATE.TEST" hosts.all.zos_data_set(name=default_data_set, state="present", type="seq") + hosts.all.file(path=DEFAULT_PATH, state="directory") hosts.all.file(path=DEFAULT_PATH_WITH_FILE, state="absent") + + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + dds.append( + { + 'dd_input': { + "dd_name": SYSIN_DD, + "content": idcams_listcat_dataset_cmd + } + } + ) + results = hosts.all.zos_mvs_raw(program_name="idcams", auth=True, dds=dds) for result in results.contacted.values(): assert result.get("ret_code", {}).get("code", -1) == 0 @@ -2007,6 +2207,8 @@ def test_concatenation_all_dd_types(ansible_zos_module, dds, input_pos, input_co finally: hosts.all.file(name=DEFAULT_PATH, state="absent") hosts.all.zos_data_set(name=default_data_set, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -2121,29 +2323,35 @@ def test_with_parms(ansible_zos_module): def test_with_multiple_of_same_dd_name(ansible_zos_module): - hosts = ansible_zos_module - results = hosts.all.zos_mvs_raw( - pgm="idcams", - auth=True, - dds=[ - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN - } - }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN - } - }, - ], - ) - for result in results.contacted.values(): - assert result.get("ret_code", {}).get("code", -1) == 8 - assert len(result.get("dd_names", [])) == 0 - assert "BGYSC0228E" in result.get("msg", "") + idcams_dataset = None + try: + hosts = ansible_zos_module + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + results = hosts.all.zos_mvs_raw( + pgm="idcams", + auth=True, + dds=[ + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd + } + }, + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd + } + }, + ], + ) + for result in results.contacted.values(): + assert result.get("ret_code", {}).get("code", -1) == 8 + assert len(result.get("dd_names", [])) == 0 + assert "BGYSC0228E" in result.get("msg", "") + finally: + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -2152,27 +2360,34 @@ def test_with_multiple_of_same_dd_name(ansible_zos_module): def test_vio_as_output(ansible_zos_module): - hosts = ansible_zos_module - results = hosts.all.zos_mvs_raw( - program_name="idcams", - auth=True, - dds=[ - { - "dd_vio":{ - "dd_name":SYSPRINT_DD, + idcams_dataset = None + try: + hosts = ansible_zos_module + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) + + results = hosts.all.zos_mvs_raw( + program_name="idcams", + auth=True, + dds=[ + { + "dd_vio":{ + "dd_name":SYSPRINT_DD, + }, }, - }, - { - "dd_input":{ - "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN - } - }, - ], - ) - for result in results.contacted.values(): - assert result.get("ret_code", {}).get("code", 0) == 0 - assert len(result.get("dd_names", [])) == 0 + { + "dd_input":{ + "dd_name":SYSIN_DD, + "content":idcams_listcat_dataset_cmd + } + }, + ], + ) + for result in results.contacted.values(): + assert result.get("ret_code", {}).get("code", 0) == 0 + assert len(result.get("dd_names", [])) == 0 + finally: + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent") # ---------------------------------------------------------------------------- # @@ -2181,9 +2396,11 @@ def test_vio_as_output(ansible_zos_module): def test_output_dd(ansible_zos_module): + idcams_dataset = None try: hosts = ansible_zos_module data_set_name = None + idcams_dataset, idcams_listcat_dataset_cmd = get_temp_idcams_dataset(hosts) results = hosts.all.zos_mvs_raw( program_name="idcams", @@ -2200,7 +2417,7 @@ def test_output_dd(ansible_zos_module): { "dd_input":{ "dd_name":SYSIN_DD, - "content":IDCAMS_STDIN + "content":idcams_listcat_dataset_cmd } }, ], @@ -2215,3 +2432,5 @@ def test_output_dd(ansible_zos_module): finally: if data_set_name: hosts.all.zos_data_set(name=data_set_name, state="absent") + if idcams_dataset: + hosts.all.zos_data_set(name=idcams_dataset, state="absent")