Skip to content

Commit 6eda303

Browse files
committed
Merge branch 'main' of github.com:mozilla/fx-desktop-qa-automation
2 parents c51a155 + 69305d3 commit 6eda303

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

choose_l10n_ci_set.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
2+
import logging
23
import os
34
import re
5+
import subprocess
46
import sys
57
from collections import defaultdict
68
from subprocess import check_output
@@ -32,16 +34,28 @@ def valid_l10n_mappings():
3234
return mapping
3335

3436

35-
def add_selected_mappings(mappings):
37+
def distribute_mappings_evenly(mappings, version):
3638
"""
3739
Write the selected mappings to the output file.
3840
3941
Args:
4042
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
43+
version (int): The beta_version of the beta.
4144
"""
42-
for site, regions in mappings.items():
43-
with open(OUTPUT_FILE, "a+") as f:
44-
f.write(f"{site} {' '.join(regions)}\n")
45+
if not mappings:
46+
return {}
47+
# sort the mappings by the length of the regions per site
48+
mappings = dict(sorted(mappings.items(), key=lambda val: len(val[1]), reverse=True))
49+
# place the mappings into 3 containers evenly according to the load
50+
loads = [0, 0, 0]
51+
containers = [defaultdict(set) for _ in range(3)]
52+
for key, value in mappings.items():
53+
min_idx = loads.index(min(loads))
54+
containers[min_idx][key] = value
55+
loads[min_idx] += len(value)
56+
# get container index according to beta beta_version
57+
run_idx = version % 3
58+
return containers[run_idx]
4559

4660

4761
def process_changed_file(f, selected_mappings):
@@ -53,7 +67,6 @@ def process_changed_file(f, selected_mappings):
5367
selected_mappings: the selected mappings dictionary (updated in place).
5468
"""
5569
split = f.split(SLASH)
56-
5770
if f.startswith(os.path.join("l10n_CM", "sites")) or f.startswith(
5871
os.path.join("l10n_CM", "constants")
5972
):
@@ -73,6 +86,23 @@ def process_changed_file(f, selected_mappings):
7386
selected_mappings[site].add(region)
7487

7588

89+
def save_mappings(selected_container):
90+
"""
91+
Save the selected mappings to the output file.
92+
93+
Args:
94+
selected_container: the selected mappings container.
95+
"""
96+
if not selected_container:
97+
return
98+
current_running_mappings = [
99+
f"{key} {' '.join(value)}\n" for key, value in selected_container.items()
100+
]
101+
logging.warning(f"Running the mappings:\n{''.join(current_running_mappings)}")
102+
with open(OUTPUT_FILE, "a+") as f:
103+
f.writelines(current_running_mappings)
104+
105+
76106
if __name__ == "__main__":
77107
if os.path.exists(".env"):
78108
with open(".env") as fh:
@@ -83,11 +113,27 @@ def process_changed_file(f, selected_mappings):
83113
os.environ["MANUAL"] = "true"
84114
with open(OUTPUT_FILE, "w") as file:
85115
pass # File is created or cleared
116+
try:
117+
beta_version = int(
118+
(
119+
subprocess.check_output(
120+
[sys.executable, "./collect_executables.py", "-n"]
121+
)
122+
.strip()
123+
.decode()
124+
)
125+
.split("-")[0]
126+
.split(".")[1]
127+
.split("b")[1]
128+
)
129+
except ValueError:
130+
# failsafe beta_version
131+
beta_version = 0
86132
l10n_mappings = valid_l10n_mappings()
87133
sample_mappings = {k: v for k, v in l10n_mappings.items() if k.startswith("demo")}
88134
if os.environ.get("TESTRAIL_REPORT") or os.environ.get("MANUAL"):
89135
# Run all tests if this is a scheduled beta or a manual run
90-
add_selected_mappings(l10n_mappings)
136+
save_mappings(distribute_mappings_evenly(l10n_mappings, beta_version))
91137
sys.exit(0)
92138

93139
re_set_all = [
@@ -148,5 +194,5 @@ def process_changed_file(f, selected_mappings):
148194
selected_mappings |= sample_mappings
149195
break
150196

151-
add_selected_mappings(selected_mappings)
197+
save_mappings(distribute_mappings_evenly(selected_mappings, beta_version))
152198
sys.exit(0)

modules/testrail_integration.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import sys
66

7-
from choose_l10n_ci_set import valid_l10n_mappings
7+
from choose_l10n_ci_set import distribute_mappings_evenly, valid_l10n_mappings
88
from modules import taskcluster as tc
99
from modules import testrail as tr
1010
from modules.testrail import TestRail
@@ -187,26 +187,31 @@ def reportable(platform_to_test=None):
187187

188188
plan_entries = this_plan.get("entries")
189189
if os.environ.get("FX_L10N"):
190-
l10n_mappings = valid_l10n_mappings()
190+
report = True
191+
beta_version = int(minor_num.split("b")[-1])
192+
distributed_mappings = distribute_mappings_evenly(
193+
valid_l10n_mappings(), beta_version
194+
)
191195
covered_mappings = 0
192196
# keeping this logic to still see how many mappings are reported.
193197
for entry in plan_entries:
194-
if entry.get("name") in l10n_mappings:
198+
if entry.get("name") in distributed_mappings:
199+
report = False
195200
site = entry.get("name")
196201
for run_ in entry.get("runs"):
197202
if run_.get("config"):
198203
run_region, run_platform = run_.get("config").split("-")
199204
covered_mappings += (
200205
1
201-
if run_region in l10n_mappings[site]
206+
if run_region in distributed_mappings[site]
202207
and platform in run_platform
203208
else 0
204209
)
205210
logging.warning(
206211
f"Potentially matching run found for {platform}, may be reportable. (Found {covered_mappings} site/region mappings reported.)"
207212
)
208213
# Only report when there is a new beta and no other site/region mappings are reported.
209-
return covered_mappings == 0
214+
return report or covered_mappings == 0
210215
else:
211216
covered_suites = 0
212217
for entry in plan_entries:
@@ -352,12 +357,6 @@ def organize_l10n_entries(
352357
if len(site_entries) != 1:
353358
logging.info("Suite entries are broken somehow")
354359

355-
# Add execution link to plan description
356-
357-
os_name = config.split(" ")[0]
358-
description = replace_link_in_description(expected_plan["description"], os_name)
359-
testrail_session.update_plan(plan_id, description=description)
360-
361360
# There should only be one entry per site per plan
362361
# Check that this entry has a run with the correct config
363362
# And if not, make that run
@@ -662,6 +661,12 @@ def collect_changes(testrail_session: TestRail, report):
662661
logging.info(f"Plan found ({expected_plan.get('id')}) but is completed.")
663662
return None
664663

664+
# Add execution link to plan description
665+
666+
os_name = config.split(" ")[0]
667+
description = replace_link_in_description(expected_plan["description"], os_name)
668+
testrail_session.update_plan(expected_plan["id"], description=description)
669+
665670
# Find or add correct config for session
666671

667672
config_matches = None

0 commit comments

Comments
 (0)