コード例 #1
0
def CMDconfig(_args):
    """Prints the config.json embedded in this zip."""
    logging_utils.prepare_logging(None)
    from bot_code import bot_main
    json.dump(bot_main.get_config(), sys.stdout, indent=2, sort_keys=True)
    print('')
    return 0
コード例 #2
0
 def test_post_error_task(self):
     self.mock(time, 'time', lambda: 126.0)
     self.mock(logging, 'error', lambda *_, **_kw: None)
     self.mock(bot_main, 'get_config', lambda: {
         'server': self.url,
         'server_version': '1'
     })
     expected_attribs = bot_main.get_attributes(None)
     botobj = bot_main.get_bot(bot_main.get_config())
     self.expected_requests([
         (
             'https://localhost:1/swarming/api/v1/bot/task_error/23',
             {
                 'data': {
                     'id': expected_attribs['dimensions']['id'][0],
                     'message': 'error',
                     'task_id': 23,
                 },
                 'follow_redirects': False,
                 'headers': {
                     'Cookie': 'GOOGAPPUID=42',
                     'X-Luci-Swarming-Bot-ID': botobj.id,
                 },
                 'timeout': remote_client.NET_CONNECTION_TIMEOUT_SEC,
             },
             {
                 'resp': 1
             },
         ),
     ])
     botobj.remote.bot_id = botobj.id
     self.assertEqual(True, bot_main._post_error_task(botobj, 'error', 23))
コード例 #3
0
ファイル: __main__.py プロジェクト: rmistry/luci-py
def CMDconfig(_args):
  """Prints the config.json embedded in this zip."""
  logging_utils.prepare_logging(None)
  from bot_code import bot_main
  json.dump(bot_main.get_config(), sys.stdout, indent=2, sort_keys=True)
  print('')
  return 0
コード例 #4
0
def CMDattributes(_args):
    """Prints out the bot's attributes."""
    from bot_code import bot_main
    botobj = bot_main.get_bot(bot_main.get_config())
    json.dump(bot_main.get_attributes(botobj),
              sys.stdout,
              indent=2,
              sort_keys=True,
              separators=(',', ': '))
    print('')
    return 0
コード例 #5
0
def CMDis_fine(_args):
  """Just reports that the code doesn't throw.

  That ensures that the bot has minimal viability before transfering control to
  it. For now, it just imports bot_main and send ping request to server but
  later it'll check the config, etc.
  """
  # pylint: disable=unused-variable
  from bot_code import bot_main
  from config import bot_config

  resp = net.url_read(bot_main.get_config()['server'] +
                      '/swarming/api/v1/bot/server_ping')
  if resp is None:
    logging.error('No response from server_ping')
    return 1
  return 0
コード例 #6
0
    def test_get_state_quarantine(self):
        botobj = bot_main.get_bot(bot_main.get_config())
        root = u'c:\\' if sys.platform == 'win32' else u'/'

        def get_state(_):
            return {
                u'disks': {
                    root: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                    botobj.base_dir: {
                        u'free_mb': 0.1,
                        u'size_mb': 1000,
                    },
                },
            }

        # This uses the default get_settings() values. The threshold used is
        # dependent on these values. This affects the error message below.
        # 'size' == 4096Mb
        # 'max_percent' == 15% * 1000Mb = 150Mb
        # 'min_percent' == 5% of 1000Mb == 50Mb
        # 'max_percent' is chosen.
        from config import bot_config
        self.mock(bot_config, 'get_state', get_state)
        expected = {
            u'disks': {
                u'c:\\' if sys.platform == 'win32' else u'/': {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
                botobj.base_dir: {
                    u'free_mb': 0.1,
                    u'size_mb': 1000,
                },
            },
            u'quarantined':
            (u'Not enough free disk space on %s. 0.1mib < 100.0mib\n'
             u'Not enough free disk space on %s. 0.1mib < 150.0mib') %
            (root, botobj.base_dir),
            u'sleep_streak':
            1,
        }
        self.assertEqual(expected, bot_main._get_state(botobj, 1))
コード例 #7
0
def CMDserver(_args):
    """Prints the server url. It's like 'config' but easier to parse."""
    logging_utils.prepare_logging(None)
    from bot_code import bot_main
    print bot_main.get_config()['server']
    return 0