Fix difference between mysql & psql of flavor-show

If you create a new flavor using a deleted flavorid,
the result of flavor-show is different between mysql and psql.

This issue is caused by the different processing for index in each db.

We need to specify the sort-type to avoid the issue.

Change-Id: Ib1029e80c1b981e1ec86d954b63f83650c9b1cc1
Closes-Bug: #1288636
(cherry picked from commit 4bbb4d8859)
This commit is contained in:
wingwj 2014-03-10 14:35:13 +08:00
parent e965ca016e
commit 9f89c30742
2 changed files with 16 additions and 0 deletions

View File

@ -4317,6 +4317,7 @@ def flavor_get_by_flavor_id(context, flavor_id, read_deleted):
"""Returns a dict describing specific flavor_id."""
result = _instance_type_get_query(context, read_deleted=read_deleted).\
filter_by(flavorid=flavor_id).\
order_by(asc("deleted"), asc("id")).\
first()
if not result:
raise exception.FlavorNotFound(flavor_id=flavor_id)

View File

@ -2723,6 +2723,21 @@ class InstanceTypeTestCase(BaseInstanceTypeTestCase):
inst_type['flavorid'], read_deleted='yes')
self.assertEqual(inst_type['id'], inst_type_by_fid['id'])
def test_flavor_get_by_flavor_id_deleted_and_recreat(self):
# NOTE(wingwj): Aims to test difference between mysql and postgresql
# for bug 1288636
param_dict = {'name': 'abc', 'flavorid': '123'}
self._create_inst_type(param_dict)
db.flavor_destroy(self.ctxt, 'abc')
# Recreate the flavor with the same params
flavor = self._create_inst_type(param_dict)
flavor_by_fid = db.flavor_get_by_flavor_id(self.ctxt,
flavor['flavorid'], read_deleted='yes')
self.assertEqual(flavor['id'], flavor_by_fid['id'])
class InstanceTypeExtraSpecsTestCase(BaseInstanceTypeTestCase):