Ejemplo n.º 1
0
    def test_setup_bot(self):
        setup_bots = []

        def setup_bot(_bot):
            setup_bots.append(1)
            return False

        from config import bot_config
        self.mock(bot_config, 'setup_bot', setup_bot)
        self.mock(bot, '_make_stack', lambda: 'fake stack')
        restarts = []
        post_event = []
        self.mock(os_utilities, 'host_reboot',
                  lambda *a, **kw: restarts.append((a, kw)))
        self.mock(bot.Bot, 'post_event', lambda *a, **kw: post_event.append(
            (a, kw)))
        self.expected_requests([])
        bot_main.setup_bot(False)
        expected = [
            (('Starting new swarming bot: %s' % bot_main.THIS_FILE, ), {
                'timeout': 900
            }),
        ]
        self.assertEqual(expected, restarts)
        # It is called twice, one as part of setup_bot(False), another as part of
        # on_shutdown_hook().
        self.assertEqual([1, 1], setup_bots)
        expected = [
            'Starting new swarming bot: %s' % bot_main.THIS_FILE,
            ('Host is stuck rebooting for: Starting new swarming bot: %s\n'
             'Calling stack:\nfake stack') % bot_main.THIS_FILE,
        ]
        self.assertEqual(expected, [i[0][2] for i in post_event])
Ejemplo n.º 2
0
def CMDstart_slave(args):
  """Ill named command that actually sets up the bot then start it."""
  # TODO(maruel): Rename function.
  logging_utils.prepare_logging(os.path.join('logs', 'bot_config.log'))

  parser = optparse.OptionParser()
  parser.add_option(
      '--survive', action='store_true',
      help='Do not reboot the host even if bot_config.setup_bot() asked to')
  options, args = parser.parse_args(args)

  try:
    from bot_code import bot_main
    bot_main.setup_bot(options.survive)
  except Exception:
    logging.exception('bot_main.py failed.')

  logging.info('Starting the bot: %s', THIS_FILE)
  return common.exec_python([THIS_FILE, 'start_bot'])
Ejemplo n.º 3
0
def CMDsetup(_args):
    """Setup the bot to auto-start but doesn't start the bot."""
    logging_utils.prepare_logging(os.path.join('logs', 'bot_config.log'))
    from bot_code import bot_main
    bot_main.setup_bot(True)
    return 0