mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Make systemctl/hostctl check functions check they're on linux
This commit is contained in:
parent
5dd5b891f0
commit
19b0db156f
6 changed files with 47 additions and 24 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue