From 21c92da7ed3b8de9f76d83149dfbe197f662fbe3 Mon Sep 17 00:00:00 2001 From: Vignesh Babu Date: Thu, 19 Oct 2023 15:35:50 -0700 Subject: [PATCH] [interop] Add absl dependency to interop clients (#34666) Similar to https://github.com/grpc/grpc/pull/33830 but adds the absl dependency on the client side. Requires a cherrypick --- src/python/grpcio_tests/commands.py | 2 +- src/python/grpcio_tests/tests/interop/BUILD.bazel | 1 + src/python/grpcio_tests/tests/interop/client.py | 14 +++++++------- src/python/grpcio_tests/tests/stress/client.py | 13 ++++++------- .../grpcio_tests/tests_aio/interop/client.py | 3 ++- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 32311cea101..4869899aeff 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -202,7 +202,7 @@ class RunInterop(test.test): from tests.interop import client sys.argv[1:] = self.args.split() - client.test_interoperability() + client.test_interoperability(client.parse_interop_client_args(sys.argv)) class RunFork(test.test): diff --git a/src/python/grpcio_tests/tests/interop/BUILD.bazel b/src/python/grpcio_tests/tests/interop/BUILD.bazel index 2d164847423..75366d67c4a 100644 --- a/src/python/grpcio_tests/tests/interop/BUILD.bazel +++ b/src/python/grpcio_tests/tests/interop/BUILD.bazel @@ -33,6 +33,7 @@ py_library( ":resources", "//src/proto/grpc/testing:py_test_proto", "//src/python/grpcio/grpc:grpcio", + requirement("absl-py"), requirement("google-auth"), ], ) diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py index 14095344b17..6075ac5a588 100644 --- a/src/python/grpcio_tests/tests/interop/client.py +++ b/src/python/grpcio_tests/tests/interop/client.py @@ -13,9 +13,10 @@ # limitations under the License. """The Python implementation of the GRPC interoperability test client.""" -import argparse import os +from absl import app +from absl.flags import argparse_flags from google import auth as google_auth from google.auth import jwt as google_auth_jwt import grpc @@ -25,8 +26,8 @@ from tests.interop import methods from tests.interop import resources -def parse_interop_client_args(): - parser = argparse.ArgumentParser() +def parse_interop_client_args(argv): + parser = argparse_flags.ArgumentParser() parser.add_argument( "--server_host", default="localhost", @@ -92,7 +93,7 @@ def parse_interop_client_args(): " round_robin " + "or pick_first)." ), ) - return parser.parse_args() + return parser.parse_args(argv[1:]) def _create_call_credentials(args): @@ -214,8 +215,7 @@ def _test_case_from_arg(test_case_arg): raise ValueError('No test case "%s"!' % test_case_arg) -def test_interoperability(): - args = parse_interop_client_args() +def test_interoperability(args): channel = _create_channel(args) stub = create_stub(channel, args) test_case = _test_case_from_arg(args.test_case) @@ -223,4 +223,4 @@ def test_interoperability(): if __name__ == "__main__": - test_interoperability() + app.run(test_interoperability, flags_parser=parse_interop_client_args) diff --git a/src/python/grpcio_tests/tests/stress/client.py b/src/python/grpcio_tests/tests/stress/client.py index a7cf40c0852..9cd88ae5917 100644 --- a/src/python/grpcio_tests/tests/stress/client.py +++ b/src/python/grpcio_tests/tests/stress/client.py @@ -13,11 +13,12 @@ # limitations under the License. """Entry point for running stress tests.""" -import argparse from concurrent import futures import queue import threading +from absl import app +from absl.flags import argparse_flags import grpc from src.proto.grpc.testing import metrics_pb2_grpc @@ -29,10 +30,8 @@ from tests.stress import metrics_server from tests.stress import test_runner -def _args(): - parser = argparse.ArgumentParser( - description="gRPC Python stress test client" - ) +def _args(argv): + parser = argparse_flags.ArgumentParser() parser.add_argument( "--server_addresses", help="comma separated list of hostname:port to run servers on", @@ -83,7 +82,7 @@ def _args(): help="the server host to which to claim to connect", type=str, ) - return parser.parse_args() + return parser.parse_args(argv[1:]) def _test_case_from_arg(test_case_arg): @@ -174,4 +173,4 @@ def run_test(args): if __name__ == "__main__": - run_test(_args()) + app.run(run_test, flags_parser=_args) diff --git a/src/python/grpcio_tests/tests_aio/interop/client.py b/src/python/grpcio_tests/tests_aio/interop/client.py index f9f7d370e58..bbc1b2fb15f 100644 --- a/src/python/grpcio_tests/tests_aio/interop/client.py +++ b/src/python/grpcio_tests/tests_aio/interop/client.py @@ -16,6 +16,7 @@ import argparse import asyncio import logging import os +import sys import grpc from grpc.experimental import aio @@ -53,7 +54,7 @@ def _test_case_from_arg(test_case_arg): async def test_interoperability(): - args = interop_client_lib.parse_interop_client_args() + args = interop_client_lib.parse_interop_client_args(sys.argv) channel = _create_channel(args) stub = interop_client_lib.create_stub(channel, args) test_case = _test_case_from_arg(args.test_case)