Skip to content

Commit

Permalink
Update playbooks
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova committed Jul 1, 2024
1 parent 60efa07 commit e32ecc0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
38 changes: 32 additions & 6 deletions playbooks/leapp_preupgrade_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,29 @@
os.remove(TXT_REPORT_PATH)
def execute_operation(command):
def parse_env_vars():
new_env = {}
for key, value in os.environ.items():
valid_prefix = "RHC_WORKER_"
if key.startswith(valid_prefix):
# This also removes multiple valid prefixes
new_env[key.replace(valid_prefix, "")] = value
else:
new_env[key] = value
return new_env
def execute_operation(command, env=None):
# NOTE: Put logic here to adjust command based on environment variables
# if "LEAPP_DEBUG" in env:
# command.append("--debug")
# if "LEAPP_NO_RHSM" in env:
# command.append("--no-rhsm")
# if "LEAPP_ENABLE_REPOS" in env:
# command.extend([["--enablerepo", repo] for repo in env["LEAPP_ENABLE_REPOS"].split(",")])
logger.info("Executing %s ...", SCRIPT_TYPE.title())
output, _ = run_subprocess(command)
output, _ = run_subprocess(command, env=env)
return output
Expand Down Expand Up @@ -483,7 +503,8 @@
if reboot_required:
message = (
"No problems found. System will be upgraded. Rebooting system in 1 minute. "
"No problems found. Please reboot the system at your earliest convenience "
"to continue with the upgrade process. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
Expand Down Expand Up @@ -564,13 +585,18 @@
install_leapp_pkg_corresponding_to_installed_rhui(rhui_pkgs)
remove_previous_reports()
leapp_output = execute_operation(operation_command)
# NOTE: adjust commands based on parameters in environment variables
env = parse_env_vars()
leapp_output = execute_operation(operation_command, env=env)
upgrade_reboot_required = REBOOT_GUIDANCE_MESSAGE in leapp_output
parse_results(output, upgrade_reboot_required)
update_insights_inventory(output)
logger.info("Operation %s finished successfully.", SCRIPT_TYPE.title())
if upgrade_reboot_required:
reboot_system()
# NOTE: Leapp has --reboot option but we are not using it because we need to send update to Insights before reboot
# if upgrade_reboot_required:
# reboot_system()
except ProcessError as exception:
logger.error(exception.report)
output = OutputCollector(
Expand Down
38 changes: 32 additions & 6 deletions playbooks/leapp_upgrade_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,29 @@
os.remove(TXT_REPORT_PATH)
def execute_operation(command):
def parse_env_vars():
new_env = {}
for key, value in os.environ.items():
valid_prefix = "RHC_WORKER_"
if key.startswith(valid_prefix):
# This also removes multiple valid prefixes
new_env[key.replace(valid_prefix, "")] = value
else:
new_env[key] = value
return new_env
def execute_operation(command, env=None):
# NOTE: Put logic here to adjust command based on environment variables
# if "LEAPP_DEBUG" in env:
# command.append("--debug")
# if "LEAPP_NO_RHSM" in env:
# command.append("--no-rhsm")
# if "LEAPP_ENABLE_REPOS" in env:
# command.extend([["--enablerepo", repo] for repo in env["LEAPP_ENABLE_REPOS"].split(",")])
logger.info("Executing %s ...", SCRIPT_TYPE.title())
output, _ = run_subprocess(command)
output, _ = run_subprocess(command, env=env)
return output
Expand Down Expand Up @@ -483,7 +503,8 @@
if reboot_required:
message = (
"No problems found. System will be upgraded. Rebooting system in 1 minute. "
"No problems found. Please reboot the system at your earliest convenience "
"to continue with the upgrade process. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
Expand Down Expand Up @@ -564,13 +585,18 @@
install_leapp_pkg_corresponding_to_installed_rhui(rhui_pkgs)
remove_previous_reports()
leapp_output = execute_operation(operation_command)
# NOTE: adjust commands based on parameters in environment variables
env = parse_env_vars()
leapp_output = execute_operation(operation_command, env=env)
upgrade_reboot_required = REBOOT_GUIDANCE_MESSAGE in leapp_output
parse_results(output, upgrade_reboot_required)
update_insights_inventory(output)
logger.info("Operation %s finished successfully.", SCRIPT_TYPE.title())
if upgrade_reboot_required:
reboot_system()
# NOTE: Leapp has --reboot option but we are not using it because we need to send update to Insights before reboot
# if upgrade_reboot_required:
# reboot_system()
except ProcessError as exception:
logger.error(exception.report)
output = OutputCollector(
Expand Down

0 comments on commit e32ecc0

Please sign in to comment.