From 8ff1200fbe40587f1fed7eff5b9057ce0a041827 Mon Sep 17 00:00:00 2001 From: Alba Hita <93577878+ahitacat@users.noreply.github.com> Date: Tue, 13 Sep 2022 04:36:18 +0200 Subject: [PATCH] Refractor cleanup local files for unregistration processes (#3520) Signed-off-by: ahitacat --- insights/client/client.py | 18 ++++++++---------- insights/client/phase/v1.py | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/insights/client/client.py b/insights/client/client.py index 7cef444750..21f03fd932 100644 --- a/insights/client/client.py +++ b/insights/client/client.py @@ -23,7 +23,6 @@ from .archive import InsightsArchive from .support import registration_check from .constants import InsightsConstants as constants -from .schedule import get_scheduler NETWORK = constants.custom_network_log_level LOG_FORMAT = ("%(asctime)s %(levelname)8s %(name)s %(message)s") @@ -200,16 +199,18 @@ def get_registration_status(config, pconn): return registration_check(pconn) +def __cleanup_local_files(): + write_unregistered_file() + delete_cache_files() + write_to_disk(constants.machine_id_file, delete=True) + logger.debug('Unregistered and removed machine-id') + + # -LEGACY- def _legacy_handle_unregistration(config, pconn): """ returns (bool): True success, False failure """ - def __cleanup_local_files(): - write_unregistered_file() - get_scheduler(config).remove_scheduling() - delete_cache_files() - write_to_disk(constants.machine_id_file, delete=True) check = get_registration_status(config, pconn) @@ -248,10 +249,7 @@ def handle_unregistration(config, pconn): unreg = pconn.unregister() if unreg or config.force: # only set if unreg was successful or --force was set - write_unregistered_file() - delete_cache_files() - write_to_disk(constants.machine_id_file, delete=True) - logger.debug('Unregistered and removed machine-id') + __cleanup_local_files() return unreg diff --git a/insights/client/phase/v1.py b/insights/client/phase/v1.py index e40278f93e..b626de6259 100644 --- a/insights/client/phase/v1.py +++ b/insights/client/phase/v1.py @@ -174,6 +174,7 @@ def post_update(client, config): # put this first to avoid conflicts with register if config.unregister: if client.unregister(): + get_scheduler(config).remove_scheduling() sys.exit(constants.sig_kill_ok) else: sys.exit(constants.sig_kill_bad)