Merge "Make the status_reason field Text instead of String(255)"

This commit is contained in:
Jenkins 2015-03-25 12:54:42 +00:00 committed by Gerrit Code Review
commit dacf488e17
5 changed files with 45 additions and 29 deletions

View File

@ -0,0 +1,32 @@
#
# 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
def upgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
for tab_name in ['stack', 'resource', 'software_deployment']:
table = sqlalchemy.Table(tab_name, meta, autoload=True)
table.c.status_reason.alter(type=sqlalchemy.Text)
def downgrade(migrate_engine):
meta = sqlalchemy.MetaData()
meta.bind = migrate_engine
for tab_name in ['stack', 'resource', 'software_deployment']:
table = sqlalchemy.Table(tab_name, meta, autoload=True)
table.c.status_reason.alter(type=sqlalchemy.String(255))

View File

@ -86,18 +86,9 @@ class SoftDelete(object):
class StateAware(object):
action = sqlalchemy.Column('action', sqlalchemy.String(255))
status = sqlalchemy.Column('status', sqlalchemy.String(255))
_status_reason = sqlalchemy.Column('status_reason', sqlalchemy.String(255))
@property
def status_reason(self):
return self._status_reason
@status_reason.setter
def status_reason(self, reason):
self._status_reason = reason and reason[:255] or ''
status_reason = sqlalchemy.Column('status_reason', sqlalchemy.Text)
class RawTemplate(BASE, HeatBase):

View File

@ -48,9 +48,7 @@ class SoftwareDeployment(base.VersionedObject,
@staticmethod
def _from_db_object(context, deployment, db_deployment):
for field in deployment.fields:
if field == 'status_reason':
deployment[field] = db_deployment['_status_reason']
elif field == 'config':
if field == 'config':
deployment[field] = (
software_config.SoftwareConfig._from_db_object(
context, software_config.SoftwareConfig(),

View File

@ -30,6 +30,7 @@ from oslo_db.sqlalchemy import test_migrations
from oslo_db.sqlalchemy import utils
from oslo_serialization import jsonutils
import six
import sqlalchemy
from heat.db.sqlalchemy import migrate_repo
from heat.db.sqlalchemy import migration
@ -72,6 +73,11 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
t = utils.get_table(engine, table)
self.assertIn(column, t.c)
def assertColumnType(self, engine, table, column, sqltype):
t = utils.get_table(engine, table)
col = getattr(t.c, column)
self.assertIsInstance(col.type, sqltype)
def assertColumnNotExists(self, engine, table, column):
t = utils.get_table(engine, table)
self.assertNotIn(column, t.c)
@ -586,6 +592,11 @@ class HeatMigrationsCheckers(test_migrations.WalkVersionsMixin,
for column in column_list:
self.assertColumnExists(engine, 'resource', column)
def _check_061(self, engine, data):
for tab_name in ['stack', 'resource', 'software_deployment']:
self.assertColumnType(engine, tab_name, 'status_reason',
sqlalchemy.Text)
class TestHeatMigrationsMySQL(HeatMigrationsCheckers,
test_base.MySQLOpportunisticTestCase):

View File

@ -1572,11 +1572,6 @@ class DBAPIStackTest(common.HeatTestCase):
self.assertIsNone(db_api.stack_get(ctx, stacks[s].id,
show_deleted=True))
def test_stack_status_reason_truncate(self):
stack = create_stack(self.ctx, self.template, self.user_creds,
status_reason='a' * 1024)
self.assertEqual('a' * 255, stack.status_reason)
class DBAPIResourceTest(common.HeatTestCase):
def setUp(self):
@ -1663,12 +1658,6 @@ class DBAPIResourceTest(common.HeatTestCase):
self.assertRaises(exception.NotFound, db_api.resource_get_all_by_stack,
self.ctx, self.stack2.id)
def test_resource_status_reason_truncate(self):
res = create_resource(self.ctx, self.stack,
status_reason='a' * 1024)
ret_res = db_api.resource_get(self.ctx, res.id)
self.assertEqual('a' * 255, ret_res.status_reason)
class DBAPIStackLockTest(common.HeatTestCase):
def setUp(self):
@ -1894,11 +1883,6 @@ class DBAPIEventTest(common.HeatTestCase):
self.assertEqual(1, db_api.event_count_all_by_stack(self.ctx,
self.stack2.id))
def test_event_resource_status_reason_truncate(self):
event = create_event(self.ctx, resource_status_reason='a' * 1024)
ret_event = db_api.event_get(self.ctx, event.id)
self.assertEqual('a' * 255, ret_event.resource_status_reason)
class DBAPIWatchRuleTest(common.HeatTestCase):
def setUp(self):