The migration script to add description for limit
This patch add the db migration script to add the description column for registred limit/project limit table. Partial-Bug: #1754185 Change-Id: I29d0c054fc6aa72c34564d0169e45090ebd8f13e
This commit is contained in:
parent
15906cc4ca
commit
403917cef9
@ -0,0 +1,15 @@
|
||||
# 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):
|
||||
pass
|
@ -0,0 +1,15 @@
|
||||
# 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):
|
||||
pass
|
@ -0,0 +1,29 @@
|
||||
# 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.
|
||||
|
||||
import sqlalchemy as sql
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
|
||||
meta = sql.MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
registered_limit_table = sql.Table(
|
||||
'registered_limit', meta, autoload=True
|
||||
)
|
||||
description = sql.Column('description', sql.Text)
|
||||
registered_limit_table.create_column(description)
|
||||
|
||||
limit_table = sql.Table('limit', meta, autoload=True)
|
||||
description = sql.Column('description', sql.Text)
|
||||
limit_table.create_column(description)
|
@ -2930,6 +2930,91 @@ class FullMigration(SqlMigrateBase, unit.TestCase):
|
||||
self.metadata, autoload=True)
|
||||
self.assertEqual(set([]), registered_limit_table.foreign_keys)
|
||||
|
||||
def test_migration_045_add_description_to_limit(self):
|
||||
|
||||
self.expand(44)
|
||||
self.migrate(44)
|
||||
self.contract(44)
|
||||
|
||||
registered_limit_table_name = 'registered_limit'
|
||||
limit_table_name = 'limit'
|
||||
|
||||
self.assertTableExists(registered_limit_table_name)
|
||||
self.assertTableExists(limit_table_name)
|
||||
self.assertTableColumns(
|
||||
registered_limit_table_name,
|
||||
['id', 'service_id', 'region_id', 'resource_name', 'default_limit']
|
||||
)
|
||||
self.assertTableColumns(
|
||||
limit_table_name,
|
||||
['id', 'project_id', 'service_id', 'region_id', 'resource_name',
|
||||
'resource_limit']
|
||||
)
|
||||
|
||||
self.expand(45)
|
||||
self.migrate(45)
|
||||
self.contract(45)
|
||||
|
||||
registered_limit_table = sqlalchemy.Table(registered_limit_table_name,
|
||||
self.metadata, autoload=True)
|
||||
limit_table = sqlalchemy.Table(limit_table_name,
|
||||
self.metadata, autoload=True)
|
||||
self.assertTableColumns(
|
||||
registered_limit_table_name,
|
||||
['id', 'service_id', 'region_id', 'resource_name', 'default_limit',
|
||||
'description']
|
||||
)
|
||||
self.assertTableColumns(
|
||||
limit_table_name,
|
||||
['id', 'project_id', 'service_id', 'region_id', 'resource_name',
|
||||
'resource_limit', 'description']
|
||||
)
|
||||
|
||||
session = self.sessionmaker()
|
||||
service_id = uuid.uuid4().hex
|
||||
service = {
|
||||
'id': service_id,
|
||||
'type': 'compute',
|
||||
'enabled': True
|
||||
}
|
||||
region = {
|
||||
'id': 'RegionOne',
|
||||
'description': 'test'
|
||||
}
|
||||
project_id = uuid.uuid4().hex
|
||||
project = {
|
||||
'id': project_id,
|
||||
'name': 'nova',
|
||||
'enabled': True,
|
||||
'domain_id': resource_base.NULL_DOMAIN_ID,
|
||||
'is_domain': False
|
||||
}
|
||||
self.insert_dict(session, 'service', service)
|
||||
self.insert_dict(session, 'region', region)
|
||||
self.insert_dict(session, 'project', project)
|
||||
|
||||
# with description
|
||||
registered_limit = {
|
||||
'id': uuid.uuid4().hex,
|
||||
'service_id': service_id,
|
||||
'region_id': 'RegionOne',
|
||||
'resource_name': 'cores',
|
||||
'default_limit': 10,
|
||||
'description': 'this is a description'
|
||||
}
|
||||
registered_limit_table.insert().values(registered_limit).execute()
|
||||
|
||||
# without description
|
||||
limit = {
|
||||
'id': uuid.uuid4().hex,
|
||||
'project_id': project_id,
|
||||
'service_id': service_id,
|
||||
'region_id': 'RegionOne',
|
||||
'resource_name': 'cores',
|
||||
'resource_limit': 5
|
||||
}
|
||||
limit_table.insert().values(limit).execute()
|
||||
|
||||
|
||||
class MySQLOpportunisticFullMigration(FullMigration):
|
||||
FIXTURE = db_fixtures.MySQLOpportunisticFixture
|
||||
|
Loading…
Reference in New Issue
Block a user