Example #1
0
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
Example #2
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
Example #3
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
Example #4
0
 def test_get_state(self):
     self.mock(time, 'time', lambda: 126.0)
     expected = os_utilities.get_state()
     expected['sleep_streak'] = 12
     # During the execution of this test case, the free disk space could have
     # changed.
     for disk in expected['disks'].itervalues():
         self.assertGreater(disk.pop('free_mb'), 1.)
     actual = bot_main.get_state(12)
     for disk in actual['disks'].itervalues():
         self.assertGreater(disk.pop('free_mb'), 1.)
     self.assertEqual(expected, actual)
Example #5
0
 def test_get_state(self):
   self.mock(time, 'time', lambda: 126.0)
   expected = os_utilities.get_state()
   expected['sleep_streak'] = 12
   # During the execution of this test case, the free disk space could have
   # changed.
   for disk in expected['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   actual = bot_main.get_state(12)
   for disk in actual['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   self.assertEqual(expected, actual)
Example #6
0
def get_state():
    """Returns dict with a state of the bot reported to the server with each poll.

  It is only for dynamic state that changes while bot is running for information
  for the sysadmins.

  The server can not use this state for immediate scheduling purposes (use
  'dimensions' for that), but it can use it for maintenance and bookkeeping
  tasks.

  See https://code.google.com/p/swarming/wiki/SwarmingMagicValues.
  """
    return os_utilities.get_state()
Example #7
0
def get_state():
  """Returns dict with a state of the bot reported to the server with each poll.

  It is only for dynamic state that changes while bot is running for information
  for the sysadmins.

  The server can not use this state for immediate scheduling purposes (use
  'dimensions' for that), but it can use it for maintenance and bookkeeping
  tasks.

  See https://code.google.com/p/swarming/wiki/SwarmingMagicValues.
  """
  return os_utilities.get_state()
Example #8
0
 def test_get_state(self):
     self.mock(time, "time", lambda: 126.0)
     expected = os_utilities.get_state()
     expected["sleep_streak"] = 12
     # During the execution of this test case, the free disk space could have
     # changed.
     for disk in expected["disks"].itervalues():
         self.assertGreater(disk.pop("free_mb"), 1.0)
     actual = bot_main.get_state(None, 12)
     for disk in actual["disks"].itervalues():
         self.assertGreater(disk.pop("free_mb"), 1.0)
     self.assertGreater(actual.pop("nb_files_in_temp"), 0)
     self.assertGreater(expected.pop("nb_files_in_temp"), 0)
     self.assertEqual(expected, actual)
def get_state(bot=None):
    """Returns dict with a state of the bot reported to the server with each poll.

    It is only for dynamic state that changes while bot is running for information
    for the sysadmins.

    The server can not use this state for immediate scheduling purposes (use
    'dimensions' for that), but it can use it for maintenance and bookkeeping
    tasks.

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

    """
    return os_utilities.get_state()
Example #10
0
def get_state(bot):
    # pylint: disable=line-too-long
    """Returns dict with a state of the bot reported to the server with each poll.

  It is only for dynamic state that changes while bot is running for information
  for the sysadmins.

  The server can not use this state for immediate scheduling purposes (use
  'dimensions' for that), but it can use it for maintenance and bookkeeping
  tasks.

  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_state()
Example #11
0
 def test_get_state(self):
   self.mock(time, 'time', lambda: 1470000000.0)
   expected = os_utilities.get_state()
   expected['sleep_streak'] = 12
   # During the execution of this test case, the free disk space could have
   # changed.
   for disk in expected['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   actual = bot_main.get_state(None, 12)
   for disk in actual['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   self.assertGreater(actual.pop('nb_files_in_temp'), 0)
   self.assertGreater(expected.pop('nb_files_in_temp'), 0)
   self.assertGreater(actual.pop('uptime'), 0)
   self.assertGreater(expected.pop('uptime'), 0)
   self.assertEqual(sorted(expected.pop('temp', {})),
                    sorted(actual.pop('temp', {})))
   self.assertEqual(expected, actual)
Example #12
0
 def test_get_state(self):
   self.mock(time, 'time', lambda: 1470000000.0)
   expected = os_utilities.get_state()
   expected['sleep_streak'] = 12
   # During the execution of this test case, the free disk space could have
   # changed.
   for disk in expected['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   actual = bot_main.get_state(None, 12)
   for disk in actual['disks'].itervalues():
     self.assertGreater(disk.pop('free_mb'), 1.)
   self.assertGreater(actual.pop('nb_files_in_temp'), 0)
   self.assertGreater(expected.pop('nb_files_in_temp'), 0)
   self.assertTrue(actual.pop('uptime') != 0)
   self.assertTrue(expected.pop('uptime') != 0)
   self.assertEqual(sorted(expected.pop('temp', {})),
                    sorted(actual.pop('temp', {})))
   self.assertEqual(expected, actual)
Example #13
0
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
Example #14
0
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
Example #15
0
def get_state(bot):
  # pylint: disable=line-too-long
  """Returns dict with a state of the bot reported to the server with each poll.
  It is only for dynamic state that changes while bot is running for information
  for the sysadmins.
  The server can not use this state for immediate scheduling purposes (use
  'dimensions' for that), but it can use it for maintenance and bookkeeping
  tasks.
  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.
  """
  state = os_utilities.get_state()
  if _DEVICE:
    state[u'device'] = _DEVICE.properties
    if _DEVICE.bot_id in _BOT_DEVICE_MAP:
      extra_state = _BOT_DEVICE_MAP[_DEVICE.bot_id].state
      if extra_state:
        state[u'device'].update(extra_state)
    if not _DEVICE.is_reachable:
      state[u'quarantined'] = 'device is not reachable'
  return state