From 7e45dcd9abda8869b4922f8879b279df6a016ead Mon Sep 17 00:00:00 2001 From: Heitor Matsui Date: Thu, 24 Oct 2024 16:40:38 -0300 Subject: [PATCH] Remove major release pre-hooks This commit simplifies the hook framework for major release deployments by removing the pre-hooks and converting all existing hooks in post-deployment hooks. The pre-hooks were removed due to ostree restrictions and possible issues caused by it's 3-way-merge for /etc, so it is easier and safer to modify directly the to-release deployed ostree filesystem after it is deployed in the host, via /ostree/1/ Test Plan PASS: AIO-SX - major release deploy and rollback stx8 -> stx10 PASS: AIO-DX - major release deploy and rollback stx8 -> stx10 Story: 2010676 Task: 51218 Change-Id: I72dec8e675f3a3443372c652f2e91c7493115e19 Signed-off-by: Heitor Matsui --- software/software/agent_hooks.py | 43 ++++++++--------------------- software/software/software_agent.py | 35 ++++++++--------------- 2 files changed, 22 insertions(+), 56 deletions(-) diff --git a/software/software/agent_hooks.py b/software/software/agent_hooks.py index 81c62039..3a2e4edd 100644 --- a/software/software/agent_hooks.py +++ b/software/software/agent_hooks.py @@ -259,13 +259,13 @@ class CreateUSMUpgradeInProgressFlag(BaseHook): super().__init__(attrs) def run(self): - flag_file = constants.USM_UPGRADE_IN_PROGRESS_FLAG + flag_file = "%s/%s" % (self.DEPLOYED_OSTREE_DIR, constants.USM_UPGRADE_IN_PROGRESS_FLAG) with open(flag_file, "w") as _: LOG.info("Created %s flag" % flag_file) class RemoveKubernetesConfigSymlinkHook(BaseHook): - K8S_ENCRYPTION_PROVIDER_FILE = "/etc/kubernetes/encryption-provider.yaml" + K8S_ENCRYPTION_PROVIDER_FILE = "%s/etc/kubernetes/encryption-provider.yaml" % BaseHook.DEPLOYED_OSTREE_DIR LUKS_K8S_ENCRYPTION_PROVIDER_FILE = ( "/var/luks/stx/luks_fs/controller/etc/kubernetes/encryption-provider.yaml" ) @@ -361,11 +361,8 @@ MAJOR_RELEASE_ROLLBACK = "major_release_rollback" # agent hooks mapping per action AGENT_HOOKS = { - MAJOR_RELEASE_UPGRADE: { - PRE: [ + MAJOR_RELEASE_UPGRADE: [ CreateUSMUpgradeInProgressFlag, - ], - POST: [ CopyPxeFilesHook, ReconfigureKernelHook, UpdateKernelParametersHook, @@ -374,12 +371,8 @@ AGENT_HOOKS = { # if everything else is done UsmInitHook, ], - }, - MAJOR_RELEASE_ROLLBACK: { - PRE: [ + MAJOR_RELEASE_ROLLBACK: [ RemoveKubernetesConfigSymlinkHook, - ], - POST: [ ReconfigureKernelHook, RemoveCephMonHook, RestartKubeApiServer, @@ -387,7 +380,6 @@ AGENT_HOOKS = { # if everything else is done UsmInitHook, ], - }, } @@ -398,32 +390,19 @@ class HookManager(object): def __init__(self, action, attrs=None): self._action = action self._attrs = attrs - self._pre_hooks = AGENT_HOOKS.get(action).get(PRE) - self._post_hooks = AGENT_HOOKS.get(action).get(POST) + self._hooks = AGENT_HOOKS.get(action) - def _run_hooks(self, timing): + def _run_hooks(self): """ - Run all hooks registered under the self._action value - :param timing: pre (before install) or post (after successful install) + Run all hooks """ - if timing == PRE: - hooks = self._pre_hooks - elif timing == POST: - hooks = self._post_hooks - else: - LOG.error("Invalid parameter: timing=%s" % timing) - return - - LOG.info("Running %s-hooks for '%s'" % (timing, self._action)) - for hook in hooks: + LOG.info("Running hooks for '%s'" % self._action) + for hook in self._hooks: pg = hook(self._attrs) pg.run() - def run_pre_hooks(self): - self._run_hooks(PRE) - - def run_post_hooks(self): - self._run_hooks(POST) + def run_hooks(self): + self._run_hooks() @staticmethod def create_hook_manager(software_version): diff --git a/software/software/software_agent.py b/software/software/software_agent.py index 97acc346..725b1dce 100644 --- a/software/software/software_agent.py +++ b/software/software/software_agent.py @@ -44,7 +44,7 @@ patch_failed_file = "/var/run/software_install_failed" node_is_locked_file = "/var/run/.node_locked" ostree_pull_completed_deployment_pending_file = \ "/var/run/ostree_pull_completed_deployment_pending" -run_post_hooks_flag = "/var/run/run_post_hooks" +run_hooks_flag = "/var/run/run_hooks" mount_pending_file = "/var/run/mount_pending" insvc_software_scripts = "/run/software/software-scripts" insvc_software_flags = "/run/software/software-flags" @@ -593,17 +593,17 @@ class PatchAgent(PatchService): LOG.info("The provided commit-id is already deployed. Skipping install.") success = True - # when in major release deployment, if post-hooks failed in a previous deploy + # when in major release deployment, if hooks failed in a previous deploy # host attempt, a flag is created so that their execution is reattempted here - if major_release and os.path.exists(run_post_hooks_flag): + if major_release and os.path.exists(run_hooks_flag): LOG.info("Major release deployment %s flag found. " - "Running post-hooks." % run_post_hooks_flag) + "Running hooks." % run_hooks_flag) try: hook_manager = agent_hooks.HookManager.create_hook_manager(major_release) - hook_manager.run_post_hooks() - clearflag(run_post_hooks_flag) + hook_manager.run_hooks() + clearflag(run_hooks_flag) except Exception as e: - LOG.exception("Failure running post-hooks: %s" % str(e)) + LOG.exception("Failure running hooks: %s" % str(e)) success = False if success: @@ -645,19 +645,6 @@ class PatchAgent(PatchService): ref = "%s:%s" % (remote, constants.OSTREE_REF) hook_manager = agent_hooks.HookManager.create_hook_manager(major_release) - # run deploy host pre-hooks for major release - try: - hook_manager.run_pre_hooks() - except Exception as e: - LOG.exception("Failure running pre-hooks: %s" % str(e)) - self.patch_failed = True - setflag(patch_failed_file) - self.state = constants.PATCH_AGENT_STATE_INSTALL_FAILED - ostree_utils.delete_ostree_remote(remote) - ostree_utils.delete_ostree_ref(constants.OSTREE_REF) - LOG.info("OSTree remote deleted: %s" % remote) - return False - self.state = constants.PATCH_AGENT_STATE_INSTALLING setflag(patch_installing_file) @@ -760,13 +747,13 @@ class PatchAgent(PatchService): clearflag(patch_failed_file) self.state = constants.PATCH_AGENT_STATE_IDLE - # run deploy host post-hooks for major release + # run deploy host hooks for major release if major_release: try: - hook_manager.run_post_hooks() + hook_manager.run_hooks() except Exception as e: - LOG.exception("Failure running post-hooks: %s" % str(e)) - setflag(run_post_hooks_flag) + LOG.exception("Failure running hooks: %s" % str(e)) + setflag(run_hooks_flag) self.patch_failed = True setflag(patch_failed_file) self.state = constants.PATCH_AGENT_STATE_INSTALL_FAILED