summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2016-02-08 14:26:44 -0800
committerDan Smith <dansmith@redhat.com>2016-02-09 10:54:08 -0800
commit526ec7ca655ec0d4c61e532189816a96496c0d5c (patch)
tree63d3d511ae9c03697e1b1d9fb0bb5a823f950570 /tools
parentf0178101ceec31b9f20ff129c229178b6602701a (diff)
downloadnova-526ec7ca655ec0d4c61e532189816a96496c0d5c.tar.gz
Add a tool for reserving migration placeholders during release time
This adds a tool to make it easy to reserve placeholder migrations after we do a release. This is something we have to do each time we do a release, and it can be somewhat silly in terms of mechanical work. This adds a script to make it trivially easy. Change-Id: I34c11f1aee64ad36887779f1c9ca4491a25580ec
Diffstat (limited to 'tools')
-rwxr-xr-xtools/reserve-migrations.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/reserve-migrations.py b/tools/reserve-migrations.py
new file mode 100755
index 0000000000..080fb3889a
--- /dev/null
+++ b/tools/reserve-migrations.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+import argparse
+import glob
+import os
+import subprocess
+
+BASE = 'nova/db/sqlalchemy/migrate_repo/versions'.split('/')
+API_BASE = 'nova/db/sqlalchemy/api_migrations/migrate_repo/versions'.split('/')
+
+STUB = """
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# This is a placeholder for backports.
+# Do not use this number for new work. New work starts after
+# all the placeholders.
+#
+# See this for more information:
+# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html
+
+
+def upgrade(migrate_engine):
+ pass
+"""
+
+
+def get_last_migration(base):
+ path = os.path.join(*tuple(base + ['[0-9]*.py']))
+ migrations = sorted([os.path.split(fn)[-1] for fn in glob.glob(path)])
+ return int(migrations[-1].split('_')[0])
+
+
+def reserve_migrations(base, number, git_add):
+ last = get_last_migration(base)
+ for i in range(last + 1, last + number + 1):
+ name = '%03i_placeholder.py' % i
+ path = os.path.join(*tuple(base + [name]))
+ with open(path, 'w') as f:
+ f.write(STUB)
+ print('Created %s' % path)
+ if git_add:
+ subprocess.call('git add %s' % path, shell=True)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-n', '--number', default=10,
+ type=int,
+ help='Number of migrations to reserve')
+ parser.add_argument('-g', '--git-add', action='store_const',
+ const=True, default=False,
+ help='Automatically git-add new migrations')
+ parser.add_argument('-a', '--api', action='store_const',
+ const=True, default=False,
+ help='Reserve migrations for the API database')
+ args = parser.parse_args()
+ if args.api:
+ base = API_BASE
+ else:
+ base = BASE
+ reserve_migrations(base, args.number, args.git_add)
+
+
+if __name__ == '__main__':
+ main()