summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorTiago Mello <tmello@linux.vnet.ibm.com>2013-02-04 19:29:00 -0200
committerTiago Mello <tmello@linux.vnet.ibm.com>2013-02-07 11:35:46 -0200
commita2c64cc3dfd287091007c6ddc654367eb04457fe (patch)
tree52cf96b1afb45ce7af50793987f1ac37b3e6e366 /nova
parentd2dad24e0a094827cc4c4e855a7ae43c4c08ce44 (diff)
downloadnova-a2c64cc3dfd287091007c6ddc654367eb04457fe.tar.gz
nova-a2c64cc3dfd287091007c6ddc654367eb04457fe.tar.xz
nova-a2c64cc3dfd287091007c6ddc654367eb04457fe.zip
Adds _(prerun|check)_134 functions to test_migrations
The _prerun_134 function populates the 'bw_usage_cache' table with real data, different in some critical ways, before migrating it. _check_134 function certifies that things were properly migrated. Partially implements bp migration-testing-with-data Change-Id: I4100c8aa3e1c9d2ff4fdb095dba4cb084b5df279
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_migrations.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index 02d7462d2..5d79dee67 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -43,6 +43,7 @@ postgres=# create database openstack_citest with owner openstack_citest;
import collections
import commands
import ConfigParser
+import datetime
import os
import urlparse
@@ -53,6 +54,7 @@ import nova.db.migration as migration
import nova.db.sqlalchemy.migrate_repo
from nova.db.sqlalchemy.migration import versioning_api as migration_api
from nova.openstack.common import log as logging
+from nova.openstack.common import timeutils
from nova import test
@@ -381,6 +383,59 @@ class TestMigrations(test.TestCase):
(version, engine))
raise
+ def _prerun_134(self, engine):
+ now = timeutils.utcnow()
+ data = [{
+ 'id': 1,
+ 'uuid': '1d739808-d7ec-4944-b252-f8363e119755',
+ 'mac': '00:00:00:00:00:01',
+ 'start_period': now,
+ 'last_refreshed': now + datetime.timedelta(seconds=10),
+ 'bw_in': 100000,
+ 'bw_out': 200000,
+ }, {
+ 'id': 2,
+ 'uuid': '1d739808-d7ec-4944-b252-f8363e119756',
+ 'mac': '2a:f2:48:31:c1:60',
+ 'start_period': now,
+ 'last_refreshed': now + datetime.timedelta(seconds=20),
+ 'bw_in': 1000000000,
+ 'bw_out': 200000000,
+ }, {
+ 'id': 3,
+ # This is intended to be the same as above.
+ 'uuid': '1d739808-d7ec-4944-b252-f8363e119756',
+ 'mac': '00:00:00:00:00:02',
+ 'start_period': now,
+ 'last_refreshed': now + datetime.timedelta(seconds=30),
+ 'bw_in': 0,
+ 'bw_out': 0,
+ }]
+
+ bw_usage_cache = get_table(engine, 'bw_usage_cache')
+ engine.execute(bw_usage_cache.insert(), data)
+ return data
+
+ def _check_134(self, engine, data):
+ bw_usage_cache = get_table(engine, 'bw_usage_cache')
+
+ # Checks if both columns have been successfuly created.
+ self.assertIn('last_ctr_in', bw_usage_cache.c)
+ self.assertIn('last_ctr_out', bw_usage_cache.c)
+
+ # Checks if all rows have been inserted.
+ bw_items = bw_usage_cache.select().execute().fetchall()
+ self.assertEqual(len(bw_items), 3)
+
+ bw = bw_usage_cache.select(
+ bw_usage_cache.c.id == 1).execute().first()
+
+ # New columns have 'NULL' as default value.
+ self.assertEqual(bw['last_ctr_in'], None)
+ self.assertEqual(bw['last_ctr_out'], None)
+
+ self.assertEqual(data[0]['mac'], bw['mac'])
+
# migration 146, availability zone transition
def _prerun_146(self, engine):
data = {