keypair-show fails with "ERROR: can't set attribute"

Bug #1223934 reported by Roman Podoliaka
40
This bug affects 8 people
Affects Status Importance Assigned to Milestone
Sahara
Fix Released
High
Sergey Lukjanov
python-novaclient
Fix Released
Undecided
Roman Podoliaka

Bug Description

Steps to reproduce on a clean DevStack deployment:
1. Create a new key pair:
malor@devstack:~/devstack$ nova keypair-add test
...

2. Show details about the given key pair:
malor@devstack:~/devstack$ nova keypair-show test
ERROR: can't set attribute

Running nova client with --debug allows to see the actual trace back:

DEBUG (shell:740) can't set attribute
Traceback (most recent call last):
  File "/opt/stack/python-novaclient/novaclient/shell.py", line 737, in main
    OpenStackComputeShell().main(map(strutils.safe_decode, sys.argv[1:]))
  File "/opt/stack/python-novaclient/novaclient/shell.py", line 673, in main
    args.func(self.cs, args)
  File "/opt/stack/python-novaclient/novaclient/v1_1/shell.py", line 2345, in do_keypair_show
    keypair = cs.keypairs.get(args.keypair)
  File "/opt/stack/python-novaclient/novaclient/v1_1/keypairs.py", line 55, in get
    return self._get("/os-keypairs/%s" % base.getid(keypair), "keypair")
  File "/opt/stack/python-novaclient/novaclient/base.py", line 141, in _get
    return self.resource_class(self, body[response_key], loaded=True)
  File "/opt/stack/python-novaclient/novaclient/base.py", line 408, in __init__
    self._add_details(info)
  File "/opt/stack/python-novaclient/novaclient/v1_1/keypairs.py", line 35, in _add_details
    setattr(self, k, v)
AttributeError: can't set attribute
ERROR: can't set attribute

Changed in python-novaclient:
assignee: nobody → Roman Podolyaka (rpodolyaka)
Revision history for this message
kesten broughton (dathomir) wrote :

I see the same error in the terminal output of the savanna process when I try to launch the cluster:

-- commandline output
stack@vmware-controller:~/savanna-venv$ http $SAVANNA_URL/clusters X-Auth-Token:$AUTH_TOKEN < cluster_create.json
HTTP/1.1 500 INTERNAL SERVER ERROR
Content-Length: 111
Content-Type: application/json
Date: Mon, 16 Sep 2013 05:08:10 GMT

{
    "error_code": 500,
    "error_message": "Error occurred during validation",
    "error_name": "INTERNAL_SERVER_ERROR"
}

--- term output

2013-09-15 21:50:52.608 23743 ERROR savanna.utils.api [-] Request aborted with status code 500 and message 'Error occurred during validation'
2013-09-15 21:50:52.608 23743 ERROR savanna.utils.api [-] Traceback (most recent call last):
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/savanna/service/validation.py", line 37, in handler
    validator(**kwargs)
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/savanna/service/validations/clusters.py", line 53, in check_cluster_create
    b.check_keypair_exists(data['user_keypair_id'])
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/savanna/service/validations/base.py", line 162, in check_keypair_exists
    nova.client().keypairs.get(keypair)
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/novaclient/v1_1/keypairs.py", line 55, in get
    return self._get("/os-keypairs/%s" % base.getid(keypair), "keypair")
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/novaclient/base.py", line 140, in _get
    return self.resource_class(self, body[response_key], loaded=True)
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/novaclient/base.py", line 387, in __init__
    self._add_details(info)
  File "/home/stack/savanna-venv/local/lib/python2.7/site-packages/novaclient/v1_1/keypairs.py", line 35, in _add_details
    setattr(self, k, v)
AttributeError: can't set attribute

Revision history for this message
kesten broughton (dathomir) wrote :

The trace is fairly helpful.
The error comes from _add_details on the setattr line.
Keypairs inherits from base.Resource in base.py.
Note the difference and the comment (setattr is surrounded with a try catch in base.Resource.
If you wrap the setattr in KeyPair's _add_details, the error goes away.

To fix:
locate v1_1/keypairs.py
for me they were located here:
/opt/stack/python-novaclient/novaclient/v1_1/keypairs.py
/home/stack/savanna-venv/lib/python2.7/site-packages/novaclient/v1_1/keypairs.py

I also deleted the .pyc versions of these files, though that shouldn't be necessary.

Test it first on
nova keypair-list
if that succeeds then stop the savana process and restart (from the parent directory to savanna-venv) with
savanna-venv/bin/python savanna-venv/bin/savanna-api --config-file savanna-venv/etc/savanna.conf

# KeyPair in keypairs.py
    def _add_details(self, info):
        dico = 'keypair' in info and \
            info['keypair'] or info
        for (k, v) in dico.items(): ## wrap this for loop in a try/catch like in base.Resource
            setattr(self, k, v)

# base.Resource in base.py
    def _add_details(self, info):
        for (k, v) in six.iteritems(info):
            try:
                setattr(self, k, v)
                self._info[k] = v
            except AttributeError:
                # In this case we already defined the attribute on the class
                pass

Changed in savanna:
importance: Undecided → High
milestone: none → 0.3a1
status: New → Confirmed
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/46897

Changed in python-novaclient:
status: New → In Progress
Changed in savanna:
status: Confirmed → Triaged
Changed in savanna:
assignee: nobody → Sergey Lukjanov (slukjanov)
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to savanna (master)

Reviewed: https://review.openstack.org/47724
Committed: http://github.com/stackforge/savanna/commit/3e344d41a82b43b2a3c68b5c43486841ba3a626a
Submitter: Jenkins
Branch: master

commit 3e344d41a82b43b2a3c68b5c43486841ba3a626a
Author: Sergey Lukjanov <email address hidden>
Date: Sun Sep 22 12:29:14 2013 +0400

    Temporarily fixes bug #1223934

    It could be removed when fix for this bug will be released in novaclient
    and novaclient version in requirements will be updated.

    Fixes: bug #1223934

    Change-Id: Idb019d5905e21948126e84c099d2abb524e7eba9

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

Reviewed: https://review.openstack.org/46897
Committed: http://github.com/openstack/python-novaclient/commit/9e8dd063c6c4215ebda25d0199cec3fb64a81837
Submitter: Jenkins
Branch: master

commit 9e8dd063c6c4215ebda25d0199cec3fb64a81837
Author: Roman Podolyaka <email address hidden>
Date: Tue Sep 17 10:21:03 2013 +0300

    Fix AttributeError in Keypair._add_details()

    _add_details() method copies keypair attributes retrieved
    from Nova to an instance of Keypair class. Trying to set
    attribute 'id' fails with AttributeError, because Keypair
    class has a read-only property 'id'.

    We can safely omit setting of attribute 'id', because it's
    just an implementation detail (the id of a table row in a
    database), and keypairs for a given tenant are uniquely
    identified using attribute 'name'.

    Fixes bug 1223934

    Change-Id: I1045730e47e9e6ad31fcdfbaefdad77e2f3b2c3e

Changed in python-novaclient:
status: In Progress → Fix Committed
Changed in savanna:
status: Fix Committed → Fix Released
Changed in savanna:
milestone: 0.3a1 → 0.3
Revision history for this message
melanie witt (melwitt) wrote :

novaclient 2.16.0 released on 2/26/2014

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.