The nova.tests.test_migrations Module

Tests for database migrations. This test case reads the configuration file test_migrations.conf for database connection settings to use in the tests. For each connection found in the config file, the test case runs a series of test cases to ensure that migrations work properly both upgrading and downgrading, and that no data loss occurs if possible.

There are also “opportunistic” tests for both mysql and postgresql in here, which allows testing against all 3 databases (sqlite in memory, mysql, pg) in a properly configured unit test environment.

For the opportunistic testing you need to set up a db named ‘openstack_citest’ with user ‘openstack_citest’ and password ‘openstack_citest’ on localhost. The test will then use that db and u/p combo to run the tests.

For postgres on Ubuntu this can be done with the following commands:

sudo -u postgres psql postgres=# create user openstack_citest with createdb login password

‘openstack_citest’;

postgres=# create database openstack_citest with owner openstack_citest;

class BaseMigrationTestCase(*args, **kwargs)

Bases: nova.test.TestCase

Base class fort testing migrations and migration utils.

DATABASE = None
PASSWD = None
USER = None
execute_cmd(cmd=None)
setUp()
tearDown()
class CommonTestsMixIn

Bases: object

These tests are shared between TestNovaMigrations and TestBaremetalMigrations.

BaseMigrationTestCase is effectively an abstract class, meant to be derived from and not directly tested against; that’s why these test_ methods need to be on a Mixin, so that they won’t be picked up as valid tests for BaseMigrationTestCase.

test_mysql_connect_fail()

Test that we can trigger a mysql connection failure and we fail gracefully to ensure we don’t break people without mysql

test_mysql_opportunistically()
test_postgresql_connect_fail()

Test that we can trigger a postgres connection failure and we fail gracefully to ensure we don’t break people without postgres

test_postgresql_opportunistically()
test_walk_versions()
class TestBaremetalMigrations(*args, **kwargs)

Bases: nova.tests.test_migrations.BaseMigrationTestCase, nova.tests.test_migrations.CommonTestsMixIn

Test sqlalchemy-migrate migrations.

DATABASE = 'openstack_baremetal_citest'
PASSWD = 'openstack_citest'
USER = 'openstack_citest'
setUp()
class TestNovaMigrations(*args, **kwargs)

Bases: nova.tests.test_migrations.BaseMigrationTestCase, nova.tests.test_migrations.CommonTestsMixIn

Test sqlalchemy-migrate migrations.

DATABASE = 'openstack_citest'
PASSWD = 'openstack_citest'
USER = 'openstack_citest'
setUp()
get_mysql_connection_info(conn_pieces)
get_pgsql_connection_info(conn_pieces)
get_table(engine, name)

Returns an sqlalchemy table dynamically from db.

Needed because the models don’t work for us in migrations as models will be far out of sync with the current data.

Previous topic

The nova.tests.test_migration_utils Module

Next topic

The nova.tests.test_misc Module

This Page