Example #1
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))
Example #2
0
  def test_attributes(self):
    actual = json.loads(subprocess42.check_output(
        [sys.executable, self._zip_file, 'attributes'],
        stderr=subprocess42.PIPE))
    # get_config() doesn't work when called outside of a zip, so patch the
    # server_version manually with the default value in config/config.json.
    expected = bot_main.get_attributes(None)
    self.assertEqual([u'N/A'], expected[u'dimensions'][u'server_version'])
    expected[u'dimensions'][u'server_version'] = [u'1']

    NON_DETERMINISTIC = (
      u'cwd', u'disks', u'nb_files_in_temp', u'pid', u'running_time',
      u'started_ts', u'uptime')
    for key in NON_DETERMINISTIC:
      del actual[u'state'][key]
      del expected[u'state'][key]
    actual[u'state'].pop('temp', None)
    expected[u'state'].pop('temp', None)
    del actual[u'version']
    del expected[u'version']
    self.assertAlmostEqual(
        actual[u'state'].pop(u'cost_usd_hour'),
        expected[u'state'].pop(u'cost_usd_hour'),
        places=5)
    self.assertEqual(expected, actual)
Example #3
0
def CMDattributes(_args):
  """Prints out the bot's attributes."""
  from bot_code import bot_main
  json.dump(
      bot_main.get_attributes(), sys.stdout, indent=2, sort_keys=True,
      separators=(',', ': '))
  print('')
  return 0
Example #4
0
 def test_attributes(self):
   actual = json.loads(subprocess42.check_output(
       [sys.executable, self._zip_file, 'attributes'],
       stderr=subprocess42.PIPE))
   expected = bot_main.get_attributes()
   for key in (
       u'cwd', u'disks', u'nb_files_in_temp', u'running_time', u'started_ts'):
     del actual[u'state'][key]
     del expected[u'state'][key]
   del actual[u'version']
   del expected[u'version']
   self.assertAlmostEqual(
       actual[u'state'].pop(u'cost_usd_hour'),
       expected[u'state'].pop(u'cost_usd_hour'),
       places=6)
   self.assertEqual(expected, actual)