• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""Generates the appropriate build.json data for all the naming tests."""
16
17import yaml
18import collections
19import hashlib
20import json
21
22_LOCAL_DNS_SERVER_ADDRESS = '127.0.0.1:15353'
23
24
25def _append_zone_name(name, zone_name):
26    return '%s.%s' % (name, zone_name)
27
28
29def _build_expected_addrs_cmd_arg(expected_addrs):
30    out = []
31    for addr in expected_addrs:
32        out.append('%s,%s' % (addr['address'], str(addr['is_balancer'])))
33    return ';'.join(out)
34
35
36def _resolver_test_cases(resolver_component_data):
37    out = []
38    for test_case in resolver_component_data['resolver_component_tests']:
39        target_name = _append_zone_name(
40            test_case['record_to_resolve'],
41            resolver_component_data['resolver_tests_common_zone_name'])
42        out.append({
43            'test_title':
44                target_name,
45            'arg_names_and_values': [
46                ('target_name', target_name),
47                ('do_ordered_address_comparison',
48                 test_case['do_ordered_address_comparison']),
49                ('expected_addrs',
50                 _build_expected_addrs_cmd_arg(test_case['expected_addrs'])),
51                ('expected_chosen_service_config',
52                 (test_case['expected_chosen_service_config'] or '')),
53                ('expected_service_config_error',
54                 (test_case['expected_service_config_error'] or '')),
55                ('expected_lb_policy', (test_case['expected_lb_policy'] or '')),
56                ('enable_srv_queries', test_case['enable_srv_queries']),
57                ('enable_txt_queries', test_case['enable_txt_queries']),
58                ('inject_broken_nameserver_list',
59                 test_case['inject_broken_nameserver_list']),
60            ],
61        })
62    return out
63
64
65def main():
66    resolver_component_data = ''
67    with open('test/cpp/naming/resolver_test_record_groups.yaml') as f:
68        resolver_component_data = yaml.load(f)
69
70    json = {
71        'resolver_tests_common_zone_name':
72            resolver_component_data['resolver_tests_common_zone_name'],
73        # this data is required by the resolver_component_tests_runner.py.template
74        'resolver_component_test_cases':
75            _resolver_test_cases(resolver_component_data),
76    }
77
78    print(yaml.dump(json))
79
80
81if __name__ == '__main__':
82    main()
83