When create keypair with the same name at the same time, create two keypair

Bug #1086333 reported by Kanami Akama
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
High
Rohan

Bug Description

When create keypair with the same name at the same time, create two keypair.

nova keypair-list
+----------+------------------------------------------------------+
| Name | Fingerprint |
+----------+------------------------------------------------------+
| keypair1 | d3:b0:8e:46:a8:90:90:67:c9:c8:b3:b3:b0:dd:fa:f6 |
| keypair1 | f2:5d:80:08:14:35:1e:98:d7:f9:75:67:64:3e:0e:ae |
+----------+------------------------------------------------------+

When keypair delete with the specified name, delete other one.

nova keypair-delete keypair1
nova keypair-list
+----------+------------------------------------------------------+
| Name | Fingerprint |
+----------+------------------------------------------------------+
| keypair1 | d3:b0:8e:46:a8:90:90:67:c9:c8:b3:b3:b0:dd:fa:f6 |
+----------+------------------------------------------------------+

If set name unique key, can not be create keypair with the keypair name that has been deleted.
When run create keypair at the same time, keypair with the same name should not create.

Tags: db
Michael Still (mikal)
tags: removed: same time
Changed in nova:
status: New → Triaged
importance: Undecided → High
Changed in nova:
assignee: nobody → Unmesh Gurjar (unmesh-gurjar)
Revision history for this message
Unmesh Gurjar (unmesh-gurjar) wrote :

To fix this issue, I have added uniqueness constraint on name and user_id columns of key_pairs table (and removed the extra DB look-up prior to the creation of key pair). However, I am facing a strange issue in SQLAlchemy, due to which, I get a TypeError instead of IntegrityError (sample stack trace http://paste.openstack.org/show/28497/ ) on creating a same named keypair for a user.

This can be overcome by replacing the 'raise' statement by 'raise exc' in _flush( ) method of /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py.

IMO, this requires a fix in SQLAlchemy session. Can someone please confirm this.

NOTE: Code branch 'master', SQLAlchemy version 0.7.9

Revision history for this message
Thierry Carrez (ttx) wrote :

I agree that concurrent usage of "_capture_exception=True" and "raise" is suspicious at best, so it looks like it would be worth reporting to SQLAlchemy folks.

Revision history for this message
Tushar Patil (tpatil) wrote :

Can someone please point out how to report this problem to the SQLAlchemy team?

Revision history for this message
Unmesh Gurjar (unmesh-gurjar) wrote :

I managed to fix the issue without modifying SQLAlchemy code. Calling session.begin( ) before calling the method save( ) and passing it the corresponding session instance fixes the issue. After the fix is in place, the expected exception 'DBDuplicateEntry' is getting raised on adding a duplicate row.

Does this solution sound correct?

PS: The same solution can also be used for similar issues (such as security group creation LP #1093458).

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

Changed in nova:
status: Triaged → In Progress
Rohan (kanaderohan)
Changed in nova:
assignee: Unmesh Gurjar (unmesh-gurjar) → Rohan (kanaderohan)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

Sean Dague (sdague)
Changed in nova:
milestone: none → grizzly-3
Changed in nova:
milestone: grizzly-3 → grizzly-rc1
aeva black (tenbrae)
tags: added: db
Revision history for this message
Tushar Patil (tpatil) wrote :

Please review this patch https://review.openstack.org/#/c/21415/.

aeva black (tenbrae)
Changed in nova:
milestone: grizzly-rc1 → havana-1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/21415
Committed: http://github.com/openstack/nova/commit/0ae598b1a7a92755fd0fcc2685816414fb6f47b0
Submitter: Jenkins
Branch: master

commit 0ae598b1a7a92755fd0fcc2685816414fb6f47b0
Author: Rohan Rhishikesh Kanade <email address hidden>
Date: Wed Feb 27 11:19:21 2013 -0800

    Return 409 on creating/importing same name keypair

    * Removed the DB look up on creating and importing a keypair.
    * Added unique constraint on user_id and name columns of key_pairs
    table.

    Fixes LP: #1086333.

    Change-Id: I2fd4697f9269d2be13bd977e65ba4ca4a27b9ac6

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: havana-1 → 2013.2
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.