Skip to content

Commit 19b0db1

Browse files
barneysowooddwoz
authored andcommitted
Make systemctl/hostctl check functions check they're on linux
1 parent 5dd5b89 commit 19b0db1

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

tests/integration/modules/test_localemod.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import pytest
44

5+
import salt.utils.platform
56
from tests.support.case import ModuleCase
67

78

89
def _check_systemctl():
910
if not hasattr(_check_systemctl, "memo"):
10-
proc = subprocess.run(["localectl"], capture_output=True, check=False)
11-
_check_systemctl.memo = b"No such file or directory" in proc.stderr
11+
if not salt.utils.platform.is_linux():
12+
_check_systemctl.memo = False
13+
else:
14+
proc = subprocess.run(["localectl"], capture_output=True, check=False)
15+
_check_systemctl.memo = b"No such file or directory" in proc.stderr
1216
return _check_systemctl.memo
1317

1418

tests/integration/modules/test_timezone.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pytest
1010

11+
import salt.utils.platform
1112
from tests.support.case import ModuleCase
1213

1314
try:
@@ -20,8 +21,11 @@
2021

2122
def _check_systemctl():
2223
if not hasattr(_check_systemctl, "memo"):
23-
proc = subprocess.run(["timedatectl"], capture_output=True, check=False)
24-
_check_systemctl.memo = b"No such file or directory" in proc.stderr
24+
if not salt.utils.platform.is_linux():
25+
_check_systemctl.memo = False
26+
else:
27+
proc = subprocess.run(["timedatectl"], capture_output=True, check=False)
28+
_check_systemctl.memo = b"No such file or directory" in proc.stderr
2529
return _check_systemctl.memo
2630

2731

tests/pytests/functional/modules/test_service.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
def _check_systemctl():
1919
if not hasattr(_check_systemctl, "memo"):
20-
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
21-
_check_systemctl.memo = (
22-
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
23-
)
20+
if not salt.utils.platform.is_linux():
21+
_check_systemctl.memo = False
22+
else:
23+
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
24+
_check_systemctl.memo = (
25+
b"Failed to get D-Bus connection: No such file or directory"
26+
in proc.stderr
27+
)
2428
return _check_systemctl.memo
2529

2630

tests/pytests/functional/modules/test_system.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222

2323
def check_hostnamectl():
2424
if not hasattr(check_hostnamectl, "memo"):
25-
proc = subprocess.run(["hostnamectl"], capture_output=True, check=False)
26-
check_hostnamectl.memo = (
27-
b"Failed to connect to bus: No such file or directory" in proc.stderr
28-
or b"Failed to create bus connection: No such file or directory"
29-
in proc.stderr
30-
)
25+
if not salt.utils.platform.is_linux():
26+
check_hostnamectl.memo = False
27+
else:
28+
proc = subprocess.run(["hostnamectl"], capture_output=True, check=False)
29+
check_hostnamectl.memo = (
30+
b"Failed to connect to bus: No such file or directory" in proc.stderr
31+
or b"Failed to create bus connection: No such file or directory"
32+
in proc.stderr
33+
)
3134
return check_hostnamectl.memo
3235

3336

tests/pytests/functional/states/test_service.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424

2525
def _check_systemctl():
2626
if not hasattr(_check_systemctl, "memo"):
27-
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
28-
_check_systemctl.memo = (
29-
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
30-
or b"Failed to connect to bus: No such file or directory" in proc.stderr
31-
)
27+
if not salt.utils.platform.is_linux():
28+
_check_systemctl.memo = False
29+
else:
30+
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
31+
_check_systemctl.memo = (
32+
b"Failed to get D-Bus connection: No such file or directory"
33+
in proc.stderr
34+
or b"Failed to connect to bus: No such file or directory" in proc.stderr
35+
)
3236
return _check_systemctl.memo
3337

3438

tests/pytests/unit/states/test_service.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020
def _check_systemctl():
2121
if not hasattr(_check_systemctl, "memo"):
22-
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
23-
_check_systemctl.memo = (
24-
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
25-
or b"Failed to connect to bus: No such file or directory" in proc.stderr
26-
)
22+
if not salt.utils.platform.is_linux():
23+
_check_systemctl.memo = False
24+
else:
25+
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
26+
_check_systemctl.memo = (
27+
b"Failed to get D-Bus connection: No such file or directory"
28+
in proc.stderr
29+
or b"Failed to connect to bus: No such file or directory" in proc.stderr
30+
)
2731
return _check_systemctl.memo
2832

2933

0 commit comments

Comments
 (0)