- 
                Notifications
    
You must be signed in to change notification settings  - Fork 45
 
Added dependency checker and unit test case #2375
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
74031fd
              9be3bab
              5ab1feb
              799542d
              0f2235d
              e860507
              80f5d28
              701d066
              f2718fd
              c550b0c
              7aa1be3
              a19b2b7
              217012c
              74d7afd
              079ab14
              7b37786
              90a2c07
              5be0f12
              14f0424
              6edc75d
              519c0ef
              bd1a5ee
              d2b05e4
              d8baed7
              1348507
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||
| # -*- coding: utf-8 -*- | ||||||
| # Copyright (c) IBM Corporation 2025 | ||||||
| # Licensed under the Apache License, Version 2.0 | ||||||
| 
     | 
||||||
| from __future__ import absolute_import, division, print_function | ||||||
| import re | ||||||
| import subprocess | ||||||
| import sys | ||||||
| import json | ||||||
| 
     | 
||||||
| __metaclass__ = type | ||||||
| 
     | 
||||||
| # ------------------------------ | ||||||
| # Compatibility Matrix | ||||||
| # ------------------------------ | ||||||
| COMPATIBILITY_MATRIX = [ | ||||||
| {"zoau_version": "1.3.5", "python_version": "3.12", "galaxy_core_version": "1.12.0", "zos_range": "2.5-3.1"}, | ||||||
                
       | 
||||||
| {"zoau_version": "1.3.5", "python_version": "3.12", "galaxy_core_version": "1.12.0", "zos_range": "2.5-3.1"}, | |
| {"zoau_version": "1.3.5", "python_version": "3.12", "collection_version": "1.12.0", "min_zos_version": "2.5", "max_zos_version": "3.1"}, | 
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be problematic, rather than catching the error here I think we should do a try in the main dependency validation, and throw an Exception from there saying something like "The dependencies could not be fetched correctly. " and maybe add some details about the dependencias that were fetched successfully
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to run zoaversion command, as we spoke before better to use the zoau_dependency_checker functionality.
try:
    from zoautil_py import ZOAU_API_VERSION
except Exception:
    ZOAU_API_VERSION = "1.4.0"        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, better to use ZOAU's zsystem python API https://www.ibm.com/docs/en/zoau/1.3.x?topic=apis-zsystem we try to avoid using commands when an API is available unless there is a bug in the python API
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are in the managed node we cannot access the collection version using ansible-galaxy command, this is what we were talking about the other day, is it possible to get through an import by fetching the valye from meta/ibm_zos_core?
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of iterating over the compatibility matrix we can use the core collection version as the key to find the correct row and only check the compatibility for the current version
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import pytest | ||
| from ansible_collections.ibm.ibm_zos_core.plugins.module_utils import dependency_checker as dc | ||
                
       | 
||
| 
     | 
||
| class FakeModule: | ||
| def run_command(self, cmd): | ||
| return 0, "", "" | ||
| 
     | 
||
| def fail_json(self, **kwargs): | ||
| raise Exception(kwargs.get("msg", "fail_json called")) | ||
| 
     | 
||
| def exit_json(self, **kwargs): | ||
| # Instead of StopIteration, store the result so we can inspect it | ||
| self.result = kwargs | ||
| raise SystemExit # This simulates Ansible stopping execution | ||
| 
     | 
||
| def test_validate_dependencies_success(monkeypatch): | ||
| # Monkeypatch fetchers to match the compatibility matrix exactly | ||
| monkeypatch.setattr(dc, "get_zoau_version", lambda mod: "1.3.5") | ||
                
       | 
||
| monkeypatch.setattr(dc, "get_zos_version", lambda mod: "2.5") | ||
| monkeypatch.setattr(dc, "get_python_version_info", lambda: (3, 12)) | ||
| monkeypatch.setattr(dc, "get_python_version", lambda: "3.12.0") | ||
| monkeypatch.setattr(dc, "get_galaxy_core_version", lambda: "1.12.0") | ||
| 
     | 
||
| mod = FakeModule() | ||
| try: | ||
| dc.validate_dependencies(mod) | ||
| except SystemExit: | ||
| # Capture the message from exit_json | ||
| print("Message:", mod.result["msg"]) | ||
| assert "Dependency compatibility check passed" in mod.result["msg"] | ||
| 
     | 
||
| def test_validate_dependencies_failure(monkeypatch): | ||
| monkeypatch.setattr(dc, "get_zoau_version", lambda mod: "9.9.9") | ||
| monkeypatch.setattr(dc, "get_zos_version", lambda mod: "9.9") | ||
| monkeypatch.setattr(dc, "get_python_version_info", lambda: (9, 9)) | ||
| monkeypatch.setattr(dc, "get_python_version", lambda: "9.9.9") | ||
| monkeypatch.setattr(dc, "get_galaxy_core_version", lambda: "9.9.9") | ||
| 
     | 
||
| mod = FakeModule() | ||
| with pytest.raises(Exception) as exc: | ||
| dc.validate_dependencies(mod) | ||
| print("Failure message:", str(exc.value)) | ||
| assert "Incompatible configuration detected" in str(exc.value) | ||
Uh oh!
There was an error while loading. Please reload this page.