From 685c43bc72237ff0bfc8ee53956b6048790b20c4 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Fri, 21 Mar 2025 11:13:49 -0600 Subject: [PATCH 1/7] Added support and tests for Sys V service files --- changelog/67888.fixed.md | 1 + pkg/rpm/salt.spec | 11 ++++ .../pytests/pkg/upgrade/test_salt_upgrade.py | 63 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 changelog/67888.fixed.md diff --git a/changelog/67888.fixed.md b/changelog/67888.fixed.md new file mode 100644 index 000000000000..d2c19844fe98 --- /dev/null +++ b/changelog/67888.fixed.md @@ -0,0 +1 @@ +Added service files for specific rpm packages to /etc/init.d diff --git a/pkg/rpm/salt.spec b/pkg/rpm/salt.spec index bb71fff631b1..ab242d3b7ccd 100644 --- a/pkg/rpm/salt.spec +++ b/pkg/rpm/salt.spec @@ -309,6 +309,13 @@ install -p -m 0644 %{_salt_src}/doc/man/salt-api.1 %{buildroot}%{_mandir}/man1/s install -p -m 0644 %{_salt_src}/doc/man/salt-cloud.1 %{buildroot}%{_mandir}/man1/salt-cloud.1 install -p -m 0644 %{_salt_src}/doc/man/salt-ssh.1 %{buildroot}%{_mandir}/man1/salt-ssh.1 +# Sys V service files +mkdir -p %{buildroot}%{_sysconfdir}/init.d +install -p -m 0755 %{_salt_src}/pkg/rpm/salt-minion %{buildroot}%{_sysconfdir}/init.d/salt-minion +install -p -m 0755 %{_salt_src}/pkg/rpm/salt-master %{buildroot}%{_sysconfdir}/init.d/salt-master +install -p -m 0755 %{_salt_src}/pkg/rpm/salt-syndic %{buildroot}%{_sysconfdir}/init.d/salt-syndic +install -p -m 0755 %{_salt_src}/pkg/rpm/salt-api %{buildroot}%{_sysconfdir}/init.d/salt-api + %clean rm -rf %{buildroot} @@ -361,6 +368,7 @@ rm -rf %{buildroot} %dir %attr(0750, salt, salt) %{_var}/cache/salt/master/roots/ %dir %attr(0750, salt, salt) %{_var}/cache/salt/master/syndics/ %dir %attr(0750, salt, salt) %{_var}/cache/salt/master/tokens/ +%{_sysconfdir}/init.d/salt-master %files minion @@ -378,12 +386,14 @@ rm -rf %{buildroot} %config(noreplace) %{_sysconfdir}/salt/pki/minion %dir %{_sysconfdir}/salt/minion.d %dir %attr(0750, root, root) %{_var}/cache/salt/minion/ +%{_sysconfdir}/init.d/salt-minion %files syndic %doc %{_mandir}/man1/salt-syndic.1* %{_bindir}/salt-syndic %{_unitdir}/salt-syndic.service +%{_sysconfdir}/init.d/salt-syndic %files api @@ -391,6 +401,7 @@ rm -rf %{buildroot} %doc %{_mandir}/man1/salt-api.1* %{_bindir}/salt-api %{_unitdir}/salt-api.service +%{_sysconfdir}/init.d/salt-api %files cloud diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index 1f07014571b0..7066d32b95c4 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -1,4 +1,6 @@ import logging +import os +import subprocess import sys import time @@ -7,6 +9,8 @@ import pytest from pytestskipmarkers.utils import platform +import salt.utils.path + log = logging.getLogger(__name__) @@ -132,6 +136,65 @@ def _get_running_named_salt_pid(process_name): return pids +def test_salt_sysv_service_files(salt_call_cli, install_salt): + """ + Test an upgrade of Salt, Minion and Master + """ + if not install_salt.upgrade: + pytest.skip("Not testing an upgrade, do not run") + + if sys.platform != "linux": + pytest.skip("Not testing on a Linux platform, do not run") + + if not (salt.utils.path.which("dpkg") or salt.utils.path.which("rpm")): + pytest.skip("Not testing on a Debian or RedHat family platform, do not run") + + print( + f"DGM test_salt_sysv_service_files entry install_salt, '{install_salt}'", + flush=True, + ) + + test_pkgs = install_salt.config_path.pkgs + print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) + for test_pkg_name in test_pkgs: + test_pkg_basename = os.path.bashname(test_pkg_name) + test_pkg_basename_adj = test_pkg_basename.split("_") + print( + f"DGM test_salt_sysv_service_files test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", + flush=True, + ) + if test_pkg_basename_adj in ( + "salt-minion", + "salt-master", + "salt-syndic", + "salt-api", + ): + test_initd_name = f"/etc/init.d/{test_pkg_basename_adj}" + if salt.utils.path.which("dpkg"): + proc = subprocess.run( + ["dpkg", "-q", "-c", f"{test_pkg_name}"], + capture_output=True, + check=True, + ) + elif salt.utils.path.which("rpm"): + proc = subprocess.run( + ["rpm", "-q", "-l", "-p", f"{test_pkg_name}"], + capture_output=True, + check=True, + ) + found_line = False + for line in proc.stdout.decode().splitlines(): + # If test_initd_name not present we should fail. + if line == test_initd_name: + found_line = True + print( + f"DGM test_salt_sysv_service_files test_initd_name, '{test_initd_name}' was FOUND", + flush=True, + ) + + assert found_line + + def test_salt_upgrade(salt_call_cli, install_salt): """ Test an upgrade of Salt, Minion and Master From 6dd5eec9b349b94ecc99b2561f607d461e34adb2 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Fri, 21 Mar 2025 12:45:20 -0600 Subject: [PATCH 2/7] Updated test --- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index 7066d32b95c4..d89278a38fbf 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -154,7 +154,7 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): flush=True, ) - test_pkgs = install_salt.config_path.pkgs + test_pkgs = install_salt.pkgs print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) for test_pkg_name in test_pkgs: test_pkg_basename = os.path.bashname(test_pkg_name) From adec54b9636258c69e6e1ffda12ea2c7580d6ee5 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Fri, 21 Mar 2025 13:39:58 -0600 Subject: [PATCH 3/7] Fixed typo --- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index d89278a38fbf..5f6ac496c67c 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -157,7 +157,7 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): test_pkgs = install_salt.pkgs print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) for test_pkg_name in test_pkgs: - test_pkg_basename = os.path.bashname(test_pkg_name) + test_pkg_basename = os.path.basename(test_pkg_name) test_pkg_basename_adj = test_pkg_basename.split("_") print( f"DGM test_salt_sysv_service_files test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", From 0df9962f74843409779f26901e22cbeee1c15336 Mon Sep 17 00:00:00 2001 From: David Murphy Date: Mon, 24 Mar 2025 10:01:42 -0600 Subject: [PATCH 4/7] Updated test --- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index 5f6ac496c67c..b615dcda6f95 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -158,9 +158,12 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) for test_pkg_name in test_pkgs: test_pkg_basename = os.path.basename(test_pkg_name) - test_pkg_basename_adj = test_pkg_basename.split("_") + # Debian/Ubuntu name typically salt-minion_300xxxxxx + # Redhat name typically salt-minion-300xxxxxx + test_pkg_basename_dashunderscore = test_pkg_basename.split("300")[0] + test_pkg_basename_adj = test_pkg_basename_dashunderscore[:-1] print( - f"DGM test_salt_sysv_service_files test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", + f"DGM test_salt_sysv_service_files test_pkg_basename_dashunderscore '{test_pkg_basename_dashunderscore}', test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", flush=True, ) if test_pkg_basename_adj in ( @@ -170,6 +173,10 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): "salt-api", ): test_initd_name = f"/etc/init.d/{test_pkg_basename_adj}" + print( + f"DGM test_salt_sysv_service_files test_initd_name, '{test_initd_name}' to check against", + flush=True, + ) if salt.utils.path.which("dpkg"): proc = subprocess.run( ["dpkg", "-q", "-c", f"{test_pkg_name}"], @@ -185,6 +192,10 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): found_line = False for line in proc.stdout.decode().splitlines(): # If test_initd_name not present we should fail. + print( + f"DGM test_salt_sysv_service_files check line, '{line}'", + flush=True, + ) if line == test_initd_name: found_line = True print( From 14c5830707d14877fe46db48c0c466fb55d6f6ee Mon Sep 17 00:00:00 2001 From: David Murphy Date: Mon, 24 Mar 2025 11:16:13 -0600 Subject: [PATCH 5/7] Removed debug statements --- .../pytests/pkg/upgrade/test_salt_upgrade.py | 27 +++---------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index b615dcda6f95..d242a23a551c 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -149,23 +149,13 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): if not (salt.utils.path.which("dpkg") or salt.utils.path.which("rpm")): pytest.skip("Not testing on a Debian or RedHat family platform, do not run") - print( - f"DGM test_salt_sysv_service_files entry install_salt, '{install_salt}'", - flush=True, - ) - test_pkgs = install_salt.pkgs - print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) for test_pkg_name in test_pkgs: test_pkg_basename = os.path.basename(test_pkg_name) # Debian/Ubuntu name typically salt-minion_300xxxxxx # Redhat name typically salt-minion-300xxxxxx - test_pkg_basename_dashunderscore = test_pkg_basename.split("300")[0] - test_pkg_basename_adj = test_pkg_basename_dashunderscore[:-1] - print( - f"DGM test_salt_sysv_service_files test_pkg_basename_dashunderscore '{test_pkg_basename_dashunderscore}', test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", - flush=True, - ) + test_pkg_basename_dash_underscore = test_pkg_basename.split("300")[0] + test_pkg_basename_adj = test_pkg_basename_dash_underscore[:-1] if test_pkg_basename_adj in ( "salt-minion", "salt-master", @@ -173,10 +163,6 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): "salt-api", ): test_initd_name = f"/etc/init.d/{test_pkg_basename_adj}" - print( - f"DGM test_salt_sysv_service_files test_initd_name, '{test_initd_name}' to check against", - flush=True, - ) if salt.utils.path.which("dpkg"): proc = subprocess.run( ["dpkg", "-q", "-c", f"{test_pkg_name}"], @@ -192,16 +178,9 @@ def test_salt_sysv_service_files(salt_call_cli, install_salt): found_line = False for line in proc.stdout.decode().splitlines(): # If test_initd_name not present we should fail. - print( - f"DGM test_salt_sysv_service_files check line, '{line}'", - flush=True, - ) if line == test_initd_name: found_line = True - print( - f"DGM test_salt_sysv_service_files test_initd_name, '{test_initd_name}' was FOUND", - flush=True, - ) + break assert found_line From 40a4ffdf299bde13b50dcb61fcf31a60adc8a62e Mon Sep 17 00:00:00 2001 From: David Murphy Date: Mon, 24 Mar 2025 11:22:57 -0600 Subject: [PATCH 6/7] Updated test to remove salt_call_cli --- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index d242a23a551c..20a1580eae07 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -136,7 +136,7 @@ def _get_running_named_salt_pid(process_name): return pids -def test_salt_sysv_service_files(salt_call_cli, install_salt): +def test_salt_sysv_service_files(install_salt): """ Test an upgrade of Salt, Minion and Master """ From 42bb0b4ed1635d0dc997bd837ca8ee5effab7e2e Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 22 Apr 2025 12:05:51 -0600 Subject: [PATCH 7/7] Fix upgrade tests for debian based systems --- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index 20a1580eae07..f648a1794858 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -164,11 +164,18 @@ def test_salt_sysv_service_files(install_salt): ): test_initd_name = f"/etc/init.d/{test_pkg_basename_adj}" if salt.utils.path.which("dpkg"): - proc = subprocess.run( - ["dpkg", "-q", "-c", f"{test_pkg_name}"], - capture_output=True, - check=True, - ) + if os.path.exists("/etc/debian_version"): + proc = subprocess.run( + ["dpkg", "-c", f"{test_pkg_name}"], + capture_output=True, + check=True, + ) + else: + proc = subprocess.run( + ["dpkg", "-q", "-c", f"{test_pkg_name}"], + capture_output=True, + check=True, + ) elif salt.utils.path.which("rpm"): proc = subprocess.run( ["rpm", "-q", "-l", "-p", f"{test_pkg_name}"],