Ejemplo n.º 1
0
    def test_get_http_service(self):
        def assert_is_appengine_service(service):
            """Verifies HttpService is configured for App Engine communications."""
            self.assertTrue(service.use_count_key)
            self.assertIsNotNone(service.authenticator)

        def assert_is_googlestorage_service(service):
            """Verifies HttpService is configured for GS communications."""
            self.assertFalse(service.use_count_key)
            self.assertIsNone(service.authenticator)

        # Can recognize app engine URLs.
        assert_is_appengine_service(
            net.get_http_service('https://appengine-app.appspot.com'))
        assert_is_appengine_service(
            net.get_http_service(
                'https://version-dot-appengine-app.appspot.com'))

        # Localhost is also sort of appengine when running on dev server...
        assert_is_appengine_service(
            net.get_http_service('http://localhost:8080'))

        # Check GS urls.
        assert_is_googlestorage_service(
            net.get_http_service('https://bucket-name.storage.googleapis.com'))
Ejemplo n.º 2
0
def CMDquery(parser, args):
    """Returns information about the bots connected to the Swarming server."""
    add_filter_options(parser)
    parser.filter_group.add_option(
        '--dead-only',
        action='store_true',
        help='Only print dead bots, useful to reap them and reimage broken bots'
    )
    parser.filter_group.add_option('-k',
                                   '--keep-dead',
                                   action='store_true',
                                   help='Do not filter out dead bots')
    parser.filter_group.add_option('-b',
                                   '--bare',
                                   action='store_true',
                                   help='Do not print out dimensions')
    options, args = parser.parse_args(args)

    if options.keep_dead and options.dead_only:
        parser.error('Use only one of --keep-dead and --dead-only')
    service = net.get_http_service(options.swarming)
    data = service.json_request('GET', '/swarming/api/v1/bots')
    if data is None:
        print >> sys.stderr, 'Failed to access %s' % options.swarming
        return 1
    timeout = datetime.timedelta(seconds=data['machine_death_timeout'])
    utcnow = datetime.datetime.utcnow()
    for machine in natsort.natsorted(data['machines'], key=lambda x: x['id']):
        last_seen = datetime.datetime.strptime(machine['last_seen'],
                                               '%Y-%m-%d %H:%M:%S')
        is_dead = utcnow - last_seen > timeout
        if options.dead_only:
            if not is_dead:
                continue
        elif not options.keep_dead and is_dead:
            continue

        # If the user requested to filter on dimensions, ensure the bot has all the
        # dimensions requested.
        dimensions = machine['dimensions']
        for key, value in options.dimensions:
            if key not in dimensions:
                break
            # A bot can have multiple value for a key, for example,
            # {'os': ['Windows', 'Windows-6.1']}, so that --dimension os=Windows will
            # be accepted.
            if isinstance(dimensions[key], list):
                if value not in dimensions[key]:
                    break
            else:
                if value != dimensions[key]:
                    break
        else:
            print machine['id']
            if not options.bare:
                print '  %s' % dimensions
    return 0
Ejemplo n.º 3
0
    def test_get_http_service(self):
        def assert_is_appengine_service(service):
            """Verifies HttpService is configured for App Engine communications."""
            self.assertTrue(service.use_count_key)
            self.assertIsNotNone(service.authenticator)

        def assert_is_googlestorage_service(service):
            """Verifies HttpService is configured for GS communications."""
            self.assertFalse(service.use_count_key)
            self.assertIsNone(service.authenticator)

        # Can recognize app engine URLs.
        assert_is_appengine_service(net.get_http_service("https://appengine-app.appspot.com"))
        assert_is_appengine_service(net.get_http_service("https://version-dot-appengine-app.appspot.com"))

        # Localhost is also sort of appengine when running on dev server...
        assert_is_appengine_service(net.get_http_service("http://localhost:8080"))

        # Check GS urls.
        assert_is_googlestorage_service(net.get_http_service("https://bucket-name.storage.googleapis.com"))
