summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwingwj <wingwj@gmail.com>2014-03-10 14:35:13 +0800
committerwingwj <wingwj@gmail.com>2014-03-19 11:54:43 +0800
commit9f89c30742abc18eb856022d18976e2685257e1a (patch)
tree6112f5337cc9b9de8470ea7f9527b08488c341a5
parente965ca016e7e1421398b29007013520a0a9f9c09 (diff)
downloadnova-9f89c30742abc18eb856022d18976e2685257e1a.tar.gz
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 4bbb4d88595cfd5f75528d8789be94d0ec9fbe62)
-rw-r--r--nova/db/sqlalchemy/api.py1
-rw-r--r--nova/tests/db/test_db_api.py15
2 files changed, 16 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 1a2c07dd7e..d32a720a14 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -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)
diff --git a/nova/tests/db/test_db_api.py b/nova/tests/db/test_db_api.py
index e6c4a80bdf..6a2cf8e872 100644
--- a/nova/tests/db/test_db_api.py
+++ b/nova/tests/db/test_db_api.py
@@ -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):