Skip to content

Commit a02bdef

Browse files
committed
Fix issues with services and pytest-salt-factories
Fixes issues with services in the pkg upgrade systemd tests: * Stopping a salt service that is using the log engine from pytest-salt-factories fails if systemd is set to KillMode=process, which is the current setup in salt's packages. Added a fixture to override for these tests, otherwise we end up with services in a failed state. * SaltPkgInstall.install() stops services on ubuntu/debian after install which is the right thing to do in most cases, but in these tests we need to check the state of services immeadiately after install. Added a stop_services arg to install()
1 parent 433c130 commit a02bdef

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

tests/pytests/pkg/upgrade/test_systemd_permissions.py

+44-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import logging
2+
import textwrap
23
import time
4+
from pathlib import Path
35

46
import packaging.version
57
import pytest
8+
from saltfactories.utils.tempfiles import temp_file
69

710
pytestmark = [
811
pytest.mark.skip_unless_on_linux(reason="Only supported on Linux family"),
@@ -11,10 +14,47 @@
1114
log = logging.getLogger(__name__)
1215

1316

17+
@pytest.fixture(scope="module")
18+
def salt_systemd_overrides():
19+
"""
20+
Fixture to create systemd overrides for salt-api, salt-minion, and
21+
salt-master services.
22+
23+
This is required because the pytest-salt-factories engine does not
24+
stop cleanly if you only kill the process. This leaves the systemd
25+
service in a failed state.
26+
"""
27+
28+
systemd_dir = Path("/etc/systemd/system")
29+
conf_name = "override.conf"
30+
contents = textwrap.dedent(
31+
"""
32+
[Service]
33+
KillMode=control-group
34+
TimeoutStopSec=10
35+
SuccessExitStatus=SIGKILL
36+
"""
37+
)
38+
39+
with temp_file(
40+
name=conf_name, directory=systemd_dir / "salt-api.service.d", contents=contents
41+
), temp_file(
42+
name=conf_name,
43+
directory=systemd_dir / "salt-minion.service.d",
44+
contents=contents,
45+
), temp_file(
46+
name=conf_name,
47+
directory=systemd_dir / "salt-master.service.d",
48+
contents=contents,
49+
):
50+
yield
51+
52+
1453
@pytest.fixture(scope="function")
1554
def salt_systemd_setup(
1655
salt_call_cli,
1756
install_salt,
57+
salt_systemd_overrides,
1858
):
1959
"""
2060
Fixture install previous version and set systemd for salt packages
@@ -75,7 +115,7 @@ def test_salt_systemd_disabled_preservation(
75115
# Upgrade Salt (inc. minion, master, etc.) from previous version and test
76116
# pylint: disable=pointless-statement
77117
install_salt.install(upgrade=True)
78-
time.sleep(10) # give it some time
118+
time.sleep(60) # give it some time
79119

80120
# test for disabled systemd state
81121
test_list = ["salt-api", "salt-minion", "salt-master"]
@@ -120,7 +160,7 @@ def test_salt_systemd_inactive_preservation(
120160
if not install_salt.upgrade:
121161
pytest.skip("Not testing an upgrade, do not run")
122162

123-
# ensure known state, disabled
163+
# ensure known state, inactive
124164
test_list = ["salt-api", "salt-minion", "salt-master"]
125165
for test_item in test_list:
126166
test_cmd = f"systemctl stop {test_item}"
@@ -129,7 +169,7 @@ def test_salt_systemd_inactive_preservation(
129169

130170
# Upgrade Salt (inc. minion, master, etc.) from previous version and test
131171
# pylint: disable=pointless-statement
132-
install_salt.install(upgrade=True)
172+
install_salt.install(upgrade=True, stop_services=False)
133173
time.sleep(10) # give it some time
134174

135175
# test for inactive systemd state
@@ -153,7 +193,7 @@ def test_salt_systemd_active_preservation(
153193

154194
# Upgrade Salt (inc. minion, master, etc.) from previous version and test
155195
# pylint: disable=pointless-statement
156-
install_salt.install(upgrade=True)
196+
install_salt.install(upgrade=True, stop_services=False)
157197
time.sleep(10) # give it some time
158198

159199
# test for active systemd state

tests/support/pkg.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ def package_python_version(self):
579579
"import sys; print('{}.{}'.format(*sys.version_info))",
580580
).stdout.strip()
581581

582-
def install(self, upgrade=False, downgrade=False):
582+
def install(self, upgrade=False, downgrade=False, stop_services=True):
583583
self._install_pkgs(upgrade=upgrade, downgrade=downgrade)
584-
if self.distro_id in ("ubuntu", "debian"):
584+
if self.distro_id in ("ubuntu", "debian") and stop_services:
585585
self.stop_services()
586586

587587
def stop_services(self):

0 commit comments

Comments
 (0)