From 54422cd6919d15a6ceac1e34645bac75ca03a907 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Thu, 12 Dec 2024 14:56:32 +0100 Subject: [PATCH 1/3] Made uninstall remove "everything" Ticket: ENT-12386 Signed-off-by: Victor Moene --- cf_remote/commands.py | 4 ++-- cf_remote/main.py | 3 ++- cf_remote/remote.py | 9 ++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cf_remote/commands.py b/cf_remote/commands.py index 3d3f90b..92f0af9 100644 --- a/cf_remote/commands.py +++ b/cf_remote/commands.py @@ -761,10 +761,10 @@ def show(ansible_inventory): return 0 -def uninstall(hosts): +def uninstall(hosts, purge=False): errors = 0 for host in hosts: - errors += uninstall_host(host) + errors += uninstall_host(host, purge=purge) return errors diff --git a/cf_remote/main.py b/cf_remote/main.py index 053ef9d..4d9f26a 100644 --- a/cf_remote/main.py +++ b/cf_remote/main.py @@ -103,6 +103,7 @@ def _get_arg_parser(): ) sp = subp.add_parser("uninstall", help="Uninstall CFEngine on the given hosts") + sp.add_argument("--purge", help="Complete uninstallation", nargs="?", const=True, type=bool) sp.add_argument("--clients", "-c", help="Where to uninstall", type=str) sp.add_argument("--hub", help="Where to uninstall", type=str) sp.add_argument("--hosts", "-H", help="Where to uninstall", type=str) @@ -296,7 +297,7 @@ def run_command_with_args(command, args): ) elif command == "uninstall": all_hosts = (args.hosts or []) + (args.hub or []) + (args.clients or []) - return commands.uninstall(all_hosts) + return commands.uninstall(all_hosts, purge=args.purge) elif command == "packages": log.warning( "packages command is deprecated, please use the new command: download" diff --git a/cf_remote/remote.py b/cf_remote/remote.py index b8075a5..5a8febb 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -283,7 +283,7 @@ def install_package(host, pkg, data, *, connection=None): @auto_connect -def uninstall_cfengine(host, data, *, connection=None): +def uninstall_cfengine(host, data, *, connection=None, purge=False): print("Uninstalling CFEngine on '{}'".format(host)) if "dpkg" in data["bin"]: @@ -328,6 +328,9 @@ def uninstall_cfengine(host, data, *, connection=None): run_command( host, "rm -rf /var/cfengine /opt/cfengine", connection=connection, sudo=True ) + if purge : + run_command(host, "rm -rf /var/log/CFEngine-Install*", connection=connection, sudo=True) + run_command(host, "rm -rf /etc/systemd/system/cf-php-fpm.service", connection=connection, sudo=True) @auto_connect @@ -553,7 +556,7 @@ def errors(self): @auto_connect -def uninstall_host(host, *, connection=None): +def uninstall_host(host, *, connection=None, purge=False): data = get_info(host, connection=connection) print_info(data) @@ -564,7 +567,7 @@ def uninstall_host(host, *, connection=None): ) ) - uninstall_cfengine(host, data, connection=connection) + uninstall_cfengine(host, data, connection=connection, purge=purge) data = get_info(host, connection=connection) if (not data) or data["agent_version"]: From 3c185c502e0e11a6b55f80cd4436670232ac8367 Mon Sep 17 00:00:00 2001 From: victormlg <101200844+victormlg@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:00:43 +0100 Subject: [PATCH 2/3] Fixed whitespace Co-authored-by: Ole Herman Schumacher Elgesem <4048546+olehermanse@users.noreply.github.com> --- cf_remote/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf_remote/remote.py b/cf_remote/remote.py index 5a8febb..c41b600 100644 --- a/cf_remote/remote.py +++ b/cf_remote/remote.py @@ -328,7 +328,7 @@ def uninstall_cfengine(host, data, *, connection=None, purge=False): run_command( host, "rm -rf /var/cfengine /opt/cfengine", connection=connection, sudo=True ) - if purge : + if purge: run_command(host, "rm -rf /var/log/CFEngine-Install*", connection=connection, sudo=True) run_command(host, "rm -rf /etc/systemd/system/cf-php-fpm.service", connection=connection, sudo=True) From 5cbc765b9c99d4870166257ef990815ac205fa1b Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem <4048546+olehermanse@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:24:28 +0100 Subject: [PATCH 3/3] Review suggestion --- cf_remote/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf_remote/main.py b/cf_remote/main.py index 4d9f26a..28240de 100644 --- a/cf_remote/main.py +++ b/cf_remote/main.py @@ -103,7 +103,7 @@ def _get_arg_parser(): ) sp = subp.add_parser("uninstall", help="Uninstall CFEngine on the given hosts") - sp.add_argument("--purge", help="Complete uninstallation", nargs="?", const=True, type=bool) + sp.add_argument("--purge", help="Complete uninstallation", action="store_true") sp.add_argument("--clients", "-c", help="Where to uninstall", type=str) sp.add_argument("--hub", help="Where to uninstall", type=str) sp.add_argument("--hosts", "-H", help="Where to uninstall", type=str)