def __virtual__(): ''' Set the virtual pkg module if the os is Windows ''' if is_windows(): return __virtualname__ return (False, "Module win_pkg: module only works on Windows systems")
def __virtual__(): ''' Only works on Windows systems ''' if platform.is_windows(): return __virtualname__ return False
def __virtual__(): ''' Load only on Windows ''' if platform.is_windows(): return __virtualname__ return (False, 'Module win_iis: module only works on Windows systems')
def __virtual__(): """Load only on Windows and only if Apply_LGPO_Delta is present.""" if not is_windows(): return False if not HAS_LGPO: return (False, 'Module "{0}" not loaded because "{1}" could not be ' 'found'.format(__virtualname__, LGPO_EXE)) return __virtualname__
def get_name(**kwargs): if _platform.is_windows(): return 'windows' elif _platform.is_darwin(): return 'osx' elif _platform.is_linux(): return 'linux' return ''
def setup_multiprocessing_logging(queue=None): """ This code should be called from within a running multiprocessing process instance. """ from salt.utils.platform import is_windows global __MP_LOGGING_CONFIGURED global __MP_LOGGING_QUEUE_HANDLER if __MP_IN_MAINPROCESS is True and not is_windows(): # We're in the MainProcess, return! No multiprocessing logging setup shall happen # Windows is the exception where we want to set up multiprocessing # logging in the MainProcess. return try: logging._acquireLock() # pylint: disable=protected-access if __MP_LOGGING_CONFIGURED is True: return # Let's set it to true as fast as possible __MP_LOGGING_CONFIGURED = True if __MP_LOGGING_QUEUE_HANDLER is not None: return # The temp null and temp queue logging handlers will store messages. # Since noone will process them, memory usage will grow. If they # exist, remove them. __remove_null_logging_handler() __remove_queue_logging_handler() # Let's add a queue handler to the logging root handlers __MP_LOGGING_QUEUE_HANDLER = SaltLogQueueHandler( queue or get_multiprocessing_logging_queue() ) logging.root.addHandler(__MP_LOGGING_QUEUE_HANDLER) # Set the logging root level to the lowest needed level to get all # desired messages. log_level = get_multiprocessing_logging_level() logging.root.setLevel(log_level) logging.getLogger(__name__).debug( "Multiprocessing queue logging configured for the process running " "under PID: %s at log level %s", os.getpid(), log_level, ) # The above logging call will create, in some situations, a futex wait # lock condition, probably due to the multiprocessing Queue's internal # lock and semaphore mechanisms. # A small sleep will allow us not to hit that futex wait lock condition. time.sleep(0.0001) finally: logging._releaseLock() # pylint: disable=protected-access
def _wait_caller(self, opts): ''' Returns when RAET Minion Yard is available ''' yardname = 'manor' dirpath = opts['sock_dir'] role = opts.get('id') if not role: emsg = ("Missing role required to setup RAET SaltCaller.") log.error(emsg + "\n") raise ValueError(emsg) kind = opts.get('__role') # application kind 'master', 'minion', etc if kind not in kinds.APPL_KINDS: emsg = ("Invalid application kind = '{0}' for RAET SaltCaller.".format(kind)) log.error(emsg + "\n") raise ValueError(emsg) if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.minion], kinds.APPL_KIND_NAMES[kinds.applKinds.caller], ]: lanename = "{0}_{1}".format(role, kind) else: emsg = ("Unsupported application kind '{0}' for RAET SaltCaller.".format(kind)) log.error(emsg + '\n') raise ValueError(emsg) ha, dirpath = Yard.computeHa(dirpath, lanename, yardname) if is_windows(): # RAET lanes do not use files on Windows. Need to use win32file # API to check for existence. exists = False while not exists: try: f = win32file.CreateFile( ha, win32file.GENERIC_WRITE | win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, 0, None) win32file.CloseHandle(f) exists = True except win32file.error: time.sleep(0.1) else: while not ((os.path.exists(ha) and not os.path.isfile(ha) and not os.path.isdir(ha))): time.sleep(0.1) time.sleep(0.5)
def __process_multiprocessing_logging_queue(opts, queue): # Avoid circular import import salt.utils.process salt.utils.process.appendproctitle("MultiprocessingLoggingQueue") # Assign UID/GID of user to proc if set from salt.utils.verify import check_user user = opts.get("user") if user: check_user(user) from salt.utils.platform import is_windows if is_windows(): # On Windows, creating a new process doesn't fork (copy the parent # process image). Due to this, we need to setup all of our logging # inside this process. setup_temp_logger() setup_console_logger( log_level=opts.get("log_level"), log_format=opts.get("log_fmt_console"), date_format=opts.get("log_datefmt_console"), ) setup_logfile_logger( opts.get("log_file"), log_level=opts.get("log_level_logfile"), log_format=opts.get("log_fmt_logfile"), date_format=opts.get("log_datefmt_logfile"), max_bytes=opts.get("log_rotate_max_bytes", 0), backup_count=opts.get("log_rotate_backup_count", 0), ) setup_extended_logging(opts) while True: try: record = queue.get() if record is None: # A sentinel to stop processing the queue break # Just log everything, filtering will happen on the main process # logging handlers logger = logging.getLogger(record.name) logger.handle(record) except (EOFError, KeyboardInterrupt, SystemExit): break except Exception as exc: # pylint: disable=broad-except logging.getLogger(__name__).warning( "An exception occurred in the multiprocessing logging " "queue thread: %r", exc, exc_info_on_loglevel=logging.DEBUG, )
def __virtual__(): """Load only on Windows and only if Apply_LGPO_Delta is present.""" if not is_windows(): return False if not HAS_WINDOWS_MODULES: return (False, '{0}: Required modules failed to load'.format(__virtualname__)) global _write_regpol_data _write_regpol_data = _namespaced_function(_write_regpol_data, globals()) return __virtualname__
def action(self): ''' Pull the queue for functions to execute ''' while self.fun.value: msg = self.fun.value.popleft() data = msg.get('pub') match = getattr( self.matcher.value, '{0}_match'.format( data.get('tgt_type', 'glob') ) )(data['tgt']) if not match: continue if 'user' in data: log.info( 'User {0[user]} Executing command {0[fun]} with jid ' '{0[jid]}'.format(data)) else: log.info( 'Executing command {0[fun]} with jid {0[jid]}'.format(data) ) log.debug('Command details {0}'.format(data)) if is_windows(): # SaltRaetNixJobber is not picklable. Pickling is necessary # when spawning a process in Windows. Since the process will # be spawned and joined on non-Windows platforms, instead of # this, just run the function directly and absorb any thrown # exceptions. try: self.proc_run(msg) except Exception as exc: log.error( 'Exception caught by jobber: {0}'.format(exc), exc_info=True) else: process = multiprocessing.Process( target=self.proc_run, kwargs={'msg': msg} ) process.start() process.join()
import salt.utils.files import salt.utils.jid import salt.utils.kinds as kinds import salt.utils.minion import salt.defaults.exitcodes from salt.cli import daemons from salt.log import LOG_LEVELS from salt.utils.platform import is_windows from salt.utils.process import MultiprocessingProcess try: from raet import raeting, nacling from raet.lane.stacking import LaneStack from raet.lane.yarding import RemoteYard, Yard if is_windows(): import win32file except ImportError: # Don't die on missing transport libs since only one transport is required pass # Import 3rd-party libs from salt.ext import six # Custom exceptions from salt.exceptions import ( SaltClientError, CommandNotFoundError, CommandExecutionError, SaltInvocationError,
""" Test win_chcp """ from salt.exceptions import CodePageError from salt.utils import platform, win_chcp from tests.support.unit import TestCase, skipIf @skipIf(not platform.is_windows(), "Windows only tests!") class CHCPTest(TestCase): """ Test case for salt.utils.win_chcp """ @classmethod def setUpClass(cls): # Stores the initial code page for _reset_code_page() # Intentionally does not catch any exception, to find out which that would be. # That exception would then be added to cmdmod.py cls._chcp_code = win_chcp.get_codepage_id() @classmethod def tearDownClass(cls): cls._chcp_code = None def setUp(self): win_chcp.set_codepage_id(self._chcp_code) def tearDown(self): win_chcp.set_codepage_id(self._chcp_code)