コード例 #1
0
ファイル: bot_main.py プロジェクト: onecityuni/luci-py
def get_dimensions(botobj):
    """Returns bot_config.py's get_attributes() dict."""
    # Importing this administrator provided script could have side-effects on
    # startup. That is why it is imported late.
    try:
        if _in_load_test_mode():
            # Returns a minimal set of dimensions so it doesn't run tasks by error.
            dimensions = os_utilities.get_dimensions()
            return {
                'id': dimensions['id'],
                'load_test': ['1'],
            }

        from config import bot_config
        out = bot_config.get_dimensions(botobj)
        if not isinstance(out, dict):
            raise ValueError('Unexpected type %s' % out.__class__)
        return out
    except Exception as e:
        logging.exception('get_dimensions() failed')
        try:
            out = os_utilities.get_dimensions()
            out['error'] = [str(e)]
            out['quarantined'] = ['1']
            return out
        except Exception as e:
            try:
                botid = os_utilities.get_hostname_short()
            except Exception as e2:
                botid = 'error_%s' % str(e2)
            return {
                'id': [botid],
                'error': ['%s\n%s' % (e, traceback.format_exc()[-2048:])],
                'quarantined': ['1'],
            }
コード例 #2
0
ファイル: bot_main.py プロジェクト: rmistry/luci-py
def get_dimensions(botobj):
  """Returns bot_config.py's get_attributes() dict."""
  # Importing this administrator provided script could have side-effects on
  # startup. That is why it is imported late.
  try:
    if _in_load_test_mode():
      # Returns a minimal set of dimensions so it doesn't run tasks by error.
      dimensions = os_utilities.get_dimensions()
      return {
        'id': dimensions['id'],
        'load_test': ['1'],
      }

    from config import bot_config
    out = bot_config.get_dimensions(botobj)
    if not isinstance(out, dict):
      raise ValueError('Unexpected type %s' % out.__class__)
    return out
  except Exception as e:
    logging.exception('get_dimensions() failed')
    try:
      out = os_utilities.get_dimensions()
      out['error'] = [str(e)]
      out['quarantined'] = ['1']
      return out
    except Exception as e:
      try:
        botid = os_utilities.get_hostname_short()
      except Exception as e2:
        botid = 'error_%s' % str(e2)
      return {
          'id': [botid],
          'error': ['%s\n%s' % (e, traceback.format_exc()[-2048:])],
          'quarantined': ['1'],
        }
コード例 #3
0
ファイル: os_utilities.py プロジェクト: rmistry/luci-py
def main():
    """Prints out the output of get_dimensions() and get_state()."""
    sys.path.insert(0, os.path.join(ROOT_DIR, 'swarming_bot'))
    import test_env_bot
    test_env_bot.setup_test_env()
    from api import os_utilities
    from api import platforms

    # Pass an empty tag, so pop it up since it has no significance.
    devices = None
    if sys.platform == 'linux2':
        devices = platforms.android.get_devices(None)
        if devices:
            try:
                data = {
                    u'dimensions':
                    os_utilities.get_dimensions_all_devices_android(devices),
                    u'state':
                    os_utilities.get_state_all_devices_android(devices),
                }
            finally:
                platforms.android.close_devices(devices)
    if not devices:
        data = {
            u'dimensions': os_utilities.get_dimensions(),
            u'state': os_utilities.get_state(),
        }

    json.dump(data,
              sys.stdout,
              indent=2,
              sort_keys=True,
              separators=(',', ': '))
    print('')
    return 0
