Use the more portable helper skip_if_not_root.

This commit is contained in:
Pedro Algarvio 2017-04-04 18:57:27 +01:00
parent dcf0a55daf
commit 7b713d9256
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
37 changed files with 127 additions and 202 deletions

View file

@ -8,10 +8,10 @@ import textwrap
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
skip_if_binaries_missing
skip_if_binaries_missing,
skip_if_not_root
)
# Import salt libs
@ -196,7 +196,7 @@ class CMDModuleTest(ModuleCase):
result = self.run_function('cmd.run_stdout', [cmd]).strip()
self.assertEqual(result, expected_result)
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_quotes_runas(self):
'''
cmd.run with quoted command

View file

@ -15,8 +15,7 @@ from salt.exceptions import CommandExecutionError
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Module Variables
ASSIGN_CMD = 'net.inet.icmp.icmplim'
@ -24,7 +23,7 @@ CONFIG = '/etc/sysctl.conf'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class DarwinSysctlModuleTest(ModuleCase):
'''
Integration tests for the darwin_sysctl module

View file

@ -7,20 +7,23 @@ import random
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
# Import 3rd-party libs
from salt.ext.six.moves import range
import salt.utils
@skip_if_not_root
class GroupModuleTest(ModuleCase):
'''
Validate the linux group system module
'''
def __init__(self, arg):
super(self.__class__, self).__init__(arg)
def setUp(self):
'''
Get current settings
'''
super(GroupModuleTest, self).setUp()
self._user = self.__random_string()
self._user1 = self.__random_string()
self._no_user = self.__random_string()
@ -28,12 +31,6 @@ class GroupModuleTest(ModuleCase):
self._no_group = self.__random_string()
self._gid = 64989
self._new_gid = 64998
def setUp(self):
'''
Get current settings
'''
super(GroupModuleTest, self).setUp()
os_grain = self.run_function('grains.item', ['kernel'])
if os_grain['kernel'] not in 'Linux':
self.skipTest(
@ -41,8 +38,6 @@ class GroupModuleTest(ModuleCase):
**os_grain
)
)
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Tests requires root')
@destructiveTest
def tearDown(self):

View file

@ -5,18 +5,16 @@
# Import Python Libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
OSA_SCRIPT = '/usr/bin/osascript'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacAssistiveTest(ModuleCase):
'''
Integration tests for the mac_assistive module.

View file

@ -5,12 +5,11 @@
# Import Python Libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import Salt Libs
import salt.utils
@ -26,8 +25,8 @@ DEL_PKG = 'acme'
@destructiveTest
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only applies to macOS')
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skipIf(not salt.utils.which('brew'), 'This test requires the brew binary')
class BrewModuleTest(ModuleCase):
'''

View file

@ -5,12 +5,10 @@ Validate the mac-defaults module
# Import Python Libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
DEFAULT_DOMAIN = 'com.apple.AppleMultitouchMouse'
DEFAULT_KEY = 'MouseHorizontalScroll'
@ -18,7 +16,7 @@ DEFAULT_VALUE = '0'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacDefaultsModuleTest(ModuleCase):
'''
Integration tests for the mac_default module

View file

@ -5,16 +5,14 @@ Integration tests for the mac_desktop execution module.
# Import Python Libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacDesktopTestCase(ModuleCase):
'''
Integration tests for the mac_desktop module.

View file

@ -5,14 +5,12 @@
# Import Python Libs
from __future__ import absolute_import
import os
import random
import string
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -39,7 +37,7 @@ REP_USER_GROUP = __random_string()
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacGroupModuleTest(ModuleCase):
'''
Integration tests for the mac_group module

View file

@ -9,9 +9,8 @@ import os
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.paths import FILES
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -28,7 +27,7 @@ PASSWD = 'salttest'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacKeychainModuleTest(ModuleCase):
'''
Integration tests for the mac_keychain module

View file

