Replace the usage of @runs_on(...) and @not_runs_on(...)

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-12-05 09:44:49 +00:00 committed by Pedro Algarvio
parent a222d9b613
commit 7af30ff1bd
17 changed files with 18 additions and 83 deletions

View file

@ -5,7 +5,6 @@ import salt.utils.files
import salt.utils.platform
import salt.utils.stringutils
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
if not salt.utils.platform.is_windows():
import grp
@ -14,7 +13,7 @@ if not salt.utils.platform.is_windows():
@pytest.mark.skip_if_not_root
@pytest.mark.destructive_test
@pytest.mark.windows_whitelisted
@runs_on(kernel=("Linux", "Windows"))
@pytest.mark.skip_unless_on_platforms(linux=True, windows=True)
class GroupModuleTest(ModuleCase):
"""
Validate the linux group system module

View file

@ -5,14 +5,13 @@
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
OSA_SCRIPT = "/usr/bin/osascript"
@pytest.mark.destructive_test
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class MacAssistiveTest(ModuleCase):
"""
Integration tests for the mac_assistive module.

View file

@ -6,7 +6,6 @@ import pytest
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
# Brew doesn't support local package installation - So, let's
# Grab some small packages available online for brew
@ -15,9 +14,9 @@ DEL_PKG = "acme"
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.destructive_test
@pytest.mark.skip_if_binaries_missing("brew")
@pytest.mark.skip_unless_on_darwin
class BrewModuleTest(ModuleCase):
"""
Integration tests for the brew module

View file

@ -5,12 +5,11 @@ Integration tests for the mac_desktop execution module.
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
@pytest.mark.destructive_test
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class MacDesktopTestCase(ModuleCase):
"""
Integration tests for the mac_desktop module.

View file

@ -7,7 +7,6 @@ from saltfactories.utils import random_string
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
# Create group name strings for tests
ADD_GROUP = random_string("RS-", lowercase=False)
@ -18,8 +17,8 @@ REP_USER_GROUP = random_string("RS-", lowercase=False)
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.destructive_test
@pytest.mark.skip_unless_on_darwin
class MacGroupModuleTest(ModuleCase):
"""
Integration tests for the mac_group module

View file

@ -8,13 +8,12 @@ import pytest
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
from tests.support.runtests import RUNTIME_VARS
@pytest.mark.destructive_test
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class MacKeychainModuleTest(ModuleCase):
"""
Integration tests for the mac_keychain module

View file

@ -5,12 +5,11 @@ integration tests for mac_ports
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_binaries_missing("port")
@pytest.mark.skip_unless_on_darwin
class MacPortsModuleTest(ModuleCase):
"""
Validate the mac_ports module

View file

@ -8,12 +8,11 @@ import pytest
import salt.utils.files
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_binaries_missing("launchctl", "plutil")
@pytest.mark.skip_unless_on_darwin
class MacServiceModuleTest(ModuleCase):
"""
Validate the mac_service module

View file

@ -8,15 +8,14 @@ import pytest
from saltfactories.utils import random_string
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
TEST_USER = random_string("RS-", lowercase=False)
NO_USER = random_string("RS-", lowercase=False)
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_binaries_missing("dscl", "pwpolicy")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class MacShadowModuleTest(ModuleCase):
"""
Validate the mac_shadow module

View file

@ -5,12 +5,11 @@ integration tests for mac_softwareupdate
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_binaries_missing("softwareupdate")
@pytest.mark.skip_unless_on_darwin
class MacSoftwareUpdateModuleTest(ModuleCase):
"""
Validate the mac_softwareupdate module

View file

@ -10,7 +10,6 @@ import pytest
import salt.utils.files
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
# Module Variables
ASSIGN_CMD = "net.inet.icmp.icmplim"
@ -18,8 +17,8 @@ CONFIG = "/etc/sysctl.conf"
@pytest.mark.destructive_test
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class DarwinSysctlModuleTest(ModuleCase):
"""
Integration tests for the darwin_sysctl module

View file

@ -10,7 +10,6 @@ from saltfactories.utils import random_string
import salt.utils.files
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
# Create user strings for tests
ADD_USER = random_string("RS-", lowercase=False)
@ -20,8 +19,8 @@ CHANGE_USER = random_string("RS-", lowercase=False)
@pytest.mark.skip_if_not_root
@runs_on(kernel="Darwin")
@pytest.mark.destructive_test
@pytest.mark.skip_unless_on_darwin
class MacUserModuleTest(ModuleCase):
"""
Integration tests for the mac_user module

