Update old utils path to new path for which() function

This commit is contained in:
rallytime 2018-02-08 14:38:25 -05:00
parent 61d86588b2
commit a16ea53430
No known key found for this signature in database
GPG Key ID: E8F1A4B90D0DEA19
2 changed files with 24 additions and 24 deletions

View File

@ -67,7 +67,7 @@ def _localectl_status():
Parse localectl status into a dict.
:return: dict
'''
if salt.utils.which('localectl') is None:
if salt.utils.path.which('localectl') is None:
raise CommandExecutionError('Unable to find "localectl"')
ret = {}

View File

@ -64,7 +64,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
{'cmd.run': MagicMock(return_value='A\nB')}):
assert localemod.list_avail() == ['A', 'B']
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out)})
def test_localectl_status_parser(self):
'''
@ -119,7 +119,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert msg == ('Odd locale parameter "Fatal error right in front of screen" detected in dbus locale output.'
' This should not happen. You should probably investigate what caused this.')
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.log', MagicMock())
def test_localectl_status_parser_no_systemd(self):
'''
@ -131,21 +131,21 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert 'Unable to find "localectl"' in six.text_type(err)
assert not localemod.log.debug.called
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_empty)})
def test_localectl_status_parser_empty(self):
with pytest.raises(CommandExecutionError) as err:
localemod._localectl_status()
assert 'Unable to parse result of "localectl"' in six.text_type(err)
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_broken)})
def test_localectl_status_parser_broken(self):
with pytest.raises(CommandExecutionError) as err:
localemod._localectl_status()
assert 'Unable to parse result of "localectl"' in six.text_type(err)
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock(return_value=locale_ctl_out_structure)})
def test_localectl_status_parser_structure(self):
out = localemod._localectl_status()
@ -156,7 +156,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert isinstance(out[key][in_key], six.text_type)
assert isinstance(out['reason'], six.text_type)
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Ubuntu', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod._parse_dbus_locale', MagicMock(return_value={'LANG': 'en_US.utf8'}))
@ -169,7 +169,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
'''
assert localemod.get_locale() == 'de_DE.utf8'
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Ubuntu', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', True)
@patch('salt.modules.localemod._parse_dbus_locale', MagicMock(return_value={'LANG': 'en_US.utf8'}))
@ -182,7 +182,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
'''
assert localemod.get_locale() == 'en_US.utf8'
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Suse', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', True)
@patch('salt.modules.localemod._parse_dbus_locale', MagicMock(return_value={'LANG': 'en_US.utf8'}))
@ -197,7 +197,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^RC_LANG" /etc/sysconfig/language'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'RedHat', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock()})
@ -210,7 +210,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^LANG=" /etc/sysconfig/i18n'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Debian', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock()})
@ -223,7 +223,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^LANG=" /etc/default/locale'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Gentoo', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock()})
@ -236,7 +236,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert localemod.__salt__['cmd.run'].call_args[0][0] == 'eselect --brief locale show'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Solaris', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock()})
@ -249,7 +249,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^LANG=" /etc/default/init'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'BSD', 'osmajorrelease': 8, 'oscodename': 'DrunkDragon'})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'cmd.run': MagicMock()})
@ -263,7 +263,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.get_locale()
assert '"DrunkDragon" is unsupported' in six.text_type(err)
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Ubuntu', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.utils.systemd.booted', MagicMock(return_value=True))
@ -277,7 +277,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.set_locale(loc)
assert localemod._localectl_set.call_args[0][0] == 'de_DE.utf8'
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Ubuntu', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', True)
@patch('salt.utils.systemd.booted', MagicMock(return_value=True))
@ -291,7 +291,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
localemod.set_locale(loc)
assert localemod._localectl_set.call_args[0][0] == 'de_DE.utf8'
@patch('salt.utils.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.utils.path.which', MagicMock(return_value="/usr/bin/localctl"))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Suse', 'osmajorrelease': 12})
@patch('salt.modules.localemod.dbus', True)
@patch('salt.modules.localemod.__salt__', MagicMock())
@ -310,7 +310,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert localemod.__salt__['file.replace'].call_args[0][1] == '^RC_LANG=.*'
assert localemod.__salt__['file.replace'].call_args[0][2] == 'RC_LANG="{}"'.format(loc)
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'RedHat', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', MagicMock())
@ -329,7 +329,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert localemod.__salt__['file.replace'].call_args[0][1] == '^LANG=.*'
assert localemod.__salt__['file.replace'].call_args[0][2] == 'LANG="{}"'.format(loc)
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value='/usr/sbin/update-locale'))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Debian', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@ -349,7 +349,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert localemod.__salt__['file.replace'].call_args[0][1] == '^LANG=.*'
assert localemod.__salt__['file.replace'].call_args[0][2] == 'LANG="{}"'.format(loc)
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Debian', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@ -367,7 +367,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert not localemod._localectl_set.called
assert 'Cannot set locale: "update-locale" was not found.' in six.text_type(err)
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Gentoo', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', MagicMock())
@ -383,7 +383,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert not localemod._localectl_set.called
assert localemod.__salt__['cmd.retcode'].call_args[0][0] == 'eselect --brief locale set de_DE.utf8'
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Solaris', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'locale.list_avail': MagicMock(return_value=['de_DE.utf8']),
@ -404,7 +404,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert localemod.__salt__['file.replace'].call_args[0][1] == '^LANG=.*'
assert localemod.__salt__['file.replace'].call_args[0][2] == 'LANG="{}"'.format(loc)
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'Solaris', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'locale.list_avail': MagicMock(return_value=['en_GB.utf8']),
@ -422,7 +422,7 @@ class LocalemodTestCase(TestCase, LoaderModuleMockMixin):
assert not localemod._localectl_set.called
assert not localemod.__salt__['file.replace'].called
@patch('salt.utils.which', MagicMock(return_value=None))
@patch('salt.utils.path.which', MagicMock(return_value=None))
@patch('salt.modules.localemod.__grains__', {'os_family': 'BSD', 'osmajorrelease': 42})
@patch('salt.modules.localemod.dbus', None)
@patch('salt.modules.localemod.__salt__', {'locale.list_avail': MagicMock(return_value=['en_GB.utf8']),