Skip tests when hostnamectl does not work

This commit is contained in:
Daniel A. Wozniak 2025-01-05 17:47:36 -07:00 committed by Daniel Wozniak
parent 90d5bd27a8
commit 05f9bcae18

View file

@ -20,6 +20,15 @@ pytestmark = [
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
)
return check_hostnamectl.memo
@pytest.fixture(scope="module")
def cmdmod(modules):
return modules.cmd
@ -205,9 +214,9 @@ def test_get_system_date_time_utc(setup_teardown_vars, system, fmt_str):
assert _same_times(t1, t2, seconds_diff=3), msg
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_date_time(setup_teardown_vars, system, hwclock_has_compare):
"""
Test changing the system clock. We are only able to set it up to a
@ -226,9 +235,9 @@ def test_set_system_date_time(setup_teardown_vars, system, hwclock_has_compare):
_test_hwclock_sync(system, hwclock_has_compare)
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_date_time_utc(setup_teardown_vars, system, hwclock_has_compare):
"""
Test changing the system clock. We are only able to set it up to a
@ -247,9 +256,9 @@ def test_set_system_date_time_utc(setup_teardown_vars, system, hwclock_has_compa
_test_hwclock_sync(system, hwclock_has_compare)
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_date_time_utcoffset_east(
setup_teardown_vars, system, hwclock_has_compare
):
@ -271,9 +280,9 @@ def test_set_system_date_time_utcoffset_east(
_test_hwclock_sync(system, hwclock_has_compare)
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_date_time_utcoffset_west(
setup_teardown_vars, system, hwclock_has_compare
):
@ -295,10 +304,10 @@ def test_set_system_date_time_utcoffset_west(
_test_hwclock_sync(system, hwclock_has_compare)
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.flaky(max_runs=4)
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_time(setup_teardown_vars, system, hwclock_has_compare):
"""
Test setting the system time without adjusting the date.
@ -317,9 +326,9 @@ def test_set_system_time(setup_teardown_vars, system, hwclock_has_compare):
_test_hwclock_sync(system, hwclock_has_compare)
@pytest.mark.skip_on_env("ON_DOCKER", eq="1")
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_system_date(setup_teardown_vars, system, hwclock_has_compare):
"""
Test setting the system date without adjusting the time.
@ -340,6 +349,7 @@ def test_set_system_date(setup_teardown_vars, system, hwclock_has_compare):
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_get_computer_desc(setup_teardown_vars, system, cmdmod):
"""
Test getting the system hostname
@ -361,6 +371,7 @@ def test_get_computer_desc(setup_teardown_vars, system, cmdmod):
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_computer_desc(setup_teardown_vars, system):
"""
Test setting the computer description
@ -375,6 +386,7 @@ def test_set_computer_desc(setup_teardown_vars, system):
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root
@pytest.mark.skipif(check_hostnamectl(), reason="hostnamctl degraded.")
def test_set_computer_desc_multiline(setup_teardown_vars, system):
"""
Test setting the computer description with a multiline string with tabs