Update which and is_windows calls to use new paths

This commit is contained in:
rallytime 2017-09-14 11:35:23 -04:00
parent a454065c74
commit 9afc84091d
7 changed files with 34 additions and 25 deletions

View file

@ -2446,7 +2446,7 @@ def default_gateway():
ip_gw: True # True if either of the above is True, False otherwise
'''
grains = {}
if not salt.utils.which('ip'):
if not salt.utils.path.which('ip'):
return {}
grains['ip_gw'] = False
grains['ip4_gw'] = False

View file

@ -25,14 +25,16 @@ import salt.client
import salt.config
import salt.loader
import salt.cache
import salt.utils.files
import salt.utils.http as http
import salt.syspaths as syspaths
from salt.ext import six
from salt.ext.six import string_types
from salt.ext.six.moves import input
from salt.ext.six.moves import filter
from salt.template import compile_template
import salt.utils.files
import salt.utils.http as http
import salt.utils.platform
import salt.utils.win_functions
from salt.utils.yamldumper import SafeOrderedDumper
# Get logging started
@ -493,9 +495,7 @@ class SPMClient(object):
# No defaults for this in config.py; default to the current running
# user and group
import salt.utils
if salt.utils.is_windows():
import salt.utils.win_functions
if salt.utils.platform.is_windows():
uname = gname = salt.utils.win_functions.get_current_user()
uname_sid = salt.utils.win_functions.get_sid_from_name(uname)
uid = self.opts.get('spm_uid', uname_sid)

View file

@ -33,8 +33,10 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch
from tests.support.paths import TMP, FILES
# Import salt libs
import salt.utils.gitfs
import salt.fileserver.gitfs as gitfs
import salt.utils.gitfs
import salt.utils.platform
import salt.utils.win_functions
log = logging.getLogger(__name__)
@ -227,9 +229,7 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
if 'USERNAME' not in os.environ:
try:
import salt.utils
if salt.utils.is_windows():
import salt.utils.win_functions
if salt.utils.platform.is_windows():
os.environ['USERNAME'] = salt.utils.win_functions.get_current_user()
else:
os.environ['USERNAME'] = pwd.getpwuid(os.geteuid()).pw_name

View file

@ -66,7 +66,7 @@ class TestGemModule(TestCase, LoaderModuleMockMixin):
{'rvm.is_installed': MagicMock(return_value=False),
'rbenv.is_installed': MagicMock(return_value=True),
'rbenv.do': mock}),\
patch('salt.utils.is_windows', return_value=False):
patch('salt.utils.platform.is_windows', return_value=False):
gem._gem(['install', 'rails'])
mock.assert_called_once_with(
['gem', 'install', 'rails'],

View file

@ -16,12 +16,12 @@ from tests.support.unit import TestCase, skipIf
from tests.support.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
# Import Salt Libs
import salt.utils
import salt.modules.groupadd as groupadd
import salt.utils.platform
@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(salt.utils.is_windows(), "Module not available on Windows")
@skipIf(salt.utils.platform.is_windows(), "Module not available on Windows")
class GroupAddTestCase(TestCase, LoaderModuleMockMixin):
'''
TestCase for salt.modules.groupadd

View file

@ -41,39 +41,48 @@ class PartedTestCase(TestCase, LoaderModuleMockMixin):
# Test __virtual__ function for module registration
def test_virtual_bails_on_windows(self):
'''If running windows, __virtual__ shouldn't register module'''
'''
If running windows, __virtual__ shouldn't register module
'''
with patch('salt.utils.platform.is_windows', lambda: True):
ret = parted.__virtual__()
err = (False, 'The parted execution module failed to load Windows systems are not supported.')
self.assertEqual(err, ret)
def test_virtual_bails_without_parted(self):
'''If parted not in PATH, __virtual__ shouldn't register module'''
'''
If parted not in PATH, __virtual__ shouldn't register module
'''
with patch('salt.utils.path.which', lambda exe: not exe == "parted"),\
patch('salt.utils.is_windows', return_value=False):
patch('salt.utils.platform.is_windows', return_value=False):
ret = parted.__virtual__()
err = (False, 'The parted execution module failed to load parted binary is not in the path.')
self.assertEqual(err, ret)
def test_virtual_bails_without_lsblk(self):
'''If lsblk not in PATH, __virtual__ shouldn't register module'''
'''
If lsblk not in PATH, __virtual__ shouldn't register module
'''
with patch('salt.utils.path.which', lambda exe: not exe == "lsblk"),\
patch('salt.utils.is_windows', return_value=False):
patch('salt.utils.platform.is_windows', return_value=False):
ret = parted.__virtual__()
err = (False, 'The parted execution module failed to load lsblk binary is not in the path.')
self.assertEqual(err, ret)
def test_virtual_bails_without_partprobe(self):
'''If partprobe not in PATH, __virtual__ shouldn't register module'''
'''
If partprobe not in PATH, __virtual__ shouldn't register module
'''
with patch('salt.utils.path.which', lambda exe: not exe == "partprobe"),\
patch('salt.utils.is_windows', return_value=False):
patch('salt.utils.platform.is_windows', return_value=False):
ret = parted.__virtual__()
err = (False, 'The parted execution module failed to load partprobe binary is not in the path.')
self.assertEqual(err, ret)
def test_virtual(self):
'''On expected platform with correct utils in PATH, register
"partition" module'''
'''
On expected platform with correct utils in PATH, register "partition" module
'''
with patch('salt.utils.platform.is_windows', lambda: False), \
patch('salt.utils.path.which', lambda exe: exe in ('parted', 'lsblk', 'partprobe')):
ret = parted.__virtual__()

View file

@ -18,7 +18,7 @@ from tests.support.mock import (
# Import Salt Libs
import salt.modules.pw_group as pw_group
import salt.utils
import salt.utils.platform
@skipIf(NO_MOCK, NO_MOCK_REASON)
@ -45,7 +45,7 @@ class PwGroupTestCase(TestCase, LoaderModuleMockMixin):
with patch.dict(pw_group.__salt__, {'cmd.run_all': mock}):
self.assertTrue(pw_group.delete('a'))
@skipIf(salt.utils.is_windows(), 'grp not available on Windows')
@skipIf(salt.utils.platform.is_windows(), 'grp not available on Windows')
def test_info(self):
'''
Tests to return information about a group
@ -59,7 +59,7 @@ class PwGroupTestCase(TestCase, LoaderModuleMockMixin):
with patch.dict(pw_group.grinfo, mock):
self.assertDictEqual(pw_group.info('name'), {})
@skipIf(salt.utils.is_windows(), 'grp not available on Windows')
@skipIf(salt.utils.platform.is_windows(), 'grp not available on Windows')
def test_getent(self):
'''
Tests for return info on all groups