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

azure_rm_galleryimageversion_info throwing error when image definition does not exist or when image definition does not have image versions #1663

Closed
zinzh opened this issue Aug 8, 2024 · 9 comments
Labels
closed It has been fixed duplicate This issue or pull request already exists not a bug Not a bug

Comments

@zinzh
Copy link

zinzh commented Aug 8, 2024

SUMMARY

azure_rm_galleryimageversion_info.py throwing error when image definition does not exist.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_galleryimageversion_info.py

ANSIBLE VERSION
ansible [core 2.16.9]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True

COLLECTION VERSION
# /usr/local/lib/python3.10/dist-packages/ansible_collections
Collection         Version
------------------ -------
azure.azcollection 2.6.0
STEPS TO REPRODUCE

Use an image definition that does not exist, or an image definition that does not have any image version under it

- name: List gallery image versions 
  azure_rm_galleryimageversion_info:
    subscription_id: "{{ xxx }}"
    client_id: "{{ xxx}}"
    tenant: "{{ xxx}}"
    secret: "{{ xxx}}"
    resource_group: "{{ xxx}}"
    gallery_name: "{{ xxx}}"
    gallery_image_name: "{{ image_definition_without_any_version }}"
  register: image_versions_info
EXPECTED RESULTS

Expext to get an empty array or an indication that no versions exist

ACTUAL RESULTS

Got an exception

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'id'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1723101762.8817968-351-53582052812445/AnsiballZ_azure_rm_galleryimageversion_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1723101762.8817968-351-53582052812445/AnsiballZ_azure_rm_galleryimageversion_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1723101762.8817968-351-53582052812445/AnsiballZ_azure_rm_galleryimageversion_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.azure.azcollection.plugins.modules.azure_rm_galleryimageversion_info', init_globals=dict(_module_fqn='ansible_collections.azure.azcollection.plugins.modules.azure_rm_galleryimageversion_info', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 278, in <module>\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 274, in main\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 145, in __init__\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py\", line 473, in __init__\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 163, in exec_module\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 257, in listbygalleryimage\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 257, in <listcomp>\n  File \"/tmp/ansible_azure_rm_galleryimageversion_info_payload_htb1j87f/ansible_azure_rm_galleryimageversion_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_galleryimageversion_info.py\", line 263, in format_item\nKeyError: 'id'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
SOME TROUBLESHOOTING I HAVE DONE

In azure_rm_galleryimageversion_info.py, format_item function, check is being done if item is None:

 def format_item(self, item):
        if not item
            return None

However if we debug item variable when no versions exist, it is not an empty array as we would expect:

"versions": [
            {
                "value": []
            }
        ]

Which is leading the condition to be skipped

@zinzh zinzh changed the title azure_rm_galleryimageversion_info throwing error when image definition does not exist azure_rm_galleryimageversion_info throwing error when image definition does not exist or when image definition does not have image versions Aug 8, 2024
@zinzh
Copy link
Author

zinzh commented Aug 8, 2024

What is the purpose of this line? if we skip it the response will be an empty array in case no image versions found

results['response'] = results['response'] + [response]

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 8, 2024

What is the purpose of this line? if we skip it the response will be an empty array in case no image versions found

results['response'] = results['response'] + [response]

@zinzh This purpose is to take the information on the next page and merge it into the information currently obtained. Thank you!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 8, 2024

@zinzh This issue duplicate with #1434 and fixed by #1436. The azure.azcollection versions higher than v2.3.0 should have been fixed. Thank you!

@Fred-sun Fred-sun added duplicate This issue or pull request already exists not a bug Not a bug closed It has been fixed labels Aug 8, 2024
@zinzh
Copy link
Author

zinzh commented Aug 8, 2024

@Fred-sun i am facing this issue in v2.6.0
I see you have added the condition in v2.3.0 but the problem here is that it is not evaluating to true when there are no image versions. am i missing something?

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 8, 2024

@zinzh I will retry it! Thanks!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 9, 2024

@zinzh This is very strange, there is a PR #1637 fix similar issues #1636. Can you update the #1637 patch and try again? Thank you!

@zinzh
Copy link
Author

zinzh commented Aug 9, 2024

@Fred-sun Updating to patch #1637 fixed my issue. May i ask what is the timeline for the next release that includes this patch? Thank you!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 9, 2024

@zinzh It will be released soon, we have a few more patches, update, will be released. Thank you!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Aug 9, 2024

Fixes by #1637,

@Fred-sun Fred-sun closed this as completed Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed It has been fixed duplicate This issue or pull request already exists not a bug Not a bug
Projects
None yet
Development

No branches or pull requests

2 participants