Move python DNS utilities to utils subdirectory

pull/14610/head
Alexander Polcyn 7 years ago
parent 3c5e12de08
commit 0a05b782fe
  1. 1
      bazel/grpc_build_system.bzl
  2. 16
      templates/test/cpp/naming/resolver_component_tests_defs.include
  3. 28
      test/cpp/naming/BUILD
  4. 6
      test/cpp/naming/generate_resolver_component_tests.bzl
  5. 40
      test/cpp/naming/resolver_component_tests_runner.sh
  6. 32
      test/cpp/naming/resolver_component_tests_runner_invoker.cc
  7. 50
      test/cpp/naming/utils/BUILD
  8. 0
      test/cpp/naming/utils/dns_resolver.py
  9. 0
      test/cpp/naming/utils/dns_server.py
  10. 0
      test/cpp/naming/utils/tcp_connect.py

@ -174,6 +174,7 @@ def grpc_py_binary(name, srcs, data = [], deps = [], external_deps = [], testonl
native.py_binary(
name = name,
srcs = srcs,
testonly = testonly,
data = data,
deps = deps + _get_external_deps(external_deps)
)

@ -21,11 +21,11 @@ set -ex
FLAGS_test_bin_path=$(echo "$1" | grep '\--test_bin_path=' | cut -d "=" -f 2)
FLAGS_dns_server_bin_path=$(echo "$2" | grep '\--dns_server_bin_path=' | cut -d "=" -f 2)
FLAGS_records_config_path=$(echo "$3" | grep '\--records_config_path=' | cut -d "=" -f 2)
FLAGS_test_dns_server_port=$(echo "$4" | grep '\--test_dns_server_port=' | cut -d "=" -f 2)
FLAGS_test_dns_resolver_bin_path=$(echo "$5" | grep '\--test_dns_resolver_bin_path=' | cut -d "=" -f 2)
FLAGS_test_tcp_connect_bin_path=$(echo "$6" | grep '\--test_tcp_connect_bin_path=' | cut -d "=" -f 2)
FLAGS_dns_server_port=$(echo "$4" | grep '\--dns_server_port=' | cut -d "=" -f 2)
FLAGS_dns_resolver_bin_path=$(echo "$5" | grep '\--dns_resolver_bin_path=' | cut -d "=" -f 2)
FLAGS_tcp_connect_bin_path=$(echo "$6" | grep '\--tcp_connect_bin_path=' | cut -d "=" -f 2)
for cmd_arg in "$FLAGS_test_bin_path" "$FLAGS_dns_server_bin_path" "$FLAGS_records_config_path" "$FLAGS_test_dns_server_port" "$FLAGS_test_dns_resolver_bin_path" "$FLAGS_test_tcp_connect_bin_path"; do
for cmd_arg in "$FLAGS_test_bin_path" "$FLAGS_dns_server_bin_path" "$FLAGS_records_config_path" "$FLAGS_dns_server_port" "$FLAGS_dns_resolver_bin_path" "$FLAGS_tcp_connect_bin_path"; do
if [[ "$cmd_arg" == "" ]]; then
echo "Missing a CMD arg" && exit 1
fi
@ -36,7 +36,7 @@ if [[ "$GRPC_DNS_RESOLVER" != "" && "$GRPC_DNS_RESOLVER" != ares ]]; then
fi
export GRPC_DNS_RESOLVER=ares
"$FLAGS_dns_server_bin_path" --records_config_path="$FLAGS_records_config_path" --port="$FLAGS_test_dns_server_port" > /dev/null 2>&1 &
"$FLAGS_dns_server_bin_path" --records_config_path="$FLAGS_records_config_path" --port="$FLAGS_dns_server_port" > /dev/null 2>&1 &
DNS_SERVER_PID=$!
echo "Local DNS server started. PID: $DNS_SERVER_PID"
@ -45,8 +45,8 @@ for ((i=0;i<30;i++));
do
echo "Retry health-check local DNS server by attempting a DNS query and TCP handshake"
RETRY=0
$FLAGS_test_dns_resolver_bin_path -s 127.0.0.1 -p "$FLAGS_test_dns_server_port" -n health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. -t 1 | grep '123.123.123.123' || RETRY=1
$FLAGS_test_tcp_connect_bin_path -s 127.0.0.1 -p "$FLAGS_test_dns_server_port" -t 1 || RETRY=1
$FLAGS_dns_resolver_bin_path -s 127.0.0.1 -p "$FLAGS_dns_server_port" -n health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. -t 1 | grep '123.123.123.123' || RETRY=1
$FLAGS_tcp_connect_bin_path -s 127.0.0.1 -p "$FLAGS_dns_server_port" -t 1 || RETRY=1
if [[ "$RETRY" == 0 ]]; then
break
fi;
@ -85,7 +85,7 @@ $FLAGS_test_bin_path \\
--expected_lb_policy='${test['expected_lb_policy']}' \\
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
% endfor

@ -34,32 +34,4 @@ grpc_sh_binary(
],
)
grpc_py_binary(
name = "test_dns_server",
srcs = ["test_dns_server.py"],
testonly = True,
data = [
"resolver_test_record_groups.yaml",
],
external_deps = [
"twisted",
"yaml",
]
)
grpc_py_binary(
name = "test_dns_resolver",
srcs = ["test_dns_resolver.py"],
testonly = True,
external_deps = [
"twisted",
]
)
grpc_py_binary(
name = "test_tcp_connect",
srcs = ["test_tcp_connect.py"],
testonly = True,
)
generate_resolver_component_tests()

