run_test_client.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright 2016 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. from absl import app
  16. from absl import flags
  17. from framework import xds_flags
  18. from framework import xds_k8s_flags
  19. from framework.infrastructure import k8s
  20. from framework.test_app import client_app
  21. logger = logging.getLogger(__name__)
  22. # Flags
  23. _CMD = flags.DEFINE_enum(
  24. 'cmd', default='run', enum_values=['run', 'cleanup'],
  25. help='Command')
  26. _SECURE = flags.DEFINE_bool(
  27. "secure", default=False,
  28. help="Run client in the secure mode")
  29. _QPS = flags.DEFINE_integer('qps', default=25, help='Queries per second')
  30. _PRINT_RESPONSE = flags.DEFINE_bool(
  31. "print_response", default=False,
  32. help="Client prints responses")
  33. _REUSE_NAMESPACE = flags.DEFINE_bool(
  34. "reuse_namespace", default=True,
  35. help="Use existing namespace if exists")
  36. _CLEANUP_NAMESPACE = flags.DEFINE_bool(
  37. "cleanup_namespace", default=False,
  38. help="Delete namespace during resource cleanup")
  39. flags.adopt_module_key_flags(xds_flags)
  40. flags.adopt_module_key_flags(xds_k8s_flags)
  41. def main(argv):
  42. if len(argv) > 1:
  43. raise app.UsageError('Too many command-line arguments.')
  44. # Base namespace
  45. namespace = xds_flags.NAMESPACE.value
  46. client_namespace = namespace
  47. runner_kwargs = dict(
  48. deployment_name=xds_flags.CLIENT_NAME.value,
  49. image_name=xds_k8s_flags.CLIENT_IMAGE.value,
  50. gcp_service_account=xds_k8s_flags.GCP_SERVICE_ACCOUNT.value,
  51. network=xds_flags.NETWORK.value,
  52. td_bootstrap_image=xds_k8s_flags.TD_BOOTSTRAP_IMAGE.value,
  53. stats_port=xds_flags.CLIENT_PORT.value,
  54. reuse_namespace=_REUSE_NAMESPACE.value)
  55. if _SECURE.value:
  56. runner_kwargs.update(
  57. deployment_template='client-secure.deployment.yaml')
  58. k8s_api_manager = k8s.KubernetesApiManager(xds_k8s_flags.KUBE_CONTEXT.value)
  59. client_runner = client_app.KubernetesClientRunner(
  60. k8s.KubernetesNamespace(k8s_api_manager, client_namespace),
  61. **runner_kwargs)
  62. # Server target
  63. server_xds_host = xds_flags.SERVER_XDS_HOST.value
  64. server_xds_port = xds_flags.SERVER_XDS_PORT.value
  65. if _CMD.value == 'run':
  66. logger.info('Run client, secure_mode=%s', _SECURE.value)
  67. client_runner.run(
  68. server_target=f'xds:///{server_xds_host}:{server_xds_port}',
  69. qps=_QPS.value,
  70. print_response=_PRINT_RESPONSE.value,
  71. secure_mode=_SECURE.value)
  72. elif _CMD.value == 'cleanup':
  73. logger.info('Cleanup client')
  74. client_runner.cleanup(force=True,
  75. force_namespace=_CLEANUP_NAMESPACE.value)
  76. if __name__ == '__main__':
  77. app.run(main)