Enhance: Stop upgrade when input version less then 1.9.0

The migration script should failure early when version is not supported

Signed-off-by: DQ <dengq@vmware.com>
This commit is contained in:
DQ 2020-04-01 15:35:49 +08:00
parent e786add88c
commit b2e1905e7a
3 changed files with 12 additions and 3 deletions

View File

@ -1,15 +1,21 @@
import os, sys, importlib, shutil, glob import os, sys, importlib, shutil, glob
from packaging import version
import click import click
from utils.misc import get_realpath from utils.misc import get_realpath
from utils.migration import read_conf, search from utils.migration import read_conf, search
from migrations import accept_versions
@click.command() @click.command()
@click.option('-i', '--input', 'input_', default='', help="The path of original config file") @click.option('-i', '--input', 'input_', help="The path of original config file")
@click.option('-o', '--output', default='', help="the path of output config file") @click.option('-o', '--output', default='', help="the path of output config file")
@click.option('-t', '--target', default='2.0.0', help="target version of input path") @click.option('-t', '--target', default='2.0.0', help="target version of input path")
def migrate(input_, output, target): def migrate(input_, output, target):
if target not in accept_versions:
click.echo('target version {} not supported'.format(target))
sys.exit(-1)
if not output: if not output:
output = input_ output = input_
input_path = get_realpath(input_) input_path = get_realpath(input_)
@ -18,6 +24,8 @@ def migrate(input_, output, target):
configs = read_conf(input_path) configs = read_conf(input_path)
input_version = configs.get('_version') input_version = configs.get('_version')
if version.parse(input_version) < version.parse('1.9.0'):
click.echo('the version {} not supported, make sure the version in input file above 1.8.0'.format(input_version))
if input_version == target: if input_version == target:
click.echo("Version of input harbor.yml is identical to target {}, no need to upgrade".format(input_version)) click.echo("Version of input harbor.yml is identical to target {}, no need to upgrade".format(input_version))

View File

@ -1,3 +1,5 @@
import os import os
MIGRATION_BASE_DIR = os.path.dirname(__file__) MIGRATION_BASE_DIR = os.path.dirname(__file__)
accept_versions = {'1.9.0', '1.10.0', '2.0.0'}

View File

@ -2,7 +2,6 @@ import yaml
import click import click
import importlib import importlib
import os import os
from collections import deque from collections import deque
from migrations import MIGRATION_BASE_DIR from migrations import MIGRATION_BASE_DIR