From eb78f6111962199501bf539fe62f6b9928dfa96d Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Thu, 17 Oct 2024 17:45:07 +0200 Subject: [PATCH 1/6] Add reboot in cleanup after package removal before file removal --- .../features/build_validation/init_clients/proxy.feature | 1 - testsuite/features/step_definitions/salt_steps.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/testsuite/features/build_validation/init_clients/proxy.feature b/testsuite/features/build_validation/init_clients/proxy.feature index 9f4baeaaf83d..4593ced06a80 100644 --- a/testsuite/features/build_validation/init_clients/proxy.feature +++ b/testsuite/features/build_validation/init_clients/proxy.feature @@ -17,7 +17,6 @@ Feature: Setup containerized proxy Scenario: Clean up sumaform leftovers on the containerized proxy When I perform a full salt minion cleanup on "proxy" - And I reboot the "proxy" host through SSH, waiting until it comes back Scenario: Log in as admin user Given I am authorized for the "Admin" section diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 9c3706fbbe80..0354530347e5 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -565,6 +565,8 @@ # Transactional systems could have also installed salt-minion via sumaform _result, code = node.run('rpm -q salt-minion', check_errors: false) node.run('transactional-update --continue -n pkg rm salt-minion', check_errors: false) if code.zero? + # Reboot needed here after package removal but before file removal + step %(I reboot the "#{host}" host through SSH, waiting until it comes back) node.run('rm -Rf /var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt', check_errors: false) if code.zero? elsif rh_host?(host) node.run('yum -y remove --setopt=clean_requirements_on_remove=1 venv-salt-minion', check_errors: false) @@ -577,6 +579,8 @@ else if transactional_system?(host) node.run('transactional-update --continue -n pkg rm salt salt-minion', check_errors: false) + # Reboot needed here after package removal but before file removal + step %(I reboot the "#{host}" host through SSH, waiting until it comes back) elsif rh_host?(host) node.run('yum -y remove --setopt=clean_requirements_on_remove=1 salt salt-minion', check_errors: false) elsif deb_host?(host) @@ -586,6 +590,10 @@ end node.run('rm -Rf /root/salt /var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt /var/tmp/.root*', check_errors: false) end + if transactional_system?(host) + # Reboot needed after file removal as well + step %(I reboot the "#{host}" host through SSH, waiting until it comes back) + end step %(I disable the repositories "tools_update_repo tools_pool_repo" on this "#{host}" without error control) end From d918e077dc987570203cb050289f549ea52e41c0 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Mon, 11 Nov 2024 14:09:44 +0100 Subject: [PATCH 2/6] Refactor salt cleanup step --- .../features/step_definitions/salt_steps.rb | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 0354530347e5..394e95fa4667 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -559,41 +559,26 @@ When(/^I perform a full salt minion cleanup on "([^"]*)"$/) do |host| node = get_target(host) - if use_salt_bundle - if transactional_system?(host) - node.run('transactional-update --continue -n pkg rm venv-salt-minion', check_errors: false) - # Transactional systems could have also installed salt-minion via sumaform - _result, code = node.run('rpm -q salt-minion', check_errors: false) - node.run('transactional-update --continue -n pkg rm salt-minion', check_errors: false) if code.zero? - # Reboot needed here after package removal but before file removal - step %(I reboot the "#{host}" host through SSH, waiting until it comes back) - node.run('rm -Rf /var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt', check_errors: false) if code.zero? - elsif rh_host?(host) - node.run('yum -y remove --setopt=clean_requirements_on_remove=1 venv-salt-minion', check_errors: false) - elsif deb_host?(host) - node.run('apt-get --assume-yes remove venv-salt-minion && apt-get --assume-yes purge venv-salt-minion && apt-get --assume-yes autoremove', check_errors: false) - else - node.run('zypper --non-interactive remove --clean-deps -y venv-salt-minion', check_errors: false) - end - node.run('rm -Rf /root/salt /var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /etc/venv-salt-minion /var/tmp/.root*', check_errors: false) + cleanup_paths = use_salt_bundle ? "/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /etc/venv-salt-minion /var/tmp/.root*" : + "/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt /var/tmp/.root*" + + # File/folder cleanup needs to happen before package removal otherwise the transaction is in an inconsistent state + node.run("rm -Rf /root/salt #{cleanup_paths}", check_errors: false) + + # Package removal using the existing step + package_list = use_salt_bundle ? 'venv-salt-minion' : 'salt salt-minion' + + if transactional_system?(host) && use_salt_bundle + # Remove venv-salt-minion and conditionally remove salt-minion if present from sumaform + step %(I remove package "#{package_list}" from this "#{host}" without error control) + _result, code = node.run('rpm -q salt-minion', check_errors: false) + step %(I remove package "salt-minion" from this "#{host}" without error control) if code.zero? else - if transactional_system?(host) - node.run('transactional-update --continue -n pkg rm salt salt-minion', check_errors: false) - # Reboot needed here after package removal but before file removal - step %(I reboot the "#{host}" host through SSH, waiting until it comes back) - elsif rh_host?(host) - node.run('yum -y remove --setopt=clean_requirements_on_remove=1 salt salt-minion', check_errors: false) - elsif deb_host?(host) - node.run('apt-get --assume-yes remove salt-common salt-minion && apt-get --assume-yes purge salt-common salt-minion && apt-get --assume-yes autoremove', check_errors: false) - else - node.run('zypper --non-interactive remove --clean-deps -y salt salt-minion', check_errors: false) - end - node.run('rm -Rf /root/salt /var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt /var/tmp/.root*', check_errors: false) - end - if transactional_system?(host) - # Reboot needed after file removal as well - step %(I reboot the "#{host}" host through SSH, waiting until it comes back) + # Standard removal of bundled or non-bundled package list + step %(I remove package "#{package_list}" from this "#{host}" without error control) end + + # Disable repositories step %(I disable the repositories "tools_update_repo tools_pool_repo" on this "#{host}" without error control) end From 8448859ca7278104c2e4bf2b4c3c616b1ac0f89b Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Mon, 11 Nov 2024 14:13:49 +0100 Subject: [PATCH 3/6] Refine directories and files deleted in cleanup --- testsuite/features/step_definitions/salt_steps.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 394e95fa4667..dad98eae7b41 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -559,10 +559,16 @@ When(/^I perform a full salt minion cleanup on "([^"]*)"$/) do |host| node = get_target(host) - cleanup_paths = use_salt_bundle ? "/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /etc/venv-salt-minion /var/tmp/.root*" : - "/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /etc/salt /var/tmp/.root*" + config_dir = use_salt_bundle ? "/etc/venv-salt-minion" : "/etc/salt" + cleanup_paths = use_salt_bundle ? "/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /var/tmp/.root*" : + "/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /var/tmp/.root*" - # File/folder cleanup needs to happen before package removal otherwise the transaction is in an inconsistent state + # Selective file cleanup within configuration directory + node.run("rm -f #{config_dir}/grains #{config_dir}/minion_id", check_errors: false) + node.run("find #{config_dir}/minion.d/ -type f ! -name '00-venv.conf' -delete", check_errors: false) + node.run("rm -f #{config_dir}/pki/minion/*", check_errors: false) + + # Additional cleanup for cached and runtime files node.run("rm -Rf /root/salt #{cleanup_paths}", check_errors: false) # Package removal using the existing step From 64ea3f55214deeb854f7b69cf066f9190f28d85c Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Mon, 11 Nov 2024 14:16:00 +0100 Subject: [PATCH 4/6] Restore reboot step at end --- testsuite/features/build_validation/init_clients/proxy.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/features/build_validation/init_clients/proxy.feature b/testsuite/features/build_validation/init_clients/proxy.feature index 4593ced06a80..9f4baeaaf83d 100644 --- a/testsuite/features/build_validation/init_clients/proxy.feature +++ b/testsuite/features/build_validation/init_clients/proxy.feature @@ -17,6 +17,7 @@ Feature: Setup containerized proxy Scenario: Clean up sumaform leftovers on the containerized proxy When I perform a full salt minion cleanup on "proxy" + And I reboot the "proxy" host through SSH, waiting until it comes back Scenario: Log in as admin user Given I am authorized for the "Admin" section From df4ef93ef66af8c7e1ce52bda2cf5c540487ac68 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Mon, 11 Nov 2024 14:19:06 +0100 Subject: [PATCH 5/6] Fix rubocop offenses --- .../features/step_definitions/salt_steps.rb | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index dad98eae7b41..3d03923eb9f2 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -559,11 +559,16 @@ When(/^I perform a full salt minion cleanup on "([^"]*)"$/) do |host| node = get_target(host) - config_dir = use_salt_bundle ? "/etc/venv-salt-minion" : "/etc/salt" - cleanup_paths = use_salt_bundle ? "/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /var/tmp/.root*" : - "/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /var/tmp/.root*" - # Selective file cleanup within configuration directory + # Define config directory and cleanup paths based on bundle usage + config_dir = use_salt_bundle ? '/etc/venv-salt-minion' : '/etc/salt' + cleanup_paths = if use_salt_bundle + '/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /var/tmp/.root*' + else + '/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /var/tmp/.root*' + end + + # Selective file cleanup within the configuration directory node.run("rm -f #{config_dir}/grains #{config_dir}/minion_id", check_errors: false) node.run("find #{config_dir}/minion.d/ -type f ! -name '00-venv.conf' -delete", check_errors: false) node.run("rm -f #{config_dir}/pki/minion/*", check_errors: false) @@ -573,15 +578,13 @@ # Package removal using the existing step package_list = use_salt_bundle ? 'venv-salt-minion' : 'salt salt-minion' + step %(I remove package "#{package_list}" from this "#{host}" without error control) + # Conditional additional package removal if transactional_system?(host) && use_salt_bundle - # Remove venv-salt-minion and conditionally remove salt-minion if present from sumaform - step %(I remove package "#{package_list}" from this "#{host}" without error control) + # Check if salt-minion is installed, remove if present from sumaform _result, code = node.run('rpm -q salt-minion', check_errors: false) step %(I remove package "salt-minion" from this "#{host}" without error control) if code.zero? - else - # Standard removal of bundled or non-bundled package list - step %(I remove package "#{package_list}" from this "#{host}" without error control) end # Disable repositories From e1b5db5588b8d58e8717380004f9306637bcc561 Mon Sep 17 00:00:00 2001 From: Konstantinos Tsamis Date: Mon, 11 Nov 2024 14:23:08 +0100 Subject: [PATCH 6/6] Fix another rubocop offense --- testsuite/features/step_definitions/salt_steps.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/testsuite/features/step_definitions/salt_steps.rb b/testsuite/features/step_definitions/salt_steps.rb index 3d03923eb9f2..2a12d0acaa9f 100644 --- a/testsuite/features/step_definitions/salt_steps.rb +++ b/testsuite/features/step_definitions/salt_steps.rb @@ -560,13 +560,16 @@ When(/^I perform a full salt minion cleanup on "([^"]*)"$/) do |host| node = get_target(host) - # Define config directory and cleanup paths based on bundle usage + # Define config directory based on bundle usage config_dir = use_salt_bundle ? '/etc/venv-salt-minion' : '/etc/salt' - cleanup_paths = if use_salt_bundle - '/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /var/tmp/.root*' - else - '/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /var/tmp/.root*' - end + + # Define cleanup paths based on bundle usage + cleanup_paths = + if use_salt_bundle + '/var/cache/venv-salt-minion /run/venv-salt-minion /var/venv-salt-minion.log /var/tmp/.root*' + else + '/var/cache/salt/minion /var/run/salt /run/salt /var/log/salt /var/tmp/.root*' + end # Selective file cleanup within the configuration directory node.run("rm -f #{config_dir}/grains #{config_dir}/minion_id", check_errors: false)