Add migration with data test for migration 151

Before the 151 migration test is run, _prerun_151 populates the task_log
table with generated date and time in string format for period_beginning and
period_ending. The _check_151 function checks that the migration from string
to DateTime worked as expected.

Partially implements: blueprint migration-testing-with-data

Change-Id: I6d354741a75804bc490ffefde04c5925dd1a2a90
This commit is contained in:
Kurt Taylor
2013-02-12 11:08:19 -05:00
parent a606c497bd
commit 466dc07d0a

View File

@@ -45,10 +45,10 @@ import commands
import ConfigParser import ConfigParser
import datetime import datetime
import os import os
import sqlalchemy
import urlparse import urlparse
from migrate.versioning import repository from migrate.versioning import repository
import sqlalchemy
import nova.db.migration as migration import nova.db.migration as migration
import nova.db.sqlalchemy.migrate_repo import nova.db.sqlalchemy.migrate_repo
@@ -529,6 +529,32 @@ class TestMigrations(BaseMigrationTestCase):
for row in result: for row in result:
self.assertIn(row['cidr'], iplist) self.assertIn(row['cidr'], iplist)
# migration 151 - changes period_beginning and period_ending to DateTime
def _prerun_151(self, engine):
task_log = get_table(engine, 'task_log')
data = {
'task_name': 'The name of the task',
'state': 'The state of the task',
'host': 'compute-host1',
'period_beginning': str(datetime.datetime(2013, 02, 11)),
'period_ending': str(datetime.datetime(2013, 02, 12)),
'message': 'The task_log message',
}
result = task_log.insert().values(data).execute()
data['id'] = result.inserted_primary_key[0]
return data
def _check_151(self, engine, data):
task_log = get_table(engine, 'task_log')
row = task_log.select(task_log.c.id == data['id']).execute().first()
self.assertTrue(isinstance(row['period_beginning'],
datetime.datetime))
self.assertTrue(isinstance(row['period_ending'],
datetime.datetime))
self.assertEqual(
data['period_beginning'], str(row['period_beginning']))
self.assertEqual(data['period_ending'], str(row['period_ending']))
# migration 152 - convert deleted from boolean to int # migration 152 - convert deleted from boolean to int
def _prerun_152(self, engine): def _prerun_152(self, engine):
host1 = 'compute-host1' host1 = 'compute-host1'