From 1e6f98745fd27deeaf00e3dadf6440515e76628d Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Thu, 9 Apr 2020 15:00:25 -0700 Subject: [PATCH] Clear Salt cache and synchronize Salt before installing/uninstalling Towards #527 --- scripts/securedrop-admin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/securedrop-admin.py b/scripts/securedrop-admin.py index b28c1e852..d3c203264 100644 --- a/scripts/securedrop-admin.py +++ b/scripts/securedrop-admin.py @@ -79,6 +79,22 @@ def validate_config(path): raise SDAdminException("Error while validating configuration") +def refresh_salt(): + """ + Cleans the Salt cache and synchronizes Salt to ensure we are applying states + from the currently installed version + """ + try: + subprocess.check_call(["sudo", "rm", "-rf", "/var/cache/salt"]) + except subprocess.CalledProcessError: + raise SDAdminException("Error while clearing Salt cache") + + try: + subprocess.check_call(["sudo", "qubesctl", "saltutil.sync_all", "refresh=true"]) + except subprocess.CalledProcessError: + raise SDAdminException("Error while synchronizing Salt") + + def perform_uninstall(): try: @@ -128,6 +144,7 @@ def main(): print("Applying configuration...") validate_config(SCRIPTS_PATH) copy_config() + refresh_salt() provision_all() elif args.uninstall: print( @@ -140,6 +157,7 @@ def main(): print("Exiting.") sys.exit(0) else: + refresh_salt() perform_uninstall() else: sys.exit(0)