Ejemplo n.º 1
0
def _post_process(snapshot, bots_active, bots_inactive, tasks_active):
  """Completes the _Snapshot instance with additional data."""
  for dimensions_json, tasks in tasks_active.iteritems():
    snapshot.get_dimensions(dimensions_json).tasks_active = len(tasks)

  snapshot.bot_ids = sorted(bots_active)
  snapshot.bot_ids_bad = sorted(bots_inactive)
  for bot_id, dimensions in bots_active.iteritems():
    # Looks at the current buckets, do not create one.
    for bucket in snapshot.buckets:
      # If this bot matches these dimensions, mark it as a member of this group.
      if task_to_run.match_dimensions(
          json.loads(bucket.dimensions), dimensions):
        # This bot could be used for requests on this dimensions filter.
        if not bot_id in bucket.bot_ids:
          bucket.bot_ids.append(bot_id)
          bucket.bot_ids.sort()

  for bot_id, dimensions in bots_inactive.iteritems():
    # Looks at the current buckets, do not create one.
    for bucket in snapshot.buckets:
      # If this bot matches these dimensions, mark it as a member of this group.
      if task_to_run.match_dimensions(
          json.loads(bucket.dimensions), dimensions):
        # This bot could be used for requests on this dimensions filter.
        if not bot_id in bucket.bot_ids_bad:
          bucket.bot_ids_bad.append(bot_id)
          bucket.bot_ids_bad.sort()
Ejemplo n.º 2
0
def _post_process(snapshot, bots_active, bots_inactive, tasks_active):
    """Completes the _Snapshot instance with additional data."""
    for dimensions_json, tasks in tasks_active.iteritems():
        snapshot.get_dimensions(dimensions_json).tasks_active = len(tasks)

    snapshot.bot_ids = sorted(bots_active)
    snapshot.bot_ids_bad = sorted(bots_inactive)
    for bot_id, dimensions in bots_active.iteritems():
        # Looks at the current buckets, do not create one.
        for bucket in snapshot.buckets:
            # If this bot matches these dimensions, mark it as a member of this group.
            if task_to_run.match_dimensions(json.loads(bucket.dimensions),
                                            dimensions):
                # This bot could be used for requests on this dimensions filter.
                if not bot_id in bucket.bot_ids:
                    bucket.bot_ids.append(bot_id)
                    bucket.bot_ids.sort()

    for bot_id, dimensions in bots_inactive.iteritems():
        # Looks at the current buckets, do not create one.
        for bucket in snapshot.buckets:
            # If this bot matches these dimensions, mark it as a member of this group.
            if task_to_run.match_dimensions(json.loads(bucket.dimensions),
                                            dimensions):
                # This bot could be used for requests on this dimensions filter.
                if not bot_id in bucket.bot_ids_bad:
                    bucket.bot_ids_bad.append(bot_id)
                    bucket.bot_ids_bad.sort()
Ejemplo n.º 3
0
    def test_match_dimensions(self):
        data_true = (
            ({}, {}),
            ({}, {"a": "b"}),
            ({"a": "b"}, {"a": "b"}),
            ({"os": "amiga"}, {"os": ["amiga", "amiga-3.1"]}),
            ({"os": "amiga", "foo": "bar"}, {"os": ["amiga", "amiga-3.1"], "a": "b", "foo": "bar"}),
        )

        for request_dimensions, bot_dimensions in data_true:
            self.assertEqual(True, task_to_run.match_dimensions(request_dimensions, bot_dimensions))

        data_false = (({"os": "amiga"}, {"os": ["Win", "Win-3.1"]}),)
        for request_dimensions, bot_dimensions in data_false:
            self.assertEqual(False, task_to_run.match_dimensions(request_dimensions, bot_dimensions))
Ejemplo n.º 4
0
    def test_match_dimensions(self):
        data_true = (
            ({}, {}),
            ({}, {
                'a': 'b'
            }),
            ({
                'a': ['b']
            }, {
                'a': ['b']
            }),
            ({
                'os': ['amiga']
            }, {
                'os': ['amiga', 'amiga-3.1']
            }),
            ({
                'os': ['amiga'],
                'foo': ['bar']
            }, {
                'os': ['amiga', 'amiga-3.1'],
                'a': 'b',
                'foo': 'bar'
            }),
            ({
                'os': ['amiga', 'amiga-3.1'],
                'foo': ['bar']
            }, {
                'os': ['amiga', 'amiga-3.1'],
                'a': 'b',
                'foo': 'bar'
            }),
        )

        for request_dimensions, bot_dimensions in data_true:
            self.assertEqual(
                True,
                task_to_run.match_dimensions(request_dimensions,
                                             bot_dimensions))

        data_false = (({'os': ['amiga']}, {'os': ['Win', 'Win-3.1']}), )
        for request_dimensions, bot_dimensions in data_false:
            self.assertEqual(
                False,
                task_to_run.match_dimensions(request_dimensions,
                                             bot_dimensions))
Ejemplo n.º 5
0
  def test_match_dimensions(self):
    data_true = (
      ({}, {}),
      ({}, {'a': 'b'}),
      ({'a': 'b'}, {'a': 'b'}),
      ({'os': 'amiga'}, {'os': ['amiga', 'amiga-3.1']}),
      ( {'os': 'amiga', 'foo': 'bar'},
        {'os': ['amiga', 'amiga-3.1'], 'a': 'b', 'foo': 'bar'}),
    )

    for request_dimensions, bot_dimensions in data_true:
      self.assertEqual(
          True,
          task_to_run.match_dimensions(request_dimensions, bot_dimensions))

    data_false = (
      ({'os': 'amiga'}, {'os': ['Win', 'Win-3.1']}),
    )
    for request_dimensions, bot_dimensions in data_false:
      self.assertEqual(
          False,
          task_to_run.match_dimensions(request_dimensions, bot_dimensions))