summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oslo/db/openstack/common/__init__.py5
-rw-r--r--oslo/db/sqlalchemy/migration.py2
-rw-r--r--oslo/db/sqlalchemy/test_migrations.py46
-rw-r--r--requirements.txt4
-rw-r--r--test-requirements.txt4
-rw-r--r--tests/sqlalchemy/test_migrations.py58
6 files changed, 73 insertions, 46 deletions
diff --git a/oslo/db/openstack/common/__init__.py b/oslo/db/openstack/common/__init__.py
index d1223ea..9dd8c3a 100644
--- a/oslo/db/openstack/common/__init__.py
+++ b/oslo/db/openstack/common/__init__.py
@@ -10,8 +10,3 @@
# 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 six
-
-
-six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
diff --git a/oslo/db/sqlalchemy/migration.py b/oslo/db/sqlalchemy/migration.py
index d7a17b3..f1cecdd 100644
--- a/oslo/db/sqlalchemy/migration.py
+++ b/oslo/db/sqlalchemy/migration.py
@@ -93,7 +93,7 @@ def _db_schema_sanity_check(engine):
onlyutf8_sql = ('SELECT TABLE_NAME,TABLE_COLLATION '
'from information_schema.TABLES '
'where TABLE_SCHEMA=%s and '
- 'TABLE_COLLATION NOT LIKE "%%utf8%%"')
+ 'TABLE_COLLATION NOT LIKE \'%%utf8%%\'')
# NOTE(morganfainberg): exclude the sqlalchemy-migrate and alembic
# versioning tables from the tables we need to verify utf8 status on.
diff --git a/oslo/db/sqlalchemy/test_migrations.py b/oslo/db/sqlalchemy/test_migrations.py
index bdd7c6e..8bfdcfb 100644
--- a/oslo/db/sqlalchemy/test_migrations.py
+++ b/oslo/db/sqlalchemy/test_migrations.py
@@ -50,7 +50,7 @@ class WalkVersionsMixin(object):
Auxiliary methods
-----------------
- `_migrate_up` and `_migrate_down` instance methods of the class can be
+ `migrate_up` and `migrate_down` instance methods of the class can be
used with auxiliary methods named `_pre_upgrade_<revision_id>`,
`_check_<revision_id>`, `_post_downgrade_<revision_id>`. The methods
intended to check applied changes for correctness of data operations.
@@ -127,14 +127,38 @@ class WalkVersionsMixin(object):
def _walk_versions(self, snake_walk=False, downgrade=True):
"""Check if migration upgrades and downgrades successfully.
+ DEPRECATED: this function is deprecated and will be removed from
+ oslo.db in a few releases. Please use walk_versions() method instead.
+ """
+ self.walk_versions(snake_walk, downgrade)
+
+ def _migrate_down(self, version, with_data=False):
+ """Migrate down to a previous version of the db.
+
+ DEPRECATED: this function is deprecated and will be removed from
+ oslo.db in a few releases. Please use migrate_down() method instead.
+ """
+ return self.migrate_down(version, with_data)
+
+ def _migrate_up(self, version, with_data=False):
+ """Migrate up to a new version of the db.
+
+ DEPRECATED: this function is deprecated and will be removed from
+ oslo.db in a few releases. Please use migrate_up() method instead.
+ """
+ self.migrate_up(version, with_data)
+
+ def walk_versions(self, snake_walk=False, downgrade=True):
+ """Check if migration upgrades and downgrades successfully.
+
Determine the latest version script from the repo, then
upgrade from 1 through to the latest, with no data
in the databases. This just checks that the schema itself
upgrades successfully.
- `_walk_versions` calls `_migrate_up` and `_migrate_down` with
+ `walk_versions` calls `migrate_up` and `migrate_down` with
`with_data` argument to check changes with data, but these methods
- can be called without any extra check outside of `_walk_versions`
+ can be called without any extra check outside of `walk_versions`
method.
:param snake_walk: enables checking that each individual migration can
@@ -165,24 +189,24 @@ class WalkVersionsMixin(object):
for version in versions:
# upgrade -> downgrade -> upgrade
- self._migrate_up(version, with_data=True)
+ self.migrate_up(version, with_data=True)
if snake_walk:
- downgraded = self._migrate_down(version - 1, with_data=True)
+ downgraded = self.migrate_down(version - 1, with_data=True)
if downgraded:
- self._migrate_up(version)
+ self.migrate_up(version)
if downgrade:
# Now walk it back down to 0 from the latest, testing
# the downgrade paths.
for version in reversed(versions):
# downgrade -> upgrade -> downgrade
- downgraded = self._migrate_down(version - 1)
+ downgraded = self.migrate_down(version - 1)
if snake_walk and downgraded:
- self._migrate_up(version)
- self._migrate_down(version - 1)
+ self.migrate_up(version)
+ self.migrate_down(version - 1)
- def _migrate_down(self, version, with_data=False):
+ def migrate_down(self, version, with_data=False):
"""Migrate down to a previous version of the db.
:param version: id of revision to downgrade.
@@ -215,7 +239,7 @@ class WalkVersionsMixin(object):
return True
- def _migrate_up(self, version, with_data=False):
+ def migrate_up(self, version, with_data=False):
"""Migrate up to a new version of the db.
:param version: id of revision to upgrade.
diff --git a/requirements.txt b/requirements.txt
index 1483c6f..a2c2f6e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,7 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+
alembic>=0.6.4
Babel>=1.3
iso8601>=0.1.9
diff --git a/test-requirements.txt b/test-requirements.txt
index f438aca..1a190ca 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,3 +1,7 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+
hacking>=0.9.2,<0.10
coverage>=3.6
diff --git a/tests/sqlalchemy/test_migrations.py b/tests/sqlalchemy/test_migrations.py
index ed93c3d..df331d4 100644
--- a/tests/sqlalchemy/test_migrations.py
+++ b/tests/sqlalchemy/test_migrations.py
@@ -39,7 +39,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
def test_migrate_up(self):
self.migration_api.db_version.return_value = 141
- self._migrate_up(141)
+ self.migrate_up(141)
self.migration_api.upgrade.assert_called_with(
self.engine, self.REPOSITORY, 141)
@@ -57,7 +57,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
'upgrade',
side_effect=exc.DbMigrationError):
log = self.useFixture(fixtures.FakeLogger())
- self.assertRaises(exc.DbMigrationError, self._migrate_up, version)
+ self.assertRaises(exc.DbMigrationError, self.migrate_up, version)
self.assertEqual(expected_output, log.output)
def test_migrate_up_with_data(self):
@@ -67,7 +67,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
self._pre_upgrade_141.return_value = test_value
self._check_141 = mock.MagicMock()
- self._migrate_up(141, True)
+ self.migrate_up(141, True)
self._pre_upgrade_141.assert_called_with(self.engine)
self._check_141.assert_called_with(self.engine, test_value)
@@ -75,7 +75,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
def test_migrate_down(self):
self.migration_api.db_version.return_value = 42
- self.assertTrue(self._migrate_down(42))
+ self.assertTrue(self.migrate_down(42))
self.migration_api.db_version.assert_called_with(
self.engine, self.REPOSITORY)
@@ -83,23 +83,23 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
with mock.patch.object(self.migration_api,
'downgrade',
side_effect=NotImplementedError):
- self.assertFalse(self._migrate_down(self.engine, 42))
+ self.assertFalse(self.migrate_down(self.engine, 42))
def test_migrate_down_with_data(self):
self._post_downgrade_043 = mock.MagicMock()
self.migration_api.db_version.return_value = 42
- self._migrate_down(42, True)
+ self.migrate_down(42, True)
self._post_downgrade_043.assert_called_with(self.engine)
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_up')
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_down')
- def test_walk_versions_all_default(self, _migrate_up, _migrate_down):
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_up')
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_down')
+ def test_walk_versions_all_default(self, migrate_up, migrate_down):
self.REPOSITORY.latest = 20
self.migration_api.db_version.return_value = self.INIT_VERSION
- self._walk_versions()
+ self.walk_versions()
self.migration_api.version_control.assert_called_with(
self.engine, self.REPOSITORY, self.INIT_VERSION)
@@ -109,18 +109,18 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
versions = range(self.INIT_VERSION + 1, self.REPOSITORY.latest + 1)
upgraded = [mock.call(v, with_data=True)
for v in versions]
- self.assertEqual(self._migrate_up.call_args_list, upgraded)
+ self.assertEqual(self.migrate_up.call_args_list, upgraded)
downgraded = [mock.call(v - 1) for v in reversed(versions)]
- self.assertEqual(self._migrate_down.call_args_list, downgraded)
+ self.assertEqual(self.migrate_down.call_args_list, downgraded)
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_up')
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_down')
- def test_walk_versions_all_true(self, _migrate_up, _migrate_down):
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_up')
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_down')
+ def test_walk_versions_all_true(self, migrate_up, migrate_down):
self.REPOSITORY.latest = 20
self.migration_api.db_version.return_value = self.INIT_VERSION
- self._walk_versions(snake_walk=True, downgrade=True)
+ self.walk_versions(snake_walk=True, downgrade=True)
versions = range(self.INIT_VERSION + 1, self.REPOSITORY.latest + 1)
upgraded = []
@@ -128,7 +128,7 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
upgraded.append(mock.call(v, with_data=True))
upgraded.append(mock.call(v))
upgraded.extend([mock.call(v) for v in reversed(versions)])
- self.assertEqual(upgraded, self._migrate_up.call_args_list)
+ self.assertEqual(upgraded, self.migrate_up.call_args_list)
downgraded_1 = [mock.call(v - 1, with_data=True) for v in versions]
downgraded_2 = []
@@ -136,15 +136,15 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
downgraded_2.append(mock.call(v - 1))
downgraded_2.append(mock.call(v - 1))
downgraded = downgraded_1 + downgraded_2
- self.assertEqual(self._migrate_down.call_args_list, downgraded)
+ self.assertEqual(self.migrate_down.call_args_list, downgraded)
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_up')
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_down')
- def test_walk_versions_true_false(self, _migrate_up, _migrate_down):
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_up')
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_down')
+ def test_walk_versions_true_false(self, migrate_up, migrate_down):
self.REPOSITORY.latest = 20
self.migration_api.db_version.return_value = self.INIT_VERSION
- self._walk_versions(snake_walk=True, downgrade=False)
+ self.walk_versions(snake_walk=True, downgrade=False)
versions = range(self.INIT_VERSION + 1, self.REPOSITORY.latest + 1)
@@ -152,23 +152,23 @@ class TestWalkVersions(test.BaseTestCase, migrate.WalkVersionsMixin):
for v in versions:
upgraded.append(mock.call(v, with_data=True))
upgraded.append(mock.call(v))
- self.assertEqual(upgraded, self._migrate_up.call_args_list)
+ self.assertEqual(upgraded, self.migrate_up.call_args_list)
downgraded = [mock.call(v - 1, with_data=True) for v in versions]
- self.assertEqual(self._migrate_down.call_args_list, downgraded)
+ self.assertEqual(self.migrate_down.call_args_list, downgraded)
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_up')
- @mock.patch.object(migrate.WalkVersionsMixin, '_migrate_down')
- def test_walk_versions_all_false(self, _migrate_up, _migrate_down):
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_up')
+ @mock.patch.object(migrate.WalkVersionsMixin, 'migrate_down')
+ def test_walk_versions_all_false(self, migrate_up, migrate_down):
self.REPOSITORY.latest = 20
self.migration_api.db_version.return_value = self.INIT_VERSION
- self._walk_versions(snake_walk=False, downgrade=False)
+ self.walk_versions(snake_walk=False, downgrade=False)
versions = range(self.INIT_VERSION + 1, self.REPOSITORY.latest + 1)
upgraded = [mock.call(v, with_data=True) for v in versions]
- self.assertEqual(upgraded, self._migrate_up.call_args_list)
+ self.assertEqual(upgraded, self.migrate_up.call_args_list)
class ModelsMigrationSyncMixin(test.BaseTestCase):