hypervisors.statistics() returns an object that cannot be printed

Bug #1370415 reported by Matthew Gilliard
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-novaclient
Fix Released
Undecided
Matthew Gilliard

Bug Description

>>> print nc.hypervisors.statistics()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/stack/python-novaclient/novaclient/v1_1/hypervisors.py", line 29, in __repr__
    return "<Hypervisor: %s>" % self.id
  File "/opt/stack/python-novaclient/novaclient/openstack/common/apiclient/base.py", line 489, in __getattr__
    raise AttributeError(k)
AttributeError: id

The root cause is at https://github.com/openstack/python-novaclient/blob/master/novaclient/v1_1/hypervisors.py#L29 - "self" does not have a property "id", so self.id throws AttributeError in __repr__().

A little digging shows this little quirk:

>>> type(nc.hypervisors.list()[0])
<class 'novaclient.v1_1.hypervisors.Hypervisor'>

>>> type(nc.hypervisors.statistics())
<class 'novaclient.v1_1.hypervisors.Hypervisor'>

Why is a collection of statistics about all hypervisors being modelled as if it were a single hypervisor? All hypervisors have ids, but a collection of statistics being does not. This is the real problem which needs fixing, IMHO.

Changed in python-novaclient:
assignee: nobody → Matthew Gilliard (matthew-gilliard-u)
description: updated
description: updated
Changed in python-novaclient:
status: New → Confirmed
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-novaclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/122436

Changed in python-novaclient:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-novaclient (master)

Reviewed: https://review.openstack.org/122436
Committed: https://git.openstack.org/cgit/openstack/python-novaclient/commit/?id=b5e36ced8fbae0b93cd713b1cf47c7cc877837b8
Submitter: Jenkins
Branch: master

commit b5e36ced8fbae0b93cd713b1cf47c7cc877837b8
Author: Matthew Gilliard <email address hidden>
Date: Thu Sep 18 14:32:45 2014 +0000

    Adds separate class for Hypervisor Stats

    Hypervisor stats was being called from the Hypervisors class, which means that
    the statistics were being modeled as if they were a single Hypervisor. This
    mostly worked, except that the stats didn't have an id field so a call to
    __repr__() (implicitly called by print, or in the REPL) would throw an
    AttributeError.

    This patch creates a new class HypervisorStats which models a collection of
    statistics about hypervisors. So you can now call:

      nc.hypervisor_stats.statistics()

    The old call of

      nc.hypervisors.statistics()

    is left for backward compatibility but just calls into the new method.

    Change-Id: Ia31aacb95b1d517dab3ad38763d6448715bab68e
    Closes-bug: 1370415

Changed in python-novaclient:
status: In Progress → Fix Committed
Michael Still (mikal)
Changed in python-novaclient:
milestone: none → 2.21.0
Michael Still (mikal)
Changed in python-novaclient:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.