Why do need the system grains here?! This is an expensive call.

This commit is contained in:
Pedro Algarvio 2017-03-29 19:15:15 +01:00
parent f82fa73fd7
commit 104f7a71f2
No known key found for this signature in database
GPG Key ID: BB36BF6584A298FF
9 changed files with 55 additions and 145 deletions

View File

@ -16,16 +16,15 @@ from salt.exceptions import CommandExecutionError
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
# Module Variables
ASSIGN_CMD = 'net.inet.icmp.icmplim'
CONFIG = '/etc/sysctl.conf'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
class DarwinSysctlModuleTest(integration.ModuleCase):
'''
Integration tests for the darwin_sysctl module
@ -58,10 +57,7 @@ class DarwinSysctlModuleTest(integration.ModuleCase):
raise CommandExecutionError(msg.format(CONFIG))
os.remove(CONFIG)
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_assign(self, grains=None):
def test_assign(self):
'''
Tests assigning a single sysctl parameter
'''
@ -80,10 +76,7 @@ class DarwinSysctlModuleTest(integration.ModuleCase):
self.run_function('sysctl.assign', [ASSIGN_CMD, self.val])
raise
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_persist_new_file(self, grains=None):
def test_persist_new_file(self):
'''
Tests assigning a sysctl value to a system without a sysctl.conf file
'''
@ -102,10 +95,7 @@ class DarwinSysctlModuleTest(integration.ModuleCase):
os.remove(CONFIG)
raise
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_persist_already_set(self, grains=None):
def test_persist_already_set(self):
'''
Tests assigning a sysctl value that is already set in sysctl.conf file
'''
@ -123,10 +113,7 @@ class DarwinSysctlModuleTest(integration.ModuleCase):
os.remove(CONFIG)
raise
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_persist_apply_change(self, grains=None):
def test_persist_apply_change(self):
'''
Tests assigning a sysctl value and applying the change to system
'''
@ -190,10 +177,7 @@ class DarwinSysctlModuleTest(integration.ModuleCase):
return True
return False
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def tearDown(self, grains=None):
def tearDown(self):
'''
Clean up after tests
'''

View File

@ -8,7 +8,6 @@ import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
requires_salt_modules,
requires_system_grains,
destructiveTest,
)
@ -25,22 +24,19 @@ def _find_new_locale(current_locale):
@skipIf(salt.utils.is_windows(), 'minion is windows')
@requires_salt_modules('locale')
class LocaleModuleTest(integration.ModuleCase):
@requires_system_grains
def test_get_locale(self, grains):
def test_get_locale(self):
locale = self.run_function('locale.get_locale')
self.assertNotEqual(None, locale)
@destructiveTest
@requires_system_grains
def test_gen_locale(self, grains):
def test_gen_locale(self):
locale = self.run_function('locale.get_locale')
new_locale = _find_new_locale(locale)
ret = self.run_function('locale.gen_locale', [new_locale])
self.assertEqual(True, ret)
@destructiveTest
@requires_system_grains
def test_set_locale(self, grains):
def test_set_locale(self):
original_locale = self.run_function('locale.get_locale')
locale_to_set = _find_new_locale(original_locale)
self.run_function('locale.gen_locale', [locale_to_set])

View File

@ -10,10 +10,7 @@ import os
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
OSA_SCRIPT = '/usr/bin/osascript'
@ -54,8 +51,7 @@ class MacAssistiveTest(integration.ModuleCase):
if smile_bundle_present:
self.run_function('assistive.remove', [smile_bundle])
@requires_system_grains
def test_install_and_remove(self, grains=None):
def test_install_and_remove(self):
'''
Tests installing and removing a bundled ID or command to use assistive access.
'''
@ -67,8 +63,7 @@ class MacAssistiveTest(integration.ModuleCase):
self.run_function('assistive.remove', [new_bundle])
)
@requires_system_grains
def test_installed(self, grains=None):
def test_installed(self):
'''
Tests the True and False return of assistive.installed.
'''
@ -83,8 +78,7 @@ class MacAssistiveTest(integration.ModuleCase):
self.run_function('assistive.installed', [OSA_SCRIPT])
)
@requires_system_grains
def test_enable(self, grains=None):
def test_enable(self):
'''
Tests setting the enabled status of a bundled ID or command.
'''
@ -106,8 +100,7 @@ class MacAssistiveTest(integration.ModuleCase):
self.run_function('assistive.enabled', [OSA_SCRIPT])
)
@requires_system_grains
def test_enabled(self, grains=None):
def test_enabled(self):
'''
Tests if a bundled ID or command is listed in assistive access returns True.
'''

View File

@ -10,16 +10,15 @@ import os
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
DEFAULT_DOMAIN = 'com.apple.AppleMultitouchMouse'
DEFAULT_KEY = 'MouseHorizontalScroll'
DEFAULT_VALUE = '0'
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
class MacDefaultsModuleTest(integration.ModuleCase):
'''
Integration tests for the mac_default module
@ -37,10 +36,7 @@ class MacDefaultsModuleTest(integration.ModuleCase):
)
)
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_macdefaults_write_read(self, grains=None):
def test_macdefaults_write_read(self):
'''
Tests that writes and reads macdefaults
'''

