vcd-cli icon indicating copy to clipboard operation
vcd-cli copied to clipboard

vcd search fails for vm and other entity types

Open hodgesrm opened this issue 7 years ago • 2 comments

Issuing a command like 'vcd search vm' fails with an obscure error on some vCD installations (mine in particular):

$ vcd search vm
Usage: vcd search [OPTIONS] [resource-type]

Error: ('application/vnd.vmware.vcloud.query.idrecords+xml', 'vm')

To reproduce:

  1. Run python -m venv to set up virtual environment and execute 'activate' to start.
  2. Clone pyvcloud and vcd-cli repos.
  3. Run 'python3 setup.py develop in pyvcloud followed by vcd-cli'.
  4. Run vcd login and then vcd search vm as shown above.

After some hacking I was able to print the stack trace, which is as follows:

Printing exception: type=<class 'KeyError'>, args=<class 'KeyError'>
Traceback (most recent call last):
  File "/home/rhodges/environment/vcd-upstream/bin/vcd", line 10, in <module>
    sys.exit(vcd())
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/rhodges/environment/vcd-upstream/lib/python3.5/site-packages/click-6.7-py3.5.egg/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/rhodges/git/vcd-cli/vcd_cli/search.py", line 109, in search
    stderr(e, ctx)
  File "/home/rhodges/git/vcd-cli/vcd_cli/utils.py", line 253, in stderr
    raise exception
  File "/home/rhodges/git/vcd-cli/vcd_cli/search.py", line 101, in search
    records = list(q.execute())
  File "/home/rhodges/git/pyvcloud/pyvcloud/vcd/client.py", line 1047, in execute
    self._find_query_uri(self._query_result_format),
  File "/home/rhodges/git/pyvcloud/pyvcloud/vcd/client.py", line 1167, in _find_query_uri
    _get_query_list_map()[(query_media_type, self._query_type_name)]
KeyError: ('application/vnd.vmware.vcloud.query.idrecords+xml', 'vm')

So the cause appears to be a failure when looking up a key.

I'll get to full root cause and submit a PR to fix.

hodgesrm avatar Apr 10 '18 03:04 hodgesrm

The error originates in pyvcloud as shown by the stack trace but vcd error reporting made it quite hard to figure out what was up. The fix should also address bug diagnosis on the vcd-cli side as well. To get the full stack trace it was necessary to add a 'raise' command to utils.stderr() to throw the exception and let normal Python exception handling take over.

hodgesrm avatar Apr 10 '18 03:04 hodgesrm

Another note on this--you can see the stack trace in vcd.log but I always forget to look there and suspect this happens to others as well. An obvious improvement would be to have the --debug option print the stack trace directly on the command line.

hodgesrm avatar Apr 11 '18 22:04 hodgesrm