From 140a0bbb689814041fa6a03ee2b703e70a20f2f2 Mon Sep 17 00:00:00 2001 From: Michal Hecko Date: Sun, 10 Nov 2024 13:54:20 +0100 Subject: [PATCH 34/40] cli: load actor configuration Load actor configuration when running `leapp upgrade` or `leapp preupgrade`. The configuration is loaded, saved to leapp's DB, and remains available to all actors via framework's global variable. --- commands/command_utils.py | 32 +++++++++++++++++++++++++++++++- commands/preupgrade/__init__.py | 3 +++ commands/upgrade/__init__.py | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/commands/command_utils.py b/commands/command_utils.py index 2810a542..190f5f03 100644 --- a/commands/command_utils.py +++ b/commands/command_utils.py @@ -1,10 +1,12 @@ +import hashlib import json import os import re import resource +from leapp.actors import config as actor_config from leapp.exceptions import CommandError -from leapp.utils import path +from leapp.utils import audit, path HANA_BASE_PATH = '/hana/shared' HANA_SAPCONTROL_PATH_X86_64 = 'exe/linuxx86_64/hdb/sapcontrol' @@ -178,3 +180,31 @@ def set_resource_limits(): if soft_fsize != fsize_limit: set_resource_limit(resource.RLIMIT_FSIZE, fsize_limit, fsize_limit) + + +def load_actor_configs_and_store_it_in_db(context, repositories, framework_cfg): + """ + Load actor configuration so that actor's can access it and store it into leapp db. + + :param context: Current execution context + :param repositories: Discovered repositories + :param framework_cfg: Leapp's configuration + """ + # Read the Actor Config and validate it against the schemas saved in the + # configuration. + + actor_config_schemas = tuple(actor.config_schemas for actor in repositories.actors) + actor_config_schemas = actor_config.normalize_schemas(actor_config_schemas) + actor_config_path = framework_cfg.get('actor_config', 'path') + + # Note: actor_config.load() stores the loaded actor config into a global + # variable which can then be accessed by functions in that file. Is this + # the right way to store that information? + actor_cfg = actor_config.load(actor_config_path, actor_config_schemas) + + # Dump the collected configuration, checksum it and store it inside the DB + config_text = json.dumps(actor_cfg) + config_text_hash = hashlib.sha256(config_text.encode('utf-8')).hexdigest() + config_data = audit.ActorConfigData(config=config_text, hash_id=config_text_hash) + db_config = audit.ActorConfig(config=config_data, context=context) + db_config.store() diff --git a/commands/preupgrade/__init__.py b/commands/preupgrade/__init__.py index a9fa40e0..631eca6b 100644 --- a/commands/preupgrade/__init__.py +++ b/commands/preupgrade/__init__.py @@ -62,6 +62,9 @@ def preupgrade(args, breadcrumbs): command_utils.set_resource_limits() workflow = repositories.lookup_workflow('IPUWorkflow')() + + command_utils.load_actor_configs_and_store_it_in_db(context, repositories, cfg) + util.warn_if_unsupported(configuration) util.process_whitelist_experimental(repositories, workflow, configuration, logger) with beautify_actor_exception(): diff --git a/commands/upgrade/__init__.py b/commands/upgrade/__init__.py index c7487fde..3dedd438 100644 --- a/commands/upgrade/__init__.py +++ b/commands/upgrade/__init__.py @@ -93,6 +93,9 @@ def upgrade(args, breadcrumbs): command_utils.set_resource_limits() workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot) + + command_utils.load_actor_configs_and_store_it_in_db(context, repositories, cfg) + util.process_whitelist_experimental(repositories, workflow, configuration, logger) util.warn_if_unsupported(configuration) with beautify_actor_exception(): -- 2.47.0