From 0f7a69fd48411caddb02ff4658db14e080391c6a Mon Sep 17 00:00:00 2001 From: Chenlong Ma Date: Mon, 13 Feb 2023 15:57:20 +0800 Subject: [PATCH 1/2] Fix FUM bug for version filter Signed-off-by: Chenlong Ma --- .../fate-upgrade-manager/upgrade-mysql.py | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/docker-build/modules/fate-upgrade-manager/upgrade-mysql.py b/docker-build/modules/fate-upgrade-manager/upgrade-mysql.py index 0ccbe0c..249bdda 100644 --- a/docker-build/modules/fate-upgrade-manager/upgrade-mysql.py +++ b/docker-build/modules/fate-upgrade-manager/upgrade-mysql.py @@ -2,24 +2,29 @@ import sys import os +from functools import cmp_to_key + + +def cmp_ver(a, b): + for va, vb in zip(a.split('.'), b.split('.')): + va, vb = int(va), int(vb) + if va > vb: + return 1 + if va < vb: + return -1 + return 0 + + +def cmp_file_ver(a, b): + return cmp_ver(a.split('-')[0], b.split('-')[0]) + def get_script_list(start_ver, target_ver): sql_script_names = os.listdir("sql") - sql_script_names.sort() - res = [] - start_index = -1 - end_index = -1 - for i in range(len(sql_script_names)): - if sql_script_names[i].startswith(start_ver): - start_index = i - if sql_script_names[i].replace(".sql", "").endswith(target_ver): - end_index = i - if start_index == -1 or end_index == -1 or start_index > end_index: - return res - res = sql_script_names[start_index:end_index+1] - print("will run scripts:") - print(res) - return res + print("FUM upgradeable sql list:", sql_script_names) + inclusive_files = filter(lambda x: cmp_ver( + x.split('-')[0], start_ver) >= 0 and cmp_ver(x.split('-')[1], target_ver) <= 0, sql_script_names) + return sorted(inclusive_files, key=cmp_to_key(cmp_file_ver)) def preprocess_script(script): @@ -51,7 +56,9 @@ def run_script(script, cursor): if __name__ == '__main__': _, user, password, start_ver, end_ver = sys.argv + print("Version upgrade span:", start_ver, end_ver) scripts_to_run = get_script_list(start_ver, end_ver) + print("Filtered sql list:", scripts_to_run) mydb = mysql.connector.connect( host="mysql", user=user, From 38e16b46a3c8118516325a07ab556eb09f9508a7 Mon Sep 17 00:00:00 2001 From: Chenlong Ma Date: Wed, 15 Feb 2023 15:22:47 +0800 Subject: [PATCH 2/2] update python version Signed-off-by: Chenlong Ma --- docker-build/modules/fate-upgrade-manager/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-build/modules/fate-upgrade-manager/Dockerfile b/docker-build/modules/fate-upgrade-manager/Dockerfile index a6509f3..772ff10 100644 --- a/docker-build/modules/fate-upgrade-manager/Dockerfile +++ b/docker-build/modules/fate-upgrade-manager/Dockerfile @@ -8,7 +8,7 @@ COPY deploy.tar.gz . RUN tar -xzf deploy.tar.gz; -FROM centos/python-36-centos7 +FROM python:3.8 WORKDIR / COPY --from=builder /data/projects/fate/deploy/upgrade/sql ./sql