From af8c6b78940b666abbc93cacec2156618b6b7c38 Mon Sep 17 00:00:00 2001 From: rallytime Date: Wed, 25 May 2016 14:13:45 -0600 Subject: [PATCH] Allow exact arg matches to work in sys.list_modules func Fixes #33500 --- salt/modules/sysmod.py | 2 ++ tests/integration/modules/sysmod.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/salt/modules/sysmod.py b/salt/modules/sysmod.py index 4f86623622..47a021b6fe 100644 --- a/salt/modules/sysmod.py +++ b/salt/modules/sysmod.py @@ -401,6 +401,8 @@ def list_modules(*args): return sorted(modules) for module in args: + if '*' not in module: + module += '*' for func in fnmatch.filter(__salt__, module): comps = func.split('.') if len(comps) < 2: diff --git a/tests/integration/modules/sysmod.py b/tests/integration/modules/sysmod.py index 7f41818747..6ceace559c 100644 --- a/tests/integration/modules/sysmod.py +++ b/tests/integration/modules/sysmod.py @@ -45,12 +45,32 @@ class SysModuleTest(integration.ModuleCase): def test_list_modules(self): ''' - sys.list_moduels + sys.list_modules ''' mods = self.run_function('sys.list_modules') self.assertTrue('hosts' in mods) self.assertTrue('pkg' in mods) + def test_list_modules_with_arg(self): + ''' + sys.list_modules u* + + Tests getting the list of modules looking for the "user" module + ''' + mods = self.run_function('sys.list_modules', 'u*') + self.assertIn('user', mods) + + def test_list_modules_with_arg_exact_match(self): + ''' + sys.list_modules user + + Tests getting the list of modules looking for the "user" module with + an exact match of 'user' being passed at the CLI instead of something + with '*'. + ''' + mods = self.run_function('sys.list_modules', 'user') + self.assertIn('user', mods) + def test_valid_docs(self): ''' Make sure no functions are exposed that don't have valid docstrings