@ -54,9 +54,9 @@ def generate_resolver_component_tests():
data = [
":resolver_component_tests_runner",
":resolver_component_test%s" % unsecure_build_config_suffix,
":test_dns_server",
":test_dns_resolver",
":test_tcp_connect",
"//test/cpp/naming/utils:dns_server",
"//test/cpp/naming/utils:dns_resolver",
"//test/cpp/naming/utils:tcp_connect",
"resolver_test_record_groups.yaml", # include the transitive dependency so that the dns sever py binary can locate this
],
args = [

@ -21,11 +21,11 @@ set -ex
FLAGS_test_bin_path=$(echo "$1" | grep '\--test_bin_path=' | cut -d "=" -f 2)
FLAGS_dns_server_bin_path=$(echo "$2" | grep '\--dns_server_bin_path=' | cut -d "=" -f 2)
FLAGS_records_config_path=$(echo "$3" | grep '\--records_config_path=' | cut -d "=" -f 2)
FLAGS_test_dns_server_port=$(echo "$4" | grep '\--test_dns_server_port=' | cut -d "=" -f 2)
FLAGS_test_dns_resolver_bin_path=$(echo "$5" | grep '\--test_dns_resolver_bin_path=' | cut -d "=" -f 2)
FLAGS_test_tcp_connect_bin_path=$(echo "$6" | grep '\--test_tcp_connect_bin_path=' | cut -d "=" -f 2)
FLAGS_dns_server_port=$(echo "$4" | grep '\--dns_server_port=' | cut -d "=" -f 2)
FLAGS_dns_resolver_bin_path=$(echo "$5" | grep '\--dns_resolver_bin_path=' | cut -d "=" -f 2)
FLAGS_tcp_connect_bin_path=$(echo "$6" | grep '\--tcp_connect_bin_path=' | cut -d "=" -f 2)
for cmd_arg in "$FLAGS_test_bin_path" "$FLAGS_dns_server_bin_path" "$FLAGS_records_config_path" "$FLAGS_test_dns_server_port" "$FLAGS_test_dns_resolver_bin_path" "$FLAGS_test_tcp_connect_bin_path"; do
for cmd_arg in "$FLAGS_test_bin_path" "$FLAGS_dns_server_bin_path" "$FLAGS_records_config_path" "$FLAGS_dns_server_port" "$FLAGS_dns_resolver_bin_path" "$FLAGS_tcp_connect_bin_path"; do
if [[ "$cmd_arg" == "" ]]; then
echo "Missing a CMD arg" && exit 1
fi
@ -36,7 +36,7 @@ if [[ "$GRPC_DNS_RESOLVER" != "" && "$GRPC_DNS_RESOLVER" != ares ]]; then
fi
export GRPC_DNS_RESOLVER=ares
"$FLAGS_dns_server_bin_path" --records_config_path="$FLAGS_records_config_path" --port="$FLAGS_test_dns_server_port" > /dev/null 2>&1 &
"$FLAGS_dns_server_bin_path" --records_config_path="$FLAGS_records_config_path" --port="$FLAGS_dns_server_port" > /dev/null 2>&1 &
DNS_SERVER_PID=$!
echo "Local DNS server started. PID: $DNS_SERVER_PID"
@ -45,8 +45,8 @@ for ((i=0;i<30;i++));
do
echo "Retry health-check local DNS server by attempting a DNS query and TCP handshake"
RETRY=0
$FLAGS_test_dns_resolver_bin_path -s 127.0.0.1 -p "$FLAGS_test_dns_server_port" -n health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. -t 1 | grep '123.123.123.123' || RETRY=1
$FLAGS_test_tcp_connect_bin_path -s 127.0.0.1 -p "$FLAGS_test_dns_server_port" -t 1 || RETRY=1
$FLAGS_dns_resolver_bin_path -s 127.0.0.1 -p "$FLAGS_dns_server_port" -n health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. -t 1 | grep '123.123.123.123' || RETRY=1
$FLAGS_tcp_connect_bin_path -s 127.0.0.1 -p "$FLAGS_dns_server_port" -t 1 || RETRY=1
if [[ "$RETRY" == 0 ]]; then
break
fi;
@ -79,7 +79,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:1234,True' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -87,7 +87,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.5:1234,True;1.2.3.6:1234,True;1.2.3.7:1234,True' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -95,7 +95,7 @@ $FLAGS_test_bin_path \
--expected_addrs='[2607:f8b0:400a:801::1001]:1234,True' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -103,7 +103,7 @@ $FLAGS_test_bin_path \
--expected_addrs='[2607:f8b0:400a:801::1002]:1234,True;[2607:f8b0:400a:801::1003]:1234,True;[2607:f8b0:400a:801::1004]:1234,True' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -111,7 +111,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:1234,True' \
--expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]}]}' \
--expected_lb_policy='round_robin' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -119,7 +119,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"NoSrvSimpleService","waitForReady":true}]}]}' \
--expected_lb_policy='round_robin' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -127,7 +127,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -135,7 +135,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -143,7 +143,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"CppService","waitForReady":true}]}]}' \
--expected_lb_policy='round_robin' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -151,7 +151,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"AlwaysPickedService","waitForReady":true}]}]}' \
--expected_lb_policy='round_robin' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -159,7 +159,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:1234,True;1.2.3.4:443,False' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -167,7 +167,7 @@ $FLAGS_test_bin_path \
--expected_addrs='[2607:f8b0:400a:801::1002]:1234,True;[2607:f8b0:400a:801::1002]:443,False' \
--expected_chosen_service_config='' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
$FLAGS_test_bin_path \
@ -175,7 +175,7 @@ $FLAGS_test_bin_path \
--expected_addrs='1.2.3.4:443,False' \
--expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooThree","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFour","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFive","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSix","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSeven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEight","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooNine","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTen","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEleven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]}]}' \
--expected_lb_policy='' \
--local_dns_server_address="127.0.0.1:$FLAGS_test_dns_server_port" &
--local_dns_server_address="127.0.0.1:$FLAGS_dns_server_port" &
wait "$!" || EXIT_CODE=1
kill -SIGTERM "$DNS_SERVER_PID" || true

