diff --git a/software/software/agent_hooks.py b/software/software/agent_hooks.py index 81c62039c..3a2e4eddb 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 97acc346a..725b1dce2 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