From bb9908c115a2179fc973ca01f932fe5e76eea4a3 Mon Sep 17 00:00:00 2001 From: Kurt Taylor Date: Tue, 12 Feb 2013 11:08:19 -0500 Subject: 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 --- nova/tests/test_migrations.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py index a0c5db9c4..392571bbe 100644 --- a/nova/tests/test_migrations.py +++ b/nova/tests/test_migrations.py @@ -45,10 +45,10 @@ import commands import ConfigParser import datetime import os +import sqlalchemy import urlparse from migrate.versioning import repository -import sqlalchemy import nova.db.migration as migration import nova.db.sqlalchemy.migrate_repo @@ -529,6 +529,32 @@ class TestMigrations(BaseMigrationTestCase): for row in result: 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 def _prerun_152(self, engine): host1 = 'compute-host1' -- cgit