From 0768bef149f54a8f0c9acf122dfc862ce0cb567f Mon Sep 17 00:00:00 2001 From: Weisson Date: Mon, 28 Nov 2022 16:43:21 +0800 Subject: [PATCH] SMC progress indicator. Signed-off-by: Weisson --- 0005-SMC-progress-indicator.patch | 118 ++++++++++++++++++++++++++++++ leapp.spec | 7 +- 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 0005-SMC-progress-indicator.patch diff --git a/0005-SMC-progress-indicator.patch b/0005-SMC-progress-indicator.patch new file mode 100644 index 0000000..0260c18 --- /dev/null +++ b/0005-SMC-progress-indicator.patch @@ -0,0 +1,118 @@ +From d65335a0699d23e7cced814d3627268b68cbb46c Mon Sep 17 00:00:00 2001 +From: Weisson +Date: Mon, 28 Nov 2022 16:36:16 +0800 +Subject: [PATCH] SMC progress indicator. + +Signed-off-by: Weisson +--- + leapp/libraries/common/smc_interface.py | 42 +++++++++++++++++++++++++ + leapp/workflows/__init__.py | 15 +++++++-- + 2 files changed, 54 insertions(+), 3 deletions(-) + create mode 100644 leapp/libraries/common/smc_interface.py + +diff --git a/leapp/libraries/common/smc_interface.py b/leapp/libraries/common/smc_interface.py +new file mode 100644 +index 0000000..62faa9c +--- /dev/null ++++ b/leapp/libraries/common/smc_interface.py +@@ -0,0 +1,42 @@ ++import json ++import os ++import time ++ ++ ++DEFAULT_JSON_STATE_PATH = "/var/tmp/state.json" ++ ++def status_log_exists(path=DEFAULT_JSON_STATE_PATH): ++ return os.path.exists(path) ++ ++def load_log_status(path=DEFAULT_JSON_STATE_PATH): ++ if status_log_exists(path): ++ with open(path, "r") as f: ++ state = json.load(f) ++ return state ++ else: ++ return None ++ ++def update_progress_infomation(progress=None, progress_info=None, err_no=None, err_msg=None, path=DEFAULT_JSON_STATE_PATH): ++ if not os.path.exists(path): ++ state_directory = path.rpartition('state.json')[0] ++ if not os.path.exists(state_directory): ++ os.makedirs(state_directory) ++ ++ state = load_log_status(path) or {"ErrorCode": 0 } ++ ++ if int(state["ErrorCode"]) != 0: ++ return ++ ++ if progress is not None: ++ state["Progress"] = int(progress) ++ if progress_info is not None: ++ state["ProgressInfo"] = progress_info ++ if err_no is not None: ++ state["ErrorCode"] = err_no ++ if err_msg is not None: ++ state["ErrorMsg"] = err_msg ++ ++ state["Timestamp"] = int(time.time()) ++ ++ with open(path, "w") as f: ++ json.dump(state, f) +diff --git a/leapp/workflows/__init__.py b/leapp/workflows/__init__.py +index 9ec2630..6463160 100644 +--- a/leapp/workflows/__init__.py ++++ b/leapp/workflows/__init__.py +@@ -18,6 +18,8 @@ from leapp.workflows.phases import Phase + from leapp.workflows.policies import Policies + from leapp.workflows.phaseactors import PhaseActors + ++from leapp.libraries.common import smc_interface ++ + + def _phase_sorter_key(a): + return a.get_index() +@@ -263,6 +265,7 @@ class Workflow(with_metaclass(WorkflowMeta)): + if not os.environ.get('LEAPP_HOSTNAME', None): + os.environ['LEAPP_HOSTNAME'] = socket.getfqdn() + ++ smc_state_file_path = os.environ.get("DEFAULT_JSON_STATE_PATH") or smc_interface.DEFAULT_JSON_STATE_PATH + self.log.info('Starting workflow execution: {name} - ID: {id}'.format( + name=self.name, id=os.environ['LEAPP_EXECUTION_ID'])) + +@@ -283,7 +286,7 @@ class Workflow(with_metaclass(WorkflowMeta)): + raise CommandError('Phase {phase} does not exist in the workflow'.format(phase=phase)) + + self._stop_after_phase_requested = False +- for phase in self._phase_actors: ++ for i, phase in enumerate(self._phase_actors): + os.environ['LEAPP_CURRENT_PHASE'] = phase[0].name + if skip_phases_until: + if skip_phases_until in phase_names(phase): +@@ -325,9 +328,10 @@ class Workflow(with_metaclass(WorkflowMeta)): + config_model=config_model, skip_dialogs=skip_dialogs) + try: + instance.run() +- except BaseException: ++ except Exception as e: ++ smc_interface.update_progress_infomation(progress=None, progress_info='fail', err_no=1, err_msg='Actor %s fails : %s' % (str(instance), str(e)), path=smc_state_file_path) + self._unhandled_exception = True +- raise ++ raise e + + self._stop_after_phase_requested = messaging.stop_after_phase or self._stop_after_phase_requested + +@@ -396,6 +400,11 @@ class Workflow(with_metaclass(WorkflowMeta)): + if early_finish: + return + ++ progress = int(float(i + 1) / len(self._phase_actors) * 100.0) ++ progress_info = phase[0].name ++ err_no = 0 ++ err_msg = "running" if progress < 100 else "done" ++ smc_interface.update_progress_infomation(progress, progress_info, err_no, err_msg, smc_state_file_path) + + def get_workflows(): + """ +-- +2.30.1 (Apple Git-130) + diff --git a/leapp.spec b/leapp.spec index 8925f16..5a2c2aa 100644 --- a/leapp.spec +++ b/leapp.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.3 +%define anolis_release .0.4 # IMPORTANT: this is for the leapp-framework capability (it's not the real # version of the leapp). The capability reflects changes in api and whatever # functionality important from the point of repository. In case of @@ -40,6 +40,7 @@ Patch0001: leapp-0001-add-remove-actor-parament.patch Patch0002: leapp-0002-add-command-no-rhsm_skip.patch Patch0003: leapp-0003-add-disablerepo-option-to-upgrade-kernel-to-RHCK.patch Patch0004: leapp-0004-report-a-default-external-link.patch +Patch0005: 0005-SMC-progress-indicator.patch %if !0%{?fedora} %if %{with python3} @@ -161,6 +162,7 @@ Python 3 leapp framework libraries. %patch0001 -p1 %patch0002 -p1 %patch0003 -p1 +%patch0005 -p1 ################################################## # Build @@ -281,6 +283,9 @@ rm -f %{buildroot}/%{_bindir}/leapp # no files here %changelog +* Mon Nov 28 2022 Weisson - 0.12.0-1.0.4 +- SMC progress indicator + * Sat Sep 24 2022 Weitao Zhou - 0.12.0-1.0.3 - patch: report a default external link -- Gitee