From d56891901083f4384ee4287e6f77205c6f57c4e8 Mon Sep 17 00:00:00 2001 From: Jose Ulises Nino Rivera Date: Wed, 24 May 2017 15:29:39 -0700 Subject: [PATCH] config: config load check tool (#969) --- docs/configuration/tools/router_check.rst | 2 +- docs/install/install.rst | 2 +- docs/install/tools/config_load_check_tool.rst | 28 +++++++++++++++ .../route_table_check_tool.rst} | 4 +-- docs/install/tools/tools.rst | 8 +++++ docs/intro/version_history.rst | 2 +- test/config_test/config_test.cc | 1 - test/integration/BUILD | 1 + test/tools/config_load_check/BUILD | 16 +++++++++ .../config_load_check/config_load_check.cc | 34 +++++++++++++++++++ 10 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 docs/install/tools/config_load_check_tool.rst rename docs/install/{tools.rst => tools/route_table_check_tool.rst} (97%) create mode 100644 docs/install/tools/tools.rst create mode 100644 test/tools/config_load_check/BUILD create mode 100644 test/tools/config_load_check/config_load_check.cc diff --git a/docs/configuration/tools/router_check.rst b/docs/configuration/tools/router_check.rst index 686c62758e32..3238feba0d2a 100644 --- a/docs/configuration/tools/router_check.rst +++ b/docs/configuration/tools/router_check.rst @@ -12,7 +12,7 @@ the route returned by a :ref:`router ` matches The tool can be used to check cluster name, virtual cluster name, virtual host name, manual path rewrite, manual host rewrite, path redirect, and header field matches. Extensions for other test cases can be added. Details about installing the tool -and sample tool input/output can be found at :ref:`installation `. +and sample tool input/output can be found at :ref:`installation `. The route table check tool config is composed of an array of json test objects. Each test object is composed of three parts. diff --git a/docs/install/install.rst b/docs/install/install.rst index ada462336eba..26c2c11ca8e1 100644 --- a/docs/install/install.rst +++ b/docs/install/install.rst @@ -11,4 +11,4 @@ Building and installation installation ref_configs sandboxes/sandboxes.rst - tools + tools/tools diff --git a/docs/install/tools/config_load_check_tool.rst b/docs/install/tools/config_load_check_tool.rst new file mode 100644 index 000000000000..ff29f5a8b638 --- /dev/null +++ b/docs/install/tools/config_load_check_tool.rst @@ -0,0 +1,28 @@ +Config load check tool +====================== + +The config load check tool checks that a configuration file in JSON format is written using valid JSON +and conforms to the Envoy JSON schema. This tool leverages the configuration test in +``test/config_test/config_test.cc``. The test loads the JSON configuration file and runs server configuration +initialization with it. + +Input + The tool expects a PATH to the root of a directory that holds JSON Envoy configuration files. The tool + will recursively go through the filesystem tree and run a configuration test for each file found. Keep in mind that + the tool will try to load all files found in the path. + +Output + The tool will output Envoy logs as it initializes the server configuration with the config it is currently testing. + If there are configuration files where the JSON file is malformed or is does not conform to the Envoy JSON schema, the + tool will exit with status EXIT_FAILURE. If the tool successfully loads all configuration files found it will + exit with status EXIT_SUCCESS. + +Building + The tool can be built locally using Bazel. :: + + bazel build //test/tools/config_load_check:config_load_check_tool + +Running + The tool takes a path as described above. :: + + bazel-bin/test/tools/config_load_check/config_load_check_tool PATH diff --git a/docs/install/tools.rst b/docs/install/tools/route_table_check_tool.rst similarity index 97% rename from docs/install/tools.rst rename to docs/install/tools/route_table_check_tool.rst index 48ce9a3b6bb0..2b75b9badc4a 100644 --- a/docs/install/tools.rst +++ b/docs/install/tools/route_table_check_tool.rst @@ -1,6 +1,6 @@ -.. _install_tools: +.. _install_tools_route_table_check_tool: -Route Table Check Tool +Route table check tool ======================= The route table check tool checks whether the route parameters returned by a router match what is expected. diff --git a/docs/install/tools/tools.rst b/docs/install/tools/tools.rst new file mode 100644 index 000000000000..611b35ffce40 --- /dev/null +++ b/docs/install/tools/tools.rst @@ -0,0 +1,8 @@ +Tools +===== + +.. toctree:: + :maxdepth: 2 + + config_load_check_tool + route_table_check_tool diff --git a/docs/intro/version_history.rst b/docs/intro/version_history.rst index 0c5b702de5ad..92f17911a491 100644 --- a/docs/intro/version_history.rst +++ b/docs/intro/version_history.rst @@ -58,7 +58,7 @@ Version history * The CPU profiler output path is now :ref:`configurable `. * A :ref:`watchdog system ` has been added that can kill the server if a deadlock is detected. -* A :ref:`route table checking tool ` has been added that can be used to test route +* A :ref:`route table checking tool ` has been added that can be used to test route tables before use. * We have added an :ref:`example repo ` that shows how to compile/link a custom filter. * Added additional cluster wide information related to outlier detection to the :ref:`/clusters diff --git a/test/config_test/config_test.cc b/test/config_test/config_test.cc index 69a79dc36a5d..5cc75e1bb26b 100644 --- a/test/config_test/config_test.cc +++ b/test/config_test/config_test.cc @@ -58,7 +58,6 @@ uint32_t run(const std::string& directory) { ConfigTest config(filename); num_tested++; } - return num_tested; } diff --git a/test/integration/BUILD b/test/integration/BUILD index 9ba65c128035..6ff1b81580ea 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -143,6 +143,7 @@ envoy_cc_test_library( "//test/mocks/upstream:upstream_mocks", "//test/test_common:environment_lib", "//test/test_common:network_utility_lib", + "//test/test_common:printers_lib", "//test/test_common:utility_lib", ], ) diff --git a/test/tools/config_load_check/BUILD b/test/tools/config_load_check/BUILD new file mode 100644 index 000000000000..3caa55e348dc --- /dev/null +++ b/test/tools/config_load_check/BUILD @@ -0,0 +1,16 @@ +licenses(["notice"]) # Apache 2 + +load( + "//bazel:envoy_build_system.bzl", + "envoy_cc_binary", + "envoy_package", +) + +envoy_package() + +envoy_cc_binary( + name = "config_load_check_tool", + testonly = 1, + srcs = ["config_load_check.cc"], + deps = ["//test/config_test:config_test_lib"], +) diff --git a/test/tools/config_load_check/config_load_check.cc b/test/tools/config_load_check/config_load_check.cc new file mode 100644 index 000000000000..a6c1bb0ad2e4 --- /dev/null +++ b/test/tools/config_load_check/config_load_check.cc @@ -0,0 +1,34 @@ +// NOLINT(namespace-envoy) +#include +#include +#include + +#include "test/config_test/config_test.h" + +#include "gtest/gtest.h" +#include "spdlog/spdlog.h" + +int main(int argc, char* argv[]) { + if (argc != 2) { + std::cerr << "Usage: config_load_check PATH\n" + "\nValidate configuration files against json schema\n" + "\n\tPATH - root of the path that holds the json files to verify." + " The tool recursively searches for json files to validate." << std::endl; + return EXIT_FAILURE; + } + try { + const uint32_t num_tested = Envoy::ConfigTest::run(std::string(argv[1])); + std::cout << fmt::format("Configs tested: {}. ", num_tested); + if (testing::Test::HasFailure()) { + std::cerr << "There were failures. Please Fix your configuration files." << std::endl; + return EXIT_FAILURE; + } else { + std::cout << "No failures." << std::endl; + return EXIT_SUCCESS; + } + } catch (const std::runtime_error& e) { + // catch directory not found runtime exception. + std::cerr << e.what() << std::endl; + } + return EXIT_FAILURE; +}