Skip to content

Commit

Permalink
Update some salt.utils.x paths for moved util functions
Browse files Browse the repository at this point in the history
Through merge forwards, some of the old-style paths have made their
way into develop. This PR corrects some of these instances on the more
popular functions.
  • Loading branch information
rallytime committed Aug 29, 2017
1 parent c666429 commit 26410c6
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/ref/modules/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ For example:
'''
Only load if git exists on the system
'''
if salt.utils.which('git') is None:
if salt.utils.path.which('git') is None:
return (False,
'The git execution module cannot be loaded: git unavailable.')
else:
Expand Down
3 changes: 2 additions & 1 deletion salt/cli/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import salt.client
import salt.output
import salt.utils
import salt.utils.files
import salt.utils.gzip_util
import salt.utils.itertools
import salt.utils.minions
Expand Down Expand Up @@ -112,7 +113,7 @@ def _file_dict(self, fn_):
err = 'The referenced file, {0} is not available.'.format(fn_)
sys.stderr.write(err + '\n')
sys.exit(42)
with salt.utils.fopen(fn_, 'r') as fp_:
with salt.utils.files.fopen(fn_, 'r') as fp_:
data = fp_.read()
return {fn_: data}

Expand Down
4 changes: 2 additions & 2 deletions salt/cloud/clouds/oneandone.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import time

# Import salt libs
import salt.utils
import salt.config as config
from salt.exceptions import (
SaltCloudConfigError,
Expand All @@ -96,6 +95,7 @@
SaltCloudExecutionTimeout,
SaltCloudSystemExit
)
import salt.utils.files

# Import salt.cloud libs
import salt.utils.cloud
Expand Down Expand Up @@ -805,7 +805,7 @@ def load_public_key(vm_):
)
)

with salt.utils.fopen(public_key_filename, 'r') as public_key:
with salt.utils.files.fopen(public_key_filename, 'r') as public_key:
key = public_key.read().replace('\n', '')

return key
Expand Down
2 changes: 1 addition & 1 deletion salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def _virtual(osdata):
command = 'system_profiler'
args = ['SPDisplaysDataType']
elif osdata['kernel'] == 'SunOS':
virtinfo = salt.utils.which('virtinfo')
virtinfo = salt.utils.path.which('virtinfo')
if virtinfo:
try:
ret = __salt__['cmd.run_all']('{0} -a'.format(virtinfo))
Expand Down
2 changes: 1 addition & 1 deletion salt/grains/disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _linux_disks():


def _windows_disks():
wmic = salt.utils.which('wmic')
wmic = salt.utils.path.which('wmic')

namespace = r'\\root\microsoft\windows\storage'
path = 'MSFT_PhysicalDisk'
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def recv(files, dest):
return 'Destination unavailable'

try:
with salt.utils.fopen(final, 'w+') as fp_:
with salt.utils.files.fopen(final, 'w+') as fp_:
fp_.write(data)
ret[final] = True
except IOError:
Expand Down
3 changes: 2 additions & 1 deletion salt/modules/runit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
# Import salt libs
from salt.exceptions import CommandExecutionError
import salt.utils.files
import salt.utils.path

