]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
neutron-db-manage: sync HEADS file with 'current' output
authorIhar Hrachyshka <ihrachys@redhat.com>
Thu, 20 Aug 2015 09:50:09 +0000 (11:50 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Thu, 20 Aug 2015 09:54:12 +0000 (11:54 +0200)
alembic.get_heads() returns all heads for all branches it can find in
scripts dir, while in alembic_version table, it does not store any heads
that were overridden by other branches, even if those depends_on it
instead of having it as down_revision.

To keep 'current' output in sync with what is in HEADS file, we can
attach liberty_* branches explicitly to kilo revision.

It's also a good idea to have a separate 'heads' command that would show
the latest alembic heads based on scripts dir state. See [1] for more
details.

While at it, since different subprojects can link their expand/contract
branches to kilo in different way (some using depends_on the previous
release branch, while others, as suggested in this patch, thru
down_revision to kilo), we kill the check on the number of heads
returned by script.get_heads() since it may differ. If we want to
validate that we don't branch more than twice from kilo, we may add a
separate validation just for that.

[1]: https://review.openstack.org/#/c/204551/

Change-Id: If551633ab26e0eac549c1e13cfa0771383a1a060
Partially-Implements: blueprint online-schema-migrations

neutron/db/migration/alembic_migrations/versions/HEADS
neutron/db/migration/alembic_migrations/versions/liberty/contract/30018084ec99_initial.py
neutron/db/migration/alembic_migrations/versions/liberty/expand/354db87e3225_nsxv_vdr_metadata.py
neutron/db/migration/cli.py
neutron/tests/unit/db/test_migration.py

index c4140b06d89860419b566595dd42422dff17cd4e..75dcdf9736907fdb52ee30cda8e5f3b6f2dfa5ee 100644 (file)
@@ -1,3 +1,2 @@
 2a16083502f3
 9859ac9c136
-kilo
index bd1ddccf930ccff05c5f5ea5a136e0fcaab00505..a4a26704cd918aba38dbcf1af127073a2204e8ff 100644 (file)
@@ -21,8 +21,7 @@ Create Date: 2015-06-22 00:00:00.000000
 
 # revision identifiers, used by Alembic.
 revision = '30018084ec99'
-down_revision = None
-depends_on = ('kilo',)
+down_revision = 'kilo'
 branch_labels = ('liberty_contract',)
 
 
index df82f17c936047d876b25d4a01caeb651f6d0bc3..33d521abbacaf5e146828fc01c6f5efddd721fcf 100644 (file)
@@ -23,9 +23,8 @@ Create Date: 2015-04-19 14:59:15.102609
 
 # revision identifiers, used by Alembic.
 revision = '354db87e3225'
-down_revision = None
+down_revision = 'kilo'
 branch_labels = ('liberty_expand',)
-depends_on = ('kilo',)
 
 from alembic import op
 import sqlalchemy as sa
index f346329fd5ec71271e940c7944280dd2deb6d2c4..7b1cee435a7b577a5ab9521b10c7c498d086bc4f 100644 (file)
@@ -255,12 +255,7 @@ def validate_labels(config):
 
 def _get_sorted_heads(script):
     '''Get the list of heads for all branches, sorted.'''
-    heads = script.get_heads()
-    # +1 stands for the core 'kilo' branch, the one that didn't have branches
-    if len(heads) > len(MIGRATION_BRANCHES) + 1:
-        alembic_util.err(_('No new branches are allowed except: %s') %
-                         ' '.join(MIGRATION_BRANCHES))
-    return sorted(heads)
+    return sorted(script.get_heads())
 
 
 def validate_heads_file(config):
index ba6e3959cbe52a931a96c7c2c4c2f9548ec920a9..35e882e8240febe2895c9f82cc6c6bebd2351c93 100644 (file)
@@ -324,17 +324,6 @@ class TestCli(base.BaseTestCase):
                 mock_open.return_value.write.assert_called_once_with(
                     '\n'.join(sorted(heads)))
 
-    def test_update_heads_file_excessive_heads_negative(self):
-        with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
-            heads = ('b', 'a', 'c', 'kilo')
-            fc.return_value.get_heads.return_value = heads
-            self.assertRaises(
-                SystemExit,
-                cli.update_heads_file,
-                mock.sentinel.config
-            )
-            self.mock_alembic_err.assert_called_once_with(mock.ANY)
-
     @mock.patch('os.path.exists')
     @mock.patch('os.remove')
     def test_update_heads_file_success(self, *os_mocks):