vcd search fails for vm and other entity types
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:
- Run
python -m venvto set up virtual environment and execute 'activate' to start. - Clone pyvcloud and vcd-cli repos.
- Run 'python3 setup.py develop in pyvcloud followed by vcd-cli'.
- Run
vcd loginand thenvcd search vmas 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.
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.
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.