@ -10,7 +10,7 @@ import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.paths import TMP
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -20,6 +20,7 @@ TEST_PKG_NAME = 'org.macports.MacPorts'
TEST_PKG = os.path.join(TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg')
@skip_if_not_root
class MacPkgutilModuleTest(ModuleCase):
'''
Validate the mac_pkgutil module
@ -35,9 +36,6 @@ class MacPkgutilModuleTest(ModuleCase):
if not salt.utils.which('pkgutil'):
self.skipTest('Test requires pkgutil binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
def tearDown(self):
'''
Reset to original settings

View file

@ -8,12 +8,13 @@ from __future__ import absolute_import, print_function
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@skip_if_not_root
class MacPortsModuleTest(ModuleCase):
'''
Validate the mac_ports module
@ -30,9 +31,6 @@ class MacPortsModuleTest(ModuleCase):
if not salt.utils.which('port'):
self.skipTest('Test requires port binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
self.AGREE_INSTALLED = 'agree' in self.run_function('pkg.list_pkgs')
self.run_function('pkg.refresh_db')

View file

@ -9,15 +9,15 @@ from __future__ import absolute_import, print_function
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacPowerModuleTest(ModuleCase):
'''
Validate the mac_power module
@ -139,9 +139,9 @@ class MacPowerModuleTest(ModuleCase):
self.assertTrue(self.run_function('power.get_restart_freeze'))
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacPowerModuleTestSleepOnPowerButton(ModuleCase):
'''
Test power.get_sleep_on_power_button
@ -189,9 +189,9 @@ class MacPowerModuleTestSleepOnPowerButton(ModuleCase):
self.run_function('power.get_sleep_on_power_button'))
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacPowerModuleTestRestartPowerFailure(ModuleCase):
'''
Test power.get_restart_power_failure
@ -238,9 +238,9 @@ class MacPowerModuleTestRestartPowerFailure(ModuleCase):
self.run_function('power.get_restart_power_failure'))
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacPowerModuleTestWakeOnNet(ModuleCase):
'''
Test power.get_wake_on_network
@ -284,9 +284,9 @@ class MacPowerModuleTestWakeOnNet(ModuleCase):
self.assertFalse(self.run_function('power.get_wake_on_network'))
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacPowerModuleTestWakeOnModem(ModuleCase):
'''
Test power.get_wake_on_modem

View file

