diff --git a/doc/conf.py b/doc/conf.py index 3446943404..62a22add8d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -72,12 +72,12 @@ MOCK_MODULES = [ 'Crypto.Signature', 'Crypto.Signature.PKCS1_v1_5', 'M2Crypto', + 'msgpack', 'yaml', 'yaml.constructor', 'yaml.nodes', 'yaml.parser', 'yaml.scanner', - 'salt.utils.yamlloader', 'zmq', 'zmq.eventloop', 'zmq.eventloop.ioloop', @@ -126,7 +126,6 @@ MOCK_MODULES = [ 'ClusterShell', 'ClusterShell.NodeSet', 'django', - 'docker', 'libvirt', 'MySQLdb', 'MySQLdb.cursors', @@ -176,7 +175,7 @@ MOCK_MODULES = [ for mod_name in MOCK_MODULES: if mod_name == 'psutil': - mock = Mock(mapping={'total': 0, 'version_info': (0, 6,0)}) # Otherwise it will crash Sphinx + mock = Mock(mapping={'total': 0}) # Otherwise it will crash Sphinx else: mock = Mock() sys.modules[mod_name] = mock diff --git a/doc/ref/states/all/index.rst b/doc/ref/states/all/index.rst index 8c02f0d7e3..1344bbc026 100644 --- a/doc/ref/states/all/index.rst +++ b/doc/ref/states/all/index.rst @@ -74,6 +74,10 @@ state modules dellchassis disk docker + docker_container + docker_image + docker_network + docker_volume drac elasticsearch elasticsearch_index diff --git a/salt/client/ssh/wrapper/state.py b/salt/client/ssh/wrapper/state.py index 2710d12ff8..9d16fc0c4e 100644 --- a/salt/client/ssh/wrapper/state.py +++ b/salt/client/ssh/wrapper/state.py @@ -43,6 +43,14 @@ def _merge_extra_filerefs(*args): return ','.join(ret) +def _thin_dir(): + ''' + Get the thin_dir from the master_opts if not in __opts__ + ''' + thin_dir = __opts__.get('thin_dir', __opts__['__master_opts__']['thin_dir']) + return thin_dir + + def sls(mods, saltenv='base', test=None, exclude=None, **kwargs): ''' Create the seed file for a state.sls run @@ -100,7 +108,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs): roster_grains) trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type']) cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format( - __opts__['thin_dir'], + _thin_dir(), test, trans_tar_sum, __opts__['hash_type']) @@ -112,7 +120,7 @@ def sls(mods, saltenv='base', test=None, exclude=None, **kwargs): **st_kwargs) single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) stdout, stderr, _ = single.cmd_block() # Clean up our tar @@ -177,7 +185,7 @@ def low(data, **kwargs): roster_grains) trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type']) cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format( - __opts__['thin_dir'], + _thin_dir(), trans_tar_sum, __opts__['hash_type']) single = salt.client.ssh.Single( @@ -188,7 +196,7 @@ def low(data, **kwargs): **st_kwargs) single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) stdout, stderr, _ = single.cmd_block() # Clean up our tar @@ -250,7 +258,7 @@ def high(data, **kwargs): roster_grains) trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type']) cmd = 'state.pkg {0}/salt_state.tgz pkg_sum={1} hash_type={2}'.format( - __opts__['thin_dir'], + _thin_dir(), trans_tar_sum, __opts__['hash_type']) single = salt.client.ssh.Single( @@ -261,7 +269,7 @@ def high(data, **kwargs): **st_kwargs) single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) stdout, stderr, _ = single.cmd_block() # Clean up our tar @@ -353,7 +361,7 @@ def highstate(test=None, **kwargs): roster_grains) trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type']) cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format( - __opts__['thin_dir'], + _thin_dir(), test, trans_tar_sum, __opts__['hash_type']) @@ -365,7 +373,7 @@ def highstate(test=None, **kwargs): **st_kwargs) single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) stdout, stderr, _ = single.cmd_block() # Clean up our tar @@ -433,7 +441,7 @@ def top(topfn, test=None, **kwargs): roster_grains) trans_tar_sum = salt.utils.get_hash(trans_tar, __opts__['hash_type']) cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format( - __opts__['thin_dir'], + _thin_dir(), test, trans_tar_sum, __opts__['hash_type']) @@ -445,7 +453,7 @@ def top(topfn, test=None, **kwargs): **st_kwargs) single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) stdout, stderr, _ = single.cmd_block() # Clean up our tar @@ -697,7 +705,7 @@ def single(fun, name, test=None, **kwargs): # We use state.pkg to execute the "state package" cmd = 'state.pkg {0}/salt_state.tgz test={1} pkg_sum={2} hash_type={3}'.format( - __opts__['thin_dir'], + _thin_dir(), test, trans_tar_sum, __opts__['hash_type']) @@ -713,7 +721,7 @@ def single(fun, name, test=None, **kwargs): # Copy the tar down single.shell.send( trans_tar, - '{0}/salt_state.tgz'.format(__opts__['thin_dir'])) + '{0}/salt_state.tgz'.format(_thin_dir())) # Run the state.pkg command on the target stdout, stderr, _ = single.cmd_block() diff --git a/salt/loader.py b/salt/loader.py index a67af505d5..584fc296f0 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -1370,7 +1370,10 @@ class LazyLoader(salt.utils.lazy.LazyDict): (importlib.machinery.SourcelessFileLoader, importlib.machinery.BYTECODE_SUFFIXES), (importlib.machinery.ExtensionFileLoader, importlib.machinery.EXTENSION_SUFFIXES), ] - file_finder = importlib.machinery.FileFinder(fpath, *loader_details) + file_finder = importlib.machinery.FileFinder( + fpath_dirname, + *loader_details + ) spec = file_finder.find_spec(mod_namespace) if spec is None: raise ImportError() diff --git a/salt/modules/rh_ip.py b/salt/modules/rh_ip.py index 58759afc54..0d0a9659eb 100644 --- a/salt/modules/rh_ip.py +++ b/salt/modules/rh_ip.py @@ -856,7 +856,7 @@ def _parse_network_settings(opts, current): _raise_error_network('hostname', ['server1.example.com']) if 'nozeroconf' in opts: - nozeroconf = salt.utils.dequote(opts['nozerconf']) + nozeroconf = salt.utils.dequote(opts['nozeroconf']) if nozeroconf in valid: if nozeroconf in _CONFIG_TRUE: result['nozeroconf'] = true_val diff --git a/salt/modules/selinux.py b/salt/modules/selinux.py index df91a08e81..8a060e418e 100644 --- a/salt/modules/selinux.py +++ b/salt/modules/selinux.py @@ -300,7 +300,7 @@ def install_semod(module_path): salt '*' selinux.install_semod [salt://]path/to/module.pp - .. versionadded:: develop + .. versionadded:: 2016.11.6 ''' if module_path.find('salt://') == 0: module_path = __salt__['cp.cache_file'](module_path) @@ -318,7 +318,7 @@ def remove_semod(module): salt '*' selinux.remove_semod module_name - .. versionadded:: develop + .. versionadded:: 2016.11.6 ''' cmd = 'semodule -r {0}'.format(module) return not __salt__['cmd.retcode'](cmd) diff --git a/salt/modules/state.py b/salt/modules/state.py index 0f761b48ba..0051fe2d89 100644 --- a/salt/modules/state.py +++ b/salt/modules/state.py @@ -258,12 +258,22 @@ def _get_opts(**kwargs): Return a copy of the opts for use, optionally load a local config on top ''' opts = copy.deepcopy(__opts__) + if 'localconfig' in kwargs: - opts = salt.config.minion_config(kwargs['localconfig'], defaults=opts) - else: - if 'saltenv' in kwargs: + return salt.config.minion_config(kwargs['localconfig'], defaults=opts) + + if 'saltenv' in kwargs: + saltenv = kwargs['saltenv'] + if not isinstance(saltenv, six.string_types): + opts['environment'] = str(kwargs['saltenv']) + else: opts['environment'] = kwargs['saltenv'] - if 'pillarenv' in kwargs: + + if 'pillarenv' in kwargs: + pillarenv = kwargs['pillarenv'] + if not isinstance(pillarenv, six.string_types): + opts['pillarenv'] = str(kwargs['pillarenv']) + else: opts['pillarenv'] = kwargs['pillarenv'] return opts diff --git a/salt/states/selinux.py b/salt/states/selinux.py index 868dbc16e3..93e45bfa2a 100644 --- a/salt/states/selinux.py +++ b/salt/states/selinux.py @@ -262,7 +262,7 @@ def module_install(name): name Path to file with module to install - .. versionadded:: develop + .. versionadded:: 2016.11.6 ''' ret = {'name': name, 'result': True, @@ -283,7 +283,7 @@ def module_remove(name): name The name of the module to remove - .. versionadded:: develop + .. versionadded:: 2016.11.6 ''' ret = {'name': name, 'result': True, diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index aedd56ee30..48c1838d2e 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -3497,3 +3497,21 @@ def dequote(val): if is_quoted(val): return val[1:-1] return val + + +def mkstemp(*args, **kwargs): + ''' + Helper function which does exactly what `tempfile.mkstemp()` does but + accepts another argument, `close_fd`, which, by default, is true and closes + the fd before returning the file path. Something commonly done throughout + Salt's code. + ''' + if 'prefix' not in kwargs: + kwargs['prefix'] = '__salt.tmp.' + close_fd = kwargs.pop('close_fd', True) + fd_, fpath = tempfile.mkstemp(*args, **kwargs) + if close_fd is False: + return (fd_, fpath) + os.close(fd_) + del fd_ + return fpath diff --git a/salt/utils/files.py b/salt/utils/files.py index 6c4d843fc1..12dd6987c6 100644 --- a/salt/utils/files.py +++ b/salt/utils/files.py @@ -9,7 +9,6 @@ import logging import os import shutil import subprocess -import tempfile import time # Import salt libs @@ -22,9 +21,9 @@ from salt.ext import six log = logging.getLogger(__name__) -TEMPFILE_PREFIX = '__salt.tmp.' REMOTE_PROTOS = ('http', 'https', 'ftp', 'swift', 's3') VALID_PROTOS = ('salt', 'file') + REMOTE_PROTOS +TEMPFILE_PREFIX = '__salt.tmp.' def guess_archive_type(name): @@ -44,20 +43,10 @@ def guess_archive_type(name): def mkstemp(*args, **kwargs): ''' - Helper function which does exactly what `tempfile.mkstemp()` does but - accepts another argument, `close_fd`, which, by default, is true and closes - the fd before returning the file path. Something commonly done throughout - Salt's code. + Should eventually reside here, but for now point back at old location in + salt.utils ''' - if 'prefix' not in kwargs: - kwargs['prefix'] = TEMPFILE_PREFIX - close_fd = kwargs.pop('close_fd', True) - fd_, fpath = tempfile.mkstemp(*args, **kwargs) - if close_fd is False: - return (fd_, fpath) - os.close(fd_) - del fd_ - return fpath + return salt.utils.mkstemp(*args, **kwargs) def recursive_copy(source, dest): diff --git a/tests/integration/modules/test_grains.py b/tests/integration/modules/test_grains.py index 81858f3053..8908026e07 100644 --- a/tests/integration/modules/test_grains.py +++ b/tests/integration/modules/test_grains.py @@ -5,6 +5,7 @@ Test the grains module # Import python libs from __future__ import absolute_import +import logging import os import time @@ -13,6 +14,8 @@ from tests.support.case import ModuleCase from tests.support.unit import skipIf from tests.support.helpers import destructiveTest +log = logging.getLogger(__name__) + class TestModulesGrains(ModuleCase): ''' @@ -110,11 +113,12 @@ class TestModulesGrains(ModuleCase): ''' test to ensure some core grains are returned ''' - grains = ['os', 'os_family', 'osmajorrelease', 'osrelease', 'osfullname', 'id'] + grains = ('os', 'os_family', 'osmajorrelease', 'osrelease', 'osfullname', 'id') os = self.run_function('grains.get', ['os']) for grain in grains: get_grain = self.run_function('grains.get', [grain]) + log.debug('Value of \'%s\' grain: \'%s\'', grain, get_grain) if os == 'Arch' and grain in ['osmajorrelease']: self.assertEqual(get_grain, '') continue diff --git a/tests/unit/modules/test_ssh.py b/tests/unit/modules/test_ssh.py index b196dc366d..fd0d4d7176 100644 --- a/tests/unit/modules/test_ssh.py +++ b/tests/unit/modules/test_ssh.py @@ -91,8 +91,13 @@ class SSHAuthKeyTestCase(TestCase, LoaderModuleMockMixin): email = 'github.com' empty_line = '\n' comment_line = '# this is a comment \n' + # Write out the authorized key to a temporary file - temp_file = tempfile.NamedTemporaryFile(delete=False) + if salt.utils.is_windows(): + temp_file = tempfile.NamedTemporaryFile(delete=False) + else: + temp_file = tempfile.NamedTemporaryFile(delete=False, mode='w+') + # Add comment temp_file.write(comment_line) # Add empty line for #41335