# Function alias to not shadow built-ins.
__func_alias__ = {
Expand Down Expand Up @@ -95,7 +96,7 @@ def __virtual__():
global __virtualname__
__virtualname__ = 'service'
return __virtualname__
if salt.utils.which('sv'):
if salt.utils.path.which('sv'):
return __virtualname__
return (False, 'Runit not available. Please install sv')

Expand Down
9 changes: 6 additions & 3 deletions salt/modules/slsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
'''
Utility functions for use with or in SLS files
'''

# Import Python libs
from __future__ import absolute_import

# Import Salt libs
import salt.exceptions
import salt.loader
import salt.template
import salt.utils
import salt.utils.args
import salt.utils.dictupdate


Expand Down Expand Up @@ -172,7 +175,7 @@ def serialize(serializer, obj, **mod_kwargs):
{% set json_string = salt.slsutil.serialize('json',
{'foo': 'Foo!'}) %}
'''
kwargs = salt.utils.clean_kwargs(**mod_kwargs)
kwargs = salt.utils.args.clean_kwargs(**mod_kwargs)
return _get_serialize_fn(serializer, 'serialize')(obj, **kwargs)


Expand All @@ -196,6 +199,6 @@ def deserialize(serializer, stream_or_string, **mod_kwargs):
{% set python_object = salt.slsutil.deserialize('json',
'{"foo": "Foo!"}') %}
'''
kwargs = salt.utils.clean_kwargs(**mod_kwargs)
kwargs = salt.utils.args.clean_kwargs(**mod_kwargs)
return _get_serialize_fn(serializer, 'deserialize')(stream_or_string,
**kwargs)
3 changes: 2 additions & 1 deletion salt/modules/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Import Salt libs
import salt
import salt.utils
import salt.utils.args
import salt.utils.hashutils
import salt.utils.platform
import salt.version
Expand Down Expand Up @@ -323,7 +324,7 @@ def arg_clean(*args, **kwargs):
salt '*' test.arg_clean 1 "two" 3.1 txt="hello" wow='{a: 1, b: "hello"}'
'''
return dict(args=args, kwargs=salt.utils.clean_kwargs(**kwargs))
return dict(args=args, kwargs=salt.utils.args.clean_kwargs(**kwargs))


def fib(num):
Expand Down
6 changes: 3 additions & 3 deletions salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4025,14 +4025,14 @@ def _write_regpol_data(data_to_write,
reg_pol_header = u'\u5250\u6765\x01\x00'
if not os.path.exists(policy_file_path):
ret = __salt__['file.makedirs'](policy_file_path)
with salt.utils.fopen(policy_file_path, 'wb') as pol_file:
with salt.utils.files.fopen(policy_file_path, 'wb') as pol_file:
if not data_to_write.startswith(reg_pol_header):
pol_file.write(reg_pol_header.encode('utf-16-le'))
pol_file.write(data_to_write.encode('utf-16-le'))
try:
gpt_ini_data = ''
if os.path.exists(gpt_ini_path):
with salt.utils.fopen(gpt_ini_path, 'rb') as gpt_file:
with salt.utils.files.fopen(gpt_ini_path, 'rb') as gpt_file:
gpt_ini_data = gpt_file.read()
if not _regexSearchRegPolData(r'\[General\]\r\n', gpt_ini_data):
gpt_ini_data = '[General]\r\n' + gpt_ini_data
Expand Down Expand Up @@ -4087,7 +4087,7 @@ def _write_regpol_data(data_to_write,
int("{0}{1}".format(str(version_nums[0]).zfill(4), str(version_nums[1]).zfill(4)), 16),
gpt_ini_data[general_location.end():])
if gpt_ini_data:
with salt.utils.fopen(gpt_ini_path, 'wb') as gpt_file:
with salt.utils.files.fopen(gpt_ini_path, 'wb') as gpt_file:
gpt_file.write(gpt_ini_data)
except Exception as e:
msg = 'An error occurred attempting to write to {0}, the exception was {1}'.format(
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ def _parse_repo_file(filename):

# Try to extract leading comments
headers = ''
with salt.utils.fopen(filename, 'r') as rawfile:
with salt.utils.files.fopen(filename, 'r') as rawfile:
for line in rawfile:
if line.strip().startswith('#'):
headers += '{0}\n'.format(line.strip())
Expand Down
4 changes: 2 additions & 2 deletions salt/states/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from salt.ext import six

# Import Salt libs
import salt.utils
import salt.utils.platform
import salt.utils.win_functions


Expand All @@ -61,7 +61,7 @@ def _changes(name,

# User and Domain names are not case sensitive in Windows. Let's make them
# all lower case so we can compare properly
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
if lgrp['members']:
lgrp['members'] = [user.lower() for user in lgrp['members']]
if members:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import tempfile

# Import Salt Libs
import salt.utils
import salt.utils.platform
import salt.modules.cmdmod as cmdmod
from salt.exceptions import CommandExecutionError
Expand Down Expand Up @@ -264,7 +263,7 @@ def test_is_valid_shell_unavailable(self):
with patch('salt.utils.files.fopen', mock_open(read_data=MOCK_SHELL_FILE)):
self.assertFalse(cmdmod._is_valid_shell('foo'))

@skipIf(salt.utils.is_windows(), 'Do not run on Windows')
@skipIf(salt.utils.platform.is_windows(), 'Do not run on Windows')
def test_os_environment_remains_intact(self):
'''
Make sure the OS environment is not tainted after running a command
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch

# Import salt libs
import salt.utils
import salt.utils.platform
import salt.modules.pip as pip
from salt.exceptions import CommandExecutionError

Expand Down Expand Up @@ -297,7 +297,7 @@ def join(*args):
mock_path.join = join
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
venv_path = 'c:\\test_env'
bin_path = os.path.join(venv_path, 'Scripts', 'pip.exe').encode('string-escape')
else:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/modules/test_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from salt.exceptions import CommandExecutionError, SaltInvocationError
import salt.modules.timezone as timezone
from salt.ext import six
import salt.utils
import salt.utils.platform
import salt.utils.stringutils

Expand Down Expand Up @@ -193,7 +192,7 @@ def test_set_zone_suse(self):
name, args, kwargs = timezone.__salt__['file.sed'].mock_calls[0]
assert args == ('/etc/sysconfig/clock', '^TIMEZONE=.*', 'TIMEZONE="UTC"')

@skipIf(salt.utils.is_windows(), 'os.symlink not available in Windows')
@skipIf(salt.utils.platform.is_windows(), 'os.symlink not available in Windows')
@patch('salt.utils.path.which', MagicMock(return_value=False))
@patch('os.path.exists', MagicMock(return_value=True))
@patch('os.unlink', MagicMock())
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_managed(self):
'G12', 'G12', 'G12', 'G12', 'G12'])
mock_if = MagicMock(side_effect=[True, False, False, False, False,
False, False, False])
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
mock_ret = MagicMock(return_value=ret)
else:
mock_ret = MagicMock(return_value=(ret, None))
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_managed(self):

