(a la #33775) allow for sys.list_state_modules to do exact matching too

This commit is contained in:
Jeffrey 'jf' Lim 2016-08-04 17:18:22 +08:00
parent 176653eded
commit 06c2407f8d
2 changed files with 22 additions and 13 deletions

View File

@ -603,17 +603,18 @@ def list_state_modules(*args):
for func in st_.states:
log.debug('func {0}'.format(func))
comps = func.split('.')
if len(comps) < 2:
continue
modules.add(comps[0])
return sorted(modules)
for module in args:
for func in fnmatch.filter(st_.states, module):
comps = func.split('.')
if len(comps) < 2:
continue
modules.add(comps[0])
if '*' not in module:
for func in st_.states:
comps = func.split('.')
if comps[0] == module:
modules.add(comps[0])
else:
for func in fnmatch.filter(st_.states, module):
modules.add(func.split('.')[0])
return sorted(modules)

View File

@ -23,6 +23,8 @@ from salt.modules import sysmod
modules = set()
functions = [
'exist.exist',
'sys.doc', 'sys.list_functions', 'sys.list_modules',
'sysctl.get', 'sysctl.show',
'system.halt', 'system.reboot',
@ -48,7 +50,9 @@ class Mockstate(object):
"""
Mock of State
"""
states = []
states = {}
for func in functions:
states[func] = None
def __init__(self, opts):
pass
@ -120,9 +124,9 @@ class SysmodTestCase(TestCase):
'''
Test if it return the docstrings for all states.
'''
self.assertDictEqual(sysmod.state_doc(), {})
self.assertDictEqual(sysmod.state_doc(), sysmod.__salt__)
self.assertDictEqual(sysmod.state_doc('sys.doc'), {})
self.assertDictEqual(sysmod.state_doc('sys.doc'), {'sys.doc': None})
# 'runner_doc' function tests: 1
@ -238,7 +242,7 @@ class SysmodTestCase(TestCase):
'''
Test if it list the functions for all state modules.
'''
self.assertListEqual(sysmod.list_state_functions(), [])
self.assertListEqual(sysmod.list_state_functions(), functions)
self.assertListEqual(sysmod.list_state_functions('file.s*'), [])
@ -248,9 +252,13 @@ class SysmodTestCase(TestCase):
'''
Test if it list the modules loaded on the minion.
'''
self.assertListEqual(sysmod.list_state_modules(), [])
self.assertListEqual(sysmod.list_state_modules(), modules)
self.assertListEqual(sysmod.list_state_modules('mysql_*'), [])
self.assertListEqual(sysmod.list_state_modules('nonexist'), [])
self.assertListEqual(sysmod.list_state_modules('user'), ['user'])
self.assertListEqual(sysmod.list_state_modules('s*'), ['sys', 'sysctl', 'system'])
# 'list_runners' function tests: 1