Merge pull request #26565 from cachedout/fix_virtual_warnings

Fix many errors with __virtual__ in tests
This commit is contained in:
Nicole Thomas 2015-08-21 15:37:53 -06:00
commit 2cd36c7ed4
3 changed files with 11 additions and 5 deletions

View file

@ -15,6 +15,7 @@ import distutils.version # pylint: disable=import-error,no-name-in-module
# Import salt libs
import salt.utils
import salt.modules.cmdmod
from salt.exceptions import CommandExecutionError
@ -32,7 +33,7 @@ def __virtual__():
'''
try:
if salt.utils.which('npm') is not None:
_check_valid_version(__salt__)
_check_valid_version()
return True
else:
return (False, 'npm execution module could not be loaded '
@ -41,14 +42,14 @@ def __virtual__():
return (False, str(exc))
def _check_valid_version(salt):
def _check_valid_version():
'''
Check the version of npm to ensure this module will work. Currently
npm must be at least version 1.2.
'''
# pylint: disable=no-member
npm_version = distutils.version.LooseVersion(
salt['cmd.run']('npm --version', python_shell=True))
salt.modules.cmdmod.run('npm --version', python_shell=True))
valid_version = distutils.version.LooseVersion('1.2')
# pylint: enable=no-member
if npm_version < valid_version:

View file

@ -16,6 +16,7 @@ import sys
# Import Salt libs
import salt.utils
import salt.modules.cmdmod
import salt.utils.decorators as decorators
log = logging.getLogger(__name__)
@ -90,7 +91,7 @@ def __virtual__():
else:
cmd = 'ls /sys/module/zfs'
if cmd and __salt__['cmd.retcode'](
if cmd and salt.modules.cmdmod.retcode(
cmd, output_loglevel='quiet', ignore_retcode=True
) == 0:
# Build dynamic functions and allow loading module

View file

@ -26,7 +26,7 @@ ensure_in_syspath('../../')
import salt.ext.six as six
from salt.config import minion_config
from salt.loader import LazyLoader, _module_dirs
from salt.loader import LazyLoader, _module_dirs, grains
class LazyLoaderVirtualEnabledTest(TestCase):
@ -36,6 +36,7 @@ class LazyLoaderVirtualEnabledTest(TestCase):
def setUp(self):
self.opts = minion_config(None)
self.opts['disable_modules'] = ['pillar']
self.opts['grains'] = grains(self.opts)
self.loader = LazyLoader(_module_dirs(self.opts, 'modules', 'module'),
self.opts,
@ -123,6 +124,7 @@ class LazyLoaderVirtualDisabledTest(TestCase):
'''
def setUp(self):
self.opts = _config = minion_config(None)
self.opts['grains'] = grains(self.opts)
self.loader = LazyLoader(_module_dirs(self.opts, 'modules', 'module'),
self.opts,
tag='module',
@ -183,6 +185,7 @@ class LazyLoaderReloadingTest(TestCase):
def setUp(self):
self.opts = _config = minion_config(None)
self.opts['grains'] = grains(self.opts)
self.tmp_dir = tempfile.mkdtemp(dir=integration.TMP)
self.count = 0
@ -307,6 +310,7 @@ class LazyLoaderSubmodReloadingTest(TestCase):
def setUp(self):
self.opts = _config = minion_config(None)
self.opts['grains'] = grains(self.opts)
self.tmp_dir = tempfile.mkdtemp(dir=integration.TMP)
os.makedirs(self.module_dir)