# Group argument is ignored on Windows systems. Group is set to
# user
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
comt = ('User salt is not available Group salt'
' is not available')
else:
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_directory(self):

mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
mock_perms = MagicMock(return_value=ret)
else:
mock_perms = MagicMock(return_value=(ret, ''))
Expand Down Expand Up @@ -803,7 +803,7 @@ def test_directory(self):

with patch.object(os.path, 'isfile', mock_f):
with patch.dict(filestate.__opts__, {'test': True}):
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
comt = 'The directory "{0}" will be changed' \
''.format(name)
p_chg = {'directory': 'new'}
Expand Down Expand Up @@ -889,7 +889,7 @@ def test_recurse(self):
'cp.list_master': mock_l}):

# Group argument is ignored on Windows systems. Group is set to user
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
comt = ('User salt is not available Group salt'
' is not available')
else:
Expand Down Expand Up @@ -1364,7 +1364,7 @@ def test_copy(self):

# Group argument is ignored on Windows systems. Group is set
# to user
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
comt = ('User salt is not available Group salt'
' is not available')
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Import Salt libs
import tests.integration as integration
import salt.modules.cmdmod
import salt.utils
import salt.utils.platform


class DocTestCase(TestCase):
Expand All @@ -35,7 +35,7 @@ def test_check_for_doc_inline_markup(self):
'''
salt_dir = integration.CODE_DIR

if salt.utils.is_windows():
if salt.utils.platform.is_windows():
# No grep in Windows, use findstr
# findstr in windows doesn't prepend 'Binary` to binary files, so
# use the '/P' switch to skip files with unprintable characters
Expand All @@ -52,7 +52,7 @@ def test_check_for_doc_inline_markup(self):
if line.startswith('Binary'):
continue

if salt.utils.is_windows():
if salt.utils.platform.is_windows():
# Need the space after the colon so it doesn't split the drive
# letter
key, val = line.split(': ', 1)
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/utils/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import absolute_import

# Import Salt Libs
import salt.utils.platform
import salt.utils.url

# Import Salt Testing Libs
Expand Down Expand Up @@ -38,7 +39,7 @@ def test_parse_salt_url(self):
'''
path = '?funny/path with {interesting|chars}'
url = 'salt://' + path
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
path = '_funny/path with {interesting_chars}'

self.assertEqual(salt.utils.url.parse(url), (path, None))
Expand All @@ -50,7 +51,7 @@ def test_parse_salt_saltenv(self):
saltenv = 'ambience'
path = '?funny/path&with {interesting|chars}'
url = 'salt://' + path + '?saltenv=' + saltenv
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
path = '_funny/path&with {interesting_chars}'

self.assertEqual(salt.utils.url.parse(url), (path, saltenv))
Expand All @@ -63,7 +64,7 @@ def test_create_url(self):
'''
path = '? interesting/&path.filetype'
url = 'salt://' + path
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
url = 'salt://_ interesting/&path.filetype'

self.assertEqual(salt.utils.url.create(path), url)
Expand All @@ -74,7 +75,7 @@ def test_create_url_saltenv(self):
'''
saltenv = 'raumklang'
path = '? interesting/&path.filetype'
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
path = '_ interesting/&path.filetype'

url = 'salt://' + path + '?saltenv=' + saltenv
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_escape_unescaped_path(self):
'''
path = 'dir/file.conf'
escaped_path = '|' + path
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
escaped_path = path

self.assertEqual(salt.utils.url.escape(path), escaped_path)
Expand All @@ -177,7 +178,7 @@ def test_escape_unescaped_url(self):
path = 'dir/file.conf'
url = 'salt://' + path
escaped_url = 'salt://|' + path
if salt.utils.is_windows():
if salt.utils.platform.is_windows():
escaped_url = url

self.assertEqual(salt.utils.url.escape(url), escaped_url)
Expand Down

0 comments on commit 26410c6

Please sign in to comment.