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] API failure is not in shown while creating dynamic inventory #421

Open
bhati-pradeep opened this issue Oct 17, 2023 · 0 comments · May be fixed by #512
Open

[Bug] API failure is not in shown while creating dynamic inventory #421

bhati-pradeep opened this issue Oct 17, 2023 · 0 comments · May be fixed by #512
Assignees
Labels
1.9.3_triage Bug fixes & Improvements bug Something isn't working

Comments

@bhati-pradeep
Copy link
Collaborator

bhati-pradeep commented Oct 17, 2023

Describe the bug
During API failure, the inventory plugin gives warning about some code error in entity.py and returns empty response.

To Reproduce
Steps to reproduce the behavior:

  1. Create dynamic inventory with wrong creds.

Stack trace

~/work/codebase/nutanix/nutanix.ansible/inventory-example imprv/issue#409 *57 !1 ?19 ❯ ansible-inventory  --list -vvvv                                                                                                            12:44:44 AM
ansible-inventory [core 2.13.0]
  config file = /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/ansible.cfg
  configured module search path = ['/Users/pradeep.bhati/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/pradeep.bhati/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.9.16 (main, Dec  7 2022, 10:15:43) [Clang 14.0.0 (clang-1400.0.29.202)]
  jinja version = 3.1.1
  libyaml = True
Using /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/ansible.cfg as config file
setting up inventory plugins
Loading collection nutanix.ncp from /Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp
[WARNING]:  * Failed to parse /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/nutanix.yml with ansible_collections.nutanix.ncp.plugins.inventory.ntnx_prism_vm_inventory plugin: 'Mock_Module' object has no
attribute 'fail_json'
  File "/usr/local/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/inventory/ntnx_prism_vm_inventory.py", line 143, in parse
    resp = vm.list(self.data)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py", line 81, in list
    resp = super(VM, self).list(data)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py", line 198, in list
    resp = self._fetch_url(
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py", line 410, in _fetch_url
    self.module.fail_json(
[WARNING]: Unable to parse /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/nutanix.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

Expected behavior
A clear API failure with message should be shown.

Additional context

Script:

ansible.cfg ->

[defaults]
inventory = nutanix.yml

[inventory]
enable_plugins = nutanix.ncp.ntnx_prism_vm_inventory

nutanix.yml ->

plugin: nutanix.ncp.ntnx_prism_vm_inventory
nutanix_hostname: IP address of PC
nutanix_password: password
nutanix_username: username
nutanix_port: 9440
validate_certs: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.9.3_triage Bug fixes & Improvements bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

6 participants