How to use the salt.utils.path.which function in salt

To help you get started, we’ve selected a few salt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saltstack / salt / tests / integration / states / test_npm.py View on Github external
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest, requires_network
from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.runtests import RUNTIME_VARS

# Import salt libs
import salt.utils.path
import salt.utils.platform
from salt.utils.versions import LooseVersion

MAX_NPM_VERSION = '5.0.0'


@skipIf(salt.utils.path.which('npm') is None, 'npm not installed')
class NpmStateTest(ModuleCase, SaltReturnAssertsMixin):

    @requires_network()
    @destructiveTest
    def test_npm_installed_removed(self):
        '''
        Basic test to determine if NPM module was successfully installed and
        removed.
        '''
        ret = self.run_state('npm.installed', name='pm2@2.10.4', registry="http://registry.npmjs.org/")
        self.assertSaltTrueReturn(ret)
        ret = self.run_state('npm.removed', name='pm2')
        self.assertSaltTrueReturn(ret)

    @skipIf(salt.utils.platform.is_darwin(), 'TODO this test hangs on mac.')
    @requires_network()
github saltstack / salt / tests / unit / ssh / test_ssh.py View on Github external
from __future__ import absolute_import, unicode_literals
import os

# Import Salt Testing libs
from tests.support.unit import skipIf
from tests.support.case import ShellCase
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock

# Import Salt libs
import salt.config
import salt.utils.path
from salt.client import ssh


@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(not salt.utils.path.which('ssh'), "No ssh binary found in path")
class SSHPasswordTests(ShellCase):
    def test_password_failure(self):
        '''
        Check password failures when trying to deploy keys
        '''
        opts = salt.config.client_config(self.get_config_file_path('master'))
        opts['list_hosts'] = False
        opts['argv'] = ['test.ping']
        opts['selected_target_option'] = 'glob'
        opts['tgt'] = 'localhost'
        opts['arg'] = []
        roster = os.path.join(self.config_dir, 'roster')
        handle_ssh_ret = [
            {'localhost': {'retcode': 255, 'stderr': u'Permission denied (publickey).\r\n', 'stdout': ''}},
        ]
        expected = {'localhost': 'Permission denied (publickey)'}
github hubblestack / hubble-salt / hubblestack_nova / cve_scan.py View on Github external
def __virtual__():
    if salt.utils.platform.is_linux() and salt.utils.path.which('oscap'):
        return True
    return False, 'This module requires Linux and the oscap binary'
github saltstack / salt / salt / utils / zfs.py View on Github external
def has_feature_flags():
    '''
    Check if zpool-features is available
    '''
    # get man location
    man = salt.utils.path.which('man')
    return _check_retcode('{man} zpool-features'.format(
        man=man
    )) if man else False
github saltstack / salt / salt / modules / cpan.py View on Github external
def __virtual__():
    '''
    Only work on supported POSIX-like systems
    '''
    if salt.utils.path.which('cpan'):
        return True
    return (False, 'Unable to locate cpan. Make sure it is installed and in the PATH.')
github saltstack / salt / salt / modules / xbpspkg.py View on Github external
def _check_xbps():
    '''
    Looks to see if xbps-install is present on the system, return full path
    '''
    return salt.utils.path.which('xbps-install')
github saltstack / salt / salt / modules / vboxmanage.py View on Github external
def vboxcmd():
    '''
    Return the location of the VBoxManage command

    CLI Example:

    .. code-block:: bash

        salt '*' vboxmanage.vboxcmd
    '''
    return salt.utils.path.which('VBoxManage')
github saltstack / salt / salt / utils / files.py View on Github external
except OSError:
            pass

    # The move could fail if the dest has xattr protections, so delete the
    # temp file in this case
    try:
        shutil.move(tgt, dest)
    except Exception:
        __clean_tmp(tgt)
        raise

    if fstat is not None:
        os.chown(dest, fstat.st_uid, fstat.st_gid)
        os.chmod(dest, fstat.st_mode)
    # If SELINUX is available run a restorecon on the file
    rcon = salt.utils.path.which('restorecon')
    if rcon:
        policy = False
        try:
            policy = salt.modules.selinux.getenforce()
        except (ImportError, CommandExecutionError):
            pass
        if policy == 'Enforcing':
            with fopen(os.devnull, 'w') as dev_null:
                cmd = [rcon, dest]
                subprocess.call(cmd, stdout=dev_null, stderr=dev_null)
    if os.path.isfile(tgt):
        # The temp file failed to move
        __clean_tmp(tgt)
github saltstack / salt / salt / modules / flatpak.py View on Github external
def __virtual__():
    if salt.utils.path.which('flatpak'):
        return __virtualname__

    return False, 'The flatpak execution module cannot be loaded: the "flatpak" binary is not in the path.'