From 95201eed94d8283625b780cfb48374caa5c8bcd0 Mon Sep 17 00:00:00 2001 From: xuezhixin Date: Tue, 5 Nov 2024 18:05:40 +0800 Subject: [PATCH] add migration.py to migration function --- ...d-migration.py-to-migration-function.patch | 160 ++++++++++++++++++ migration-tools.spec | 7 +- 2 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 0032-add-migration.py-to-migration-function.patch diff --git a/0032-add-migration.py-to-migration-function.patch b/0032-add-migration.py-to-migration-function.patch new file mode 100644 index 0000000..44cb6a6 --- /dev/null +++ b/0032-add-migration.py-to-migration-function.patch @@ -0,0 +1,160 @@ +From 8cd79eb6eea6032de7ba93b9be82cb0891b2ea63 Mon Sep 17 00:00:00 2001 +From: xuezhixin +Date: Fri, 10 Nov 2023 13:35:58 +0800 +Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0migration.py=EF=BC=8C?= + =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E8=BF=81=E7=A7=BB=E7=9B=B8=E5=85=B3=E5=8A=9F?= + =?UTF-8?q?=E8=83=BD=E4=BD=BF=E7=94=A8?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + sysmig_agent/check.py | 37 ---------------------- + sysmig_agent/migration.py | 66 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 66 insertions(+), 37 deletions(-) + create mode 100644 sysmig_agent/migration.py + +diff --git a/sysmig_agent/check.py b/sysmig_agent/check.py +index 3d4d3e9..141a734 100644 +--- a/sysmig_agent/check.py ++++ b/sysmig_agent/check.py +@@ -18,12 +18,6 @@ from sysmig_agent.Abitxt2xls import * + + os.chdir('/usr/lib/migration-tools-agent') + +-def migInit_porgress(): +- uelc_rpm = os.popen('rpm -qa|wc -l').readlines() +- with open('/var/tmp/uos-migration/.rpms','w+') as fp: +- fp.write(uelc_rpm[0]) +- fp.close() +- + + def init_dir(): + if not os.path.isdir(PRE_MIG_DIR): +@@ -517,13 +511,6 @@ def mig_kernel(kernel_version): + return 1 + + +-def migprogress(): +- with open(RPMS,'r+') as fpro: +- data = fpro.read() +- fpro.close() +- return int(data) +- +- + def migration_details(data_j): + uos_sysmig_conf = json.loads(getSysMigConf()) + AGENT_IP = json.loads(uos_sysmig_conf).get('agentip').strip()[1:-1] +@@ -539,18 +526,6 @@ def migration_details(data_j): + return list_to_json(keylist,valuelist) + + +-def readline_log(): +- path = '/var/tmp/uos-migration/UOS_migration_log/mig_log.txt' +- if not os.path.exists(path): +- return 0 +- else: +- ln = 0 +- with open(path,'r') as rf: +- for line in rf: +- ln = ln + 1 +- rf.close() +- return ln +- + ##迁移进度 + def rpmsProgress(): + percent = 99 +@@ -561,18 +536,6 @@ def rpmsProgress(): + return rpms_progress + + +-def mig_check_migration_progress(): +- percent = 98 +- rpms = migprogress() +- lines = readline_log() +- lines = lines//4 +- if lines >= rpms: +- lines = rpms +- data = percent*(lines/rpms) +- data = format(data, '.1f') +- messageProgress(data) +- +- + def check_migration_progress(data_j): + uos_sysmig_conf = json.loads(getSysMigConf()) + AGENT_IP = json.loads(uos_sysmig_conf).get('agentip').strip()[1:-1] +diff --git a/sysmig_agent/migration.py b/sysmig_agent/migration.py +new file mode 100644 +index 0000000..c635041 +--- /dev/null ++++ b/sysmig_agent/migration.py +@@ -0,0 +1,66 @@ ++# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. ++# SPDX-License-Identifier: MulanPubL-2.0-or-later ++ ++from sysmig_agent.centos82uos import * ++ ++#sys.path.append("..") ++from connect_sql import DBHelper ++ ++RPMS = '/var/tmp/uos-migration/.rpms' ++ ++# migrations function ++ ++# migrations progress ++# 迁移进度 ++ ++def mig_whether_success(): ++ # rpms = int(migprogress()) ++ cmdrpm = 'rpm -qa | wc -l' ++ cmduelc = 'rpm -qa | grep oe1|wc -l' ++ rpms = int(os.popen(cmdrpm).readlines()[0]) ++ ret = int(os.popen(cmduelc).readlines()[0]) ++ res = (ret / rpms)*100 ++ res = format(res, '.0f') ++ return int(res) ++ ++ ++def migprogress(): ++ with open(RPMS, 'r+') as fpro: ++ data = fpro.read() ++ fpro.close() ++ return int(data) ++ ++ ++def readline_log(): ++ path = '/var/tmp/uos-migration/UOS_migration_log/mig_log.txt' ++ if not os.path.exists(path): ++ return None ++ else: ++ ln = 0 ++ with open(path, 'r') as rf: ++ for line in rf: ++ ln = ln + 1 ++ rf.close() ++ return ln ++ ++ ++def migInit_porgress(): ++ uelc_rpm = os.popen('rpm -qa|wc -l').readlines() ++ with open('/var/tmp/uos-migration/.rpms', 'w+') as fp: ++ fp.write(uelc_rpm[0]) ++ fp.close() ++ ++ ++# check_migration_progress ++def mig_check_migration_progress(): ++ percent = 98 ++ rpms = migprogress() ++ lines = readline_log() ++ if not lines: ++ return 0 ++ lines = lines // 6 ++ if lines >= rpms: ++ lines = rpms ++ data = percent * (lines / rpms) ++ data = format(data, '.1f') ++ return data +-- +2.20.1 + diff --git a/migration-tools.spec b/migration-tools.spec index e11115b..a27e8f9 100644 --- a/migration-tools.spec +++ b/migration-tools.spec @@ -1,6 +1,6 @@ Name: migration-tools Version: 1.0.2 -Release: 31 +Release: 32 License: MulanPSL-2.0 Summary: A tool to help users migrate the Centos system to the UOS system and openEuler system Source0: %{name}-%{version}.tar.gz @@ -38,7 +38,7 @@ Patch28: 0028-send-agent-task.patch Patch29: 0029-json-and-list-format-interchange.patch Patch30: 0030-system-information-import-info-the-database-after-migration.patch Patch31: 0031-migration-check-and-extract-macros.patch - +Patch32: 0032-add-migration.py-to-migration-function.patch BuildArch: noarch BuildRequires: systemd @@ -137,6 +137,9 @@ rm -rf /usr/bin/migration-tools %endif %changelog +* Tue Nov 5 2024 xuezhixin - 1.0.2-32 +- 0032-add-migration.py-to-migration-function.patch + * Tue Nov 5 2024 xuezhixin - 1.0.2-31 - 0031-migration-check-and-extract-macros.patch -- Gitee