get_all_flavor cannot return all flavors if the deleted flavor has same name

Bug #1215295 reported by chieh chu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Medium
Joshua Hesketh

Bug Description

Now it is allowed that the flavor with specified name was deleted, and later a new flavor is created with the same name, by this way, you can there are two records in the DB (table "instance_types") with the same name but different id/flavorid.

But if you are going to retrieve all flavors via nova.compute.flavors:get_all_flavors(inactive=True), you would find that only the last flavor which has the same name can be fetched. This is because that all instance types retrieved from DB will be set into a dict and the 'name' is used as the key.

+---------------------+---------------------+---------------------+-------------+----+-----------+-------+------+-------------+----------+-------------+---------+--------------+----------+-----------+---------+
| created_at | updated_at | deleted_at | name | id | memory_mb | vcpus | swap | vcpu_weight | flavorid | rxtx_factor | root_gb | ephemeral_gb | disabled | is_public | deleted |
+---------------------+---------------------+---------------------+-------------+----+-----------+-------+------+-------------+----------+-------------+---------+--------------+----------+-----------+---------+
| NULL | NULL | NULL | m1.medium | 1 | 4096 | 2 | 0 | NULL | 3 | 1 | 40 | 0 | 0 | 1 | 0 |
| NULL | NULL | NULL | m1.tiny | 2 | 512 | 1 | 0 | NULL | 1 | 1 | 1 | 0 | 0 | 1 | 0 |
| NULL | NULL | NULL | m1.large | 3 | 8192 | 4 | 0 | NULL | 4 | 1 | 80 | 0 | 0 | 1 | 0 |
| NULL | NULL | NULL | m1.xlarge | 4 | 16384 | 8 | 0 | NULL | 5 | 1 | 160 | 0 | 0 | 1 | 0 |
| NULL | NULL | NULL | m1.small | 5 | 2048 | 1 | 0 | NULL | 2 | 1 | 20 | 0 | 0 | 1 | 0 |
| 2013-08-21 23:31:35 | 2013-08-21 23:31:49 | 2013-08-21 23:31:49 | test_flavor | 6 | 512 | 1 | 0 | NULL | 20 | 1 | 0 | 0 | 0 | 1 | 6 |
| 2013-08-21 23:36:04 | 2013-08-21 23:37:12 | 2013-08-21 23:37:12 | test_flavor | 7 | 4598 | 1 | 0 | NULL | 22 | 1 | 0 | 0 | 0 | 1 | 7 |
| 2013-08-21 23:37:23 | 2013-08-21 23:37:29 | 2013-08-21 23:37:29 | test_flavor | 8 | 1916 | 1 | 0 | NULL | 22 | 1 | 0 | 0 | 0 | 1 | 8 |
| 2013-08-21 23:37:36 | 2013-08-21 23:38:30 | 2013-08-21 23:38:30 | tmp | 9 | 512 | 1 | 0 | NULL | 20 | 1 | 0 | 0 | 0 | 1 | 9 |
| 2013-08-22 01:41:48 | 2013-08-22 01:42:42 | 2013-08-22 01:42:42 | tmp | 10 | 1024 | 8 | 0 | NULL | 20 | 1 | 0 | 0 | 0 | 1 | 10 |
| 2013-08-22 01:43:00 | 2013-08-22 01:45:11 | 2013-08-22 01:45:11 | tmp | 11 | 1024 | 3 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 11 |
| 2013-08-22 01:45:13 | 2013-08-22 01:47:14 | 2013-08-22 01:47:14 | tmp | 12 | 1024 | 3 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 12 |
| 2013-08-22 01:47:17 | 2013-08-22 01:49:18 | 2013-08-22 01:49:18 | tmp | 13 | 1024 | 3 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 13 |
| 2013-08-22 01:49:20 | 2013-08-22 01:51:26 | 2013-08-22 01:51:26 | tmp | 14 | 1024 | 9 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 14 |
| 2013-08-22 01:51:29 | 2013-08-22 01:53:30 | 2013-08-22 01:53:30 | tmp | 15 | 1024 | 9 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 15 |
| 2013-08-22 01:53:32 | 2013-08-22 01:55:32 | 2013-08-22 01:55:32 | tmp | 16 | 1024 | 9 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 16 |
| 2013-08-22 01:55:57 | 2013-08-22 01:56:28 | 2013-08-22 01:56:28 | tmp | 17 | 1024 | 8 | 0 | NULL | 6 | 1 | 0 | 0 | 0 | 1 | 17 |
+---------------------+---------------------+---------------------+-------------+----+-----------+-------+------+-------------+----------+-------------+---------+-------------

flavor_refs = flavors.get_all_flavors(self.ctxt, inactive=True)

(Pdb) for flavor in flavor_refs.values(): flavor['id']
1L
17L
5L
3L
2L
4L
8L
(Pdb) flavor_refs.keys()
[u'm1.medium', u'tmp', u'm1.small', u'm1.large', u'm1.tiny', u'm1.xlarge', u'test_flavor']

Tags: db
chieh chu (chieh-chu)
Changed in nova:
assignee: nobody → chieh chu (chieh-chu)
tags: added: db
Changed in nova:
status: New → In Progress
Changed in nova:
assignee: chieh chu (chieh-chu) → Joshua Hesketh (joshua.hesketh)
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/45819

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

Reviewed: https://review.openstack.org/45819
Committed: http://github.com/openstack/nova/commit/3dc84154db18f1112f2023e75a5472bcf28b8f84
Submitter: Jenkins
Branch: master

commit 3dc84154db18f1112f2023e75a5472bcf28b8f84
Author: Joshua Hesketh <email address hidden>
Date: Tue Sep 10 17:00:30 2013 +1000

    Ensure get_all_flavors returns deleted items

    When a flavor is deleted a new one may be created with the same name.
    However when calling flavors.get_all_flavors(inactive=True) only the
    latest flavor with the same name is returned. When inactive=True all
    flavors should be returned regardless of their name or replacement
    state.

    Change the key used in the returned dictionary from
    flavors.get_all_flavors() to the flavorid rather than the name. This
    allows multiple flavors with the same name to be returned.

    Fixes bug 1215295
    Change-Id: I1b0c93b3e12714a5c0798aa87c9e3fe9bc14519a

Changed in nova:
status: In Progress → Fix Committed
Changed in nova:
milestone: none → havana-rc1
Revision history for this message
Vish Ishaya (vishvananda) wrote :

Setting this back to triaged because I disagree with the fix. Both name and flavorid are unique string keys, so you have just swapped one for the other. Now get_all_flavors will only return the latest version of a deleted flavor with the same flavorid. If you really want all copies the key needs to be 'id' which is autoinc and unique across all rows.

Changed in nova:
importance: Undecided → Medium
status: Fix Committed → Triaged
Revision history for this message
Joshua Hesketh (joshua.hesketh) wrote :

Well caught Vish.

I've set the dictionary to 'id' here https://review.openstack.org/#/c/48570/

Sorry for the mistake!

Changed in nova:
status: Triaged → In Progress
Thierry Carrez (ttx)
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-rc1 → 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.