mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixing a bug that prevents specifying wildcards for filenames.
This commit is contained in:
parent
00d06bda76
commit
2e01c55e7e
2 changed files with 35 additions and 1 deletions
|
@ -6213,6 +6213,16 @@ def grep(path,
|
|||
'''
|
||||
path = os.path.expanduser(path)
|
||||
|
||||
# Backup the path in case the glob returns nothing
|
||||
_path = path
|
||||
path = glob.glob(path)
|
||||
|
||||
# If the list is empty no files exist
|
||||
# so we revert back to the original path
|
||||
# so the result is an error.
|
||||
if not path:
|
||||
path = _path
|
||||
|
||||
split_opts = []
|
||||
for opt in opts:
|
||||
try:
|
||||
|
@ -6227,7 +6237,10 @@ def grep(path,
|
|||
)
|
||||
split_opts.extend(split)
|
||||
|
||||
cmd = ['grep'] + split_opts + [pattern, path]
|
||||
if isinstance(path, list):
|
||||
cmd = ['grep'] + split_opts + [pattern] + path
|
||||
else:
|
||||
cmd = ['grep'] + split_opts + [pattern, path]
|
||||
try:
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
except (IOError, OSError) as exc:
|
||||
|
|
|
@ -522,6 +522,27 @@ class FileBlockReplaceTestCase(TestCase, LoaderModuleMockMixin):
|
|||
backup=False
|
||||
)
|
||||
|
||||
def test_grep_query_exists_wildcard(self):
|
||||
_file = '{0}-junk*'.format(self.tfile.name)
|
||||
result = filemod.grep(_file,
|
||||
'Lorem ipsum')
|
||||
|
||||
self.assertTrue(result, None)
|
||||
self.assertTrue(result['retcode'] == 0)
|
||||
self.assertTrue(result['stdout'] == 'Lorem ipsum dolor sit amet, consectetur')
|
||||
self.assertTrue(result['stderr'] == '')
|
||||
|
||||
def test_grep_file_not_exists_wildcard(self):
|
||||
_file = '{0}-junk*'.format(self.tfile.name)
|
||||
result = filemod.grep(_file,
|
||||
'Lorem ipsum')
|
||||
|
||||
self.assertTrue(result, None)
|
||||
self.assertFalse(result['retcode'] == 0)
|
||||
self.assertFalse(result['stdout'] == 'Lorem ipsum dolor sit amet, consectetur')
|
||||
_expected_stderr = 'grep: {0}-junk*: No such file or directory'.format(self.tfile.name)
|
||||
self.assertTrue(result['stderr'] == _expected_stderr)
|
||||
|
||||
|
||||
class FileModuleTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue