Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] zoau_version_checker not working correctly for ZOAU v1.2.3 #783

Closed
2 tasks done
ketankelkar opened this issue May 31, 2023 · 0 comments · Fixed by #796, #797 or #800
Closed
2 tasks done

[Bug] zoau_version_checker not working correctly for ZOAU v1.2.3 #783

ketankelkar opened this issue May 31, 2023 · 0 comments · Fixed by #796, #797 or #800
Assignees
Labels
Bug Something isn't working as designed.

Comments

@ketankelkar
Copy link
Collaborator

Is there an existing issue for this?

  • There are no existing issues.

Are the dependencies a supported version?

  • The dependencies are supported.

IBM Z Open Automation Utilities

v1.2.3

IBM Enterprise Python

v3.11.x

IBM z/OS Ansible core Version

v1.5.0

ansible-version

latest

z/OS version

v2.4

Ansible module

zos_gather_facts

Bug description

zos_gather_facts does not get past the zoau version checker if the target host is on ZOAU v1.2.3 because of changes which were made to the output of zoaversion which were not caught and adjusted for in the ibm_zos_core module_utils/zoau_version_checker.py code. The logic in the get_zoau_version_str parses zoaversion output from the end (-1 index). Soon after the checker was written and released, the output of zoaversion was amended to include additional build info. This means the version checker has been silently failing since ZOAU v1.2.1 introduced additional build info (see below to compare output between v1.2.0 and other versions):

Zoaversion output for various ZOAU versions:

  • v1.2.0:
    2021/07/07 22:36:30 CUT V1.2.0
  • v1.2.1:
    2022/09/07 15:26:50 CUT V1.2.1 d2f6557 1880
  • v1.2.2:
    2022/12/06 20:44:00 CUT V1.2.2 ee30137 2525
  • v1.2.3:
    2023/03/16 18:17:00 CUT V1.2.3 1aa591fb 2148 PH50145

Code from zoau_version_checker.py's get_zoau_version_str function:

    version_list = (
        zoaversion_out
        .stdout
        .decode('UTF-8')
        .strip()
        .split(' ')[-1][1:]
        .split('.')
    )

link to problem line.

My proposal is to rewrite the code to grab the version info from the front of the array, index 3, rather than the end.

# python3
Python 3.11.2 (heads/pyz_dev-3.11:806b16f89d, Mar 21 2023, 14:33:14) [Clang 14.0.0 ] on zos
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> zoaversion_out = subprocess.run('zoaversion', shell=True, capture_output=True, check=False)
>>> zoaversion_out
CompletedProcess(args='zoaversion', returncode=0, stdout=b'2023/03/16 18:17:00 CUT V1.2.3 1aa591fb 2148 PH50145\n', stderr=b'')
>>> cleaned_up=zoaversion_out.stdout.decode('UTF-8').strip().split(' ')
>>> cleaned_up
['2023/03/16', '18:17:00', 'CUT', 'V1.2.3', '1aa591fb', '2148', 'PH50145']
>>> version_list = cleaned_up[3][1:].split('.')
>>> version_list
['1', '2', '3']
>>> 

On a longer term, it is worth exploring if it is possible to leverage zoautil_py rather than calling and parsing command line utils.

Playbook verbosity output.

Playbook calling zos_gather_facts with ZOAU v1.2.3 on target host:

---
- hosts: zos_host
  collections:
    - "ibm.ibm_zos_core"

  gather_facts: no
  vars:
    ZOAU: /zoau/v1.2.3
    PYZ: /allpython/3.11/usr/lpp/IBM/cyp/v3r11/pyz/

  environment:
    _BPXK_AUTOCVT: "ON"
    ZOAU_HOME: "{{ ZOAU }}"
    PYTHONPATH: "{{ ZOAU }}/lib"
    LIBPATH: "{{ ZOAU }}/lib:{{ PYZ }}/lib:/lib:/usr/lib:."
    PATH: "{{ ZOAU }}/bin:{{ PYZ }}/bin:/bin:/var/bin"
    _CEE_RUNOPTS: "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
    _TAG_REDIR_ERR: "txt"
    _TAG_REDIR_IN: "txt"
    _TAG_REDIR_OUT: "txt"
    LANG: "C"
    PYTHONSTDINENCODING: "cp1047"

  tasks:
      
    # ##########################################################################
    # Call z/OS fact gathering with the 'ipl' subset and filter down to
    # master_catalog facts.
    # ##########################################################################
    - name: Collect z/OS facts on master_catalog.
      zos_gather_facts:
        gather_subset:
          - 'ipl'
        filter:
          - 'master*'

Yields output:

TASK [Collect z/OS facts on master_catalog.] ************************************************************************************************************************* An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: invalid literal for int() with base 10: 'H50145' fatal: [ec18]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 107, in <module>\n File \"<stdin>\", line 99, in _ansiballz_main\n File \"<stdin>\", line 47, in invoke_module\n File \"<frozen runpy>\", line 226, in run_module\n File \"<frozen runpy>\", line 98, in _run_module_code\n File \"<frozen runpy>\", line 88, in _run_code\n File \"/tmp/ansible_zos_gather_facts_payload_mgcthlf5/ansible_zos_gather_facts_payload.zip/ansible_collections/ibm/ibm_zos_core/plugins/modules/zos_gather_facts.py\", line 292, in <module>\n File \"/tmp/ansible_zos_gather_facts_payload_mgcthlf5/ansible_zos_gather_facts_payload.zip/ansible_collections/ibm/ibm_zos_core/plugins/modules/zos_gather_facts.py\", line 288, in main\n File \"/tmp/ansible_zos_gather_facts_payload_mgcthlf5/ansible_zos_gather_facts_payload.zip/ansible_collections/ibm/ibm_zos_core/plugins/modules/zos_gather_facts.py\", line 219, in run_module\n File \"/tmp/ansible_zos_gather_facts_payload_mgcthlf5/ansible_zos_gather_facts_payload.zip/ansible_collections/ibm/ibm_zos_core/plugins/module_utils/zoau_version_checker.py\", line 35, in is_zoau_version_higher_than\n File \"/tmp/ansible_zos_gather_facts_payload_mgcthlf5/ansible_zos_gather_facts_payload.zip/ansible_collections/ibm/ibm_zos_core/plugins/module_utils/zoau_version_checker.py\", line 35, in <listcomp>\nValueError: invalid literal for int() with base 10: 'H50145'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

In the python interpreter, with ZOAU v1.2.3 in the path:

# python3
Python 3.11.2 (heads/pyz_dev-3.11:806b16f89d, Mar 21 2023, 14:33:14) [Clang 14.0.0 ] on zos
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> zoaversion_out = subprocess.run('zoaversion', shell=True, capture_output=True, check=False)
>>> cleaned_up=zoaversion_out.stdout.decode('UTF-8').strip().split(' ')                        
>>> cleaned_up                                                                                 
['2023/03/16', '18:17:00', 'CUT', 'V1.2.3', '1aa591fb', '2148', 'PH50145']
>>> version_list = cleaned_up[-1][1:].split('.')                                               
>>> version_list
['H50145']
>>> 

Note that the 'H' is the cause of zoau_version_checker failing because there's an implicit conversion to int at [line 35](system_version_list = [int(i) for i in system_version_list]) for the contents returned by the get_zoau_version_str which in this case is ['H50145'].

Ansible configuration.

No response

Contents of the inventory

No response

Contents of group_vars or host_vars

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment