Пример #1
0
 def test_verify_socket(self):
     self.assertTrue(verify_socket("", 18000, 18001))
     if socket.has_ipv6:
         # Only run if Python is built with IPv6 support; otherwise
         # this will just fail.
         try:
             self.assertTrue(verify_socket("::", 18000, 18001))
         except socket.error as serr:
             # Python has IPv6 enabled, but the system cannot create
             # IPv6 sockets (otherwise the test would return a bool)
             # - skip the test
             #
             # FIXME - possibly emit a message that the system does
             # not support IPv6.
             pass
Пример #2
0
 def test_verify_socket(self):
     self.assertTrue(verify_socket('', 18000, 18001))
     if socket.has_ipv6:
         # Only run if Python is built with IPv6 support; otherwise
         # this will just fail.
         try:
             self.assertTrue(verify_socket('::', 18000, 18001))
         except socket.error as serr:
             # Python has IPv6 enabled, but the system cannot create
             # IPv6 sockets (otherwise the test would return a bool)
             # - skip the test
             #
             # FIXME - possibly emit a message that the system does
             # not support IPv6.
             pass
Пример #3
0
    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()
Пример #4
0
    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()
Пример #5
0
    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()
Пример #6
0
class Master(parsers.MasterOptionParser):
    '''
    Creates a master server
    '''

    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)

        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')

        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()
Пример #7
0
    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()
Пример #8
0
    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'],
                    ]
                if self.config.get('transport') == 'raet':
                    v_dirs.append(os.path.join(self.config['pki_dir'], 'accepted'))
                    v_dirs.append(os.path.join(self.config['pki_dir'], 'pending'))
                    v_dirs.append(os.path.join(self.config['pki_dir'], 'rejected'))
                    v_dirs.append(os.path.join(self.config['cachedir'], 'raet'))
                verify_env(
                    v_dirs,
                    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)
                # 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 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 Master')

        # TODO: AIO core is separate from transport
        if self.config['transport'].lower() in ('zeromq', 'tcp'):
            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)
        else:
            # Add a udp port check here
            import salt.daemons.flo
            self.master = salt.daemons.flo.IofloMaster(self.config)
        self.daemonize_if_required()
        self.set_pidfile()
        salt.utils.process.notify_systemd()
Пример #9
0
 def test_verify_socket(self):
     self.assertTrue(verify_socket('', 18000, 18001))
     if socket.has_ipv6:
         # Only run if Python is built with IPv6 support; otherwise
         # this will just fail.
         self.assertTrue(verify_socket('::', 18000, 18001))
Пример #10
0
 def test_verify_socket(self):
     self.assertTrue(verify_socket('', 18000, 18001))
Пример #11
0
    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()
Пример #12
0
class Master(object):
    '''
    Creates a master server
    '''
    def __init__(self):
        self.cli = self.__parse_cli()
        # command line overrides config
        if self.cli['user']:
            self.opts['user'] = self.cli['user']

        # Send the pidfile location to the opts
        if self.cli['pidfile']:
            self.opts['pidfile'] = self.cli['pidfile']

    def __parse_cli(self):
        '''
        Parse the cli for options passed to a master daemon
        '''
        import salt.log
        parser = optparse.OptionParser(version="%%prog %s" % __version__)
        parser.add_option('-d',
                          '--daemon',
                          dest='daemon',
                          default=False,
                          action='store_true',
                          help='Run the master as a daemon')
        parser.add_option('-c',
                          '--config',
                          dest='config',
                          default='/etc/salt/master',
                          help='Pass in an alternative configuration file')
        parser.add_option('-u',
                          '--user',
                          dest='user',
                          help='Specify user to run master')
        parser.add_option('--pid-file',
                          dest='pidfile',
                          help=('Specify the location of the pidfile.'))
        parser.add_option(
            '-l',
            '--log-level',
            dest='log_level',
            choices=list(salt.log.LOG_LEVELS),
            help='Console log level. One of %s. For the logfile settings '
            'see the config file. Default: \'warning\'.' %
            ', '.join([repr(l) for l in salt.log.SORTED_LEVEL_NAMES]))

        options, args = parser.parse_args()

        self.opts = salt.config.master_config(options.config)

        if not options.log_level:
            options.log_level = self.opts['log_level']

        salt.log.setup_console_logger(options.log_level,
                                      log_format=self.opts['log_fmt_console'],
                                      date_format=self.opts['log_datefmt'])

        cli = {
            'daemon': options.daemon,
            'config': options.config,
            'user': options.user,
            'pidfile': options.pidfile
        }

        return cli

    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'],
                       permissive=self.opts['permissive_pki_access'])
        except OSError, err:
            sys.exit(err.errno)

        import salt.log
        salt.log.setup_logfile_logger(self.opts['log_file'],
                                      self.opts['log_level_logfile']
                                      or self.opts['log_level'],
                                      log_format=self.opts['log_fmt_logfile'],
                                      date_format=self.opts['log_datefmt'])
        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
        if not verify_socket(self.opts['interface'], self.opts['publish_port'],
                             self.opts['ret_port']):
            log.critical('The ports are not available to bind')
            sys.exit(4)

        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()
Пример #13
0
 def test_verify_socket(self):
     self.assertTrue(verify_socket('', 18000, 18001))
     if socket.has_ipv6:
         # Only run if Python is built with IPv6 support; otherwise
         # this will just fail.
         self.assertTrue(verify_socket('::', 18000, 18001))