コード例 #4
0
def main():
  """Prints out the output of get_dimensions() and get_state()."""
  sys.path.insert(0, os.path.join(ROOT_DIR, 'swarming_bot'))
  import test_env_bot
  test_env_bot.setup_test_env()
  from api import os_utilities
  from api import platforms

  # Pass an empty tag, so pop it up since it has no significance.
  devices = None
  if sys.platform == 'linux2':
    devices = platforms.android.get_devices(None)
    if devices:
      try:
        data = {
          u'dimensions': os_utilities.get_dimensions_all_devices_android(
              devices),
          u'state': os_utilities.get_state_all_devices_android(devices),
        }
      finally:
        platforms.android.close_devices(devices)
  if not devices:
    data = {
      u'dimensions': os_utilities.get_dimensions(),
      u'state': os_utilities.get_state(),
    }

  json.dump(data, sys.stdout, indent=2, sort_keys=True, separators=(',', ': '))
  print('')
  return 0
コード例 #5
0
def get_dimensions(bot=None):
    """Returns dict with the bot's dimensions.

    The dimensions are what are used to select the bot that can run each task.

    By default, the bot id will be automatically selected based on
    the hostname with os_utilities.get_dimensions(). This method
    overrides the default id returned by os_utilities.get_dimensions().

    Assume the bot's working directory is like BOT_ROOT/bot_23/
    we will parse the id "23" from the directory name and append it to the
    hostname to form the bot id. so the bot id would look like
    chromeos-server31-23

    See https://github.com/luci/luci-py/blob/master/appengine/
    swarming/doc/Magic-Values.md

    @returns: Dict with the bot's dimentions.

    """
    d = os_utilities.get_dimensions()
    m = re.match('.*/bot_([\d]+).*', os.getcwd())
    suffix = ''
    if m:
        suffix = '-' + m.group(1)
    d[u'id'] = [os_utilities.get_hostname_short() + suffix]
    return d
コード例 #6
0
ファイル: bot_main.py プロジェクト: molodiuc/luci-py
def get_state(botobj, sleep_streak):
    """Returns dict with a state of the bot reported to the server with each poll.
  """
    try:
        if _in_load_test_mode():
            state = os_utilities.get_state()
            state['dimensions'] = os_utilities.get_dimensions()
        else:
            from config import bot_config
            state = bot_config.get_state(botobj)
            if not isinstance(state, dict):
                state = {'error': state}
    except Exception as e:
        logging.exception('get_state() failed')
        state = {
            'error': '%s\n%s' % (e, traceback.format_exc()[-2048:]),
            'quarantined': True,
        }

    if not state.get('quarantined') and not is_base_dir_ok(botobj):
        # Use super hammer in case of dangerous environment.
        state['quarantined'] = 'Can\'t run from blacklisted directory'

    state['sleep_streak'] = sleep_streak
    return state
コード例 #7
0
def get_dimensions():
    """Returns dict with the bot's dimensions.

  The dimensions are what are used to select the bot that can run each task.

  The bot id will be automatically selected based on the hostname with
  os_utilities.get_dimensions(). If you want something more special, specify it
  in your bot_config.py and override the item 'id'.

  See https://code.google.com/p/swarming/wiki/SwarmingMagicValues.
  """
    return os_utilities.get_dimensions()
コード例 #8
0
ファイル: bot_config.py プロジェクト: eakuefner/luci-py
def get_dimensions():
  """Returns dict with the bot's dimensions.

  The dimensions are what are used to select the bot that can run each task.

  The bot id will be automatically selected based on the hostname with
  os_utilities.get_dimensions(). If you want something more special, specify it
  in your bot_config.py and override the item 'id'.

  See https://code.google.com/p/swarming/wiki/SwarmingMagicValues.
  """
  return os_utilities.get_dimensions()
コード例 #9
0
def get_dimensions(bot):
    # pylint: disable=line-too-long
    """Returns dict with the bot's dimensions.

  The dimensions are what are used to select the bot that can run each task.

  The bot id will be automatically selected based on the hostname with
  os_utilities.get_dimensions(). If you want something more special, specify it
  in your bot_config.py and override the item 'id'.

  The dimensions returned here will be joined with server defined dimensions
  (extracted from bots.cfg config file based on the bot id). Server defined
  dimensions override the ones provided by the bot. See bot.Bot.dimensions for
  more information.

  See https://github.com/luci/luci-py/tree/master/appengine/swarming/doc/Magic-Values.md.

  Arguments:
  - bot: bot.Bot instance or None. See ../api/bot.py.
  """
    return os_utilities.get_dimensions()
