Example #1
0
def CMDshell(args):
    """Starts a shell with api.* in.."""
    logging_utils.prepare_logging(None)
    logging_utils.set_console_level(logging.DEBUG)

    from bot_code import bot_main
    from api import os_utilities
    from api import platforms
    local_vars = {
        'bot_main': bot_main,
        'json': json,
        'os_utilities': os_utilities,
        'platforms': platforms,
    }
    # Can't use: from api.platforms import *
    local_vars.update((k, v) for k, v in platforms.__dict__.iteritems()
                      if not k.startswith('_'))

    if args:
        for arg in args:
            exec code.compile_command(arg) in local_vars
    else:
        code.interact('Locals:\n  ' + '\n  '.join(sorted(local_vars)), None,
                      local_vars)
    return 0
Example #2
0
def main(args):
  # Add SWARMING_HEADLESS into environ so subcommands know that they are running
  # in a headless (non-interactive) mode.
  os.environ['SWARMING_HEADLESS'] = '1'

  # TODO(maruel): Get rid of all flags and support no option at all.
  # https://code.google.com/p/swarming/issues/detail?id=111
  parser = optparse.OptionParser(
      usage='%prog [options]',
      description=sys.modules[__name__].__doc__)
  # TODO(maruel): Always True.
  parser.add_option('-v', '--verbose', action='count', default=0,
                    help='Set logging level to INFO, twice for DEBUG.')

  error = None
  try:
    # Do this late so an error is reported. It could happen when a flag is
    # removed but the auto-update script was not upgraded properly.
    options, args = parser.parse_args(args)
    levels = [logging.WARNING, logging.INFO, logging.DEBUG]
    logging_utils.set_console_level(levels[min(options.verbose, len(levels)-1)])
    if args:
      parser.error('Unsupported args.')
  except Exception as e:
    # Do not reboot here, because it would just cause a reboot loop.
    error = str(e)
  try:
    return run_bot(error)
  finally:
    call_hook(bot.Bot(None, None, None, None, ROOT_DIR, None),
              'on_bot_shutdown')
Example #3
0
def CMDshell(args):
  """Starts a shell with api.* in.."""
  logging_utils.prepare_logging(None)
  logging_utils.set_console_level(logging.DEBUG)

  from bot_code import bot_main
  from api import os_utilities
  from api import platforms
  local_vars = {
    'bot_main': bot_main,
    'json': json,
    'os_utilities': os_utilities,
    'platforms': platforms,
  }
  # Can't use: from api.platforms import *
  local_vars.update(
      (k, v) for k, v in platforms.__dict__.iteritems()
      if not k.startswith('_'))

  if args:
    for arg in args:
      exec code.compile_command(arg) in local_vars
  else:
    code.interact(
        'Locals:\n  ' + '\n  '.join( sorted(local_vars)), None, local_vars)
  return 0
Example #4
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('bot_config.log')
  logging_utils.set_console_level(logging.DEBUG)

  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)

  # User provided bot_config.py
  logging.info(
      'importing bot_config: %s, %s', THIS_FILE, zip_package.generate_version())
  try:
    import bot_main
    bot_main.setup_bot(options.survive)
  except Exception:
    logging.exception('bot_config.py is invalid.')

  logging.info('Starting the bot: %s', THIS_FILE)
  cmd = [sys.executable, THIS_FILE, 'start_bot']
  if sys.platform in ('cygwin', 'win32'):
    try:
      subprocess.Popen(cmd)
      return 0
    except Exception as e:
      logging.exception('failed to start: %s', e)
      return 1
  else:
    os.execv(cmd[0], cmd)
Example #5
0
def CMDstart_bot(args):
  """Starts the swarming bot."""
  logging_utils.prepare_logging('swarming_bot.log')
  logging_utils.set_console_level(logging.DEBUG)
  logging.info(
      'importing bot_main: %s, %s', THIS_FILE, zip_package.generate_version())
  import bot_main
  result = bot_main.main(args)
  logging.info('bot_main exit code: %d', result)
  return result
Example #6
0
        }
        self.assertEqual(expected, set(os.listdir(self.root_dir)))
        expected = {
            u'exit_code':
            1 if sys.platform == 'win32' else -signal.SIGTERM,
            u'hard_timeout':
            False,
            u'io_timeout':
            False,
            u'must_signal_internal_failure':
            u'task_runner received signal %d' % task_runner.SIG_BREAK_OR_TERM,
            u'version':
            3,
        }
        with open(task_result_file, 'rb') as f:
            self.assertEqual(expected, json.load(f))
        self.assertEqual(0, proc.returncode)


if __name__ == '__main__':
    fix_encoding.fix_encoding()
    if '-v' in sys.argv:
        unittest.TestCase.maxDiff = None
    logging_utils.prepare_logging(None)
    logging_utils.set_console_level(logging.DEBUG if '-v' in
                                    sys.argv else logging.CRITICAL + 1)
    # Fix litteral text expectation.
    os.environ['LANG'] = 'en_US.UTF-8'
    os.environ['LANGUAGE'] = 'en_US.UTF-8'
    unittest.main()
Example #7
0
      'logs',
      # TODO(maruel): Move inside work.
      'task_runner_in.json',
      'task_runner_out.json',
    }
    self.assertEqual(expected, set(os.listdir(self.root_dir)))
    expected = {
      u'exit_code': 1 if sys.platform == 'win32' else -signal.SIGTERM,
      u'hard_timeout': False,
      u'io_timeout': False,
      u'must_signal_internal_failure':
          u'task_runner received signal %d' % task_runner.SIG_BREAK_OR_TERM,
      u'version': 3,
    }
    with open(task_result_file, 'rb') as f:
      self.assertEqual(expected, json.load(f))
    self.assertEqual(0, proc.returncode)


if __name__ == '__main__':
  fix_encoding.fix_encoding()
  if '-v' in sys.argv:
    unittest.TestCase.maxDiff = None
  logging_utils.prepare_logging(None)
  logging_utils.set_console_level(
      logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1)
  # Fix litteral text expectation.
  os.environ['LANG'] = 'en_US.UTF-8'
  os.environ['LANGUAGE'] = 'en_US.UTF-8'
  unittest.main()