From d61db49b482d1fa7e08f8338570aa76c49ff4732 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 May 2021 08:16:11 +0200 Subject: [PATCH] Add python3.8 aarch64 wheel distribtest (#26136) * add python3.8 aarch64 distribtest * register qemu emulator for linux distribtests --- test/distrib/python/distribtest.py | 2 +- .../python_python38_buster_aarch64/Dockerfile | 18 +++++++++ .../helper_scripts/prepare_qemu_rc | 37 +++++++++++++++++++ tools/internal_ci/linux/grpc_distribtests.sh | 5 +++ .../artifacts/distribtest_targets.py | 1 + 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tools/dockerfile/distribtest/python_python38_buster_aarch64/Dockerfile create mode 100644 tools/internal_ci/helper_scripts/prepare_qemu_rc diff --git a/test/distrib/python/distribtest.py b/test/distrib/python/distribtest.py index 1144786c48d..0fc2854c778 100644 --- a/test/distrib/python/distribtest.py +++ b/test/distrib/python/distribtest.py @@ -18,4 +18,4 @@ import grpc # which is what we are testing here. channel = grpc.insecure_channel('localhost:1000') del channel -print 'Success!' +print('Success!') diff --git a/tools/dockerfile/distribtest/python_python38_buster_aarch64/Dockerfile b/tools/dockerfile/distribtest/python_python38_buster_aarch64/Dockerfile new file mode 100644 index 00000000000..8b14a4396b7 --- /dev/null +++ b/tools/dockerfile/distribtest/python_python38_buster_aarch64/Dockerfile @@ -0,0 +1,18 @@ +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# this an aarch64 image, qemu emulator will be used to run the tests +FROM arm64v8/python:3.8-buster + +RUN pip install virtualenv diff --git a/tools/internal_ci/helper_scripts/prepare_qemu_rc b/tools/internal_ci/helper_scripts/prepare_qemu_rc new file mode 100644 index 00000000000..55bffcc2b5c --- /dev/null +++ b/tools/internal_ci/helper_scripts/prepare_qemu_rc @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright 2021 The gRPC Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Source this rc script to setup and configure qemu userspace emulator on kokoro worker so that we can seamlessly emulate processes running +# inside docker containers. + +# show pre-existing qemu registration +cat /proc/sys/fs/binfmt_misc/qemu-aarch64 + +# Kokoro ubuntu1604 workers have already qemu-user and qemu-user-static packages installed, but it's and old version that: +# * prints warning about some syscalls (e.g "qemu: Unsupported syscall: 278") +# * doesn't register with binfmt_misc with the persistent ("F") flag we need (see below) +# +# To overcome the above limitations, we use the https://github.com/multiarch/qemu-user-static +# docker image to provide a new enough version of qemu-user-static and register it with +# the desired binfmt_misc flags. The most important flag we need is "F" (set by "--persistent yes"), +# which allows the qemu-aarch64-static binary to be loaded eagerly at the time of registration with binfmt_misc. +# That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator +# binary to be accessible from the docker image we're emulating. +# Note that on newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient +# to install qemu-user-static with the right flags. +docker run --rm --privileged multiarch/qemu-user-static:5.2.0-2 --reset --credential yes --persistent yes + +# Print current qemu reqistration to make sure everything is setup correctly. +cat /proc/sys/fs/binfmt_misc/qemu-aarch64 diff --git a/tools/internal_ci/linux/grpc_distribtests.sh b/tools/internal_ci/linux/grpc_distribtests.sh index 47e4bf877a2..b2ec2bf3159 100644 --- a/tools/internal_ci/linux/grpc_distribtests.sh +++ b/tools/internal_ci/linux/grpc_distribtests.sh @@ -20,6 +20,11 @@ cd $(dirname $0)/../../.. source tools/internal_ci/helper_scripts/prepare_build_linux_rc +# some distribtests use a pre-registered binfmt_misc hook +# to automatically execute foreign binaries (such as aarch64) +# under qemu emulator. +source tools/internal_ci/helper_scripts/prepare_qemu_rc + set +ex [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh set -e # rvm commands are very verbose diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index cfbd2905a8e..a2c8d6b1cdd 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -353,6 +353,7 @@ def targets(): PythonDistribTest('linux', 'x64', 'arch'), PythonDistribTest('linux', 'x64', 'ubuntu1604'), PythonDistribTest('linux', 'x64', 'ubuntu1804'), + PythonDistribTest('linux', 'aarch64', 'python38_buster'), PythonDistribTest('linux', 'x64', 'alpine3.7', source=True), PythonDistribTest('linux', 'x64', 'jessie', source=True), PythonDistribTest('linux', 'x86', 'jessie', source=True),