How to use the salt.utils.platform.is_windows 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 / shell / test_call.py View on Github external
    @skipIf(salt.utils.platform.is_windows(), 'Skip on Windows')
    def test_syslog_file_not_found(self):
        '''
        test when log_file is set to a syslog file that does not exist
        '''
        old_cwd = os.getcwd()
        config_dir = os.path.join(TMP, 'log_file_incorrect')
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)

        os.chdir(config_dir)

        with salt.utils.files.fopen(self.get_config_file_path('minion'), 'r') as fh_:
            minion_config = salt.utils.yaml.load(fh_.read())
            minion_config['log_file'] = 'file:///dev/doesnotexist'
            with salt.utils.files.fopen(os.path.join(config_dir, 'minion'), 'w') as fh_:
                fh_.write(
github saltstack / salt / tests / integration / modules / test_pip.py View on Github external
    @skipIf(salt.utils.platform.is_windows(), 'test specific for linux usage of /bin/python')
    def test_system_pip3(self):
        self.run_function('pip.install', pkgs=['lazyimport==0.0.1'], bin_env='/bin/pip3')
        ret1 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport')
        self.run_function('pip.uninstall', pkgs=['lazyimport'], bin_env='/bin/pip3')
        ret2 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport')
        assert 'lazyimport==0.0.1' in ret1
        assert ret2 == ''
github saltstack / salt / tests / integration / states / test_pip_state.py View on Github external
def _create_virtualenv(self, path, **kwargs):
        '''
        The reason why the virtualenv creation is proxied by this function is mostly
        because under windows, we can't seem to properly create a virtualenv off of
        another virtualenv(we can on linux) and also because, we really don't want to
        test virtualenv creation off of another virtualenv, we want a virtualenv created
        from the original python.
        Also, one windows, we must also point to the virtualenv binary outside the existing
        virtualenv because it will fail otherwise
        '''
        self.addCleanup(shutil.rmtree, path, ignore_errors=True)
        try:
            if salt.utils.platform.is_windows():
                python = os.path.join(sys.real_prefix, os.path.basename(sys.executable))
            else:
                python_binary_names = [
                    'python{}.{}'.format(*sys.version_info),
                    'python{}'.format(*sys.version_info),
                    'python'
                ]
                for binary_name in python_binary_names:
                    python = os.path.join(sys.real_prefix, 'bin', binary_name)
                    if os.path.exists(python):
                        break
                else:
                    self.fail(
                        'Couldn\'t find a python binary name under \'{}\' matching: {}'.format(
                            os.path.join(sys.real_prefix, 'bin'),
                            python_binary_names
github saltstack / salt / tests / integration / modules / test_git.py View on Github external
Test git.add with a directory
        '''
        newdir = 'quux'
        # Change to the repo dir
        newdir_path = os.path.join(self.repo, newdir)
        _makedirs(newdir_path)
        files = [os.path.join(newdir_path, x) for x in self.files]
        files_relpath = [os.path.join(newdir, x) for x in self.files]
        for path in files:
            with salt.utils.files.fopen(path, 'wb') as fp_:
                fp_.write(
                    'This is a test file with relative path {0}.\n'.format(path).encode('utf-8')
                )
        ret = self.run_function('git.add', [self.repo, newdir])
        res = '\n'.join(sorted(['add \'{0}\''.format(x) for x in files_relpath]))
        if salt.utils.platform.is_windows():
            res = res.replace('\\', '/')
        self.assertEqual(ret, res)
github saltstack / salt / salt / modules / inspector.py View on Github external
def __virtual__():
    '''
    Only work on POSIX-like systems
    '''
    return not salt.utils.platform.is_windows() and 'inspector'
github saltstack / salt / salt / grains / core.py View on Github external
# Provides:
    #   virtual
    #   virtual_subtype

    grains = {'virtual': osdata.get('virtual', 'physical')}

    # Skip the below loop on platforms which have none of the desired cmds
    # This is a temporary measure until we can write proper virtual hardware
    # detection.
    skip_cmds = ('AIX',)

    # list of commands to be executed to determine the 'virtual' grain
    _cmds = ['systemd-detect-virt', 'virt-what', 'dmidecode']
    # test first for virt-what, which covers most of the desired functionality
    # on most platforms
    if not salt.utils.platform.is_windows() and osdata['kernel'] not in skip_cmds:
        if salt.utils.path.which('virt-what'):
            _cmds = ['virt-what']

    # Check if enable_lspci is True or False
    if __opts__.get('enable_lspci', True) is True:
        # /proc/bus/pci does not exists, lspci will fail
        if os.path.exists('/proc/bus/pci'):
            _cmds += ['lspci']

    # Add additional last resort commands
    if osdata['kernel'] in skip_cmds:
        _cmds = ()

    # Quick backout for BrandZ (Solaris LX Branded zones)
    # Don't waste time trying other commands to detect the virtual grain
    if HAS_UNAME and osdata['kernel'] == 'Linux' and 'BrandZ virtual linux' in os.uname():
github saltstack / salt / salt / utils / win_reg.py View on Github external
def __virtual__():
    '''
    Only works on Windows systems with the PyWin32
    '''
    if not salt.utils.platform.is_windows():
        return (False, 'reg execution module failed to load: '
                       'The module will only run on Windows systems')

    if not HAS_WINDOWS_MODULES:
        return (False, 'reg execution module failed to load: '
                       'One of the following libraries did not load: '
                       'win32gui, win32con, win32api')

    return __virtualname__
github saltstack / salt / salt / utils / http.py View on Github external
'/etc/ssl/certs/ca-certificates.crt',
        # RedHat is also very common
        '/etc/pki/tls/certs/ca-bundle.crt',
        '/etc/pki/tls/certs/ca-bundle.trust.crt',
        # RedHat's link for Debian compatibility
        '/etc/ssl/certs/ca-bundle.crt',
        # SUSE has an unusual path
        '/var/lib/ca-certificates/ca-bundle.pem',
        # OpenBSD has an unusual path
        '/etc/ssl/cert.pem',
    )
    for path in locations:
        if os.path.exists(path):
            return path

    if salt.utils.platform.is_windows() and HAS_CERTIFI:
        return certifi.where()

    return None
github hubblestack / hubble-salt / hubblestack_nova / firewall.py View on Github external
def __virtual__():
    if salt.utils.platform.is_windows():
        return False, 'This audit module only runs on linux'
    if not salt.utils.path.which('iptables'):
        return (False, 'The iptables execution module cannot be loaded: iptables not installed.')
    return True