View file

@ -7,12 +7,11 @@ import os
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
from tests.support.runtests import RUNTIME_VARS
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_binaries_missing("xattr")
@pytest.mark.skip_unless_on_darwin
class MacXattrModuleTest(ModuleCase):
"""
Validate the mac_xattr module

View file

@ -4,7 +4,6 @@ Validate the mac-defaults module
import pytest
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
DEFAULT_DOMAIN = "com.apple.AppleMultitouchMouse"
DEFAULT_KEY = "MouseHorizontalScroll"
@ -12,8 +11,8 @@ DEFAULT_VALUE = "0"
@pytest.mark.destructive_test
@runs_on(kernel="Darwin")
@pytest.mark.skip_if_not_root
@pytest.mark.skip_unless_on_darwin
class MacDefaultsModuleTest(ModuleCase):
"""
Integration tests for the mac_default module

View file

@ -13,7 +13,7 @@ import salt.modules.nilrt_ip as ip
import salt.utils.files
import salt.utils.platform
from tests.support.case import ModuleCase
from tests.support.helpers import requires_system_grains, runs_on
from tests.support.helpers import requires_system_grains
from tests.support.unit import skipIf
try:
@ -33,7 +33,6 @@ INTERFACE_FOR_TEST = "eth1"
@pytest.mark.skip_if_not_root
@skipIf(not pyiface, "The python pyiface package is not installed")
@skipIf(not CaseInsensitiveDict, "The python package requests is not installed")
@runs_on(os_family="NILinuxRT", reason="Tests applicable only to NILinuxRT")
@pytest.mark.destructive_test
class NilrtIpModuleTest(ModuleCase):
"""
@ -43,6 +42,8 @@ class NilrtIpModuleTest(ModuleCase):
@requires_system_grains
@classmethod
def setUpClass(cls, grains): # pylint: disable=arguments-differ
if grains["os_family"] != "NILinuxRT":
pytest.skip(reason="Tests applicable only to NILinuxRT")
cls.initialState = {}
cls.grains = grains

View file

@ -7,10 +7,9 @@ import pytest
from saltfactories.utils import random_string
from tests.support.case import ModuleCase
from tests.support.helpers import runs_on
@runs_on(kernel="FreeBSD")
@pytest.mark.skip_unless_on_freebsd
class PwUserModuleTest(ModuleCase):
@pytest.mark.destructive_test
@pytest.mark.skip_if_not_root

View file

@ -1084,57 +1084,6 @@ def requires_system_grains(func):
return decorator
@requires_system_grains
def runs_on(grains=None, **kwargs):
"""
Skip the test if grains don't match the values passed into **kwargs
if a kwarg value is a list then skip if the grains don't match any item in the list
"""
reason = kwargs.pop("reason", None)
for kw, value in kwargs.items():
if isinstance(value, list):
if not any(str(grains.get(kw)).lower() != str(v).lower() for v in value):
if reason is None:
reason = "This test does not run on {}={}".format(
kw, grains.get(kw)
)
return skip(reason)
else:
if str(grains.get(kw)).lower() != str(value).lower():
if reason is None:
reason = "This test runs on {}={}, not {}".format(
kw, value, grains.get(kw)
)
return skip(reason)
return _id
@requires_system_grains
def not_runs_on(grains=None, **kwargs):
"""
Reverse of `runs_on`.
Skip the test if any grains match the values passed into **kwargs
if a kwarg value is a list then skip if the grains match any item in the list
"""
reason = kwargs.pop("reason", None)
for kw, value in kwargs.items():
if isinstance(value, list):
if any(str(grains.get(kw)).lower() == str(v).lower() for v in value):
if reason is None:
reason = "This test does not run on {}={}".format(
kw, grains.get(kw)
)
return skip(reason)
else:
if str(grains.get(kw)).lower() == str(value).lower():
if reason is None:
reason = "This test does not run on {}={}, got {}".format(
kw, value, grains.get(kw)
)
return skip(reason)
return _id
def _check_required_sminion_attributes(sminion_attr, *required_items):
"""
:param sminion_attr: The name of the sminion attribute to check, such as 'functions' or 'states'