run_dns_server_for_lb_interop_tests.py
Go to the documentation of this file.
1 #!/usr/bin/env python2.7
2 # Copyright 2015 gRPC authors.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import argparse
17 import os
18 import signal
19 import subprocess
20 import sys
21 import tempfile
22 import time
23 
24 import yaml
25 
26 argp = argparse.ArgumentParser(
27  description='Runs a DNS server for LB interop tests')
28 argp.add_argument('-l',
29  '--grpclb_ips',
30  default=None,
31  type=str,
32  help='Comma-separated list of IP addresses of balancers')
33 argp.add_argument(
34  '-f',
35  '--fallback_ips',
36  default=None,
37  type=str,
38  help='Comma-separated list of IP addresses of fallback servers')
39 argp.add_argument(
40  '-c',
41  '--cause_no_error_no_data_for_balancer_a_record',
42  default=False,
43  action='store_const',
44  const=True,
45  help=('Used for testing the case in which the grpclb '
46  'balancer A record lookup results in a DNS NOERROR response '
47  'but with no ANSWER section i.e. no addresses'))
48 args = argp.parse_args()
49 
50 balancer_records = []
51 grpclb_ips = args.grpclb_ips.split(',')
52 if grpclb_ips[0]:
53  for ip in grpclb_ips:
54  balancer_records.append({
55  'TTL': '2100',
56  'data': ip,
57  'type': 'A',
58  })
59 fallback_records = []
60 fallback_ips = args.fallback_ips.split(',')
61 if fallback_ips[0]:
62  for ip in fallback_ips:
63  fallback_records.append({
64  'TTL': '2100',
65  'data': ip,
66  'type': 'A',
67  })
68 records_config_yaml = {
69  'resolver_tests_common_zone_name':
70  'test.google.fr.',
71  'resolver_component_tests': [{
72  'records': {
73  '_grpclb._tcp.server': [{
74  'TTL': '2100',
75  'data': '0 0 12000 balancer',
76  'type': 'SRV'
77  },],
78  'balancer': balancer_records,
79  'server': fallback_records,
80  }
81  }]
82 }
83 if args.cause_no_error_no_data_for_balancer_a_record:
84  balancer_records = records_config_yaml['resolver_component_tests'][0][
85  'records']['balancer']
86  assert not balancer_records
87  # Insert a TXT record at the balancer.test.google.fr. domain.
88  # This TXT record won't actually be resolved or used by gRPC clients;
89  # inserting this record is just a way get the balancer.test.google.fr.
90  # A record queries to return NOERROR DNS responses that also have no
91  # ANSWER section, in order to simulate this failure case.
92  balancer_records.append({
93  'TTL': '2100',
94  'data': 'arbitrary string that wont actually be resolved',
95  'type': 'TXT',
96  })
97 # Generate the actual DNS server records config file
98 records_config_path = tempfile.mktemp()
99 with open(records_config_path, 'w') as records_config_generated:
100  records_config_generated.write(yaml.dump(records_config_yaml))
101 
102 with open(records_config_path, 'r') as records_config_generated:
103  sys.stderr.write('===== DNS server records config: =====\n')
104  sys.stderr.write(records_config_generated.read())
105  sys.stderr.write('======================================\n')
106 
107 # Run the DNS server
108 # Note that we need to add the extra
109 # A record for metadata.google.internal in order for compute engine
110 # OAuth creds and ALTS creds to work.
111 # TODO(apolcyn): should metadata.google.internal always resolve
112 # to 169.254.169.254?
113 subprocess.check_output([
114  '/var/local/git/grpc/test/cpp/naming/utils/dns_server.py',
115  '--port=53',
116  '--records_config_path',
117  records_config_path,
118  '--add_a_record=metadata.google.internal:169.254.169.254',
119 ])
open
#define open
Definition: test-fs.c:46


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:08