@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -18,8 +18,7 @@ import salt.utils
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('launchctl'), 'Test requires launchctl binary')
@skipIf(not salt.utils.which('plutil'), 'Test requires plutil binary')
@skipIf(salt.utils.get_uid(salt.utils.get_user()) != 0,
'Test requires root')
@skip_if_not_root
class MacServiceModuleTest(ModuleCase):
'''
Validate the mac_service module

View file

@ -10,8 +10,9 @@ import random
import string
# Import Salt Testing libs
from tests.support.unit import skipIf
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -32,6 +33,10 @@ TEST_USER = __random_string()
NO_USER = __random_string()
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('dscl'), '\'dscl\' binary not found in $PATH')
@skipIf(not salt.utils.which('pwpolicy'), '\'pwpolicy\' binary not found in $PATH')
class MacShadowModuleTest(ModuleCase):
'''
Validate the mac_system module
@ -41,17 +46,7 @@ class MacShadowModuleTest(ModuleCase):
'''
Get current settings
'''
if not salt.utils.is_darwin():
self.skipTest('Test only available on macOS')
if not salt.utils.which('dscl'):
self.skipTest('Test requires dscl binary')
if not salt.utils.which('pwpolicy'):
self.skipTest('Test requires pwpolicy binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
self.run_function('user.add', [TEST_USER])
def tearDown(self):
'''
@ -59,13 +54,10 @@ class MacShadowModuleTest(ModuleCase):
'''
self.run_function('user.delete', [TEST_USER])
@destructiveTest
def test_info(self):
'''
Test shadow.info
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
ret = self.run_function('shadow.info', [TEST_USER])
self.assertEqual(ret['name'], TEST_USER)
@ -79,8 +71,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.get_account_created
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
text_date = self.run_function('shadow.get_account_created', [TEST_USER])
self.assertNotEqual(text_date, 'Invalid Timestamp')
@ -97,8 +87,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.get_last_change
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
text_date = self.run_function('shadow.get_last_change', [TEST_USER])
self.assertNotEqual(text_date, 'Invalid Timestamp')
@ -115,8 +103,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.get_login_failed_last
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
text_date = self.run_function('shadow.get_login_failed_last', [TEST_USER])
self.assertNotEqual(text_date, 'Invalid Timestamp')
@ -133,8 +119,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.get_login_failed_count
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertEqual(
self.run_function('shadow.get_login_failed_count', [TEST_USER]),
@ -151,8 +135,6 @@ class MacShadowModuleTest(ModuleCase):
Test shadow.get_maxdays
Test shadow.set_maxdays
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertTrue(
self.run_function('shadow.set_maxdays', [TEST_USER, 20]))
@ -173,8 +155,6 @@ class MacShadowModuleTest(ModuleCase):
Test shadow.get_change
Test shadow.set_change
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertTrue(
self.run_function('shadow.set_change', [TEST_USER, '02/11/2011']))
@ -195,8 +175,6 @@ class MacShadowModuleTest(ModuleCase):
Test shadow.get_expire
Test shadow.set_expire
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertTrue(
self.run_function('shadow.set_expire', [TEST_USER, '02/11/2011']))
@ -216,8 +194,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.del_password
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertTrue(self.run_function('shadow.del_password', [TEST_USER]))
self.assertEqual(
@ -233,8 +209,6 @@ class MacShadowModuleTest(ModuleCase):
'''
Test shadow.set_password
'''
self.run_function('user.add', [TEST_USER])
# Correct Functionality
self.assertTrue(
self.run_function('shadow.set_password', [TEST_USER, 'Pa$$W0rd']))

View file

@ -7,13 +7,17 @@ integration tests for mac_softwareupdate
from __future__ import absolute_import
# Import Salt Testing libs
from tests.support.unit import skipIf
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('softwareupdate'), '\'softwareupdate\' binary not found in $PATH')
class MacSoftwareUpdateModuleTest(ModuleCase):
'''
Validate the mac_softwareupdate module
@ -26,15 +30,6 @@ class MacSoftwareUpdateModuleTest(ModuleCase):
'''
Get current settings
'''
if not salt.utils.is_darwin():
self.skipTest('Test only available on macOS')
if not salt.utils.which('softwareupdate'):
self.skipTest('Test requires softwareupdate binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
self.IGNORED_LIST = self.run_function('softwareupdate.list_ignored')
self.SCHEDULE = self.run_function('softwareupdate.schedule')
self.CATALOG = self.run_function('softwareupdate.get_catalog')

View file

@ -11,7 +11,7 @@ import string
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -32,9 +32,9 @@ SET_COMPUTER_NAME = __random_string()
SET_SUBNET_NAME = __random_string()
@skipIf(not salt.utils.is_darwin()
or not salt.utils.which('systemsetup')
or salt.utils.get_uid(salt.utils.get_user()) != 0, 'Test requirements not met')
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacSystemModuleTest(ModuleCase):
'''
Validate the mac_system module

View file

@ -17,12 +17,15 @@ import datetime
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@skip_if_not_root
@skipIf(not salt.utils.is_darwin(), 'Test only available on macOS')
@skipIf(not salt.utils.which('systemsetup'), '\'systemsetup\' binary not found in $PATH')
class MacTimezoneModuleTest(ModuleCase):
'''
Validate the mac_timezone module
@ -37,15 +40,6 @@ class MacTimezoneModuleTest(ModuleCase):
'''
Get current settings
'''
if not salt.utils.is_darwin():
self.skipTest('Test only available on macOS')
if not salt.utils.which('systemsetup'):
self.skipTest('Test requires systemsetup binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
self.USE_NETWORK_TIME = self.run_function('timezone.get_using_network_time')
self.TIME_SERVER = self.run_function('timezone.get_time_server')
self.TIME_ZONE = self.run_function('timezone.get_zone')

View file

@ -5,14 +5,12 @@
# Import Python Libs
from __future__ import absolute_import
import os
import random
import string
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -38,7 +36,7 @@ CHANGE_USER = __random_string()
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class MacUserModuleTest(ModuleCase):
'''
Integration tests for the mac_user module

View file

@ -10,12 +10,13 @@ import time
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@skip_if_not_root
@skipIf(not salt.utils.is_linux(), 'These tests can only be run on linux')
class Nilrt_ipModuleTest(ModuleCase):
'''
@ -35,8 +36,6 @@ class Nilrt_ipModuleTest(ModuleCase):
if os_grain['os_family'] != 'NILinuxRT':
self.skipTest('Tests applicable only to NILinuxRT')
super(Nilrt_ipModuleTest, self).setUp()
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
self.run_function('file.copy', ['/var/lib/connman', '/tmp/connman', 'recurse=True', 'remove_existing=True'])
def tearDown(self):

View file

@ -18,6 +18,7 @@ import tempfile
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.paths import TMP
from tests.support.helpers import skip_if_not_root
# Import salt libs
import salt.utils
@ -87,7 +88,7 @@ class PipModuleTest(ModuleCase):
ret
)
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_requirements_as_list_of_chains__sans_no_chown__cwd_set__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -125,7 +126,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_requirements_as_list_of_chains__sans_no_chown__cwd_not_set__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -164,7 +165,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_requirements_as_list__sans_no_chown__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -195,7 +196,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_requirements_as_list__sans_no_chown__non_absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -231,7 +232,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_chained_requirements__sans_no_chown__absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -258,7 +259,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_chained_requirements__sans_no_chown__non_absolute_file_path(self):
self.run_function('virtualenv.create', [self.venv_dir])
@ -289,7 +290,7 @@ class PipModuleTest(ModuleCase):
pprint.pprint(ret)
raise
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_issue_4805_nested_requirements_user_no_chown(self):
self.run_function('virtualenv.create', [self.venv_dir])

View file

@ -7,14 +7,12 @@
'''
# Import python libs
from __future__ import absolute_import
import os
import string
import random
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import 3rd-party libs
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
@ -39,7 +37,7 @@ class PwUserModuleTest(ModuleCase):
)
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_groups_includes_primary(self):
# Let's create a user, which usually creates the group matching the
# name

View file

@ -2,15 +2,13 @@
# Import python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import requires_salt_modules
from tests.support.helpers import requires_salt_modules, skip_if_not_root
@skipIf(os.geteuid() != 0, 'You must be root to run this test')
@skip_if_not_root
@requires_salt_modules('rabbitmq')
class RabbitModuleTest(ModuleCase):
'''

View file

@ -12,13 +12,14 @@ import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
from salt.ext.six.moves import range
@skip_if_not_root
@skipIf(not salt.utils.is_linux(), 'These tests can only be run on linux')
class ShadowModuleTest(ModuleCase):
'''
@ -43,8 +44,6 @@ class ShadowModuleTest(ModuleCase):
**os_grain
)
)
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
def tearDown(self):
'''

View file

@ -11,7 +11,7 @@ import subprocess
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -176,7 +176,7 @@ class SystemModuleTest(ModuleCase):
self.assertTrue(self._same_times(t1, t2, seconds_diff=2), msg=msg)
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_date_time(self):
'''
Test changing the system clock. We are only able to set it up to a
@ -194,7 +194,7 @@ class SystemModuleTest(ModuleCase):
self._test_hwclock_sync()
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_date_time_utc(self):
'''
Test changing the system clock. We are only able to set it up to a
@ -212,7 +212,7 @@ class SystemModuleTest(ModuleCase):
self._test_hwclock_sync()
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_date_time_utcoffset_east(self):
'''
Test changing the system clock. We are only able to set it up to a
@ -232,7 +232,7 @@ class SystemModuleTest(ModuleCase):
self._test_hwclock_sync()
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_date_time_utcoffset_west(self):
'''
Test changing the system clock. We are only able to set it up to a
@ -252,7 +252,7 @@ class SystemModuleTest(ModuleCase):
self._test_hwclock_sync()
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_time(self):
'''
Test setting the system time without adjusting the date.
@ -271,7 +271,7 @@ class SystemModuleTest(ModuleCase):
self._test_hwclock_sync()
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_system_date(self):
'''
Test setting the system date without adjusting the time.
@ -292,7 +292,7 @@ class SystemModuleTest(ModuleCase):
self.assertTrue(self._same_times(time_now, cmp_time), msg=msg)
self._test_hwclock_sync()
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_get_computer_desc(self):
'''
Test getting the system hostname
@ -312,7 +312,7 @@ class SystemModuleTest(ModuleCase):
self.assertIn(res, data.decode('string_escape'))
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_set_computer_desc(self):
'''
Test setting the system hostname
@ -325,7 +325,7 @@ class SystemModuleTest(ModuleCase):
self.assertTrue(ret)
self.assertIn(desc, computer_desc)
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_has_hwclock(self):
'''
Verify platform has a settable hardware clock, if possible.

View file

@ -5,12 +5,11 @@ Integration Tests for restcherry salt-api with pam eauth
# Import python libs
from __future__ import absolute_import
import os
# Import test support libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
import tests.support.cherrypy_testclasses as cptc
# Import Salt Libs
@ -38,7 +37,7 @@ class TestAuthPAM(cptc.BaseRestCherryPyTest, ModuleCase):
'''
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
def setUp(self):
super(TestAuthPAM, self).setUp()
try:
@ -118,7 +117,7 @@ class TestAuthPAM(cptc.BaseRestCherryPyTest, ModuleCase):
self.assertEqual(response.status, '200 OK')
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
def tearDown(self):
'''
Clean up after tests. Delete user

View file

@ -6,15 +6,13 @@
# Import python libs
from __future__ import absolute_import
import os
import pwd
import grp
import random
# Import Salt Testing libs
from tests.support.case import ShellCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
# Import salt libs
import salt.utils
@ -42,6 +40,8 @@ def gen_password():
return (password, hashed_pwd)
@skip_if_not_root
@destructiveTest
class AuthTest(ShellCase):
'''
Test auth mechanisms
@ -49,14 +49,10 @@ class AuthTest(ShellCase):
_call_binary_ = 'salt'
is_not_root = os.geteuid() != 0
userA = 'saltdev'
userB = 'saltadm'
group = 'saltops'
@destructiveTest
@skipIf(is_not_root, 'You must be logged in as root to run this test')
def setUp(self):
# This is a little wasteful but shouldn't be a problem
for user in (self.userA, self.userB):
@ -126,8 +122,6 @@ class AuthTest(ShellCase):
'minion:' in resp
)
@destructiveTest
@skipIf(is_not_root, 'You must be logged in as root to run this test')
def test_zzzz_tearDown(self):
for user in (self.userA, self.userB):
if pwd.getpwnam(user):

View file

@ -12,9 +12,9 @@ import shutil
# Import Salt Testing libs
from tests.integration.utils import testprogram
from tests.support.case import ShellCase
from tests.support.unit import skipIf
from tests.support.paths import TMP
from tests.support.mixins import ShellCaseCommonTestsMixin
from tests.support.helpers import skip_if_not_root
# Import 3rd-party libs
import yaml
@ -178,7 +178,7 @@ class RunTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin)
stdout=stdout, stderr=stderr
)
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
def test_salt_run_with_eauth_all_args(self):
'''
test salt-run with eauth
@ -193,7 +193,7 @@ class RunTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin)
self.assertEqual(expect, run_cmd)
self._remove_user()
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
def test_salt_run_with_eauth_bad_passwd(self):
'''
test salt-run with eauth and bad password