コード例 #10
0
ファイル: bot_main.py プロジェクト: onecityuni/luci-py
def get_state(botobj, sleep_streak):
    """Returns dict with a state of the bot reported to the server with each poll.
  """
    try:
        if _in_load_test_mode():
            state = os_utilities.get_state()
            state['dimensions'] = os_utilities.get_dimensions()
        else:
            from config import bot_config
            state = bot_config.get_state(botobj)
            if not isinstance(state, dict):
                state = {'error': state}
    except Exception as e:
        logging.exception('get_state() failed')
        state = {
            'error': '%s\n%s' % (e, traceback.format_exc()[-2048:]),
            'quarantined': True,
        }

    state['sleep_streak'] = sleep_streak
    return state
コード例 #11
0
ファイル: bot_main.py プロジェクト: rmistry/luci-py
def get_state(botobj, sleep_streak):
  """Returns dict with a state of the bot reported to the server with each poll.
  """
  try:
    if _in_load_test_mode():
      state = os_utilities.get_state()
      state['dimensions'] = os_utilities.get_dimensions()
    else:
      from config import bot_config
      state = bot_config.get_state(botobj)
      if not isinstance(state, dict):
        state = {'error': state}
  except Exception as e:
    logging.exception('get_state() failed')
    state = {
      'error': '%s\n%s' % (e, traceback.format_exc()[-2048:]),
      'quarantined': True,
    }

  state['sleep_streak'] = sleep_streak
  return state
コード例 #12
0
def get_dimensions(bot):
  # pylint: disable=line-too-long
  """Returns dict with the bot's dimensions.
  The dimensions are what are used to select the bot that can run each task.
  The bot id will be automatically selected based on the hostname with
  os_utilities.get_dimensions(). If you want something more special, specify it
  in your bot_config.py and override the item 'id'.
  The dimensions returned here will be joined with server defined dimensions
  (extracted from bots.cfg config file based on the bot id). Server defined
  dimensions override the ones provided by the bot. See bot.Bot.dimensions for
  more information.
  See https://github.com/luci/luci-py/tree/master/appengine/swarming/doc/Magic-Values.md.
  Arguments:
  - bot: bot.Bot instance or None. See ../api/bot.py.
  """
  dimensions = os_utilities.get_dimensions()
  # The bot base directory is formatted like <HOME>/bots/<Id>
  id = '%s--%s' % (
      os_utilities.get_hostname_short(),
      os.path.basename(bot.base_dir))
  dimensions[u'id'] = [id]
  if id in _BOT_DEVICE_MAP:
    dimensions.update(_BOT_DEVICE_MAP[id].dimensions)
    global _DEVICE
    if not _DEVICE:
      device_ip = dimensions[u'device_ip']
      # use first device_ip in list of device IPs for pulling device attributes
      if device_ip:
        assert isinstance(device_ip, (list, tuple)), repr(device_ip)
        _DEVICE = Device(device_ip[0], id)
    if _DEVICE:
      dimensions[u'build'] = _DEVICE.build_fingerprint,
      dimensions[u'hardware'] = _DEVICE.hardware,
      dimensions[u'product'] = _DEVICE.product,
  # TODO(jonesmi): don't strip these anymore after swarming fix goes in for limit on # dimensions
  del dimensions[u'cores']
  del dimensions[u'cpu']
  del dimensions[u'gpu']
  del dimensions[u'machine_type']
  return dimensions
コード例 #13
0
ファイル: local_smoke_test.py プロジェクト: eakuefner/luci-py
 def setUpClass(cls):
     cls.dimensions = os_utilities.get_dimensions()
コード例 #14
0
 def setUpClass(cls):
   cls.dimensions = os_utilities.get_dimensions()