mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update old utils paths to new utils paths
This commit is contained in:
parent
08c71f13e4
commit
db5866d097
21 changed files with 51 additions and 45 deletions
|
@ -20,6 +20,7 @@ import salt.utils.data
|
|||
import salt.utils.files
|
||||
import salt.utils.hashutils
|
||||
import salt.utils.platform
|
||||
import salt.utils.state
|
||||
import salt.utils.thin
|
||||
import salt.roster
|
||||
import salt.state
|
||||
|
@ -47,7 +48,7 @@ def _set_retcode(ret, highstate=None):
|
|||
if isinstance(ret, list):
|
||||
__context__['retcode'] = 1
|
||||
return
|
||||
if not salt.utils.check_state_result(ret, highstate=highstate):
|
||||
if not salt.utils.state.check_result(ret, highstate=highstate):
|
||||
|
||||
__context__['retcode'] = 2
|
||||
|
||||
|
@ -357,7 +358,7 @@ def _get_test_value(test=None, **kwargs):
|
|||
'''
|
||||
ret = True
|
||||
if test is None:
|
||||
if salt.utils.test_mode(test=test, **kwargs):
|
||||
if salt.utils.args.test_mode(test=test, **kwargs):
|
||||
ret = True
|
||||
else:
|
||||
ret = __opts__.get('test', None)
|
||||
|
|
|
@ -40,7 +40,7 @@ def config():
|
|||
if 'conf_file' not in __opts__:
|
||||
return {}
|
||||
if os.path.isdir(__opts__['conf_file']):
|
||||
if salt.utils.is_proxy():
|
||||
if salt.utils.platform.is_proxy():
|
||||
gfn = os.path.join(
|
||||
__opts__['conf_file'],
|
||||
'proxy.d',
|
||||
|
@ -53,7 +53,7 @@ def config():
|
|||
'grains'
|
||||
)
|
||||
else:
|
||||
if salt.utils.is_proxy():
|
||||
if salt.utils.platform.is_proxy():
|
||||
gfn = os.path.join(
|
||||
os.path.dirname(__opts__['conf_file']),
|
||||
'proxy.d',
|
||||
|
|
|
@ -2005,8 +2005,8 @@ def line(path, content=None, match=None, mode=None, location=None,
|
|||
if __opts__['test'] is False:
|
||||
fh_ = None
|
||||
try:
|
||||
# Make sure we match the file mode from salt.utils.fopen
|
||||
mode = 'wb' if six.PY2 and salt.utils.is_windows() else 'w'
|
||||
# Make sure we match the file mode from salt.utils.files.fopen
|
||||
mode = 'wb' if six.PY2 and salt.utils.platform.is_windows() else 'w'
|
||||
fh_ = salt.utils.atomicfile.atomic_open(path, mode)
|
||||
fh_.write(body)
|
||||
finally:
|
||||
|
|
|
@ -27,6 +27,7 @@ from salt.ext import six
|
|||
import salt.utils.compat
|
||||
import salt.utils.data
|
||||
import salt.utils.files
|
||||
import salt.utils.platform
|
||||
import salt.utils.yamldumper
|
||||
from salt.defaults import DEFAULT_TARGET_DELIM
|
||||
from salt.exceptions import SaltException
|
||||
|
@ -230,7 +231,7 @@ def setvals(grains, destructive=False):
|
|||
raise SaltException('setvals grains must be a dictionary.')
|
||||
grains = {}
|
||||
if os.path.isfile(__opts__['conf_file']):
|
||||
if salt.utils.is_proxy():
|
||||
if salt.utils.platform.is_proxy():
|
||||
gfn = os.path.join(
|
||||
os.path.dirname(__opts__['conf_file']),
|
||||
'proxy.d',
|
||||
|
@ -243,7 +244,7 @@ def setvals(grains, destructive=False):
|
|||
'grains'
|
||||
)
|
||||
elif os.path.isdir(__opts__['conf_file']):
|
||||
if salt.utils.is_proxy():
|
||||
if salt.utils.platform.is_proxy():
|
||||
gfn = os.path.join(
|
||||
__opts__['conf_file'],
|
||||
'proxy.d',
|
||||
|
@ -256,7 +257,7 @@ def setvals(grains, destructive=False):
|
|||
'grains'
|
||||
)
|
||||
else:
|
||||
if salt.utils.is_proxy():
|
||||
if salt.utils.platform.is_proxy():
|
||||
gfn = os.path.join(
|
||||
os.path.dirname(__opts__['conf_file']),
|
||||
'proxy.d',
|
||||
|
|
|
@ -46,6 +46,7 @@ except ImportError:
|
|||
|
||||
# Import Salt libs
|
||||
import salt.utils.platform
|
||||
import salt.utils.stringutils
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
@ -76,7 +77,7 @@ def _to_mbcs(vdata):
|
|||
Converts unicode to to current users character encoding. Use this for values
|
||||
returned by reg functions
|
||||
'''
|
||||
return salt.utils.to_unicode(vdata, 'mbcs')
|
||||
return salt.utils.stringutils.to_unicode(vdata, 'mbcs')
|
||||
|
||||
|
||||
def _to_unicode(vdata):
|
||||
|
@ -84,7 +85,7 @@ def _to_unicode(vdata):
|
|||
Converts from current users character encoding to unicode. Use this for
|
||||
parameters being pass to reg functions
|
||||
'''
|
||||
return salt.utils.to_unicode(vdata, 'utf-8')
|
||||
return salt.utils.stringutils.to_unicode(vdata, 'utf-8')
|
||||
|
||||
|
||||
class Registry(object): # pylint: disable=R0903
|
||||
|
|
|
@ -1837,4 +1837,4 @@ def compare_versions(ver1='', oper='==', ver2=''):
|
|||
if ver2 == 'Not Found':
|
||||
ver2 = '0.0.0.0.0'
|
||||
|
||||
return salt.utils.compare_versions(ver1, oper, ver2, ignore_epoch=True)
|
||||
return salt.utils.versions.compare(ver1, oper, ver2, ignore_epoch=True)
|
||||
|
|
|
@ -59,7 +59,7 @@ from __future__ import absolute_import
|
|||
|
||||
# Import python libs
|
||||
import logging
|
||||
import salt.utils
|
||||
import salt.utils.stringutils
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -188,13 +188,13 @@ def present(name,
|
|||
|
||||
if vdata == reg_current['vdata'] and reg_current['success']:
|
||||
ret['comment'] = u'{0} in {1} is already configured' \
|
||||
''.format(salt.utils.to_unicode(vname, 'utf-8') if vname else u'(Default)',
|
||||
salt.utils.to_unicode(name, 'utf-8'))
|
||||
''.format(salt.utils.stringutils.to_unicode(vname, 'utf-8') if vname else u'(Default)',
|
||||
salt.utils.stringutils.to_unicode(name, 'utf-8'))
|
||||
return ret
|
||||
|
||||
add_change = {'Key': r'{0}\{1}'.format(hive, key),
|
||||
'Entry': u'{0}'.format(salt.utils.to_unicode(vname, 'utf-8') if vname else u'(Default)'),
|
||||
'Value': salt.utils.to_unicode(vdata, 'utf-8')}
|
||||
'Entry': u'{0}'.format(salt.utils.stringutils.to_unicode(vname, 'utf-8') if vname else u'(Default)'),
|
||||
'Value': salt.utils.stringutils.to_unicode(vdata, 'utf-8')}
|
||||
|
||||
# Check for test option
|
||||
if __opts__['test']:
|
||||
|
|
|
@ -59,7 +59,7 @@ def __clean_tmp(tmp):
|
|||
Remove temporary files
|
||||
'''
|
||||
try:
|
||||
salt.utils.rm_rf(tmp)
|
||||
rm_rf(tmp)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
|
|
@ -368,6 +368,7 @@ import salt.utils.minion
|
|||
import salt.utils.platform
|
||||
import salt.utils.process
|
||||
import salt.utils.stringutils
|
||||
import salt.utils.user
|
||||
import salt.loader
|
||||
import salt.minion
|
||||
import salt.payload
|
||||
|
@ -961,7 +962,7 @@ class Schedule(object):
|
|||
|
||||
func_globals = {
|
||||
'__jid__': jid,
|
||||
'__user__': salt.utils.get_user(),
|
||||
'__user__': salt.utils.user.get_user(),
|
||||
'__tag__': tag,
|
||||
'__jid_event__': weakref.proxy(namespaced_event),
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ def symlink(source, link_name):
|
|||
'''
|
||||
Handle symlinks on Windows with Python < 3.2
|
||||
'''
|
||||
if salt.utils.is_windows():
|
||||
if salt.utils.platform.is_windows():
|
||||
win32file.CreateSymbolicLink(link_name, source)
|
||||
else:
|
||||
os.symlink(source, link_name)
|
||||
|
@ -209,6 +209,6 @@ class FileModuleTest(ModuleCase):
|
|||
def test_file_line_content(self):
|
||||
self.minion_run('file.line', self.myfile, 'Goodbye',
|
||||
mode='insert', after='Hello')
|
||||
with salt.utils.fopen(self.myfile, 'r') as fp:
|
||||
with salt.utils.files.fopen(self.myfile, 'r') as fp:
|
||||
content = fp.read()
|
||||
self.assertEqual(content, 'Hello' + os.linesep + 'Goodbye' + os.linesep)
|
||||
|
|
|
@ -14,7 +14,7 @@ from tests.support.case import ModuleCase
|
|||
from tests.support.helpers import destructiveTest, skip_if_not_root
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
import salt.utils.files
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -174,7 +174,7 @@ class MacUserModuleTest(ModuleCase):
|
|||
|
||||
# Are the contents of the file correct
|
||||
test_data = b'.\xf8\'B\xa0\xd9\xad\x8b\xcd\xcdl'
|
||||
with salt.utils.fopen('/etc/kcpassword', 'rb') as f:
|
||||
with salt.utils.files.fopen('/etc/kcpassword', 'rb') as f:
|
||||
file_data = f.read()
|
||||
self.assertEqual(test_data, file_data)
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ from tests.support.case import SSHCase
|
|||
from tests.support.unit import skipIf
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
import salt.utils.platform
|
||||
|
||||
|
||||
@skipIf(salt.utils.is_windows(), 'salt-ssh not available on Windows')
|
||||
@skipIf(salt.utils.platform.is_windows(), 'salt-ssh not available on Windows')
|
||||
class SSHMineTest(SSHCase):
|
||||
'''
|
||||
testing salt-ssh with mine
|
||||
|
|
|
@ -8,10 +8,10 @@ from tests.support.case import SSHCase
|
|||
from tests.support.unit import skipIf
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
import salt.utils.platform
|
||||
|
||||
|
||||
@skipIf(salt.utils.is_windows(), 'salt-ssh not available on Windows')
|
||||
@skipIf(salt.utils.platform.is_windows(), 'salt-ssh not available on Windows')
|
||||
class SSHPillarTest(SSHCase):
|
||||
'''
|
||||
testing pillar with salt-ssh
|
||||
|
|
|
@ -618,7 +618,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
log.debug('Trying with nonexistant destination file')
|
||||
do_test()
|
||||
log.debug('Trying with destination file already present')
|
||||
with salt.utils.fopen(name, 'w'):
|
||||
with salt.utils.files.fopen(name, 'w'):
|
||||
pass
|
||||
try:
|
||||
do_test(clean=False)
|
||||
|
|
|
@ -654,13 +654,13 @@ class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
'spm_share_dir': os.path.join(self._tmp_spm, 'share'),
|
||||
})
|
||||
|
||||
import salt.utils
|
||||
import salt.utils.files
|
||||
import yaml
|
||||
|
||||
if not os.path.isdir(config['formula_path']):
|
||||
os.makedirs(config['formula_path'])
|
||||
|
||||
with salt.utils.fopen(os.path.join(self._tmp_spm, 'spm'), 'w') as fp:
|
||||
with salt.utils.files.fopen(os.path.join(self._tmp_spm, 'spm'), 'w') as fp:
|
||||
fp.write(yaml.dump(config))
|
||||
|
||||
return config
|
||||
|
|
|
@ -699,7 +699,7 @@ SwapTotal: 4789244 kB'''
|
|||
raise Exception("{0} is suppose to be empty. value: {1} \
|
||||
exists".format(key, value))
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_fqdn_return(self):
|
||||
'''
|
||||
test ip4 and ip6 return values
|
||||
|
@ -710,7 +710,7 @@ SwapTotal: 4789244 kB'''
|
|||
self._run_fqdn_tests(net_ip4_mock, net_ip6_mock,
|
||||
ip4_empty=False, ip6_empty=False)
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_fqdn6_empty(self):
|
||||
'''
|
||||
test when ip6 is empty
|
||||
|
@ -721,7 +721,7 @@ SwapTotal: 4789244 kB'''
|
|||
self._run_fqdn_tests(net_ip4_mock, net_ip6_mock,
|
||||
ip4_empty=False)
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_fqdn4_empty(self):
|
||||
'''
|
||||
test when ip4 is empty
|
||||
|
@ -732,7 +732,7 @@ SwapTotal: 4789244 kB'''
|
|||
self._run_fqdn_tests(net_ip4_mock, net_ip6_mock,
|
||||
ip6_empty=False)
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_fqdn_all_empty(self):
|
||||
'''
|
||||
test when both ip4 and ip6 are empty
|
||||
|
@ -775,7 +775,7 @@ SwapTotal: 4789244 kB'''
|
|||
value = get_fqdn[key]
|
||||
_check_type(key, value, ip4_empty, ip6_empty)
|
||||
|
||||
@skipIf(not salt.utils.is_linux(), 'System is not Linux')
|
||||
@skipIf(not salt.utils.platform.is_linux(), 'System is not Linux')
|
||||
def test_dns_return(self):
|
||||
'''
|
||||
test the return for a dns grain. test for issue:
|
||||
|
|
|
@ -8,7 +8,7 @@ from __future__ import absolute_import
|
|||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
# Import Salt libs
|
||||
|
@ -148,7 +148,7 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin):
|
|||
device = '/dev/sdX1'
|
||||
mock = MagicMock(return_value=0)
|
||||
with patch.dict(disk.__salt__, {'cmd.retcode': mock}),\
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
patch('salt.utils.path.which', MagicMock(return_value=True)):
|
||||
self.assertEqual(disk.format_(device), True)
|
||||
|
||||
@skipIf(not salt.utils.path.which('lsblk') and not salt.utils.path.which('df'),
|
||||
|
@ -162,7 +162,7 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value='FSTYPE\n{0}'.format(fs_type))
|
||||
with patch.dict(disk.__grains__, {'kernel': 'Linux'}), \
|
||||
patch.dict(disk.__salt__, {'cmd.run': mock}), \
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
patch('salt.utils.path.which', MagicMock(return_value=True)):
|
||||
self.assertEqual(disk.fstype(device), fs_type)
|
||||
|
||||
def test_resize2fs(self):
|
||||
|
@ -172,6 +172,6 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin):
|
|||
device = '/dev/sdX1'
|
||||
mock = MagicMock()
|
||||
with patch.dict(disk.__salt__, {'cmd.run_all': mock}), \
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
patch('salt.utils.path.which', MagicMock(return_value=True)):
|
||||
disk.resize2fs(device)
|
||||
mock.assert_called_once_with('resize2fs {0}'.format(device), python_shell=False)
|
||||
|
|
|
@ -17,7 +17,7 @@ from tests.support.mock import (
|
|||
# Import Salt Libs
|
||||
import salt.modules.win_file as win_file
|
||||
from salt.exceptions import CommandExecutionError
|
||||
import salt.utils
|
||||
import salt.utils.platform
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
|
@ -26,7 +26,7 @@ class WinFileTestCase(TestCase):
|
|||
Test cases for salt.modules.win_file
|
||||
'''
|
||||
FAKE_RET = {'fake': 'ret data'}
|
||||
if salt.utils.is_windows():
|
||||
if salt.utils.platform.is_windows():
|
||||
FAKE_PATH = os.sep.join(['C:', 'path', 'does', 'not', 'exist'])
|
||||
else:
|
||||
FAKE_PATH = os.sep.join(['path', 'does', 'not', 'exist'])
|
||||
|
|
|
@ -19,7 +19,7 @@ from tests.support.paths import TMP
|
|||
# Import Salt libs
|
||||
import salt.roster
|
||||
import salt.config
|
||||
import salt.utils
|
||||
import salt.utils.files
|
||||
|
||||
ROSTER = '''
|
||||
localhost:
|
||||
|
@ -53,7 +53,7 @@ class SSHRosterDefaults(TestCase):
|
|||
root_dir = os.path.join(tempdir, 'foo', 'bar')
|
||||
os.makedirs(root_dir)
|
||||
fpath = os.path.join(root_dir, 'config')
|
||||
with salt.utils.fopen(fpath, 'w') as fp_:
|
||||
with salt.utils.files.fopen(fpath, 'w') as fp_:
|
||||
fp_.write(
|
||||
'''
|
||||
roster_defaults:
|
||||
|
|
|
@ -19,6 +19,7 @@ import salt.exceptions
|
|||
import salt.transport.ipc
|
||||
import salt.transport.server
|
||||
import salt.transport.client
|
||||
import salt.utils.platform
|
||||
|
||||
from salt.ext.six.moves import range
|
||||
|
||||
|
@ -30,7 +31,7 @@ from tests.support.unit import skipIf
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@skipIf(salt.utils.is_windows(), 'Windows does not support Posix IPC')
|
||||
@skipIf(salt.utils.platform.is_windows(), 'Windows does not support Posix IPC')
|
||||
class BaseIPCReqCase(tornado.testing.AsyncTestCase):
|
||||
'''
|
||||
Test the req server/client pair
|
||||
|
|
|
@ -18,6 +18,7 @@ from tests.support.mock import (
|
|||
)
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.platform
|
||||
import salt.utils.process
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -107,7 +108,7 @@ class TestProcessManager(TestCase):
|
|||
process_manager.add_process(self.spin_kill)
|
||||
initial_pid = next(six.iterkeys(process_manager._process_map))
|
||||
# kill the child
|
||||
if salt.utils.is_windows():
|
||||
if salt.utils.platform.is_windows():
|
||||
os.kill(initial_pid, signal.SIGTERM)
|
||||
else:
|
||||
os.kill(initial_pid, signal.SIGKILL)
|
||||
|
|
Loading…
Add table
Reference in a new issue