|
1 | 1 | import logging
|
| 2 | +import os |
| 3 | +import subprocess |
2 | 4 | import sys
|
3 | 5 | import time
|
4 | 6 |
|
|
7 | 9 | import pytest
|
8 | 10 | from pytestskipmarkers.utils import platform
|
9 | 11 |
|
| 12 | +import salt.utils.path |
| 13 | + |
10 | 14 | log = logging.getLogger(__name__)
|
11 | 15 |
|
12 | 16 |
|
@@ -126,6 +130,65 @@ def _get_running_named_salt_pid(process_name):
|
126 | 130 | return pids
|
127 | 131 |
|
128 | 132 |
|
| 133 | +def test_salt_sysv_service_files(salt_call_cli, install_salt): |
| 134 | + """ |
| 135 | + Test an upgrade of Salt, Minion and Master |
| 136 | + """ |
| 137 | + if not install_salt.upgrade: |
| 138 | + pytest.skip("Not testing an upgrade, do not run") |
| 139 | + |
| 140 | + if sys.platform != "linux": |
| 141 | + pytest.skip("Not testing on a Linux platform, do not run") |
| 142 | + |
| 143 | + if not (salt.utils.path.which("dpkg") or salt.utils.path.which("rpm")): |
| 144 | + pytest.skip("Not testing on a Debian or RedHat family platform, do not run") |
| 145 | + |
| 146 | + print( |
| 147 | + f"DGM test_salt_sysv_service_files entry install_salt, '{install_salt}'", |
| 148 | + flush=True, |
| 149 | + ) |
| 150 | + |
| 151 | + test_pkgs = install_salt.config_path.pkgs |
| 152 | + print(f"DGM test_salt_sysv_service_files test_pkgs, '{test_pkgs}'", flush=True) |
| 153 | + for test_pkg_name in test_pkgs: |
| 154 | + test_pkg_basename = os.path.bashname(test_pkg_name) |
| 155 | + test_pkg_basename_adj = test_pkg_basename.split("_") |
| 156 | + print( |
| 157 | + f"DGM test_salt_sysv_service_files test_pkg_basename_adj '{test_pkg_basename_adj}' from name test_pkg_basename '{test_pkg_basename}'", |
| 158 | + flush=True, |
| 159 | + ) |
| 160 | + if test_pkg_basename_adj in ( |
| 161 | + "salt-minion", |
| 162 | + "salt-master", |
| 163 | + "salt-syndic", |
| 164 | + "salt-api", |
| 165 | + ): |
| 166 | + test_initd_name = f"/etc/init.d/{test_pkg_basename_adj}" |
| 167 | + if salt.utils.path.which("dpkg"): |
| 168 | + proc = subprocess.run( |
| 169 | + ["dpkg", "-q", "-c", f"{test_pkg_name}"], |
| 170 | + capture_output=True, |
| 171 | + check=True, |
| 172 | + ) |
| 173 | + elif salt.utils.path.which("rpm"): |
| 174 | + proc = subprocess.run( |
| 175 | + ["rpm", "-q", "-l", "-p", f"{test_pkg_name}"], |
| 176 | + capture_output=True, |
| 177 | + check=True, |
| 178 | + ) |
| 179 | + found_line = False |
| 180 | + for line in proc.stdout.decode().splitlines(): |
| 181 | + # If test_initd_name not present we should fail. |
| 182 | + if line == test_initd_name: |
| 183 | + found_line = True |
| 184 | + print( |
| 185 | + f"DGM test_salt_sysv_service_files test_initd_name, '{test_initd_name}' was FOUND", |
| 186 | + flush=True, |
| 187 | + ) |
| 188 | + |
| 189 | + assert found_line |
| 190 | + |
| 191 | + |
129 | 192 | def test_salt_upgrade(salt_call_cli, install_salt):
|
130 | 193 | """
|
131 | 194 | Test an upgrade of Salt, Minion and Master
|
|
0 commit comments