Pull out parsing functions

pull/23892/head
Richard Belleville 4 years ago
parent a12674fac1
commit 324ade3638
  1. 38
      src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py

@ -271,6 +271,28 @@ def _run(args: argparse.Namespace, methods: Sequence[str],
method_handle.stop() method_handle.stop()
def parse_metadata_arg(metadata_arg: str) -> PerMethodMetadataType:
metadata = metadata_arg.split(",") if args.metadata else []
per_method_metadata = collections.defaultdict(list)
for metadatum in metadata:
elems = metadatum.split(":")
if len(elems) != 3:
raise ValueError(
f"'{metadatum}' was not in the form 'METHOD:KEY:VALUE'")
if elems[0] not in _SUPPORTED_METHODS:
raise ValueError(f"Unrecognized method '{elems[0]}'")
per_method_metadata[elems[0]].append((elems[1], elems[2]))
return per_method_metadata
def parse_rpc_arg(rpc_arg: str) -> Sequence[str]:
methods = rpc_arg.split(",")
if set(methods) - set(_SUPPORTED_METHODS):
raise ValueError("--rpc supported methods: {}".format(
", ".join(_SUPPORTED_METHODS)))
return methods
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Run Python XDS interop client.') description='Run Python XDS interop client.')
@ -325,18 +347,4 @@ if __name__ == "__main__":
file_handler = logging.FileHandler(args.log_file, mode='a') file_handler = logging.FileHandler(args.log_file, mode='a')
file_handler.setFormatter(formatter) file_handler.setFormatter(formatter)
logger.addHandler(file_handler) logger.addHandler(file_handler)
methods = args.rpc.split(",") _run(args, parse_rpc_arg(args.rpc), parse_metadata_arg(args.metadata))
if set(methods) - set(_SUPPORTED_METHODS):
raise ValueError("--rpc supported methods: {}".format(
", ".join(_SUPPORTED_METHODS)))
per_method_metadata = collections.defaultdict(list)
metadata = args.metadata.split(",") if args.metadata else []
for metadatum in metadata:
elems = metadatum.split(":")
if len(elems) != 3:
raise ValueError(
f"'{metadatum}' was not in the form 'METHOD:KEY:VALUE'")
if elems[0] not in _SUPPORTED_METHODS:
raise ValueError(f"Unrecognized method '{elems[0]}'")
per_method_metadata[elems[0]].append((elems[1], elems[2]))
_run(args, methods, per_method_metadata)

Loading…
Cancel
Save