View file

@ -15,9 +15,8 @@ import tornado.web
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.paths import FILES
from tests.support.helpers import get_unused_localhost_port
from tests.support.helpers import get_unused_localhost_port, skip_if_not_root
from tests.support.mixins import SaltReturnAssertsMixin
# Import salt libs
@ -134,7 +133,7 @@ class ArchiveTest(ModuleCase, SaltReturnAssertsMixin):
self._check_extracted(UNTAR_FILE)
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_archive_extracted_with_root_user_and_group(self):
'''
test archive.extracted with user and group set to "root"

View file

@ -13,8 +13,8 @@ import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.paths import FILES
from tests.support.helpers import skip_if_not_root
# Import salt libs
import salt.utils
@ -27,7 +27,7 @@ class StateMatchTest(ModuleCase):
Validate the file state
'''
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_issue_2167_ipcidr_no_AttributeError(self):
subnets = self.run_function('network.subnets')
self.assertTrue(len(subnets) > 0)

View file

@ -22,7 +22,8 @@ from tests.support.runtests import RUNTIME_VARS
from tests.support.helpers import (
destructiveTest,
requires_system_grains,
with_system_user
with_system_user,
skip_if_not_root
)
# Import salt libs
from tests.support.case import ModuleCase
@ -208,7 +209,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
shutil.rmtree(venv_dir)
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
@with_system_user('issue-6912', on_existing='delete', delete=True)
def test_issue_6912_wrong_owner(self, username):
venv_dir = os.path.join(

View file

@ -4,13 +4,14 @@ Tests for the rabbitmq state
'''
# Import python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import skip_if_not_root
from tests.support.mixins import SaltReturnAssertsMixin
@skip_if_not_root
class RabbitUserTestCase(ModuleCase, SaltReturnAssertsMixin):
'''
Validate the rabbitmq user states.
@ -21,8 +22,6 @@ class RabbitUserTestCase(ModuleCase, SaltReturnAssertsMixin):
if not rabbit_installed:
self.skipTest('rabbitmq-server not installed')
if os.geteuid() != 0:
self.skipTest('You must be root to run this test')
def test_present(self):
'''

View file

@ -5,13 +5,14 @@ Tests for the rabbitmq state
'''
# Import python libs
from __future__ import absolute_import
import os
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import skip_if_not_root
from tests.support.mixins import SaltReturnAssertsMixin
@skip_if_not_root
class RabbitVHostTestCase(ModuleCase, SaltReturnAssertsMixin):
'''
Validate the rabbitmq virtual host states.
@ -22,8 +23,6 @@ class RabbitVHostTestCase(ModuleCase, SaltReturnAssertsMixin):
if not rabbit_installed:
self.skipTest('rabbitmq-server not installed')
if os.geteuid() != 0:
self.skipTest('You must be root to run this test')
def test_present(self):
'''

View file

@ -10,13 +10,13 @@ import shutil
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.runtests import RUNTIME_VARS
from tests.support.helpers import (
destructiveTest,
with_system_user,
skip_if_binaries_missing
skip_if_binaries_missing,
skip_if_not_root
)
# Import salt libs
@ -159,7 +159,7 @@ class SSHKnownHostsStateTest(ModuleCase, SaltReturnAssertsMixin):
class SSHAuthStateTests(ModuleCase, SaltReturnAssertsMixin):
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
@with_system_user('issue_7409', on_existing='delete', delete=True)
def test_issue_7409_no_linebreaks_between_keys(self, username):
@ -196,7 +196,7 @@ class SSHAuthStateTests(ModuleCase, SaltReturnAssertsMixin):
)
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
@with_system_user('issue_10198', on_existing='delete', delete=True)
def test_issue_10198_keyfile_from_another_env(self, username=None):
userdetails = self.run_function('user.info', [username])