Ejemplo n.º 4
0
def CMDquery(parser, args):
  """Returns information about the bots connected to the Swarming server."""
  add_filter_options(parser)
  parser.filter_group.add_option(
      '--dead-only', action='store_true',
      help='Only print dead bots, useful to reap them and reimage broken bots')
  parser.filter_group.add_option(
      '-k', '--keep-dead', action='store_true',
      help='Do not filter out dead bots')
  parser.filter_group.add_option(
      '-b', '--bare', action='store_true',
      help='Do not print out dimensions')
  options, args = parser.parse_args(args)

  if options.keep_dead and options.dead_only:
    parser.error('Use only one of --keep-dead and --dead-only')

  auth.ensure_logged_in(options.swarming)
  service = net.get_http_service(options.swarming)

  data = service.json_request('GET', '/swarming/api/v1/bots')
  if data is None:
    print >> sys.stderr, 'Failed to access %s' % options.swarming
    return 1
  for machine in natsort.natsorted(data['machines'], key=lambda x: x['id']):
    if options.dead_only:
      if not machine['is_dead']:
        continue
    elif not options.keep_dead and machine['is_dead']:
      continue

    # If the user requested to filter on dimensions, ensure the bot has all the
    # dimensions requested.
    dimensions = machine['dimensions']
    for key, value in options.dimensions:
      if key not in dimensions:
        break
      # A bot can have multiple value for a key, for example,
      # {'os': ['Windows', 'Windows-6.1']}, so that --dimension os=Windows will
      # be accepted.
      if isinstance(dimensions[key], list):
        if value not in dimensions[key]:
          break
      else:
        if value != dimensions[key]:
          break
    else:
      print machine['id']
      if not options.bare:
        print '  %s' % dimensions
  return 0
Ejemplo n.º 5
0
def CMDquery(parser, args):
    """Returns information about the bots connected to the Swarming server."""
    add_filter_options(parser)
    parser.filter_group.add_option(
        "--dead-only", action="store_true", help="Only print dead bots, useful to reap them and reimage broken bots"
    )
    parser.filter_group.add_option("-k", "--keep-dead", action="store_true", help="Do not filter out dead bots")
    parser.filter_group.add_option("-b", "--bare", action="store_true", help="Do not print out dimensions")
    options, args = parser.parse_args(args)

    if options.keep_dead and options.dead_only:
        parser.error("Use only one of --keep-dead and --dead-only")
    service = net.get_http_service(options.swarming)
    data = service.json_request("GET", "/swarming/api/v1/bots")
    if data is None:
        print >> sys.stderr, "Failed to access %s" % options.swarming
        return 1
    timeout = datetime.timedelta(seconds=data["machine_death_timeout"])
    utcnow = datetime.datetime.utcnow()
    for machine in natsort.natsorted(data["machines"], key=lambda x: x["tag"]):
        last_seen = datetime.datetime.strptime(machine["last_seen"], "%Y-%m-%d %H:%M:%S")
        is_dead = utcnow - last_seen > timeout
        if options.dead_only:
            if not is_dead:
                continue
        elif not options.keep_dead and is_dead:
            continue

        # If the user requested to filter on dimensions, ensure the bot has all the
        # dimensions requested.
        dimensions = machine["dimensions"]
        for key, value in options.dimensions:
            if key not in dimensions:
                break
            # A bot can have multiple value for a key, for example,
            # {'os': ['Windows', 'Windows-6.1']}, so that --dimension os=Windows will
            # be accepted.
            if isinstance(dimensions[key], list):
                if value not in dimensions[key]:
                    break
            else:
                if value != dimensions[key]:
                    break
        else:
            print machine["tag"]
            if not options.bare:
                print "  %s" % dimensions
    return 0
Ejemplo n.º 6
0
 def __init__(self, url):
     self._service = net.get_http_service(url)
Ejemplo n.º 7
0
 def __init__(self, url):
   self._service = net.get_http_service(url)