Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
198 changes: 198 additions & 0 deletions tests/functional/modules/test_zos_data_set_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# -*- coding: utf-8 -*-

# Copyright (c) IBM Corporation 2019, 2020
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)

from __future__ import absolute_import, division

import os
import sys
import warnings

import ansible.constants
import ansible.errors
import ansible.utils
import pytest
from pprint import pprint
__metaclass__ = type

# TODO: determine if data set names need to be more generic for testcases
# TODO: add additional tests to check additional data set creation parameter combinations


data_set_types = [
('pds'),
('seq'),
('pdse'),
('esds'),
('rrds'),
('lds'),
(None),
]

@pytest.mark.parametrize("dstype", data_set_types)
def data_set_typesset_creation_when_present_no_replace(ansible_zos_module, dstype):
hosts = ansible_zos_module
hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype, replace=True)
results = hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype)
pprint(vars(results))
for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == False
assert result.get('module_stderr') == None

@pytest.mark.parametrize("dstype", data_set_types)
def test_data_set_creation_when_present_replace(ansible_zos_module, dstype):
hosts = ansible_zos_module
hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype, replace=True)
results = hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype, replace=True)
for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == True
assert result.get('module_stderr') == None

@pytest.mark.parametrize("dstype", data_set_types)
def test_data_set_creation_when_absent(ansible_zos_module, dstype):
hosts = ansible_zos_module
hosts.all.zos_data_set(name='imstestl.ims1.test05', state='absent')
results = hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype)
for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == True
assert result.get('module_stderr') == None

@pytest.mark.parametrize("dstype", data_set_types)
def test_data_set_deletion_when_present(ansible_zos_module, dstype):
hosts = ansible_zos_module
hosts.all.zos_data_set(name='imstestl.ims1.test05', state='present', type=dstype)
results = hosts.all.zos_data_set(name='imstestl.ims1.test05', state='absent')
for result in results.contacted.values():
assert result.get('original_message').get('state') == 'absent'
assert result.get('changed') == True
assert result.get('module_stderr') == None

def test_data_set_deletion_when_absent(ansible_zos_module):
hosts = ansible_zos_module
hosts.all.zos_data_set(name='imstestl.ims1.test05', state='absent')
results = hosts.all.zos_data_set(name='imstestl.ims1.test05', state='absent')
for result in results.contacted.values():
assert result.get('original_message').get('state') == 'absent'
assert result.get('changed') == False
assert result.get('module_stderr') == None

