Skip to content

Commit 39f2117

Browse files
KyeMaloy97GitHub Enterprise
authored andcommitted
Merge pull request #68 from CICS/feat.CICSVersionInfo
Adds CICS version support via new module_util
2 parents bff8461 + f9a9ab7 commit 39f2117

File tree

10 files changed

+208
-5
lines changed

10 files changed

+208
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
docs/build/
33
.idea
4+
.vscode/settings.json
45
__pycache__
56
venv*
67
.venv

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ echo "/* -----------------------------------------------------------------------
3333
echo "/* Integration tests Python 3.8 */"
3434
echo "/* -------------------------------------------------------------------------- */"
3535
(set -x; ansible-test integration cics_cmci --python 3.8)
36+
(set -x; ansible-test integration cics_utilities --python 3.8)
37+
3638

3739
echo "/* -------------------------------------------------------------------------- */"
3840
echo "/* Integration tests for missing libraries Python 3.8 */"
@@ -59,6 +61,7 @@ echo "/* -----------------------------------------------------------------------
5961
echo "/* Integration tests Python 2.7 */"
6062
echo "/* -------------------------------------------------------------------------- */"
6163
(set -x; ansible-test integration cics_cmci --python 2.7)
64+
(set -x; ansible-test integration cics_utilities --python 2.7)
6265
deactivate
6366

