Skip to content

Commit

Permalink
add distribtest flow support, try for C# and php
Browse files Browse the repository at this point in the history
  • Loading branch information
jtattermusch committed Sep 29, 2023
1 parent 7118953 commit 6b371fa
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/bazelify_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports_files([
"grpc_run_tests_harness_test.sh",
"grpc_run_bazel_distribtest_test.sh",
"grpc_run_cpp_distribtest_test.sh",
"grpc_run_distribtest_test.sh",
"grpc_run_simple_command_test.sh",
"grpc_build_artifact_task.sh",
"grpc_build_artifact_task_build_test.sh",
Expand Down
40 changes: 40 additions & 0 deletions tools/bazelify_tests/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,43 @@ def grpc_build_artifact_task(name, timeout = None, artifact_deps = [], tags = []
"$(location " + out_archive_name + ")",
]
_dockerized_sh_test(name = test_name, srcs = test_srcs, args = test_args, data = test_data, size = "small", tags = tags, exec_compatible_with = exec_compatible_with, flaky = flaky, docker_image_version = docker_image_version, env = test_env, docker_run_as_root = False)

def grpc_run_distribtest_test(name, artifact_deps = [], size = "medium", timeout = None, tags = [], exec_compatible_with = [], flaky = None, docker_image_version = None, build_script = None, docker_run_as_root = False):
"""Run a distribtest for a previously built artifact/package
Args:
name: The name of the test.
artifact_deps: List of dependencies on artifacts built by another grpc_build_artifact_task.
size: The size of the test.
timeout: The test timeout.
tags: The tags for the test.
exec_compatible_with: A list of constraint values that must be
satisifed for the platform.
flaky: Whether this test is flaky.
docker_image_version: The docker .current_version file to use for docker containerization.
build_script: The script that runs the test.
docker_run_as_root: If True, the test will run under docker as root.
"""

data = [
"//tools/bazelify_tests:grpc_repo_archive_with_submodules.tar.gz",
build_script,
]

args = [
"$(location //tools/bazelify_tests:grpc_repo_archive_with_submodules.tar.gz)",
"$(location " + build_script + ")",
]

# for each artifact task we depends on, use the correponding tar.gz as extra data item and pass its location as an extra arg.
for dep in artifact_deps:
dep_archive_name = str(dep + ".tar.gz")
args.append("$(location " + dep_archive_name + ")")
data.append(dep_archive_name)

srcs = [
"//tools/bazelify_tests:grpc_run_distribtest_test.sh",
]

env = {}
_dockerized_sh_test(name = name, srcs = srcs, args = args, data = data, size = size, timeout = timeout, tags = tags, exec_compatible_with = exec_compatible_with, flaky = flaky, docker_image_version = docker_image_version, env = env, docker_run_as_root = docker_run_as_root)
44 changes: 44 additions & 0 deletions tools/bazelify_tests/grpc_run_distribtest_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Copyright 2023 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.

set -e

ARCHIVE_WITH_SUBMODULES="$1"
BUILD_SCRIPT="$2"
shift 2

# Extract grpc repo archive
tar -xopf ${ARCHIVE_WITH_SUBMODULES}
cd grpc

# Extract all input archives with artifacts into input_artifacts directory
mkdir -p input_artifacts
pushd input_artifacts >/dev/null
# all remaining args are .tar.gz archives with input artifacts
for input_artifact_archive in "$@"
do
# extract the .tar.gz with artifacts into a directory named after a basename
# of the archive itself (and strip the "artifact/" prefix)
# Note that input artifacts from different dependencies can have files
# with the same name, so disambiguating through the name of the archive
# is important.
tar --strip-components=1 --one-top-level -xopf ../../${input_artifact_archive}
done
popd >/dev/null

ls -lR input_artifacts

# Run build script passed as arg.
"${BUILD_SCRIPT}"
86 changes: 85 additions & 1 deletion tools/bazelify_tests/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

load("//bazel:grpc_build_system.bzl", "grpc_package")
load("//tools/bazelify_tests:build_defs.bzl", "grpc_build_artifact_task", "grpc_run_cpp_distribtest_test", "grpc_run_simple_command_test", "grpc_run_tests_harness_test")
load("//tools/bazelify_tests:build_defs.bzl", "grpc_build_artifact_task", "grpc_run_cpp_distribtest_test", "grpc_run_distribtest_test", "grpc_run_simple_command_test", "grpc_run_tests_harness_test")
load(":portability_tests.bzl", "generate_run_tests_portability_tests")
load(":bazel_distribtests.bzl", "generate_bazel_distribtests")

Expand Down Expand Up @@ -294,6 +294,88 @@ grpc_build_artifact_task(
docker_image_version = "tools/dockerfile/test/csharp_debian11_x64.current_version",
)

# C# distribtests

grpc_run_distribtest_test(
name = "distribtest_csharp_linux_x64_debian10",
# depend on the C# packages
artifact_deps = [
"package_csharp_linux",
],
build_script = "run_distribtest_csharp_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/csharp_debian10_x64.current_version",
)

grpc_run_distribtest_test(
name = "distribtest_csharp_linux_x64_ubuntu2204",
# depend on the C# packages
artifact_deps = [
"package_csharp_linux",
],
build_script = "run_distribtest_csharp_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/csharp_ubuntu2204_x64.current_version",
)

grpc_run_distribtest_test(
name = "distribtest_csharp_linux_x64_alpine",
# depend on the C# packages
artifact_deps = [
"package_csharp_linux",
],
build_script = "run_distribtest_csharp_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/csharp_alpine_x64.current_version",
)

grpc_run_distribtest_test(
name = "distribtest_csharp_linux_x64_dotnet31",
# depend on the C# packages
artifact_deps = [
"package_csharp_linux",
],
build_script = "run_distribtest_csharp_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/csharp_dotnet31_x64.current_version",
)

grpc_run_distribtest_test(
name = "distribtest_csharp_linux_x64_dotnet5",
# depend on the C# packages
artifact_deps = [
"package_csharp_linux",
],
build_script = "run_distribtest_csharp_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/csharp_dotnet5_x64.current_version",
)

test_suite(
name = "csharp_distribtests_linux",
tests = [
":distribtest_csharp_linux_x64_alpine",
":distribtest_csharp_linux_x64_debian10",
":distribtest_csharp_linux_x64_dotnet31",
":distribtest_csharp_linux_x64_dotnet5",
":distribtest_csharp_linux_x64_ubuntu2204",
],
)

# PHP distribtests

grpc_run_distribtest_test(
name = "distribtest_php_linux_x64_debian10",
artifact_deps = [
"artifact_php_linux_x64",
],
build_script = "run_distribtest_php_linux.sh",
docker_image_version = "tools/dockerfile/distribtest/php7_debian10_x64.current_version",
docker_run_as_root = True,
)

test_suite(
name = "php_distribtests_linux",
tests = [
":distribtest_php_linux_x64_debian10",
],
)

# TODO(jtattermusch): add grpc_build_artifact_task targets for ruby artifacts (which is tricky, since ruby artifact builds do not run under docker since they invoke docker themselves)

test_suite(
Expand All @@ -316,6 +398,8 @@ test_suite(
":bazel_build_tests_linux",
":bazel_distribtests_linux",
":cpp_distribtests_linux",
":csharp_distribtests_linux",
":php_distribtests_linux",
":portability_tests_linux",
],
)
28 changes: 28 additions & 0 deletions tools/bazelify_tests/test/run_distribtest_csharp_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Copyright 2023 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.

set -ex

# List all input artifacts we obtained for easier troubleshooting.
ls -lR input_artifacts

# Put the input packages where the legacy logic for running
# C# distribtest expects to find them.
# See distribtest_targets.py for details.
# TODO(jtattermusch): get rid of the manual renames of artifact files.
export EXTERNAL_GIT_ROOT="$(pwd)"
mv input_artifacts/package_csharp_linux/* input_artifacts/ || true

test/distrib/csharp/run_distrib_test_dotnetcli.sh
28 changes: 28 additions & 0 deletions tools/bazelify_tests/test/run_distribtest_php_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Copyright 2023 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.

set -ex

# List all input artifacts we obtained for easier troubleshooting.
ls -lR input_artifacts

# Put the input packages where the legacy logic for running
# PHP distribtest expects to find them.
# See distribtest_targets.py for details.
# TODO(jtattermusch): get rid of the manual renames of artifact files.
export EXTERNAL_GIT_ROOT="$(pwd)"
mv input_artifacts/artifact_php_linux_x64/* input_artifacts/ || true

test/distrib/php/run_distrib_test.sh

0 comments on commit 6b371fa

Please sign in to comment.