def test_batch_data_set_creation_and_deletion(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_data_set(batch=[
{
'name': 'imstestl.ims1.test05',
'state': 'absent'
},
{
'name': 'imstestl.ims1.test05',
'type': 'pds',
'state': 'present'
},
{
'name': 'imstestl.ims1.test05',
'state': 'absent'
},
])
for result in results.contacted.values():
assert result.get('changed') == True
assert result.get('module_stderr') == None

def test_batch_data_set_and_member_creation(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_data_set(batch=[
{
'name': 'imstestl.ims1.test05',
'type': 'pds',
},
{
'name': 'imstestl.ims1.test05(newmem1)',
'type': 'member',
},
{
'name': 'imstestl.ims1.test05(newmem2)',
'type': 'member',
'state': 'present'
},
{
'name': 'imstestl.ims1.test05',
'state': 'absent'
},
])
for result in results.contacted.values():
assert result.get('changed') == True
assert result.get('module_stderr') == None

def test_repeated_operations(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4',
type='PDS',
size='5CYL',
record_length=15,
replace=True
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == True
assert result.get('module_stderr') == None

results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4',
type='PDS',
# size='15TRK',
# record_length=30,
replace=True
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == True
assert result.get('module_stderr') == None

results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4(testme)',
type='MEMBER',
replace=True
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == True
assert result.get('module_stderr') == None

results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4(testme)',
type='MEMBER'
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'present'
assert result.get('changed') == False
assert result.get('module_stderr') == None

results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4(testme)',
type='MEMBER',
state='absent'
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'absent'
assert result.get('changed') == True
assert result.get('module_stderr') == None

results = hosts.all.zos_data_set(
name='USER.PRIVATE.TEST4(testme)',
type='MEMBER',
state='absent'
)

for result in results.contacted.values():
assert result.get('original_message').get('state') == 'absent'
assert result.get('changed') == False
assert result.get('module_stderr') == None
71 changes: 71 additions & 0 deletions tests/functional/modules/test_zos_job_output_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-

# Copyright (c) IBM Corporation 2019, 2020
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)

from __future__ import absolute_import, division
from shellescape import quote
import tempfile

__metaclass__ = type

JCL_FILE_CONTENTS="""//HELLO JOB (T043JM,JM00,1,0,0,0),'HELLO WORLD - JRM',CLASS=R,
// MSGCLASS=X,MSGLEVEL=1,NOTIFY=S0JM
//STEP0001 EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD *
HELLO, WORLD
/*
//SYSUT2 DD SYSOUT=*
//
"""

TEMP_PATH= '/tmp/ansible/jcl'

def test_zos_job_output_no_job_id(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_job_output(job_id='NO_JOBID')
for result in results.contacted.values():
print(result)
assert result.get('changed') is False
assert result.get('zos_job_output') is not None


def test_zos_job_output_no_job_name(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_job_output(job_name='NO_JOBNAME')
for result in results.contacted.values():
print(result)
assert result.get('changed') is False
assert result.get('zos_job_output') is not None


def test_zos_job_output_no_owner(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_job_output(owner='NO_OWNER')
for result in results.contacted.values():
print(result)
assert result.get('changed') is False
assert result.get('zos_job_output') is not None


def test_zos_job_output_reject(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_job_output()
for result in results.contacted.values():
print(result)
assert result.get('changed') is False
assert result.get('msg') is not None


def test_zos_job_output_job_exists(ansible_zos_module):
hosts = ansible_zos_module
hosts.all.file(path=TEMP_PATH, state='directory')
hosts.all.shell(cmd='echo {} > {}/SAMPLE'.format(quote(JCL_FILE_CONTENTS), TEMP_PATH))
hosts.all.zos_job_submit(src='{}/SAMPLE'.format(TEMP_PATH), location="USS", wait=True, volume=None)
hosts.all.file(path=TEMP_PATH, state='absent')
results = hosts.all.zos_job_output(job_name='SAMPLE')
for result in results.contacted.values():
assert result.get('changed') is False
assert result.get('zos_job_output') is not None
27 changes: 27 additions & 0 deletions tests/functional/modules/test_zos_job_query_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-

# Copyright (c) IBM Corporation 2019, 2020
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)

from __future__ import absolute_import, division

import os
import sys
import warnings

import ansible.constants
import ansible.errors
import ansible.utils
import pytest
from pprint import pprint

__metaclass__ = type


def test_zos_job_query_func(ansible_zos_module):
hosts = ansible_zos_module
results = hosts.all.zos_job_query(job_name='*',owner='*')
pprint(vars(results))
for result in results.contacted.values():
assert result.get('changed') == False
assert result.get('jobs') != None
91 changes: 91 additions & 0 deletions tests/functional/modules/test_zos_job_submit_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-

# Copyright (c) IBM Corporation 2019, 2020
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)

from __future__ import absolute_import, division

import os
import sys
import warnings

import ansible.constants
import ansible.errors
import ansible.utils
import pytest
from shellescape import quote
import tempfile

__metaclass__ = type


JCL_FILE_CONTENTS="""//HELLO JOB (T043JM,JM00,1,0,0,0),'HELLO WORLD - JRM',CLASS=R,
// MSGCLASS=X,MSGLEVEL=1,NOTIFY=S0JM
//STEP0001 EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD *
HELLO, WORLD
/*
//SYSUT2 DD SYSOUT=*
//
"""

TEMP_PATH= '/tmp/ansible/jcl'
DATA_SET_NAME = 'imstestl.ims1.test05'

def test_job_submit_PDS(ansible_zos_module):
hosts = ansible_zos_module
hosts.all.file(path=TEMP_PATH, state='directory')
hosts.all.shell(cmd='echo {} > {}/SAMPLE'.format(quote(JCL_FILE_CONTENTS), TEMP_PATH))
hosts.all.zos_data_set(name=DATA_SET_NAME, state='present', type='pds', replace=True)
hosts.all.shell(cmd='cp {}/SAMPLE "//\'{}(SAMPLE)\'"'.format(TEMP_PATH, DATA_SET_NAME))
results = hosts.all.zos_job_submit(src='{}(SAMPLE)'.format(DATA_SET_NAME), location="DATA_SET", wait=True)
hosts.all.file(path=TEMP_PATH, state='absent')
for result in results.contacted.values():
assert result.get('jobs')[0].get('ret_code').get('msg_code') == '0000'
assert result.get('jobs')[0].get('ret_code').get('code') == 0
assert result.get('changed') == True

def test_job_submit_USS(ansible_zos_module):
hosts = ansible_zos_module
hosts.all.file(path=TEMP_PATH, state='directory')
hosts.all.shell(cmd='echo {} > {}/SAMPLE'.format(quote(JCL_FILE_CONTENTS), TEMP_PATH))
results = hosts.all.zos_job_submit(src='{}/SAMPLE'.format(TEMP_PATH), location="USS", wait=True, volume=None)
hosts.all.file(path=TEMP_PATH, state='absent')
for result in results.contacted.values():
assert result.get('jobs')[0].get('ret_code').get('msg_code') == '0000'
assert result.get('jobs')[0].get('ret_code').get('code') == 0
assert result.get('changed') == True

def test_job_submit_LOCAL(ansible_zos_module):
tmp_file = tempfile.NamedTemporaryFile(delete=False)
with open(tmp_file.name, 'w') as f:
f.write(JCL_FILE_CONTENTS)
hosts = ansible_zos_module
results = hosts.all.zos_job_submit(src=tmp_file.name, location="LOCAL", wait=True, volume='')

for result in results.contacted.values():
print(result)
assert result.get('jobs')[0].get('ret_code').get('msg_code') == '0000'
assert result.get('jobs')[0].get('ret_code').get('code') == 0

assert result.get('changed') == True

# * currently don't have volume support from ZOAU python API, so this will not be reproduceable
# * in CI/CD testing environment (for now)
# def test_job_submit_PDS_volume(ansible_zos_module):
# hosts = ansible_zos_module
# results = hosts.all.zos_job_submit(src='BJMAXY.UNCATLOG.JCL(SAMPLE)', location="DATA_SET", wait=False, volume='P2SS01')
# for result in results.contacted.values():
# assert result.get('jobs')[0].get('ret_code').get('code') == '0000'
# assert result.get('changed') == True


# * short run in some other environments would fail, so "normal" run currently has wait=True specified
# def test_job_submit_PDS_long(ansible_zos_module):
# hosts = ansible_zos_module
# results = hosts.all.zos_job_submit(src='BJMAXY.HILL3(LONGRUN)', location="DATA_SET", wait=True, volume=None)
# for result in results.contacted.values():
# assert result.get('jobs')[0].get('ret_code').get('code')== '0000'
# assert result.get('changed') == True
Binary file removed tests/units/modules/.DS_Store
Binary file not shown.
Empty file removed tests/units/modules/.keep
Empty file.
Binary file removed tests/units/modules/data_sets/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# TODO: add back in testcases for currently removed safe and unsafe data set write functionality

# Used my some mock modules, should match import directly below
IMPORT_NAME = 'ansible_collections_ibm_zos_core.plugins.modules.zos_data_set'
IMPORT_NAME = 'ibm_zos_core.plugins.modules.zos_data_set'


# * Tests for create_data_set()
Expand Down
Loading