aboutsummaryrefslogtreecommitdiff
path: root/src/python/grpcio_tests/tests_aio/interop/client.py
blob: bbc1b2fb15f2570d52eb7c40e3ba3422593ce031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2019 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.

import argparse
import asyncio
import logging
import os
import sys

import grpc
from grpc.experimental import aio

from tests.interop import client as interop_client_lib
from tests_aio.interop import methods

_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.DEBUG)


def _create_channel(args):
    target = f"{args.server_host}:{args.server_port}"

    if (
        args.use_tls
        or args.use_alts
        or args.custom_credentials_type is not None
    ):
        (
            channel_credentials,
            options,
        ) = interop_client_lib.get_secure_channel_parameters(args)
        return aio.secure_channel(target, channel_credentials, options)
    else:
        return aio.insecure_channel(target)


def _test_case_from_arg(test_case_arg):
    for test_case in methods.TestCase:
        if test_case_arg == test_case.value:
            return test_case
    else:
        raise ValueError('No test case "%s"!' % test_case_arg)


async def test_interoperability():
    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)
    await methods.test_interoperability(test_case, stub, args)


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    asyncio.get_event_loop().set_debug(True)
    asyncio.get_event_loop().run_until_complete(test_interoperability())