From 8b599699ea77971d41c9949d2143d4f93c1ecc95 Mon Sep 17 00:00:00 2001 From: Jessica Castelino Date: Fri, 16 Dec 2022 02:59:19 +0000 Subject: [PATCH] Sync patch restart scripts to other hosts This commit ensures that the patch restart scripts for in-service patching are copied to all hosts. Subsequently, we have moved the in-service patch restart script staging directory from /run/patching/patch-scripts to /var/www/pages/updates/patch-scripts which can be rsynced. Test Plan: [PASS] Verify from patching-insvc.log that the restart scripts are run on all hosts Closes-Bug: 1999841 Signed-off-by: Jessica Castelino Change-Id: I25f9b13777a9fc4ff7ee5c15d38ceb80dbfffcf1 --- sw-patch/cgcs-patch/cgcs_patch/constants.py | 2 +- sw-patch/cgcs-patch/cgcs_patch/patch_agent.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sw-patch/cgcs-patch/cgcs_patch/constants.py b/sw-patch/cgcs-patch/cgcs_patch/constants.py index 287ceb26..06830c6e 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/constants.py +++ b/sw-patch/cgcs-patch/cgcs_patch/constants.py @@ -47,7 +47,7 @@ OSTREE_REMOTE = "debian" FEED_OSTREE_BASE_DIR = "/var/www/pages/feed" SYSROOT_OSTREE = "/sysroot/ostree/repo" OSTREE_BASE_DEPLOYMENT_DIR = "/ostree/deploy/debian/deploy/" -PATCH_SCRIPTS_STAGING_DIR = "/run/patching/patch-scripts" +PATCH_SCRIPTS_STAGING_DIR = "/var/www/pages/updates/patch-scripts" ENABLE_DEV_CERTIFICATE_PATCH_IDENTIFIER = 'ENABLE_DEV_CERTIFICATE' diff --git a/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py b/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py index 66373e72..06c2dc31 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py +++ b/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py @@ -68,6 +68,20 @@ def clearflag(fname): LOG.exception("Failed to clear %s flag", fname) +def pull_restart_scripts_from_controller(): + # If the rsync fails, it raises an exception to + # the caller "handle_install()" and fails the + # host-install request for this host + output = subprocess.check_output(["rsync", + "-acv", + "--delete", + "--exclude", "tmp", + "rsync://controller/repo/patch-scripts/", + "%s/" % insvc_patch_scripts], + stderr=subprocess.STDOUT) + LOG.info("Synced restart scripts from controller: %s", output) + + def check_install_uuid(): controller_install_uuid_url = "http://controller:%s/feed/rel-%s/install_uuid" % (http_port_real, SW_VERSION) try: @@ -257,7 +271,6 @@ class PatchMessageAgentInstallReq(messages.PatchMessage): resp.reject_reason = 'Node must be locked.' resp.send(sock, addr) return - resp.status = pa.handle_install() resp.send(sock, addr) @@ -490,6 +503,7 @@ class PatchAgent(PatchService): ostree_utils.mount_new_deployment(deployment_dir) clearflag(mount_pending_file) LOG.info("Running in-service patch-scripts") + pull_restart_scripts_from_controller() subprocess.check_output(run_insvc_patch_scripts_cmd, stderr=subprocess.STDOUT) # Clear the node_is_patched flag, since we've handled it in-service