def start(self): ''' Execute this method to start up a syndic. ''' verify_env([ self.opts['pki_dir'], self.opts['cachedir'], os.path.dirname(self.opts['log_file']), ]) import salt.log salt.log.setup_logfile_logger(self.opts['log_file'], self.opts['log_level']) for name, level in self.opts['log_granular_levels'].iteritems(): salt.log.set_logger_level(name, level) import logging # Late import so logging works correctly import salt.minion log = logging.getLogger(__name__) if self.cli['daemon']: # Late import so logging works correctly import salt.utils salt.utils.daemonize() set_pidfile(self.cli['pidfile']) if check_user(self.opts['user'], log): try: syndic = salt.minion.Syndic(self.opts) syndic.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Syndic Minion') raise SystemExit('\nExiting on Ctrl-c')
def start(self): ''' Run the sequence to start a salt master server ''' verify_env([ os.path.join(self.opts['pki_dir'], 'minions'), os.path.join(self.opts['pki_dir'], 'minions_pre'), os.path.join(self.opts['pki_dir'], 'minions_rejected'), os.path.join(self.opts['cachedir'], 'jobs'), os.path.dirname(self.opts['log_file']), self.opts['sock_dir'], ]) import salt.log salt.log.setup_logfile_logger(self.opts['log_file'], self.opts['log_level']) for name, level in self.opts['log_granular_levels'].iteritems(): salt.log.set_logger_level(name, level) import logging log = logging.getLogger(__name__) # Late import so logging works correctly import salt.master master = salt.master.Master(self.opts) if self.cli['daemon']: # Late import so logging works correctly import salt.utils salt.utils.daemonize() set_pidfile(self.opts['pidfile']) if check_user(self.opts['user'], log): try: master.start() except salt.master.MasterExit: sys.exit()
def start(self): ''' Execute this method to start up a minion. ''' verify_env([ self.opts['pki_dir'], self.opts['cachedir'], self.opts['extension_modules'], os.path.dirname(self.opts['log_file']), ]) import salt.log salt.log.setup_logfile_logger(self.opts['log_file'], self.opts['log_level']) for name, level in self.opts['log_granular_levels'].iteritems(): salt.log.set_logger_level(name, level) import logging # Late import so logging works correctly import salt.minion log = logging.getLogger(__name__) if self.cli['daemon']: # Late import so logging works correctly import salt.utils # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion cound halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize salt.utils.daemonize() minion = salt.minion.Minion(self.opts) set_pidfile(self.cli['pidfile']) if check_user(self.opts['user'], log): try: minion.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Minion') raise SystemExit('\nExiting on Ctrl-c')
def run(self): """ Execute the salt call! """ self.parse_args() if self.config["verify_env"]: verify_env( [self.config["pki_dir"], self.config["cachedir"], os.path.dirname(self.config["log_file"])], self.config["user"], permissive=self.config["permissive_pki_access"], pki_dir=self.config["pki_dir"], ) if self.options.local: self.config["file_client"] = "local" # Setup file logging! self.setup_logfile_logger() caller = salt.cli.caller.Caller(self.config) if self.options.doc: caller.print_docs() self.exit(0) if self.options.grains_run: caller.print_grains() self.exit(0) caller.run()
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' super(Syndic, self).prepare() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], root_dir=self.config['root_dir'], pki_dir=self.config['pki_dir'], ) except OSError as error: self.environment_failure(error) self.setup_logfile_logger() verify_log(self.config) self.action_log_info('Setting up "{0}"'.format(self.config['id'])) # Late import so logging works correctly import salt.minion self.daemonize_if_required() self.syndic = salt.minion.SyndicManager(self.config) self.set_pidfile()
def get_temp_config(config_for, **config_overrides): rootdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) #self.addCleanup(shutil.rmtree, rootdir) for key in ('cachedir', 'pki_dir', 'sock_dir'): if key not in config_overrides: config_overrides[key] = key if 'log_file' not in config_overrides: config_overrides['log_file'] = 'logs/{}.log'.format(config_for) if 'user' not in config_overrides: config_overrides['user'] = RUNTIME_VARS.RUNNING_TESTS_USER config_overrides['root_dir'] = rootdir cdict = AdaptedConfigurationTestCaseMixin.get_config(config_for, from_scratch=True) if config_for in ('master', 'client_config'): rdict = salt.config.apply_master_config(config_overrides, cdict) if config_for == 'minion': rdict = salt.config.apply_minion_config(config_overrides, cdict) verify_env([os.path.join(rdict['pki_dir'], 'minions'), os.path.join(rdict['pki_dir'], 'minions_pre'), os.path.join(rdict['pki_dir'], 'minions_rejected'), os.path.join(rdict['pki_dir'], 'minions_denied'), os.path.join(rdict['cachedir'], 'jobs'), os.path.join(rdict['cachedir'], 'raet'), os.path.join(rdict['cachedir'], 'tokens'), os.path.join(rdict['root_dir'], 'cache', 'tokens'), os.path.join(rdict['pki_dir'], 'accepted'), os.path.join(rdict['pki_dir'], 'rejected'), os.path.join(rdict['pki_dir'], 'pending'), os.path.dirname(rdict['log_file']), rdict['sock_dir'], ], RUNTIME_VARS.RUNNING_TESTS_USER) return rdict
def prepare(self): ''' Run the preparation sequence required to start a salt master server. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' super(Master, self).prepare() try: if self.config['verify_env']: v_dirs = [ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_denied'), os.path.join(self.config['pki_dir'], 'minions_autosign'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), self.config['sock_dir'], self.config['token_dir'], self.config['syndic_dir'], self.config['sqlite_queue_dir'], ] verify_env( v_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], root_dir=self.config['root_dir'], pki_dir=self.config['pki_dir'], ) # Clear out syndics from cachedir for syndic_file in os.listdir(self.config['syndic_dir']): os.remove( os.path.join(self.config['syndic_dir'], syndic_file)) except OSError as error: self.environment_failure(error) self.setup_logfile_logger() verify_log(self.config) self.action_log_info('Setting up') # TODO: AIO core is separate from transport if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.shutdown(4, 'The ports are not available to bind') self.config['interface'] = ip_bracket(self.config['interface']) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.master self.master = salt.master.Master(self.config) self.daemonize_if_required() self.set_pidfile() salt.utils.process.notify_systemd()
def run(self): ''' Execute salt-key ''' self.parse_args() if self.config['verify_env']: verify_env_dirs = [] if not self.config['gen_keys']: verify_env_dirs.extend([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), ]) verify_env( verify_env_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if (not self.config['key_logfile'].startswith('tcp://') or not self.config['key_logfile'].startswith('udp://') or not self.config['key_logfile'].startswith('file://')): # Logfile is not using Syslog, verify verify_files( [self.config['key_logfile']], self.config['user'] ) self.setup_logfile_logger() key = salt.key.KeyCLI(self.config) key.run()
def __enter__(self): ''' Start a master and minion ''' self.master_opts = salt.config.master_config( os.path.join(INTEGRATION_TEST_DIR, 'files/conf/master')) self.minion_opts = salt.config.minion_config( os.path.join(INTEGRATION_TEST_DIR, 'files/conf/minion')) self.master_opts['file_roots'] = FILES self.master_opts['hosts.file'] = os.path.join(TMP, 'hosts') self.minion_opts['file_roots'] = FILES self.minion_opts['hosts.file'] = os.path.join(TMP, 'hosts') verify_env([os.path.join(self.master_opts['pki_dir'], 'minions'), os.path.join(self.master_opts['pki_dir'], 'minions_pre'), os.path.join(self.master_opts['pki_dir'], 'minions_rejected'), os.path.join(self.master_opts['cachedir'], 'jobs'), os.path.dirname(self.master_opts['log_file']), self.minion_opts['extension_modules'], self.master_opts['sock_dir'], ]) master = salt.master.Master(self.master_opts) self.master_process = multiprocessing.Process(target=master.start) self.master_process.start() minion = salt.minion.Minion(self.minion_opts) self.minion_process = multiprocessing.Process(target=minion.tune_in) self.minion_process.start() return self
def run(self): ''' Execute salt-key ''' self.parse_args() if self.config['verify_env']: verify_env_dirs = [] if not self.config['gen_keys']: verify_env_dirs.extend([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), ]) verify_env( verify_env_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith( ('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([self.config['key_logfile']], self.config['user']) self.setup_logfile_logger() key = salt.key.KeyCLI(self.config) if check_user(self.config['user']): key.run()
def run(self): ''' Execute the salt call! ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], os.path.dirname(self.config['log_file']) ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) caller = salt.cli.caller.Caller(self.config) if self.options.doc: caller.print_docs() self.exit(0) if self.options.grains_run: caller.print_grains() self.exit(0) caller.run()
def run(self): ''' Execute salt-key ''' self.parse_args() if self.config['verify_env']: verify_env_dirs = [] if not self.config['gen_keys']: verify_env_dirs.extend([ os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), os.path.dirname(self.config['key_logfile']) ]) verify_env( verify_env_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) self.setup_logfile_logger() key = salt.cli.key.Key(self.config) key.run()
def run(self): """ Execute salt-key """ self.parse_args() if self.config["verify_env"]: verify_env_dirs = [] if not self.config["gen_keys"]: verify_env_dirs.extend( [ self.config["pki_dir"], os.path.join(self.config["pki_dir"], "minions"), os.path.join(self.config["pki_dir"], "minions_pre"), os.path.join(self.config["pki_dir"], "minions_rejected"), os.path.dirname(self.config["key_logfile"]), ] ) verify_env( verify_env_dirs, self.config["user"], permissive=self.config["permissive_pki_access"], pki_dir=self.config["pki_dir"], ) self.setup_logfile_logger() key = salt.key.KeyCLI(self.config) key.run()
def start(self): ''' Execute this method to start up a minion. ''' verify_env([self.opts['pki_dir'], self.opts['cachedir'], self.opts['extension_modules'], os.path.dirname(self.opts['log_file']), ]) import salt.log salt.log.setup_logfile_logger( self.opts['log_file'], self.opts['log_level'] ) for name, level in self.opts['log_granular_levels'].iteritems(): salt.log.set_logger_level(name, level) import logging # Late import so logging works correctly import salt.minion log = logging.getLogger(__name__) if self.cli['daemon']: # Late import so logging works correctly import salt.utils # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion cound halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize salt.utils.daemonize() minion = salt.minion.Minion(self.opts) set_pidfile(self.cli['pidfile']) if check_user(self.opts['user'], log): try: minion.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Minion') raise SystemExit('\nExiting on Ctrl-c')
def start(self): ''' Execute this method to start up a syndic. ''' verify_env([self.opts['pki_dir'], self.opts['cachedir'], os.path.dirname(self.opts['log_file']), ], self.opts['user']) import salt.log salt.log.setup_logfile_logger( self.opts['log_file'], self.opts['log_level'] ) for name, level in self.opts['log_granular_levels'].items(): salt.log.set_logger_level(name, level) import logging # Late import so logging works correctly import salt.minion log = logging.getLogger(__name__) if self.cli['daemon']: # Late import so logging works correctly import salt.utils salt.utils.daemonize() set_pidfile(self.cli['pidfile']) if check_user(self.opts['user'], log): try: syndic = salt.minion.Syndic(self.opts) syndic.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Syndic Minion') raise SystemExit('\nExiting on Ctrl-c')
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' super(Syndic, self).prepare() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError as error: self.environment_failure(error) self.setup_logfile_logger() verify_log(self.config) self.action_log_info('Setting up "{0}"'.format(self.config['id'])) # Late import so logging works correctly import salt.minion self.daemonize_if_required() self.syndic = salt.minion.SyndicManager(self.config) self.set_pidfile()
def prepare(self): """ Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() """ super().prepare() try: if self.config["verify_env"]: verify_env( [ self.config["pki_dir"], self.config["cachedir"], self.config["sock_dir"], self.config["extension_modules"], ], self.config["user"], permissive=self.config["permissive_pki_access"], root_dir=self.config["root_dir"], pki_dir=self.config["pki_dir"], ) except OSError as error: self.environment_failure(error) self.action_log_info('Setting up "{}"'.format(self.config["id"])) # Late import so logging works correctly import salt.minion self.daemonize_if_required() self.syndic = salt.minion.SyndicManager(self.config) self.set_pidfile()
def start(self): ''' Run the sequence to start a salt master server ''' self.parse_args() try: if self.config['verify_env']: verify_env([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.dirname(self.config['log_file']), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError, err: sys.exit(err.errno)
def start(self): ''' Run the sequence to start a salt master server ''' verify_env([self.opts['pki_dir'], os.path.join(self.opts['pki_dir'], 'minions'), os.path.join(self.opts['pki_dir'], 'minions_pre'), os.path.join(self.opts['pki_dir'], 'minions_rejected'), self.opts['cachedir'], os.path.join(self.opts['cachedir'], 'jobs'), os.path.dirname(self.opts['log_file']), self.opts['sock_dir'], ], self.opts['user']) import salt.log salt.log.setup_logfile_logger( self.opts['log_file'], self.opts['log_level'] ) for name, level in self.opts['log_granular_levels'].items(): salt.log.set_logger_level(name, level) import logging log = logging.getLogger(__name__) # Late import so logging works correctly import salt.master master = salt.master.Master(self.opts) if self.cli['daemon']: # Late import so logging works correctly import salt.utils salt.utils.daemonize() set_pidfile(self.opts['pidfile']) if check_user(self.opts['user'], log): try: master.start() except salt.master.MasterExit: sys.exit()
def run(self): """ Execute salt-run """ self.parse_args() if self.config["verify_env"]: verify_env( [self.config["pki_dir"], self.config["cachedir"]], self.config["user"], permissive=self.config["permissive_pki_access"], pki_dir=self.config["pki_dir"], ) if not self.config["log_file"].startswith(("tcp://", "udp://", "file://")): # Logfile is not using Syslog, verify verify_files([self.config["log_file"]], self.config["user"]) # Setup file logging! self.setup_logfile_logger() runner = salt.runner.Runner(self.config) if self.options.doc: runner._print_docs() self.exit(salt.exitcodes.EX_OK) # Run this here so SystemExit isn't raised anywhere else when # someone tries to use the runners via the python API try: if check_user(self.config["user"]): runner.run() except SaltClientError as exc: raise SystemExit(str(exc))
def get_temp_config(config_for, **config_overrides): rootdir = config_overrides.get( "root_dir", tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) ) if not os.path.exists(rootdir): os.makedirs(rootdir) conf_dir = config_overrides.pop("conf_dir", os.path.join(rootdir, "conf")) for key in ("cachedir", "pki_dir", "sock_dir"): if key not in config_overrides: config_overrides[key] = key if "log_file" not in config_overrides: config_overrides["log_file"] = "logs/{}.log".format(config_for) if "user" not in config_overrides: config_overrides["user"] = RUNTIME_VARS.RUNNING_TESTS_USER config_overrides["root_dir"] = rootdir cdict = AdaptedConfigurationTestCaseMixin.get_config( config_for, from_scratch=True ) if config_for in ("master", "client_config"): rdict = salt.config.apply_master_config(config_overrides, cdict) if config_for == "minion": minion_id = ( config_overrides.get("id") or config_overrides.get("minion_id") or cdict.get("id") or cdict.get("minion_id") or random_string("temp-minion-") ) config_overrides["minion_id"] = config_overrides["id"] = minion_id rdict = salt.config.apply_minion_config( config_overrides, cdict, cache_minion_id=False, minion_id=minion_id ) verify_env( [ os.path.join(rdict["pki_dir"], "minions"), os.path.join(rdict["pki_dir"], "minions_pre"), os.path.join(rdict["pki_dir"], "minions_rejected"), os.path.join(rdict["pki_dir"], "minions_denied"), os.path.join(rdict["cachedir"], "jobs"), os.path.join(rdict["cachedir"], "tokens"), os.path.join(rdict["root_dir"], "cache", "tokens"), os.path.join(rdict["pki_dir"], "accepted"), os.path.join(rdict["pki_dir"], "rejected"), os.path.join(rdict["pki_dir"], "pending"), os.path.dirname(rdict["log_file"]), rdict["sock_dir"], conf_dir, ], RUNTIME_VARS.RUNNING_TESTS_USER, root_dir=rdict["root_dir"], ) rdict["conf_file"] = os.path.join(conf_dir, config_for) with salt.utils.files.fopen(rdict["conf_file"], "w") as wfh: salt.utils.yaml.safe_dump(rdict, wfh, default_flow_style=False) return rdict
def prepare(self): ''' Run the preparation sequence required to start a salt master server. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_denied'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith( ('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.info('Setting up the Salt Master') if self.config['transport'].lower() == 'zeromq': if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.exit(4, 'The ports are not available to bind\n') self.config['interface'] = ip_bracket(self.config['interface']) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.master self.master = salt.master.Master(self.config) else: # Add a udp port check here import salt.daemons self.master = salt.daemons.IoFloMaster(self.config) self.daemonize_if_required() self.set_pidfile()
def prepare(self): ''' Run the preparation sequence required to start a salt minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: confd = os.path.join( os.path.dirname(self.config['conf_file']), 'minion.d' ) verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], confd, ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if (not self.config['log_file'].startswith('tcp://') or not self.config['log_file'].startswith('udp://') or not self.config['log_file'].startswith('file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) verify_files( [self.config['log_file']], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.warn( 'Setting up the Salt Minion "{0}"'.format( self.config['id'] ) ) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.minion # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion could halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize self.daemonize_if_required() self.minion = salt.minion.Minion(self.config) self.set_pidfile()
def test_verify_env(self): root_dir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR) var_dir = os.path.join(root_dir, 'var', 'log', 'salt') verify_env([var_dir], getpass.getuser()) self.assertTrue(os.path.exists(var_dir)) dir_stat = os.stat(var_dir) self.assertEqual(dir_stat.st_uid, os.getuid()) self.assertEqual(dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(dir_stat.st_mode & stat.S_IRWXG, 40) self.assertEqual(dir_stat.st_mode & stat.S_IRWXO, 5)
def test_verify_env(self): root_dir = tempfile.mkdtemp(dir=integration.SYS_TMP_DIR) var_dir = os.path.join(root_dir, "var", "log", "salt") verify_env([var_dir], getpass.getuser()) self.assertTrue(os.path.exists(var_dir)) dir_stat = os.stat(var_dir) self.assertEqual(dir_stat.st_uid, os.getuid()) self.assertEqual(dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(dir_stat.st_mode & stat.S_IRWXG, 40) self.assertEqual(dir_stat.st_mode & stat.S_IRWXO, 5)
def start(self): ''' Execute this method to start up a syndic. ''' try: verify_env([ self.opts['pki_dir'], self.opts['cachedir'], os.path.dirname(self.opts['log_file']), ], self.opts['user']) except OSError, err: sys.exit(err.errno)
def test_verify_env(self): root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) var_dir = os.path.join(root_dir, 'var', 'log', 'salt') key_dir = os.path.join(root_dir, 'key_dir') verify_env([var_dir], getpass.getuser(), root_dir=root_dir) self.assertTrue(os.path.exists(var_dir)) dir_stat = os.stat(var_dir) self.assertEqual(dir_stat.st_uid, os.getuid()) self.assertEqual(dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(dir_stat.st_mode & stat.S_IRWXG, 40) self.assertEqual(dir_stat.st_mode & stat.S_IRWXO, 5)
def run(self): ''' Execute the salt call! ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) if self.options.file_root: # check if the argument is pointing to a file on disk file_root = os.path.abspath(self.options.file_root) self.config['file_roots'] = {'base': [file_root]} if self.options.pillar_root: # check if the argument is pointing to a file on disk pillar_root = os.path.abspath(self.options.pillar_root) self.config['pillar_roots'] = {'base': [pillar_root]} if self.options.local: self.config['file_client'] = 'local' if self.options.master: self.config['master'] = self.options.master # Setup file logging! self.setup_logfile_logger() #caller = salt.cli.caller.Caller(self.config) caller = salt.cli.caller.Caller.factory(self.config) if self.options.doc: caller.print_docs() self.exit(salt.exitcodes.EX_OK) if self.options.grains_run: caller.print_grains() self.exit(salt.exitcodes.EX_OK) caller.run()
def test_verify_env(self): root_dir = tempfile.mkdtemp() var_dir = os.path.join(root_dir, 'var', 'log', 'salt') verify_env([var_dir], getpass.getuser()) self.assertTrue(os.path.exists(var_dir)) dir_stat = os.stat(var_dir) self.assertEqual(dir_stat.st_uid, os.getuid()) self.assertEqual(dir_stat.st_gid, os.getgid()) self.assertEqual(dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(dir_stat.st_mode & stat.S_IRWXG, 40) self.assertEqual(dir_stat.st_mode & stat.S_IRWXO, 5)
def run(self): ''' Execute the salt call! ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) if self.options.file_root: # check if the argument is pointing to a file on disk file_root = os.path.abspath(self.options.file_root) self.config['file_roots'] = {'base': [file_root]} if self.options.pillar_root: # check if the argument is pointing to a file on disk pillar_root = os.path.abspath(self.options.pillar_root) self.config['pillar_roots'] = {'base': [pillar_root]} if self.options.local: self.config['file_client'] = 'local' if self.options.master: self.config['master'] = self.options.master # Setup file logging! self.setup_logfile_logger() caller = salt.cli.caller.Caller(self.config) if self.options.doc: caller.print_docs() self.exit(0) if self.options.grains_run: caller.print_grains() self.exit(0) caller.run()
def prepare(self): ''' Run the preparation sequence required to start a salt master server. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.info('Setting up the Salt Master') if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.exit(4, 'The ports are not available to bind\n') self.config['interface'] = ip_bracket(self.config['interface']) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.master self.master = salt.master.Master(self.config) self.daemonize_if_required() self.set_pidfile()
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' super(Syndic, self).prepare() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify current_umask = os.umask(0o027) verify_files([logfile], self.config['user']) os.umask(current_umask) except OSError as err: log.exception('Failed to prepare salt environment') self.shutdown(err.errno) self.setup_logfile_logger() verify_log(self.config) log.info( 'Setting up the Salt Syndic Minion "{0}"'.format( self.config['id'] ) ) # Late import so logging works correctly import salt.minion self.daemonize_if_required() # if its a multisyndic, do so if isinstance(self.config.get('master'), list): self.syndic = salt.minion.MultiSyndic(self.config) else: self.syndic = salt.minion.Syndic(self.config) self.set_pidfile()
def start(self): ''' Execute this method to start up a syndic. ''' try: verify_env([ self.opts['pki_dir'], self.opts['cachedir'], os.path.dirname(self.opts['log_file']), ], self.opts['user'], permissive=self.opts['permissive_pki_access']) except OSError, err: sys.exit(err.errno)
def start(self): ''' Execute this method to start up a minion. ''' try: verify_env([ self.opts['pki_dir'], self.opts['cachedir'], self.opts['sock_dir'], self.opts['extension_modules'], os.path.dirname(self.opts['log_file']), ], self.opts['user']) except OSError, err: sys.exit(err.errno)
def run(self): """ Run the api """ ui = salt.spm.SPMCmdlineInterface() self.parse_args() self.setup_logfile_logger() v_dirs = [ self.config["spm_cache_dir"], ] verify_env( v_dirs, self.config["user"], root_dir=self.config["root_dir"], ) verify_log(self.config) client = salt.spm.SPMClient(ui, self.config) client.run(self.args)
def run(self): ''' Execute saltkey ''' verify_env([ os.path.join(self.opts['pki_dir'], 'minions'), os.path.join(self.opts['pki_dir'], 'minions_pre'), os.path.join(self.opts['pki_dir'], 'minions_rejected'), os.path.dirname(self.opts['log_file']), ], self.opts['user']) import salt.log salt.log.setup_logfile_logger(self.opts['key_logfile'], self.opts['loglevel']) key = salt.cli.key.Key(self.opts) key.run()
def run(self): """ Execute the salt call! """ self.parse_args() if self.config["verify_env"]: verify_env( [self.config["pki_dir"], self.config["cachedir"]], self.config["user"], permissive=self.config["permissive_pki_access"], pki_dir=self.config["pki_dir"], ) if not self.config["log_file"].startswith(("tcp://", "udp://", "file://")): # Logfile is not using Syslog, verify verify_files([self.config["log_file"]], self.config["user"]) if self.options.file_root: # check if the argument is pointing to a file on disk file_root = os.path.abspath(self.options.file_root) self.config["file_roots"] = {"base": [file_root]} if self.options.pillar_root: # check if the argument is pointing to a file on disk pillar_root = os.path.abspath(self.options.pillar_root) self.config["pillar_roots"] = {"base": [pillar_root]} if self.options.local: self.config["file_client"] = "local" if self.options.master: self.config["master"] = self.options.master # Setup file logging! self.setup_logfile_logger() # caller = salt.cli.caller.Caller(self.config) caller = salt.cli.caller.Caller.factory(self.config) if self.options.doc: caller.print_docs() self.exit(salt.exitcodes.EX_OK) if self.options.grains_run: caller.print_grains() self.exit(salt.exitcodes.EX_OK) caller.run()
def start(self): ''' Run the sequence to start a salt master server ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), os.path.dirname(self.config['log_file']), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logging.getLogger(__name__).warn('Setting up the Salt Master') # Late import so logging works correctly if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.exit(4, 'The ports are not available to bind\n') migrations.migrate_paths(self.config) import salt.master master = salt.master.Master(self.config) self.daemonize_if_required() self.set_pidfile() if check_user(self.config['user']): try: master.start() except salt.master.MasterExit: sys.exit()
def start(self): ''' Run the sequence to start a salt master server ''' try: verify_env([ self.opts['pki_dir'], os.path.join(self.opts['pki_dir'], 'minions'), os.path.join(self.opts['pki_dir'], 'minions_pre'), os.path.join(self.opts['pki_dir'], 'minions_rejected'), self.opts['cachedir'], os.path.join(self.opts['cachedir'], 'jobs'), os.path.dirname(self.opts['log_file']), self.opts['sock_dir'], ], self.opts['user']) except OSError, err: sys.exit(err.errno)
def start(self): ''' Execute this method to start up a syndic. ''' self.parse_args() try: if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], os.path.dirname(self.config['log_file']), ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError, err: sys.exit(err.errno)
def run(self): ''' Execute salt-key ''' import salt.key self.parse_args() if self.config['verify_env']: verify_env_dirs = [] if not self.config['gen_keys']: if self.config['transport'] == 'raet': verify_env_dirs.extend([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'accepted'), os.path.join(self.config['pki_dir'], 'pending'), os.path.join(self.config['pki_dir'], 'rejected'), ]) elif self.config['transport'] == 'zeromq': verify_env_dirs.extend([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), ]) verify_env( verify_env_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['key_logfile']], self.config['user'] ) self.setup_logfile_logger() key = salt.key.KeyCLI(self.config) if check_user(self.config['user']): key.run()
def run(self): """ Execute saltkey """ verify_env( [ os.path.join(self.opts["pki_dir"], "minions"), os.path.join(self.opts["pki_dir"], "minions_pre"), os.path.join(self.opts["pki_dir"], "minions_rejected"), os.path.dirname(self.opts["log_file"]), ] ) import salt.log salt.log.setup_logfile_logger(self.opts["key_logfile"], self.opts["loglevel"]) key = salt.cli.key.Key(self.opts) key.run()
def run(self): ''' Run the api ''' ui = salt.spm.SPMCmdlineInterface() self.parse_args() self.setup_logfile_logger() v_dirs = [ self.config['cachedir'], ] verify_env( v_dirs, self.config['user'], ) verify_log(self.config) client = salt.spm.SPMClient(ui, self.config) client.run(self.args)
def run(self): ''' Execute saltkey ''' verify_env([ os.path.join(self.opts['pki_dir'], 'minions'), os.path.join(self.opts['pki_dir'], 'minions_pre'), os.path.join(self.opts['pki_dir'], 'minions_rejected'), os.path.dirname(self.opts['log_file']), ], self.opts['user'], permissive=self.opts['permissive_pki_access']) import salt.log salt.log.setup_logfile_logger(self.opts['key_logfile'], self.opts['loglevel']) key = salt.cli.key.Key(self.opts) key.run()
def get_temp_config(config_for, **config_overrides): rootdir = config_overrides.get( "root_dir", tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) ) conf_dir = config_overrides.pop("conf_dir", os.path.join(rootdir, "conf")) for key in ("cachedir", "pki_dir", "sock_dir"): if key not in config_overrides: config_overrides[key] = key if "log_file" not in config_overrides: config_overrides["log_file"] = "logs/{}.log".format(config_for) if "user" not in config_overrides: config_overrides["user"] = RUNTIME_VARS.RUNNING_TESTS_USER config_overrides["root_dir"] = rootdir cdict = AdaptedConfigurationTestCaseMixin.get_config( config_for, from_scratch=True ) if config_for in ("master", "client_config"): rdict = salt.config.apply_master_config(config_overrides, cdict) if config_for == "minion": rdict = salt.config.apply_minion_config(config_overrides, cdict) verify_env([os.path.join(rdict['pki_dir'], 'minions'), os.path.join(rdict['pki_dir'], 'minions_pre'), os.path.join(rdict['pki_dir'], 'minions_rejected'), os.path.join(rdict['pki_dir'], 'minions_denied'), os.path.join(rdict['cachedir'], 'jobs'), os.path.join(rdict['cachedir'], 'tokens'), os.path.join(rdict['root_dir'], 'cache', 'tokens'), os.path.join(rdict['pki_dir'], 'accepted'), os.path.join(rdict['pki_dir'], 'rejected'), os.path.join(rdict['pki_dir'], 'pending'), os.path.dirname(rdict['log_file']), rdict['sock_dir'], conf_dir ], RUNTIME_VARS.RUNNING_TESTS_USER, root_dir=rdict['root_dir'], ) rdict['conf_file'] = os.path.join(conf_dir, config_for) with salt.utils.files.fopen(rdict['conf_file'], 'w') as wfh: salt.utils.yaml.safe_dump(rdict, wfh, default_flow_style=False) return rdict
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if (not self.config['log_file'].startswith('tcp://') or not self.config['log_file'].startswith('udp://') or not self.config['log_file'].startswith('file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.warn( 'Setting up the Salt Syndic Minion "{0}"'.format( self.config['id'] ) ) # Late import so logging works correctly import salt.minion self.daemonize_if_required() self.syndic = salt.minion.Syndic(self.config) self.set_pidfile()
def start(self): ''' Run the sequence to start a salt master server ''' self.parse_args() try: if self.config['verify_env']: verify_env([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), os.path.dirname(self.config['log_file']), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logging.getLogger(__name__).warn('Setting up the Salt Master') # Late import so logging works correctly if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.exit(4, 'The ports are not available to bind\n') migrations.migrate_paths(self.config) import salt.master master = salt.master.Master(self.config) self.daemonize_if_required() self.set_pidfile() if check_user(self.config['user']): try: master.start() except salt.master.MasterExit: sys.exit()
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: logger.exception('Failed to prepare salt environment') sys.exit(err.errno) self.setup_logfile_logger() logger.info( 'Setting up the Salt Syndic Minion "{0}"'.format( self.config['id'] ) ) # Late import so logging works correctly import salt.minion self.daemonize_if_required() self.syndic = salt.minion.Syndic(self.config) self.set_pidfile()
def run(self): ''' Execute the salt call! ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if (not self.config['log_file'].startswith('tcp://') or not self.config['log_file'].startswith('udp://') or not self.config['log_file'].startswith('file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) if self.options.local: self.config['file_client'] = 'local' if self.options.master: self.config['master'] = self.options.master # Setup file logging! self.setup_logfile_logger() caller = salt.cli.caller.Caller(self.config) if self.options.doc: caller.print_docs() self.exit(0) if self.options.grains_run: caller.print_grains() self.exit(0) caller.run()
def run(self): """ Execute salt-key """ self.parse_args() if self.config["verify_env"]: verify_env_dirs = [] if not self.config["gen_keys"]: if self.config["transport"] == "raet": verify_env_dirs.extend( [ self.config["pki_dir"], os.path.join(self.config["pki_dir"], "accepted"), os.path.join(self.config["pki_dir"], "pending"), os.path.join(self.config["pki_dir"], "rejected"), ] ) elif self.config["transport"] == "zeromq": verify_env_dirs.extend( [ self.config["pki_dir"], os.path.join(self.config["pki_dir"], "minions"), os.path.join(self.config["pki_dir"], "minions_pre"), os.path.join(self.config["pki_dir"], "minions_rejected"), ] ) verify_env( verify_env_dirs, self.config["user"], permissive=self.config["permissive_pki_access"], pki_dir=self.config["pki_dir"], ) if not self.config["log_file"].startswith(("tcp://", "udp://", "file://")): # Logfile is not using Syslog, verify verify_files([self.config["key_logfile"]], self.config["user"]) self.setup_logfile_logger() key = salt.key.KeyCLI(self.config) if check_user(self.config["user"]): key.run()
def get_temp_config(config_for, **config_overrides): rootdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) conf_dir = os.path.join(rootdir, 'conf') for key in ('cachedir', 'pki_dir', 'sock_dir'): if key not in config_overrides: config_overrides[key] = key if 'log_file' not in config_overrides: config_overrides['log_file'] = 'logs/{}.log'.format(config_for) if 'user' not in config_overrides: config_overrides['user'] = RUNTIME_VARS.RUNNING_TESTS_USER config_overrides['root_dir'] = rootdir cdict = AdaptedConfigurationTestCaseMixin.get_config(config_for, from_scratch=True) if config_for in ('master', 'client_config'): rdict = salt.config.apply_master_config(config_overrides, cdict) if config_for == 'minion': rdict = salt.config.apply_minion_config(config_overrides, cdict) verify_env([os.path.join(rdict['pki_dir'], 'minions'), os.path.join(rdict['pki_dir'], 'minions_pre'), os.path.join(rdict['pki_dir'], 'minions_rejected'), os.path.join(rdict['pki_dir'], 'minions_denied'), os.path.join(rdict['cachedir'], 'jobs'), os.path.join(rdict['cachedir'], 'raet'), os.path.join(rdict['cachedir'], 'tokens'), os.path.join(rdict['root_dir'], 'cache', 'tokens'), os.path.join(rdict['pki_dir'], 'accepted'), os.path.join(rdict['pki_dir'], 'rejected'), os.path.join(rdict['pki_dir'], 'pending'), os.path.dirname(rdict['log_file']), rdict['sock_dir'], conf_dir ], RUNTIME_VARS.RUNNING_TESTS_USER, root_dir=rdict['root_dir'], ) rdict['config_dir'] = conf_dir rdict['conf_file'] = os.path.join(conf_dir, config_for) with salt.utils.files.fopen(rdict['conf_file'], 'w') as wfh: wfh.write(yaml.dump(rdict, default_flow_style=False)) return rdict
def start(self): ''' Execute this method to start up a minion. ''' self.parse_args() try: if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], os.path.dirname(self.config['log_file']), ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() log = logging.getLogger(__name__) log.warn( 'Setting up the Salt Minion "{0}"'.format( self.config['id']) ) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.minion # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion could halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize self.daemonize_if_required() try: minion = salt.minion.Minion(self.config) self.set_pidfile() if check_user(self.config['user']): minion.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Minion') raise SystemExit('\nExiting on Ctrl-c')
def start(self): ''' Execute this method to start up a minion. ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], os.path.dirname(self.config['log_file']), ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() log = logging.getLogger(__name__) log.warn('Setting up the Salt Minion "{0}"'.format(self.config['id'])) migrations.migrate_paths(self.config) # Late import so logging works correctly import salt.minion # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion could halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize self.daemonize_if_required() try: minion = salt.minion.Minion(self.config) self.set_pidfile() if check_user(self.config['user']): minion.tune_in() except KeyboardInterrupt: log.warn('Stopping the Salt Minion') raise SystemExit('\nExiting on Ctrl-c')
def test_verify_env(self): root_dir = tempfile.mkdtemp(dir=TMP) var_dir = os.path.join(root_dir, 'var', 'log', 'salt') key_dir = os.path.join(root_dir, 'key_dir') verify_env([var_dir, key_dir], getpass.getuser(), sensitive_dirs=[key_dir]) self.assertTrue(os.path.exists(var_dir)) self.assertTrue(os.path.exists(key_dir)) var_dir_stat = os.stat(var_dir) self.assertEqual(var_dir_stat.st_uid, os.getuid()) self.assertEqual(var_dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(var_dir_stat.st_mode & stat.S_IRWXG, 40) self.assertEqual(var_dir_stat.st_mode & stat.S_IRWXO, 5) key_dir_stat = os.stat(key_dir) self.assertEqual(key_dir_stat.st_mode & stat.S_IRWXU, stat.S_IRWXU) self.assertEqual(key_dir_stat.st_mode & stat.S_IRWXG, 0) self.assertEqual(key_dir_stat.st_mode & stat.S_IRWXO, 0)