View File

@ -10,12 +10,10 @@ import os
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
class MacDesktopTestCase(integration.ModuleCase):
'''
@ -34,17 +32,14 @@ class MacDesktopTestCase(integration.ModuleCase):
)
)
@requires_system_grains
def test_get_output_volume(self, grains=None):
def test_get_output_volume(self):
'''
Tests the return of get_output_volume.
'''
ret = self.run_function('desktop.get_output_volume')
self.assertIsNotNone(ret)
@destructiveTest
@requires_system_grains
def test_set_output_volume(self, grains=None):
def test_set_output_volume(self):
'''
Tests the return of set_output_volume.
'''
@ -59,9 +54,7 @@ class MacDesktopTestCase(integration.ModuleCase):
# Set volume back to what it was before
self.run_function('desktop.set_output_volume', [current_vol])
@destructiveTest
@requires_system_grains
def test_screensaver(self, grains=None):
def test_screensaver(self):
'''
Tests the return of the screensaver function.
'''
@ -69,9 +62,7 @@ class MacDesktopTestCase(integration.ModuleCase):
self.run_function('desktop.screensaver')
)
@destructiveTest
@requires_system_grains
def test_lock(self, grains=None):
def test_lock(self):
'''
Tests the return of the lock function.
'''
@ -79,9 +70,7 @@ class MacDesktopTestCase(integration.ModuleCase):
self.run_function('desktop.lock')
)
@destructiveTest
@requires_system_grains
def test_say(self, grains=None):
def test_say(self):
'''
Tests the return of the say function.
'''

View File

@ -12,10 +12,7 @@ import string
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -41,6 +38,8 @@ ADD_USER = __random_string()
REP_USER_GROUP = __random_string()
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
class MacGroupModuleTest(integration.ModuleCase):
'''
Integration tests for the mac_group module
@ -58,10 +57,7 @@ class MacGroupModuleTest(integration.ModuleCase):
)
)
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_group_add(self, grains=None):
def test_mac_group_add(self):
'''
Tests the add group function
'''
@ -73,10 +69,7 @@ class MacGroupModuleTest(integration.ModuleCase):
self.run_function('group.delete', [ADD_GROUP])
raise
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_group_delete(self, grains=None):
def test_mac_group_delete(self):
'''
Tests the delete group function
'''
@ -92,10 +85,7 @@ class MacGroupModuleTest(integration.ModuleCase):
except CommandExecutionError:
raise
@destructiveTest
@skipIf(os.getuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_group_chgid(self, grains=None):
def test_mac_group_chgid(self):
'''
Tests changing the group id
'''
@ -112,10 +102,7 @@ class MacGroupModuleTest(integration.ModuleCase):
self.run_function('group.delete', [CHANGE_GROUP])
raise
@destructiveTest
@skipIf(os.getuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_adduser(self, grains=None):
def test_mac_adduser(self):
'''
Tests adding user to the group
'''
@ -132,10 +119,7 @@ class MacGroupModuleTest(integration.ModuleCase):
self.run_function('group.delete', [ADD_GROUP])
raise
@destructiveTest
@skipIf(os.getuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_deluser(self, grains=None):
def test_mac_deluser(self):
'''
Test deleting user from a group
'''
@ -151,10 +135,7 @@ class MacGroupModuleTest(integration.ModuleCase):
group_info = self.run_function('group.info', [ADD_GROUP])
self.assertNotIn(ADD_USER, ''.join(group_info['members']))
@destructiveTest
@skipIf(os.getuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_members(self, grains=None):
def test_mac_members(self):
'''
Test replacing members of a group
'''
@ -174,10 +155,7 @@ class MacGroupModuleTest(integration.ModuleCase):
self.assertIn(REP_USER_GROUP, str(group_info['members']))
self.assertNotIn(ADD_USER, str(group_info['members']))
@destructiveTest
@skipIf(os.getuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def test_mac_getent(self, grains=None):
def test_mac_getent(self):
'''
Test returning info on all groups
'''
@ -193,10 +171,7 @@ class MacGroupModuleTest(integration.ModuleCase):
self.assertIn(ADD_GROUP, str(getinfo))
self.assertIn(ADD_USER, str(getinfo))
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
def tearDown(self, grains=None):
def tearDown(self):
'''
Clean up after tests
'''

View File

@ -10,10 +10,7 @@ import os
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -57,8 +54,7 @@ class MacKeychainModuleTest(integration.ModuleCase):
if CERT_ALIAS in certs_list:
self.run_function('keychain.uninstall', [CERT_ALIAS])
@requires_system_grains
def test_mac_keychain_install(self, grains=None):
def test_mac_keychain_install(self):
'''
Tests that attempts to install a certificate
'''
@ -69,8 +65,7 @@ class MacKeychainModuleTest(integration.ModuleCase):
certs_list = self.run_function('keychain.list_certs')
self.assertIn(CERT_ALIAS, certs_list)
@requires_system_grains
def test_mac_keychain_uninstall(self, grains=None):
def test_mac_keychain_uninstall(self):
'''
Tests that attempts to uninstall a certificate
'''
@ -91,8 +86,7 @@ class MacKeychainModuleTest(integration.ModuleCase):
except CommandExecutionError:
self.run_function('keychain.uninstall', [CERT_ALIAS])
@requires_system_grains
def test_mac_keychain_get_friendly_name(self, grains=None):
def test_mac_keychain_get_friendly_name(self):
'''
Test that attempts to get friendly name of a cert
'''
@ -105,8 +99,7 @@ class MacKeychainModuleTest(integration.ModuleCase):
get_name = self.run_function('keychain.get_friendly_name', [CERT, PASSWD])
self.assertEqual(get_name, CERT_ALIAS)
@requires_system_grains
def test_mac_keychain_get_default_keychain(self, grains=None):
def test_mac_keychain_get_default_keychain(self):
'''
Test that attempts to get the default keychain
'''
@ -115,8 +108,7 @@ class MacKeychainModuleTest(integration.ModuleCase):
['security default-keychain -d user'])
self.assertEqual(salt_get_keychain, sys_get_keychain)
@requires_system_grains
def test_mac_keychain_list_certs(self, grains=None):
def test_mac_keychain_list_certs(self):
'''
Test that attempts to list certs
'''

View File

@ -12,10 +12,7 @@ import string
# Import Salt Testing Libs
import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
requires_system_grains
)
from tests.support.helpers import destructiveTest
# Import Salt Libs
from salt.exceptions import CommandExecutionError
@ -42,7 +39,6 @@ CHANGE_USER = __random_string()
@destructiveTest
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
@requires_system_grains
class MacUserModuleTest(integration.ModuleCase):
'''
Integration tests for the mac_user module
@ -61,7 +57,7 @@ class MacUserModuleTest(integration.ModuleCase):
)
)
def test_mac_user_add(self, grains=None):
def test_mac_user_add(self):
'''
Tests the add function
'''
@ -73,7 +69,7 @@ class MacUserModuleTest(integration.ModuleCase):
self.run_function('user.delete', [ADD_USER])
raise
def test_mac_user_delete(self, grains=None):
def test_mac_user_delete(self):
'''
Tests the delete function
'''
@ -90,7 +86,7 @@ class MacUserModuleTest(integration.ModuleCase):
except CommandExecutionError:
raise
def test_mac_user_primary_group(self, grains=None):
def test_mac_user_primary_group(self):
'''
Tests the primary_group function
'''
@ -110,7 +106,7 @@ class MacUserModuleTest(integration.ModuleCase):
self.run_function('user.delete', [PRIMARY_GROUP_USER])
raise
def test_mac_user_changes(self, grains=None):
def test_mac_user_changes(self):
'''
Tests mac_user functions that change user properties
'''
@ -154,7 +150,7 @@ class MacUserModuleTest(integration.ModuleCase):
self.run_function('user.delete', [CHANGE_USER])
raise
def tearDown(self, grains=None):
def tearDown(self):
'''
Clean up after tests
'''

View File

@ -2,7 +2,6 @@
# Import python libs
from __future__ import absolute_import
import os
import string
import random
@ -11,6 +10,7 @@ import tests.integration as integration
from tests.support.unit import skipIf
from tests.support.helpers import (
destructiveTest,
skip_if_not_root,
requires_system_grains
)
@ -20,21 +20,10 @@ import salt.utils
# Import 3rd-party libs
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
IS_ADMIN = False
if salt.utils.is_windows():
import salt.utils.win_functions
current_user = salt.utils.win_functions.get_current_user()
if current_user == 'SYSTEM':
IS_ADMIN = True
else:
IS_ADMIN = salt.utils.win_functions.is_admin(current_user)
else:
IS_ADMIN = os.geteuid() == 0
@destructiveTest
@skipIf(not salt.utils.is_linux(), 'These tests can only be run on linux')
@skipIf(not IS_ADMIN, 'You must be root to run these tests')
@skip_if_not_root
class UseraddModuleTestLinux(integration.ModuleCase):
def setUp(self):
@ -54,7 +43,7 @@ class UseraddModuleTestLinux(integration.ModuleCase):
)
@requires_system_grains
def test_groups_includes_primary(self, grains=None):
def test_groups_includes_primary(self, grains):
# Let's create a user, which usually creates the group matching the
# name
uname = self.__random_string()
@ -96,7 +85,7 @@ class UseraddModuleTestLinux(integration.ModuleCase):
self.run_function('user.delete', [uname, True, True])
raise
def test_user_primary_group(self, grains=None):
def test_user_primary_group(self):
'''
Tests the primary_group function
'''
@ -120,7 +109,7 @@ class UseraddModuleTestLinux(integration.ModuleCase):
@destructiveTest
@skipIf(not salt.utils.is_windows(), 'These tests can only be run on Windows')
@skipIf(not IS_ADMIN, 'You must be Administrator to run these tests')
@skip_if_not_root
class UseraddModuleTestWindows(integration.ModuleCase):
def __random_string(self, size=6):