novaclient list servers by update attribute throws TypeError instead of CommandError
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-novaclient |
Fix Released
|
Undecided
|
Theodoros Tsioutsias |
Bug Description
Description
===========
nova list command fails with TypeError instead of CommandError when an existing but not valid attribute of the object is given as field.
$ /usr/bin/nova list --all --status ERROR --fields update
ERROR (TypeError): object.
Steps to reproduce
==================
At least one server has to exist so that the list is not empty.
In this case update was given as a field.
The Server object has an update method so the (not hasattr) check is False:
python-
1634 def _get_list_
1635 filters=None):
[...]
1680 for field in fields.split(','):
1681 if not hasattr(obj, field):
1682 non_existent_
1683 continue
1684 if field in exclude_fields:
1685 continue
1686 field_title, formatter = utils.make_
1687 filters)
1688 columns.
1689 formatters[
1690 exclude_
As a result of this check, all of the attributes of the server object can be used as fields.
Most of them cause a TypeError to be raised.
e.g:
[devstack-006 ~]$ /usr/bin/nova list --fields __dict__
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields __getattr__
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields __getattribute__
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields __hash__
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields __init__
ERROR (TypeError): object.
[devstack-006 v2]$ /usr/bin/nova list --field unshelve
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields to_dict
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields revert_resize
ERROR (TypeError): object.
[devstack-006 ~]$ /usr/bin/nova list --fields _add_details
ERROR (TypeError): object.
[...]
Expected result
===============
A CommandError should be raised.
Actual result
=============
A TypeError is raised.
Environment
===========
$ rpm -qf /usr/bin/nova
python2-
Reproduced in devstack:
[devstack-006 ~]$ /usr/bin/nova list --field update
ERROR (TypeError): object.
[devstack-006 python-novaclient]$ git log -1
commit c9e7a64ca83302b
Merge: dd520c7 bef6765
Author: Zuul <email address hidden>
Date: Tue Nov 21 19:51:32 2017 +0000
Merge "Microversion 2.54 - Enable reset keypair while rebuild"
Logs & Configs
==============
Attaching the debug output of the command.
Comments
========
Attributes like __module__ or __class__, are not raising a TypeError. Should they be allowed?
[devstack-006 ~]$ /usr/bin/nova list --field __class__
+------
| ID | Class |
+------
| 353e6118-
| b7f1f1f2-
| d7d99415-
+------
[devstack-006 ~]$ /usr/bin/nova list --field __module__
+------
| ID | Module |
+------
| 353e6118-
| b7f1f1f2-
| d7d99415-
+------
affects: | nova → python-novaclient |
Fix proposed to branch: master /review. openstack. org/525110
Review: https:/