6467
source "$CMCI_PYTHON_38/bin/activate"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# (c) Copyright IBM Corp. 2023
4+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
5+
from __future__ import (absolute_import, division, print_function)
6+
__metaclass__ = type
7+
try:
8+
import zoautil_py.datasets as Datasets
9+
import zoautil_py.exceptions as ZOAUExceptions
10+
except ImportError as imp_exc:
11+
ZOAUTIL_IMPORT_ERROR = imp_exc
12+
else:
13+
ZOAUTIL_IMPORT_ERROR = None
14+
15+
16+
def get_dataset_member_version_record(dataset): # type: (str) -> str
17+
try:
18+
records = Datasets.read("%s.SDFHSAMP(DFH0SINX)" % dataset)
19+
return records.split("STATUS = ", 1)[1].split(" ")[0]
20+
except ZOAUExceptions.ZOAUException:
21+
raise Exception("Error reading dataset for calculating CICS version.")

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# (c) Copyright IBM Corp. 2020,2021
22
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3-
requests==2.27.1
3+
requests==2.27.1;python_version<'3.7'
4+
requests==2.31.0;python_version>='3.7'
45
xmltodict==0.12.0
56
typing;python_version<"3.5"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pyz: "/python/v3r9/usr/lpp/IBM/cyp/v3r9/pyz"
2+
3+
zoau: "/tools/zoautil"
4+
5+
environment_vars:
6+
_BPXK_AUTOCVT: "ON"
7+
ZOAU_HOME: "{{ zoau }}"
8+
PYTHONPATH: "{{ zoau }}/lib"
9+
LIBPATH: "{{ zoau }}/lib:{{ pyz }}/lib:/lib:/usr/lib:."
10+
PATH: "{{ zoau }}/bin:{{ pyz }}/bin:/bin:/var/bin"
11+
_CEE_RUNOPTS: "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
12+
_TAG_REDIR_ERR: "txt"
13+
_TAG_REDIR_IN: "txt"
14+
_TAG_REDIR_OUT: "txt"
15+
LANG: "C"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# (c) Copyright IBM Corp. 2023
5+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
6+
7+
from __future__ import absolute_import, division, print_function
8+
__metaclass__ = type
9+
from ansible.module_utils.basic import AnsibleModule
10+
from ansible_collections.ibm.ibm_zos_cics.plugins.module_utils.cicsgetversion import (get_dataset_member_version_record)
11+
12+
from typing import Dict
13+
14+
HIGH_LEVEL_QUALIFIER = 'CICS_HLQ'
15+
16+
17+
class CicsVersion(object):
18+
19+
def __init__(self):
20+
self._module = AnsibleModule(
21+
argument_spec=self.init_argument_spec(),
22+
) # type AnsibleModule
23+
self.result = dict(changed=False) # type: dict
24+
25+
def init_argument_spec(self): # type: () -> Dict
26+
return {
27+
HIGH_LEVEL_QUALIFIER: {
28+
'required': True,
29+
'type': 'str'
30+
},
31+
}
32+
33+
def _fail(self, msg): # type: (str) -> None
34+
self._module.fail_json(msg=msg, **self.result)
35+
36+
def _exit(self):
37+
self._module.exit_json(**self.result)
38+
39+
def main(self):
40+
self.result['params'] = self._module.params
41+
42+
try:
43+
cics_version = get_dataset_member_version_record(self._module.params.get(HIGH_LEVEL_QUALIFIER))
44+
self.result['cics_version'] = cics_version
45+
self.result['rc'] = 0
46+
self._exit()
47+
except Exception as e:
48+
self.result['rc'] = 1
49+
self.result['exception'] = e
50+
self._fail("Error fetching version information from dataset with {0}".format(self._module.params.get(HIGH_LEVEL_QUALIFIER)))
51+
52+
53+
def main():
54+
CicsVersion().main()
55+
56+
57+
if __name__ == '__main__':
58+
main()
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# (c) Copyright IBM Corp. 2023
2+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
3+
---
4+
- name: CICS Version Integration Test
5+
hosts: "all"
6+
gather_facts: false
7+
8+
tasks:
9+
############################################################################
10+
# Get CICS version for development version
11+
############################################################################
12+
- name: Retrieve CICS version information
13+
environment: "{{ environment_vars }}"
14+
cics_version:
15+
CICS_HLQ: 'ANTZ.CICS.TS.DEV.INTEGRAT'
16+
register: result
17+
18+
- name: Assert 1
19+
ansible.builtin.assert:
20+
that:
21+
- result is not changed
22+
- result.cics_version == '7.5.0'
23+
- result.rc == 0
24+
- "'exception' not in result"
25+
26+
############################################################################
27+
# Get CICS version for 6.1
28+
############################################################################
29+
- name: Retrieve CICS version information
30+
environment: "{{ environment_vars }}"
31+
cics_version:
32+
CICS_HLQ: 'CTS610.CICS740'
33+
register: result
34+
35+
- name: Assert 2
36+
ansible.builtin.assert:
37+
that:
38+
- result is not changed
39+
- result.cics_version == '7.4.0'
40+
- result.rc == 0
41+
- "'exception' not in result"
42+
43+
############################################################################
44+
# Get CICS version for 5.6
45+
############################################################################
46+
- name: Retrieve CICS version information
47+
environment: "{{ environment_vars }}"
48+
cics_version:
49+
CICS_HLQ: 'CTS560.CICS730'
50+
register: result
51+
52+
- name: Assert 3
53+
ansible.builtin.assert:
54+
that:
55+
- result is not changed
56+
- result.cics_version == '7.3.0'
57+
- result.rc == 0
58+
- "'exception' not in result"
59+
60+
############################################################################
61+
# Get CICS version for 5.4
62+
############################################################################
63+
- name: Retrieve CICS version information
64+
environment: "{{ environment_vars }}"
65+
cics_version:
66+
CICS_HLQ: 'CTS540.CICS710'
67+
register: result
68+
69+
- name: Assert 4
70+
ansible.builtin.assert:
71+
that:
72+
- result is not changed
73+
- result.cics_version == '7.1.0'
74+
- result.rc == 0
75+
- "'exception' not in result"
76+
77+
############################################################################
78+
# Fail to get CICS version from incorrect HLQ
79+
############################################################################
80+
- name: Fail to get CICS version information from incorrect HLQ
81+
environment: "{{ environment_vars }}"
82+
cics_version:
83+
CICS_HLQ: 'ANZ.CIS.TS.EV.IEGRAT'
84+
register: result
85+
failed_when: false
86+
87+
- name: Assert 5
88+
ansible.builtin.assert:
89+
that:
90+
- result is not changed
91+
- result.rc != 0
92+
- "'exception' in result"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# (c) Copyright IBM Corp. 2023
3+
# Apache License, Version 2.0 (see https://opensource.org/licenses/Apache-2.0)
4+
set -eux # This is important to ensure that return codes from failing tests are propagated
5+
ANSIBLE_LIBRARY=./library ansible-playbook -i zos_inventory playbooks/cics_get_version.yml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source_system:
2+
hosts:
3+
zos_host:
4+
ansible_host: __ANSIBLE_TEST_HOST__
5+
ansible_user: __ANSIBLE_TEST_USER__
6+
ansible_python_interpreter: /python/v3r9/usr/lpp/IBM/cyp/v3r9/pyz/bin/python3.9
7+
ansible_ssh_common_args: "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

tests/unit/modules/test_cmci_get.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from ansible.module_utils import basic
1515

1616
import pytest
17-
import re
1817
import sys
1918

2019

@@ -90,9 +89,10 @@ def test_unknown_host(monkeypatch):
9089
with pytest.raises(AnsibleFailJson) as exc_info:
9190
cmci_get.main()
9291

93-
exp = \
94-
'Error performing CMCI request: <[^>]*>: Failed to establish a new connection: .*'
95-
assert re.match(exp, exc_info.value.args[0]['msg']), exc_info.value.args[0]['msg'] + " didn't match"
92+
if sys.version_info.major <= 2:
93+
assert exc_info.value.args[0]['msg'].__contains__('Failed to establish a new connection')
94+
else:
95+
assert exc_info.value.args[0]['msg'].__contains__('([Errno -2] Name or service not known)')
9696

9797

9898
def test_invalid_port_type(cmci_module): # type: (CMCITestHelper) -> None

0 commit comments

Comments
 (0)