@ -103,17 +103,17 @@ void InvokeResolverComponentTestsRunner(std::string test_runner_bin_path,
std::string test_bin_path,
std::string dns_server_bin_path,
std::string records_config_path,
std::string test_dns_resolver_bin_path,
std::string test_tcp_connect_bin_path) {
int test_dns_server_port = grpc_pick_unused_port_or_die();
SubProcess* test_driver = new SubProcess(
{test_runner_bin_path, "--test_bin_path=" + test_bin_path,
"--dns_server_bin_path=" + dns_server_bin_path,
"--records_config_path=" + records_config_path,
"--test_dns_server_port=" + std::to_string(test_dns_server_port),
"--test_dns_resolver_bin_path=" + test_dns_resolver_bin_path,
"--test_tcp_connect_bin_path=" + test_tcp_connect_bin_path});
std::string dns_resolver_bin_path,
std::string tcp_connect_bin_path) {
int dns_server_port = grpc_pick_unused_port_or_die();
SubProcess* test_driver =
new SubProcess({test_runner_bin_path, "--test_bin_path=" + test_bin_path,
"--dns_server_bin_path=" + dns_server_bin_path,
"--records_config_path=" + records_config_path,
"--dns_server_port=" + std::to_string(dns_server_port),
"--dns_resolver_bin_path=" + dns_resolver_bin_path,
"--tcp_connect_bin_path=" + tcp_connect_bin_path});
gpr_mu test_driver_mu;
gpr_mu_init(&test_driver_mu);
gpr_cv test_driver_cv;
@ -174,9 +174,9 @@ int main(int argc, char** argv) {
// sure that we're using bazel's test environment.
grpc::testing::InvokeResolverComponentTestsRunner(
bin_dir + "/resolver_component_tests_runner",
bin_dir + "/" + FLAGS_test_bin_name, bin_dir + "/test_dns_server",
bin_dir + "/" + FLAGS_test_bin_name, bin_dir + "/utils/dns_server",
bin_dir + "/resolver_test_record_groups.yaml",
bin_dir + "/test_dns_resolver", bin_dir + "/test_tcp_connect");
bin_dir + "/utils/dns_resolver", bin_dir + "/utils/tcp_connect");
} else {
// Get the current binary's directory relative to repo root to invoke the
// correct build config (asan/tsan/dbg, etc.).
@ -185,10 +185,10 @@ int main(int argc, char** argv) {
grpc::testing::InvokeResolverComponentTestsRunner(
"test/cpp/naming/resolver_component_tests_runner.sh",
bin_dir + "/" + FLAGS_test_bin_name,
"test/cpp/naming/test_dns_server.py",
"test/cpp/naming/utils/dns_server.py",
"test/cpp/naming/resolver_test_record_groups.yaml",
"test/cpp/naming/test_dns_resolver.py",
"test/cpp/naming/test_tcp_connect.py");
"test/cpp/naming/utils/dns_resolver.py",
"test/cpp/naming/utils/tcp_connect.py");
}
grpc_shutdown();
return 0;

@ -0,0 +1,50 @@
# Copyright 2017 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.
package(
default_visibility = ["//visibility:public"],
features = [
"-layering_check",
"-parse_headers",
],
)
licenses(["notice"]) # Apache v2
load("//bazel:grpc_build_system.bzl", "grpc_py_binary")
grpc_py_binary(
name = "dns_server",
srcs = ["dns_server.py"],
testonly = True,
external_deps = [
"twisted",
"yaml",
]
)
grpc_py_binary(
name = "dns_resolver",
srcs = ["dns_resolver.py"],
testonly = True,
external_deps = [
"twisted",
]
)
grpc_py_binary(
name = "tcp_connect",
srcs = ["tcp_connect.py"],
testonly = True,
)
Loading…
Cancel
Save