Make systemctl/hostctl check functions check they're on linux

This commit is contained in:
Barney Sowood 2025-01-11 01:41:50 +00:00 committed by Daniel Wozniak
parent 5dd5b891f0
commit 19b0db156f
6 changed files with 47 additions and 24 deletions

View file

@ -2,13 +2,17 @@ import subprocess
import pytest
import salt.utils.platform
from tests.support.case import ModuleCase
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
proc = subprocess.run(["localectl"], capture_output=True, check=False)
_check_systemctl.memo = b"No such file or directory" in proc.stderr
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["localectl"], capture_output=True, check=False)
_check_systemctl.memo = b"No such file or directory" in proc.stderr
return _check_systemctl.memo

View file

@ -8,6 +8,7 @@ import subprocess
import pytest
import salt.utils.platform
from tests.support.case import ModuleCase
try:
@ -20,8 +21,11 @@ except ImportError:
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
proc = subprocess.run(["timedatectl"], capture_output=True, check=False)
_check_systemctl.memo = b"No such file or directory" in proc.stderr
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["timedatectl"], capture_output=True, check=False)
_check_systemctl.memo = b"No such file or directory" in proc.stderr
return _check_systemctl.memo

View file

@ -17,10 +17,14 @@ pytestmark = [
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
)
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory"
in proc.stderr
)
return _check_systemctl.memo

View file

@ -22,12 +22,15 @@ log = logging.getLogger(__name__)
def check_hostnamectl():
if not hasattr(check_hostnamectl, "memo"):
proc = subprocess.run(["hostnamectl"], capture_output=True, check=False)
check_hostnamectl.memo = (
b"Failed to connect to bus: No such file or directory" in proc.stderr
or b"Failed to create bus connection: No such file or directory"
in proc.stderr
)
if not salt.utils.platform.is_linux():
check_hostnamectl.memo = False
else:
proc = subprocess.run(["hostnamectl"], capture_output=True, check=False)
check_hostnamectl.memo = (
b"Failed to connect to bus: No such file or directory" in proc.stderr
or b"Failed to create bus connection: No such file or directory"
in proc.stderr
)
return check_hostnamectl.memo

View file

@ -24,11 +24,15 @@ RUNNING = True
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
or b"Failed to connect to bus: No such file or directory" in proc.stderr
)
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory"
in proc.stderr
or b"Failed to connect to bus: No such file or directory" in proc.stderr
)
return _check_systemctl.memo

View file

@ -19,11 +19,15 @@ log = logging.getLogger(__name__)
def _check_systemctl():
if not hasattr(_check_systemctl, "memo"):
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory" in proc.stderr
or b"Failed to connect to bus: No such file or directory" in proc.stderr
)
if not salt.utils.platform.is_linux():
_check_systemctl.memo = False
else:
proc = subprocess.run(["systemctl"], capture_output=True, check=False)
_check_systemctl.memo = (
b"Failed to get D-Bus connection: No such file or directory"
in proc.stderr
or b"Failed to connect to bus: No such file or directory" in proc.stderr
)
return _check_systemctl.memo