View file

@ -17,7 +17,7 @@ import grp
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest, requires_system_grains
from tests.support.helpers import destructiveTest, requires_system_grains, skip_if_not_root
from tests.support.mixins import SaltReturnAssertsMixin
# Import salt libs
@ -36,7 +36,7 @@ else:
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
class UserTest(ModuleCase, SaltReturnAssertsMixin):
'''
test for user absent

View file

@ -15,7 +15,7 @@ import shutil
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.runtests import RUNTIME_VARS
@ -27,7 +27,7 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
@skipIf(salt.utils.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
class VirtualenvTest(ModuleCase, SaltReturnAssertsMixin):
@destructiveTest
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
@skip_if_not_root
def test_issue_1959_virtualenv_runas(self):
user = 'issue-1959'
self.assertSaltTrueReturn(self.run_state('user.present', name=user))

View file

@ -11,7 +11,7 @@ import os
# Import Salt Testing libs
from tests.support.unit import TestCase, skipIf
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock
from tests.support.helpers import skip_if_not_root
# Import salt libs
from salt import minion
from salt.utils import event
@ -28,7 +28,7 @@ class MinionTestCase(TestCase):
with patch.dict(__opts__, {'ipv6': False, 'master': float('127.0'), 'master_port': '4555', 'retry_dns': False}):
self.assertRaises(SaltSystemExit, minion.resolve_dns, __opts__)
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
def test_sock_path_len(self):
'''
This tests whether or not a larger hash causes the sock path to exceed

View file

@ -5,11 +5,10 @@
# Import python libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
from tests.support.unit import skipIf, TestCase
from tests.support.helpers import destructiveTest
from tests.support.helpers import destructiveTest, skip_if_not_root
from tests.support.mock import (
MagicMock,
patch,
@ -103,7 +102,7 @@ class ObjectView(object): # pylint: disable=too-few-public-methods
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@skip_if_not_root
class LogSettingsParserTests(TestCase):
'''
Unit Tests for Log Level Mixin with Salt parsers