Skip to content

Commit 78cfd39

Browse files
sreenithicopybara-github
authored andcommitted
[Python] Fix Python Linux distribtests copy conflicts (grpc#39558)
Recently, the Python Linux distribtests have been having flake failures with an error like: ``` + '[' artifacts '!=' '' ']' + cp -r /tmp/tmp.nb7ZJvoaIS/artifacts /tmpfs/altsrc/github/grpc cp: cannot create regular file '/tmpfs/altsrc/github/grpc/artifacts/grpcio-1.73.0.dev0-cp311-cp311-linux_armv7l.whl': File exists ``` The root cause was found to be one of our recent changes while adding support for musllinux_1_1_aarch64 wheels. Some context on the Linux distribtests build - As part of building the Linux artifacts (`.whl` files), we have [3 types of build targets](https://github.com/grpc/grpc/blob/master/tools/run_tests/task_runner.py#L29-L32) - `artifact_targets`, `distrib_targets` and `package_targets`. Recently in Q1, we added support for `musllinux_1_1_aarch64` wheels and separated the build for these wheels into a separate job by using exclude parameters in the original `distribtests_python` config: [Reference](https://github.com/grpc/grpc/blob/master/tools/internal_ci/linux/grpc_distribtests_python.cfg#L30). While both '[artifact_targets](https://github.com/grpc/grpc/blob/master/tools/internal_ci/linux/grpc_distribtests_python.sh#L44)' and '[distrib_targets](https://github.com/grpc/grpc/blob/master/tools/internal_ci/linux/grpc_distribtests_python.sh#L73)' use these exclude filters during invocation, these exclude filters were missing for the '[package_targets](https://github.com/grpc/grpc/blob/master/tools/internal_ci/linux/grpc_distribtests_python.sh#L56)' causing both package builds to run as below: ``` tools/run_tests/task_runner.py -f package linux python -x build_packages/sponge_log.xml 2025-05-13 16:08:21,278 START: Building targets. Will build 2 targets: python_package, labels ['package', 'python', 'linux'] python_package_musllinux_1_1_aarch64, labels ['package', 'python', 'linux', 'musllinux_1_1', 'aarch64'] ``` But looking at [build_package_python.sh](https://github.com/grpc/grpc/blob/master/tools/run_tests/artifacts/build_package_python.sh#L24) shows that the job only copies all the built artifacts starting with `python_` with no further filters on the type of architecture, meaning that both jobs were trying to copy all the python built artifacts to the same mounted directory parallely, causing these copy conflicts/race conditions. To resolve this, the following fixes are done in this PR: * add exclude flags for musllinux aarch64 while building package_targets * improve package_targets job to include the exclude flag and selectively copy files, such that `python_package_musllinux_1_1_aarch64` job only copies those artifacts and the `python_package` job doesn't copy the musllinux aarch64 artifacts * fixed exclude flags logic as it wasn't working as expected Closes grpc#39558 COPYBARA_INTEGRATE_REVIEW=grpc#39558 from sreenithi:fix_linux_distribtest_cp c51d74e PiperOrigin-RevId: 761890365
1 parent b8cc89c commit 78cfd39

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

tools/internal_ci/linux/grpc_distribtests_python.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ mkdir -p input_artifacts
4949
cp -r artifacts/* input_artifacts/ || true
5050

5151
# This step simply collects python artifacts from subdirectories of input_artifacts/ and copies them to artifacts/
52-
if [[ "${IS_AARCH64_MUSL}" == "True" ]]; then
53-
# Not using TASK_RUNNER_EXTRA_FILTERS since we don't have a target with presubmit tag.
54-
tools/run_tests/task_runner.py -f package linux python musllinux_1_1 aarch64 -x build_packages/sponge_log.xml || FAILED="true"
55-
else
56-
tools/run_tests/task_runner.py -f package linux python -x build_packages/sponge_log.xml || FAILED="true"
57-
fi
52+
53+
# PythonPackage targets do not support the `presubmit` label.
54+
# For this reason we remove `presubmit` label selector from TASK_RUNNER_EXTRA_FILTERS,
55+
# which looks like TASK_RUNNER_EXTRA_FILTERS="presubmit -e aarch64 musllinux_1_1"
56+
# for a presubmit with an exclude filter.
57+
PACKAGE_TASK_RUNNER_EXTRA_FILTERS="${TASK_RUNNER_EXTRA_FILTERS//presubmit /}"
58+
59+
tools/run_tests/task_runner.py -f package linux python ${PACKAGE_TASK_RUNNER_EXTRA_FILTERS} -x build_packages/sponge_log.xml || FAILED="true"
5860

5961
# the next step expects to find the artifacts from the previous step in the "input_artifacts" folder.
6062
# in addition to that, preserve the contents of "artifacts" directory since we want kokoro

tools/run_tests/artifacts/build_package_python.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
set -ex
16+
set -eux
1717

1818
cd "$(dirname "$0")/../../.."
1919

2020
mkdir -p artifacts/
2121

2222
# All the python packages have been built in the artifact phase already
2323
# and we only collect them here to deliver them to the distribtest phase.
24-
cp -r "${EXTERNAL_GIT_ROOT}"/input_artifacts/python_*/* artifacts/ || true
24+
find "${EXTERNAL_GIT_ROOT}"/input_artifacts/ \
25+
-maxdepth 1 \
26+
-type d \
27+
-name "${ARTIFACT_PREFIX}*" \
28+
-not -name "${EXCLUDE_PATTERN}" \
29+
-print0 \
30+
| xargs -0 -I% find % -type f -maxdepth 1 -exec cp -v {} ./artifacts \;
2531

2632
# TODO: all the artifact builder configurations generate a grpcio-VERSION.tar.gz
2733
# source distribution package, and only one of them will end up

tools/run_tests/artifacts/package_targets.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,23 @@ def build_jobspec(self, inner_jobs=None):
165165
dockerfile_dir = (
166166
"tools/dockerfile/grpc_artifact_python_manylinux2014_x64"
167167
)
168+
environ = {
169+
"PYTHON": "/opt/python/cp39-cp39/bin/python",
170+
"ARTIFACT_PREFIX": "python_",
171+
"EXCLUDE_PATTERN": "python_musllinux_1_1_aarch64_*",
172+
}
168173
if "musllinux_1_1" in self.platform and "aarch64" in self.arch:
169174
dockerfile_dir = (
170175
"tools/dockerfile/grpc_artifact_python_musllinux_1_1_aarch64"
171176
)
177+
environ["ARTIFACT_PREFIX"] = "python_musllinux_1_1_aarch64_"
178+
environ["EXCLUDE_PATTERN"] = ""
179+
172180
return create_docker_jobspec(
173181
self.name,
174182
dockerfile_dir,
175183
"tools/run_tests/artifacts/build_package_python.sh",
176-
environ={"PYTHON": "/opt/python/cp39-cp39/bin/python"},
184+
environ=environ,
177185
)
178186

179187

tools/run_tests/task_runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def _create_build_map():
115115
targets = [t for t in targets if all(f in t.labels for f in args.filter)]
116116

117117
# Exclude target if it has ALL of the specified exclude labels.
118-
targets = [t for t in targets if not all(l in args.exclude for l in t.labels)]
118+
if args.exclude:
119+
targets = [
120+
t for t in targets if not all(l in t.labels for l in args.exclude)
121+
]
119122

120123
print("Will build %d targets:" % len(targets))
121124
for target in targets:

0 commit comments

Comments
 (0)