Skip to content

Commit

Permalink
commands: add library function for easier loading of cfgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Hecko committed Nov 3, 2024
1 parent 76d1bc7 commit ea722ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
32 changes: 31 additions & 1 deletion commands/command_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import hashlib
import os
import re

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'
Expand Down Expand Up @@ -140,3 +142,31 @@ def vet_upgrade_path(args):
flavor=flavor,
choices=','.join(supported_target_versions)))
return (target_release, flavor)


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()
6 changes: 1 addition & 5 deletions commands/preupgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ def preupgrade(args, breadcrumbs):

workflow = repositories.lookup_workflow('IPUWorkflow')()

# 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 = cfg.get('actor_config', 'path')
actor_config.load(actor_config_path, actor_config_schemas)
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)
Expand Down
11 changes: 1 addition & 10 deletions commands/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import uuid

from leapp.actors import config as actor_config
from leapp.cli.commands import command_utils
from leapp.cli.commands.config import get_config
from leapp.cli.commands.upgrade import breadcrumbs, util
Expand Down Expand Up @@ -92,15 +91,7 @@ def upgrade(args, breadcrumbs):
raise CommandError(exc.message)
workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot)

# 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 = 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_config.load(actor_config_path, actor_config_schemas)
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)
Expand Down

0 comments on commit ea722ce

Please sign in to comment.