Use utf8_bin collation on the flavor extra-specs table in MySQL

On the MySQL backend, change the collation type on flavor extra-specs
to be utf8_bin, i.e., case-sensitive.

Other backends (e.g., SQLite) are case-sensitive, and the code
around extra-spec duplicate detection assumes this is universally
true.  This author is of the opinion that treating what is essentially
user-input as case-sensitive is a good idea, so assume the code is
correct, and fix the database.

TrivialFix
Change-Id: I64f1cc1b5c604085f879a25cbbd47c04b05e096d
Closes-Bug: 1463948
This commit is contained in:
Nicolas Simonds 2015-06-10 11:59:11 -07:00
parent 4454cf1d26
commit 402b3abf99
3 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,20 @@
# Copyright 2015 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
def upgrade(migrate_engine):
if migrate_engine.name == "mysql":
migrate_engine.execute("ALTER TABLE instance_type_extra_specs "
"CONVERT TO CHARACTER SET utf8 "
"COLLATE utf8_bin;")

View File

@ -1022,6 +1022,7 @@ class InstanceTypeExtraSpecs(BASE, NovaBase):
name=("uniq_instance_type_extra_specs0"
"instance_type_id0key0deleted")
),
{'mysql_collate': 'utf8_bin'},
)
id = Column(Integer, primary_key=True)
key = Column(String(255))

View File

@ -761,6 +761,11 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
def _check_297(self, engine, data):
self.assertColumnExists(engine, 'services', 'forced_down')
def _check_298(self, engine, data):
# NOTE(nic): This is a MySQL-specific migration, and is a no-op from
# the point-of-view of unit tests, since they use SQLite
pass
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
test_base.DbTestCase,