summaryrefslogtreecommitdiff
path: root/nova/objects/flavor.py
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2016-12-30 12:27:48 -0500
committerMatt Riedemann <mriedem@us.ibm.com>2016-12-30 12:27:48 -0500
commiteda54b1ed73b0c102f4352e1522e34908dc7c17f (patch)
tree41bb6a064a20f4a854c667f2ae7e609f5bad5856 /nova/objects/flavor.py
parent641f5f4529509debef6e8e58f01a2ea20109c0be (diff)
downloadnova-eda54b1ed73b0c102f4352e1522e34908dc7c17f.tar.gz
Handle unicode when dealing with duplicate flavors during online migrations
In python 2.7 you can't cast unicode to str and you'll get a UnicodeEncodeError if you try. Since our exception messages are translated, they can contain unicode and if we hit a duplicate flavor exception while performing online flavor migrations it will break the migration and block any further migrations until resolved - which would require manual intervention. This patch fixes the bug so that we use six.text_type instead of str for logging the duplicate exception and adds a test to exhibit the bug and prove it's fixed. On a side note, it's curious that we don't delete the duplicate flavor from the main database during the online data migration, but it's also strange that you'd have duplicates in the API database because the Flavor.create() checks to see if all flavors have been migrated from the main DB to the API DB and if not you can't create new flavors in the API DB - so the only way to get the duplicates is either by inserting them into the API DB manually or perhaps some other kind of race issue. Anyway, that's not dealt with here. Change-Id: I3bdb1a8ca72c3e72ddc3bc5102cff8df18148617 Partial-Bug: #1653261
Diffstat (limited to 'nova/objects/flavor.py')
-rw-r--r--nova/objects/flavor.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/nova/objects/flavor.py b/nova/objects/flavor.py
index 0f93e8bb6e..37f6c9006d 100644
--- a/nova/objects/flavor.py
+++ b/nova/objects/flavor.py
@@ -15,6 +15,7 @@
from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_log import log as logging
+import six
from sqlalchemy import or_
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.expression import asc
@@ -723,7 +724,7 @@ def migrate_flavors(ctxt, count, hard_delete=False):
LOG.warning(_LW('Flavor id %(id)i disappeared during migration'),
{'id': flavor_id})
except (exception.FlavorExists, exception.FlavorIdExists) as e:
- LOG.error(str(e))
+ LOG.error(six.text_type(e))
return count_all, count_hit