Example #1
0
  def _gen_data(self):
    dimensions = {'os': 'Amiga', 'hostname': 'host3'}
    # Description of the log entries:
    # - host3 is idle
    # - 100 was enqueue
    # - 101 was started by host2
    # - 101 was completed by host2
    # - 201 had bot host1 died on it
    # - 300 expired
    # - 402 is running on host4
    data = (
      stats._pack_entry(action='bot_active', bot_id='host3', dimensions={}),
      stats._pack_entry(action='bot_inactive', bot_id='failed1', dimensions={}),

      stats._pack_entry(
          action='task_enqueued', task_id='100', dimensions={}, user='******'),
      stats._pack_entry(
          action='run_started', run_id='101', bot_id='host2',
          dimensions={}, pending_ms=1500, user='******'),
      stats._pack_entry(
          action='run_completed', run_id='101', bot_id='host2',
          dimensions={}, runtime_ms=6000, user='******'),
      stats._pack_entry(
          action='task_completed', task_id='100',
          dimensions={}, pending_ms=6000, user='******'),

      stats._pack_entry(
          action='run_bot_died', run_id='201', bot_id='host1',
          dimensions=dimensions, user='******'),

      stats._pack_entry(
          action='task_request_expired', task_id='300', dimensions={},
          user='******'),

      stats._pack_entry(
          action='run_updated', run_id='402', bot_id='host4',
          dimensions={}),
    )
    actions_tested = sorted(stats._unpack_entry(i)['action'] for i in data)
    self.assertEqual(sorted(map(unicode, stats._VALID_ACTIONS)), actions_tested)

    snapshot = stats._Snapshot()
    bots_active = {}
    bots_inactive = {}
    tasks_active = {}
    for line in data:
      actual = stats._parse_line(
          line, snapshot, bots_active, bots_inactive, tasks_active)
      self.assertIs(True, actual, line)

    stats._post_process(snapshot, bots_active, bots_inactive, tasks_active)
    return snapshot
Example #2
0
    def test_parse_task_active(self):
        # It is important to note that it is the request properties that are logged,
        # not the bot properties.
        data = (
            stats._pack_entry(action='run_updated',
                              run_id='201',
                              bot_id='host1',
                              dimensions={'os': 'Linux'}),
            stats._pack_entry(action='run_updated',
                              run_id='201',
                              bot_id='host1',
                              dimensions={'os': 'Linux'}),
            stats._pack_entry(action='run_updated',
                              run_id='301',
                              bot_id='host2',
                              dimensions={'os': 'Windows'}),
            stats._pack_entry(action='bot_active',
                              bot_id='host3',
                              dimensions={'os': ['Windows', 'Windows-3.1']}),
            stats._pack_entry(action='bot_active',
                              bot_id='host4',
                              dimensions={'os': ['Linux', 'Linux-12.04']}),
        )

        snapshot = stats._Snapshot()
        bots_active = {}
        bots_inactive = {}
        tasks_active = {}
        for line in data:
            actual = stats._parse_line(line, snapshot, bots_active,
                                       bots_inactive, tasks_active)
            self.assertEqual(True, actual)
        stats._post_process(snapshot, bots_active, bots_inactive, tasks_active)

        expected = [
            '{"os":"Linux"}',
            '{"os":"Windows"}',
        ]
        self.assertEqual(expected, [i.dimensions for i in snapshot.buckets])
        self.assertEqual(0, len(snapshot.users))
Example #3
0
  def test_parse_task_active(self):
    # It is important to note that it is the request properties that are logged,
    # not the bot properties.
    data = (
      stats._pack_entry(
          action='run_updated', run_id='201', bot_id='host1',
          dimensions={'os': 'Linux'}),
      stats._pack_entry(
          action='run_updated', run_id='201', bot_id='host1',
          dimensions={'os': 'Linux'}),
      stats._pack_entry(
          action='run_updated', run_id='301', bot_id='host2',
          dimensions={'os': 'Windows'}),
      stats._pack_entry(
          action='bot_active', bot_id='host3',
          dimensions={'os': ['Windows', 'Windows-3.1']}),
      stats._pack_entry(
          action='bot_active', bot_id='host4',
          dimensions={'os': ['Linux', 'Linux-12.04']}),
    )

    snapshot = stats._Snapshot()
    bots_active = {}
    bots_inactive = {}
    tasks_active = {}
    for line in data:
      actual = stats._parse_line(
          line, snapshot, bots_active, bots_inactive, tasks_active)
      self.assertEqual(True, actual)
    stats._post_process(snapshot, bots_active, bots_inactive, tasks_active)

    expected = [
      '{"os":"Linux"}',
      '{"os":"Windows"}',
    ]
    self.assertEqual(expected, [i.dimensions for i in snapshot.buckets])
    self.assertEqual(0, len(snapshot.users))
Example #4
0
    def _gen_data(self):
        dimensions = {'os': 'Amiga', 'hostname': 'host3'}
        # Description of the log entries:
        # - host3 is idle
        # - 100 was enqueue
        # - 101 was started by host2
        # - 101 was completed by host2
        # - 201 had bot host1 died on it
        # - 300 expired
        # - 402 is running on host4
        data = (
            stats._pack_entry(action='bot_active',
                              bot_id='host3',
                              dimensions={}),
            stats._pack_entry(action='bot_inactive',
                              bot_id='failed1',
                              dimensions={}),
            stats._pack_entry(action='task_enqueued',
                              task_id='100',
                              dimensions={},
                              user='******'),
            stats._pack_entry(action='run_started',
                              run_id='101',
                              bot_id='host2',
                              dimensions={},
                              pending_ms=1500,
                              user='******'),
            stats._pack_entry(action='run_completed',
                              run_id='101',
                              bot_id='host2',
                              dimensions={},
                              runtime_ms=6000,
                              user='******'),
            stats._pack_entry(action='task_completed',
                              task_id='100',
                              dimensions={},
                              pending_ms=6000,
                              user='******'),
            stats._pack_entry(action='run_bot_died',
                              run_id='201',
                              bot_id='host1',
                              dimensions=dimensions,
                              user='******'),
            stats._pack_entry(action='task_request_expired',
                              task_id='300',
                              dimensions={},
                              user='******'),
            stats._pack_entry(action='run_updated',
                              run_id='402',
                              bot_id='host4',
                              dimensions={}),
        )
        actions_tested = sorted(stats._unpack_entry(i)['action'] for i in data)
        self.assertEqual(sorted(map(unicode, stats._VALID_ACTIONS)),
                         actions_tested)

        snapshot = stats._Snapshot()
        bots_active = {}
        bots_inactive = {}
        tasks_active = {}
        for line in data:
            actual = stats._parse_line(line, snapshot, bots_active,
                                       bots_inactive, tasks_active)
            self.assertIs(True, actual, line)

        stats._post_process(snapshot, bots_active, bots_inactive, tasks_active)
        return snapshot
Example #5
0
 def _parse_line(self, line):
   # pylint: disable=W0212
   actual = stats._parse_line(line, stats._Snapshot(), {}, {}, {})
   self.assertIs(True, actual, line)
Example #6
0
 def _parse_line(self, line):
     # pylint: disable=W0212
     actual = stats._parse_line(line, stats._Snapshot(), {}, {}, {})
     self.assertEqual(True, actual, line)