Commit c7d37970 authored by Caleb Rouleau's avatar Caleb Rouleau Committed by Commit Bot

[Perf] Make trigger script use python3 print function.

Make the unittests exercise this by adding
    args.multiple_dimension_script_verbose = True
which makes verbose be true everywhere so that we
can make sure the print statements work.

Also add in some additional print statements to clarify what is
happening.

Also fix a couple easy formatting issues.

Bug: 984504, 956637
Change-Id: Ib4dc4236e57f47f0c92eba84db5ae4d9cc969309
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934526
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Auto-Submit: Caleb Rouleau <crouleau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718921}
parent 507f4ee8
......@@ -44,6 +44,8 @@ This script is normally called from the swarming recipe module in tools/build.
"""
from __future__ import print_function
import argparse
import copy
import json
......@@ -56,7 +58,7 @@ import urllib
import base_test_triggerer
class Bot(object):
""" Eligible bots to run the task"""
"""Eligible bots to run the task."""
def __init__(self, bot_id, is_alive):
self._bot_id = bot_id
self._is_alive = is_alive
......@@ -161,7 +163,7 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
shard_to_bot_assignment_map[shard_index] = \
unallocated_healthy_bots.pop()
if verbose:
print 'First time shard %d has been triggered' % shard_index
print('First time shard %d has been triggered' % shard_index)
elif not bot:
shard_to_bot_assignment_map[shard_index] = unallocated_bad_bots.pop()
......@@ -172,8 +174,9 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
healthy_bot = unallocated_healthy_bots.pop()
shard_to_bot_assignment_map[shard_index] = healthy_bot
if verbose:
print ('Device affinity broken for bot %s, new '
'mapping to bot %s' % (dead_bot.id(), healthy_bot.id()))
print('Device affinity broken for shard #%d. bot %s is dead, new '
'mapping to bot %s' % (
shard_index, dead_bot.id(), healthy_bot.id()))
# Now populate the indices into the bot_configs array
selected_configs = []
......@@ -190,17 +193,18 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
def _print_device_affinity_info(
self, new_map, existing_map, health_map, num_shards):
print()
for shard_index in xrange(num_shards):
existing = existing_map.get(shard_index, None)
new = new_map.get(shard_index, None)
existing_id = ""
existing_id = ''
if existing:
existing_id = existing.id()
new_id = ""
new_id = ''
if new:
new_id = new.id()
print "Shard %d\n\tprevious: %s\n\tnew: %s" % (
shard_index, existing_id, new_id)
print('Shard %d\n\tprevious: %s\n\tnew: %s' % (
shard_index, existing_id, new_id))
healthy_bots = []
dead_bots = []
......@@ -209,12 +213,16 @@ class PerfDeviceTriggerer(base_test_triggerer.BaseTestTriggerer):
healthy_bots.append(b.id())
else:
dead_bots.append(b.id())
print "Healthy bots: %s" % healthy_bots
print "Dead Bots: %s" % dead_bots
print('Shards needed: %d' % num_shards)
print('Total bots (dead + healthy): %d' % (
len(dead_bots) + len(healthy_bots)))
print('Healthy bots, %d: %s' % (len(healthy_bots), healthy_bots))
print('Dead Bots, %d: %s' % (len(dead_bots), dead_bots))
print()
def _query_swarming_for_eligible_bot_configs(self, dimensions):
""" Query Swarming to figure out which bots are available.
"""Query Swarming to figure out which bots are available.
Returns: a dictionary in which the keys are the bot id and
the values are Bot object that indicate the health status
......
......@@ -58,6 +58,7 @@ class UnitTest(unittest.TestCase):
args = Args()
args.shards = len(previous_task_assignment_map)
args.dump_json = 'output.json'
args.multiple_dimension_script_verbose = True
swarming_args = [
'trigger',
'--swarming',
......@@ -275,7 +276,7 @@ class UnitTest(unittest.TestCase):
self.assertIn(expected_task_assignment.get(1), new_healthy_bots)
self.assertIn(expected_task_assignment.get(2), new_healthy_bots)
def test_previously_duplicate_task_assignemnts(self):
def test_previously_duplicate_task_assignments(self):
triggerer = self.setup_and_trigger(
previous_task_assignment_map={0: 'build3', 1: 'build3', 2: 'build5',
3: 'build6'},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment