From 58b14b5597d62c52918166bd4436ff0aa4e05f99 Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 19 Jan 2024 09:01:17 +0100 Subject: [PATCH 1/5] Validate YAML tags on parsing Signed-off-by: tempate Uncrustify Signed-off-by: tempate Rename validate_tags_ to validate_tags Signed-off-by: tempate Validate new YAML options Signed-off-by: tempate Make tag-sets static Signed-off-by: tempate --- .../src/cpp/YamlReader_configuration.cpp | 83 +++++++++++++++---- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 1479b4676..bb1044870 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include #include #include @@ -23,6 +25,7 @@ #include #include #include +#include #include #include @@ -57,7 +60,7 @@ void YamlReader::fill( // Optional Topic QoS if (is_tag_present(yml, SPECS_QOS_TAG)) { - fill(object.topic_qos, get_value_in_tag(yml, SPECS_QOS_TAG), version); + object.topic_qos = YamlReader::get(yml, SPECS_QOS_TAG, version); core::types::TopicQoS::default_topic_qos.set_value(object.topic_qos); } @@ -95,6 +98,34 @@ void YamlReader::fill( } } +template <> +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + static const std::set tags{ + NUMBER_THREADS_TAG, + REMOVE_UNUSED_ENTITIES_TAG, + SPECS_QOS_TAG, + DISCOVERY_TRIGGER_TAG, + LOG_CONFIGURATION_TAG, + MONITOR_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + +template <> +ddsrouter::core::SpecsConfiguration YamlReader::get( + const Yaml& yml, + const YamlReaderVersion version) +{ + YamlValidator::validate(yml, version); + + ddsrouter::core::SpecsConfiguration object; + fill(object, yml, version); + return object; +} + template <> ddsrouter::core::types::ParticipantKind YamlReader::get( const Yaml& yml, @@ -190,21 +221,14 @@ void YamlReader::fill( // Get optional routes if (YamlReader::is_tag_present(yml, ROUTES_TAG)) { - YamlReader::fill( - object.routes, - YamlReader::get_value_in_tag(yml, ROUTES_TAG), - version); + object.routes = YamlReader::get(yml, ROUTES_TAG, version); } ///// // Get optional topic routes if (YamlReader::is_tag_present(yml, TOPIC_ROUTES_TAG)) { - // get list, and parse each element as above - YamlReader::fill( - object.topic_routes, - YamlReader::get_value_in_tag(yml, TOPIC_ROUTES_TAG), - version); + object.topic_routes = YamlReader::get(yml, TOPIC_ROUTES_TAG, version); } ///// @@ -221,6 +245,9 @@ core::DdsPipeConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + // The DdsPipeConfiguration's fields don't correspond to a YAML section and, therefore, can't be validated. + // Instead, they are validated in the methods above (most of them in the DdsRouterConfiguration). + core::DdsPipeConfiguration object; fill(object, yml, version); return object; @@ -250,6 +277,7 @@ void YamlReader::fill( { ddsrouter::core::types::ParticipantKind kind = YamlReader::get(conf, PARTICIPANT_KIND_TAG, version); + object.participants_configurations.insert( { kind, @@ -262,10 +290,9 @@ void YamlReader::fill( // Get optional specs configuration if (YamlReader::is_tag_present(yml, SPECS_TAG)) { - YamlReader::fill( - object.advanced_options, - YamlReader::get_value_in_tag(yml, SPECS_TAG), - version); + object.advanced_options = get(YamlReader::get_value_in_tag(yml, + SPECS_TAG), + version); } // DDS Pipe Configuration @@ -286,18 +313,38 @@ void YamlReader::fill( // Get optional xml configuration if (YamlReader::is_tag_present(yml, XML_TAG)) { - YamlReader::fill( - object.xml_configuration, - YamlReader::get_value_in_tag(yml, XML_TAG), - version); + object.xml_configuration = YamlReader::get(yml, XML_TAG, version); } } +template <> +DDSPIPE_YAML_DllAPI +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + static const std::set tags{ + VERSION_TAG, + COLLECTION_PARTICIPANTS_TAG, + XML_TAG, + ALLOWLIST_TAG, + BLOCKLIST_TAG, + BUILTIN_TAG, + ROUTES_TAG, + TOPIC_ROUTES_TAG, + TOPICS_TAG, + SPECS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> ddsrouter::core::DdsRouterConfiguration YamlReader::get( const Yaml& yml, const YamlReaderVersion version) { + YamlValidator::validate(yml, version); + ddsrouter::core::DdsRouterConfiguration object; fill(object, yml, version); return object; From 34284fd6dfd6135ca9a8a1aa4e6357f13ff3848a Mon Sep 17 00:00:00 2001 From: tempate Date: Wed, 24 Apr 2024 13:38:07 +0200 Subject: [PATCH 2/5] Remove the obsolete YAML validator Signed-off-by: tempate --- .dev/README.md | 2 - .github/docker/ddsrouter/Dockerfile | 4 +- README.md | 37 - docs/index.rst | 1 - .../installation/sources/linux.rst | 36 - .../installation/sources/windows.rst | 36 - docs/rst/notes/previous_versions/v0.4.0.rst | 2 +- docs/rst/spelling_wordlist.txt | 2 - docs/rst/user_manual/yaml_validator.rst | 29 - tools/ddsrouter_yaml_validator/.gitignore | 98 --- .../ddsrouter_yaml_validator/__init__.py | 0 .../ddsrouter_config_schema.json | 679 ------------------ .../ddsrouter_yaml_validator.py | 31 - .../full_example.yaml | 90 --- .../ddsrouter_yaml_validator/parser.py | 54 -- .../ddsrouter_yaml_validator/validator.py | 103 --- tools/ddsrouter_yaml_validator/package.xml | 17 - .../resource/ddsrouter_yaml_validator | 0 tools/ddsrouter_yaml_validator/setup.cfg | 4 - tools/ddsrouter_yaml_validator/setup.py | 31 - .../tests/__init__.py | 0 .../tests/ddsrouter_yaml_validator_test.py | 51 -- .../address_no_ip_nor_domain.yaml | 35 - .../address_no_port.yaml | 36 - .../builtin_topic_no_name.yaml | 14 - .../builtin_topic_no_type.yaml | 14 - ..._participant_no_discovery_server_guid.yaml | 33 - ...no_listening_nor_connection_addresses.yaml | 20 - .../filter_topic_no_name.yaml | 14 - .../initial_peers_no_addresses.yaml | 16 - .../no_participant_kind.yaml | 16 - .../no_participant_name.yaml | 16 - .../no_version.yaml | 15 - .../tls_ca_no_private_key_provided_cert.yaml | 40 -- .../tls_no_ca.yaml | 42 -- 35 files changed, 2 insertions(+), 1616 deletions(-) delete mode 100644 docs/rst/user_manual/yaml_validator.rst delete mode 100644 tools/ddsrouter_yaml_validator/.gitignore delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/__init__.py delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_config_schema.json delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_yaml_validator.py delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/full_example.yaml delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/parser.py delete mode 100644 tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/validator.py delete mode 100644 tools/ddsrouter_yaml_validator/package.xml delete mode 100644 tools/ddsrouter_yaml_validator/resource/ddsrouter_yaml_validator delete mode 100644 tools/ddsrouter_yaml_validator/setup.cfg delete mode 100644 tools/ddsrouter_yaml_validator/setup.py delete mode 100644 tools/ddsrouter_yaml_validator/tests/__init__.py delete mode 100644 tools/ddsrouter_yaml_validator/tests/ddsrouter_yaml_validator_test.py delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_ip_nor_domain.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_port.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_name.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_type.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_discovery_server_guid.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_listening_nor_connection_addresses.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/filter_topic_no_name.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/initial_peers_no_addresses.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_kind.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_name.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_version.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_ca_no_private_key_provided_cert.yaml delete mode 100644 tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_no_ca.yaml diff --git a/.dev/README.md b/.dev/README.md index 698f50ad7..6c45c33dd 100644 --- a/.dev/README.md +++ b/.dev/README.md @@ -34,8 +34,6 @@ The modules contained in this repository are the following: * **ddsrouter_docs** (hosted in directory `docs`) This package contains the user documentation built with sphinx. -* **ddsrouter_yaml_validator** This is an application used for validating DDS Router `yaml` configuration files. - This is the dependency graph of the packages: ```sh diff --git a/.github/docker/ddsrouter/Dockerfile b/.github/docker/ddsrouter/Dockerfile index a15198e9a..f4338a9fa 100644 --- a/.github/docker/ddsrouter/Dockerfile +++ b/.github/docker/ddsrouter/Dockerfile @@ -35,9 +35,7 @@ RUN pip3 install \ colcon-mixin \ lxml \ vcstool \ - GitPython \ - pyyaml \ - jsonschema + GitPython WORKDIR /ddsrouter diff --git a/README.md b/README.md index 54914b595..9e28f2afa 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,6 @@ environment are provided below. These installation instructions are a summarized * [CMake](https://cmake.org/), [g++](https://gcc.gnu.org/), [pip](https://pypi.org/project/pip/), [wget](https://www.gnu.org/software/wget/) and [git](https://git-scm.com/) * [Colcon](https://colcon.readthedocs.io/en/released/) [optional, not required for CMake-only installation] * [Gtest](https://github.com/google/googletest) [for test only] -* [PyYAML](https://pyyaml.org/) [for YAML Validator only] -* [jsonschema](https://python-jsonschema.readthedocs.io/) [for YAML Validator only] #### CMake, g++, pip, wget and git @@ -98,28 +96,6 @@ compile tests. It is possible to activate them with the opportune [CMake options [CMake](https://cmake.org/). For a detailed description of the Gtest installation process, please refer to the [Gtest Installation Guide](https://github.com/google/googletest). -#### PyYAML - -[PyYAML](https://pyyaml.org/) is a YAML parser and emitter for Python. -It is used by the DDS-Router YAML Validator for loading the content of configuration files. -Install `pyyaml` by executing the following command: - -```bash -pip3 install -U pyyaml -``` - -#### jsonschema - -[jsonschema](https://python-jsonschema.readthedocs.io/) is an implementation of the JSON Schema specification for -Python. -It is used by the DDS-Router YAML Validator for performing validation of configuration files against a given JSON -schema. -Install `jsonschema` by executing the following command: - -```bash -pip3 install -U jsonschema -``` - ### Dependencies #### Asio and TinyXML2 libraries @@ -189,7 +165,6 @@ These packages are: * `ddsrouter_yaml`: library to configure a DDS Router from a YAML. * `ddsrouter_tool`: application to execute a DDS Router from a YAML configuration file. * `ddsrouter_docs`: package to generate the DDS Router documentation using sphinx. -* `ddsrouter_yaml_validator`: application to validate DDS Router YAML configuration files. > *NOTE:* Those packages could be installed and use independently (according with each package dependency). In order to compile only a package and its dependencies, use the colcon argument `--packages-up-to `. @@ -209,18 +184,6 @@ source /setup.bash .//ddsrouter_tool/bin/ddsrouter ``` -### Validate a configuration file - -To validate a *DDS Router* YAML configuration file, execute the following commands: - -```bash -# Source installation -source /setup.bash - -# Validate a DDS Router configuration file -ddsrouter_yaml_validator --config-file ddsrouter-config.yaml -``` - ### Testing By default, *DDS Router* does not compile tests. However, they can be activated by downloading and installing diff --git a/docs/index.rst b/docs/index.rst index d23e42b6a..f9b92eba9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -50,7 +50,6 @@ Participant /rst/user_manual/configuration /rst/user_manual/wan_configuration - /rst/user_manual/yaml_validator /rst/user_manual/user_manual_glossary diff --git a/docs/rst/developer_manual/installation/sources/linux.rst b/docs/rst/developer_manual/installation/sources/linux.rst index cc24b60e1..cf25c22ce 100644 --- a/docs/rst/developer_manual/installation/sources/linux.rst +++ b/docs/rst/developer_manual/installation/sources/linux.rst @@ -47,8 +47,6 @@ installed in the system: * :ref:`cmake_gcc_pip_wget_git_sl` * :ref:`colcon_install` [optional] * :ref:`gtest_sl` [for test only] -* :ref:`py_yaml` [for YAML Validator only] -* :ref:`json_schema` [for YAML Validator only] .. _cmake_gcc_pip_wget_git_sl: @@ -104,40 +102,6 @@ Use the following command to download the code: git clone --branch release-1.12.0 https://github.com/google/googletest src/googletest-distribution - -.. _py_yaml: - -PyYAML -^^^^^^ - -`PyYAML `_ is a YAML parser and emitter for Python. - -It is used by the DDS-Router :ref:`yaml_validator` for loading the content of configuration files. - -Install ``pyyaml`` by executing the following command: - -.. code-block:: bash - - pip3 install -U pyyaml - - -.. _json_schema: - -jsonschema -^^^^^^^^^^ - -`jsonschema `_ is an implementation of the JSON Schema specification for -Python. - -It is used by the DDS-Router :ref:`yaml_validator` for performing validation of configuration files against a given -JSON schema. - -Install ``jsonschema`` by executing the following command: - -.. code-block:: bash - - pip3 install -U jsonschema - .. _dependencies: Dependencies diff --git a/docs/rst/developer_manual/installation/sources/windows.rst b/docs/rst/developer_manual/installation/sources/windows.rst index b21eef514..15b1c477e 100644 --- a/docs/rst/developer_manual/installation/sources/windows.rst +++ b/docs/rst/developer_manual/installation/sources/windows.rst @@ -50,8 +50,6 @@ installed in the system: * :ref:`windows_sources_cmake_pip3_wget_git` * :ref:`windows_sources_colcon_install` [optional] * :ref:`windows_sources_gtest` [for test only] -* :ref:`windows_py_yaml` [for YAML Validator only] -* :ref:`windows_json_schema` [for YAML Validator only] .. _windows_sources_visual_studio: @@ -127,40 +125,6 @@ or refer to the `Gtest Installation Guide `_ for a detailed description of the Gtest installation process. - -.. _windows_py_yaml: - -PyYAML -^^^^^^ - -`PyYAML `_ is a YAML parser and emitter for Python. - -It is used by the DDS-Router :ref:`yaml_validator` for loading the content of configuration files. - -Install ``pyyaml`` by executing the following command: - -.. code-block:: bash - - pip3 install -U pyyaml - - -.. _windows_json_schema: - -jsonschema -^^^^^^^^^^ - -`jsonschema `_ is an implementation of the JSON Schema specification for -Python. - -It is used by the DDS-Router :ref:`yaml_validator` for performing validation of configuration files against a given -JSON schema. - -Install ``jsonschema`` by executing the following command: - -.. code-block:: bash - - pip3 install -U jsonschema - .. _windows_sources_dependencies: Dependencies diff --git a/docs/rst/notes/previous_versions/v0.4.0.rst b/docs/rst/notes/previous_versions/v0.4.0.rst index 309545ead..aa1cc34d6 100644 --- a/docs/rst/notes/previous_versions/v0.4.0.rst +++ b/docs/rst/notes/previous_versions/v0.4.0.rst @@ -4,7 +4,7 @@ Version v0.4.0 This release includes the following **features**: -* New :ref:`yaml_validator`, a simple tool to assert the correctness of DDS Router configuration files. +* New *Yaml Validator*, a simple tool to assert the correctness of DDS Router configuration files. * New :ref:`user_manual_user_interface_version_argument` to show the current version of DDS Router. This release includes the following **improvementes**: diff --git a/docs/rst/spelling_wordlist.txt b/docs/rst/spelling_wordlist.txt index b3f2c3d16..caab9498b 100644 --- a/docs/rst/spelling_wordlist.txt +++ b/docs/rst/spelling_wordlist.txt @@ -27,7 +27,6 @@ gMock Gtest guid IPv -jsonschema kubernetes localhost metatraffic @@ -41,7 +40,6 @@ Requiredness runtime scalable utils -validator Vulcanexus wget yaml diff --git a/docs/rst/user_manual/yaml_validator.rst b/docs/rst/user_manual/yaml_validator.rst deleted file mode 100644 index 5134624bb..000000000 --- a/docs/rst/user_manual/yaml_validator.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. include:: ../exports/alias.include -.. include:: ../exports/roles.include - -.. _yaml_validator: - -############## -YAML Validator -############## - -Configuration files used to launch a DDS-Router instance need to follow a specific structure, which is extensively -described along section :ref:`user_manual_configuration`. The *YAML Validator tool* has been developed for the sole -purpose of validating user-defined configuration files in an easy manner. - -.. note:: - - Yaml Validator tool is supported for ``3.0`` configuration version only. - -After having sourced the |ddsrouter| workspace, execute the following command in order to validate a YAML configuration -file: - -.. code-block:: bash - - ddsrouter_yaml_validator --config-file ddsrouter-config.yaml - -Alternatively, the user may choose to validate against a different schema, by using instead the command below: - -.. code-block:: bash - - ddsrouter_yaml_validator --config-file ddsrouter-config.yaml --schema schema.json diff --git a/tools/ddsrouter_yaml_validator/.gitignore b/tools/ddsrouter_yaml_validator/.gitignore deleted file mode 100644 index f42e32aba..000000000 --- a/tools/ddsrouter_yaml_validator/.gitignore +++ /dev/null @@ -1,98 +0,0 @@ - -### C++ ### -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -### Vim ### -# swap -[._]*.s[a-w][a-z] -[._]s[a-w][a-z] -# session -Session.vim -# temporary -.netrwhist -*~ -# auto-generated tag files -tags - -build/ -install/ -# Log is commented because some internal modules could be called like that -# log/ - -### Visual Studio ### -.vs - -### Visual Studio Code ### -.vscode - -### Documentation ### -docs/rst/_static/css/online_eprosima_rtd_theme.css - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/__init__.py b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_config_schema.json b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_config_schema.json deleted file mode 100644 index 46e01806b..000000000 --- a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_config_schema.json +++ /dev/null @@ -1,679 +0,0 @@ -{ - "$schema":"http://json-schema.org/draft-07/schema#", - "$ref":"#/definitions/BaseObject", - "definitions":{ - "BaseObject":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "threads":{ - "type":"integer" - }, - "version":{ - "type":"string", - "enum":[ - "v3.0" - ] - }, - "allowlist":{ - "type":"array", - "items":{ - "$ref":"#/definitions/TopicFilter" - } - }, - "blocklist":{ - "type":"array", - "items":{ - "$ref":"#/definitions/TopicFilter" - } - }, - "builtin-topics":{ - "type":"array", - "items":{ - "$ref":"#/definitions/TopicBuiltins" - } - }, - "participants":{ - "type":"array", - "minItems":1, - "items":{ - "$ref":"#/definitions/Participant" - }, - "uniqueKeys":[ - "/name" - ] - } - }, - "required":[ - "version", - "participants" - ], - "title":"BaseObject" - }, - "TopicFilter":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "name":{ - "type":"string" - }, - "type":{ - "type":"string" - }, - "keyed":{ - "type":"boolean" - } - }, - "required":[ - "name" - ], - "title":"TopicFilter" - }, - "TopicBuiltins":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "name":{ - "type":"string" - }, - "type":{ - "type":"string" - }, - "keyed":{ - "type":"boolean" - }, - "reliable":{ - "type":"boolean" - } - }, - "required":[ - "name", - "type" - ], - "title":"TopicBuiltins" - }, - "Participant":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "name":{ - "type":"string" - }, - "kind":{ - "type":"string", - "enum":[ - "void", - "echo", - "dummy", - "local", - "simple", - "discovery-server", - "ds", - "local-ds", - "local-discovery-server", - "wan-ds", - "wan-discovery-server", - "wan", - "router" - ] - }, - "domain":{ - "type":"integer", - "minimum":0, - "maximum":230 - }, - "repeater":{ - "type":"boolean" - }, - "discovery-server-guid":{ - "$ref":"#/definitions/DiscoveryServerGUID" - }, - "listening-addresses":{ - "type":"array", - "items":{ - "$ref":"#/definitions/Address" - }, - "minItems": 1 - }, - "connection-addresses":{ - "type":"array", - "items":{ - "anyOf":[ - { - "$ref":"#/definitions/DsConnectionAddress" - }, - { - "$ref":"#/definitions/Address" - } - ] - }, - "minItems": 1 - }, - "tls":{ - "$ref":"#/definitions/TLS" - }, - "discovery":{ - "type":"boolean" - }, - "data":{ - "type":"boolean" - }, - "verbose":{ - "type":"boolean" - } - }, - "required":[ - "kind", - "name" - ], - "allOf":[ - { - "if":{ - "properties":{ - "kind":{ - "type":"string", - "enum":[ - "void", - "dummy" - ] - } - } - }, - "then":{ - "properties":{ - "domain":{ - "not":{ - - } - }, - "discovery-server-guid":{ - "not":{ - - } - }, - "listening-addresses":{ - "not":{ - - } - }, - "connection-addresses":{ - "not":{ - - } - }, - "tls":{ - "not":{ - - } - }, - "repeater":{ - "not":{ - - } - }, - "discovery":{ - "not":{ - - } - }, - "data":{ - "not":{ - - } - }, - "verbose":{ - "not":{ - - } - } - } - } - }, - { - "if":{ - "properties":{ - "kind":{ - "type":"string", - "enum":[ - "echo" - ] - } - } - }, - "then":{ - "properties":{ - "domain":{ - "not":{ - - } - }, - "discovery-server-guid":{ - "not":{ - - } - }, - "listening-addresses":{ - "not":{ - - } - }, - "connection-addresses":{ - "not":{ - - } - }, - "tls":{ - "not":{ - - } - }, - "repeater":{ - "not":{ - - } - } - } - } - }, - { - "if":{ - "properties":{ - "kind":{ - "type":"string", - "enum":[ - "local", - "simple" - ] - } - } - }, - "then":{ - "allOf":[ - { - "properties":{ - "discovery-server-guid":{ - "not":{ - - } - }, - "listening-addresses":{ - "not":{ - - } - }, - "connection-addresses":{ - "not":{ - - } - }, - "tls":{ - "not":{ - - } - }, - "repeater":{ - "not":{ - - } - }, - "discovery":{ - "not":{ - - } - }, - "data":{ - "not":{ - - } - }, - "verbose":{ - "not":{ - - } - } - } - } - ] - } - }, - { - "if":{ - "properties":{ - "kind":{ - "type":"string", - "enum":[ - "discovery-server", - "ds", - "local-ds", - "local-discovery-server", - "wan-ds", - "wan-discovery-server" - ] - } - } - }, - "then":{ - "allOf":[ - { - "properties":{ - "domain":{ - "not":{ - - } - }, - "discovery":{ - "not":{ - - } - }, - "data":{ - "not":{ - - } - }, - "verbose":{ - "not":{ - - } - } - } - }, - { - "required":[ - "discovery-server-guid" - ] - }, - { - "anyOf":[ - { - "required":[ - "listening-addresses" - ] - }, - { - "required":[ - "connection-addresses" - ] - } - ] - } - ] - } - }, - { - "if":{ - "properties":{ - "kind":{ - "type":"string", - "enum":[ - "wan", - "router" - ] - } - } - }, - "then":{ - "allOf":[ - { - "properties":{ - "discovery-server-guid":{ - "not":{ - - } - }, - "discovery":{ - "not":{ - - } - }, - "data":{ - "not":{ - - } - }, - "verbose":{ - "not":{ - - } - } - } - }, - { - "anyOf":[ - { - "required":[ - "listening-addresses" - ] - }, - { - "required":[ - "connection-addresses" - ] - } - ] - } - ] - } - } - ], - "title":"Participant" - }, - "DiscoveryServerGUID":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "guid":{ - "type":"string" - }, - "id":{ - "type":"integer" - }, - "ros-discovery-server":{ - "type":"boolean" - } - }, - "anyOf":[ - { - "required":[ - "guid" - ] - }, - { - "required":[ - "id" - ] - } - ], - "title":"DiscoveryServerGUID" - }, - "DsConnectionAddress":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "discovery-server-guid":{ - "$ref":"#/definitions/DiscoveryServerGUID" - }, - "addresses":{ - "type":"array", - "items":{ - "$ref":"#/definitions/Address" - } - } - }, - "required":[ - "addresses", - "discovery-server-guid" - ], - "title":"DsConnectionAddress" - }, - "TLS":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "ca":{ - "type":"string" - }, - "password":{ - "type":"string" - }, - "private_key":{ - "type":"string" - }, - "cert":{ - "type":"string" - }, - "dh_params":{ - "type":"string" - }, - "peer_verification":{ - "type":"boolean" - }, - "sni_host":{ - "type":"string" - } - }, - "required":[ - "ca" - ], - "allOf":[ - { - "if":{ - "properties":{ - "password":{ - "type":"string" - } - }, - "required":[ - "password" - ] - }, - "then":{ - "required":[ - "private_key", - "cert" - ] - } - }, - { - "if":{ - "properties":{ - "private_key":{ - "not":{ - "pattern":"^$" - } - } - }, - "required":[ - "private_key" - ] - }, - "then":{ - "properties":{ - "private_key":{ - "not":{ - "pattern":"^\\s*$" - } - } - }, - "required":[ - "password", - "cert" - ] - } - }, - { - "if":{ - "properties":{ - "cert":{ - "type":"string" - } - }, - "required":[ - "cert" - ] - }, - "then":{ - "properties":{ - "cert":{ - "not":{ - "pattern":"^\\s*$" - } - } - }, - "required":[ - "password", - "private_key" - ] - } - } - ], - "title":"TLS" - }, - "Address":{ - "type":"object", - "additionalProperties":false, - "properties":{ - "ip":{ - "type":"string", - "anyOf":[ - { - "format":"v4" - }, - { - "format":"v6" - } - ] - }, - "domain":{ - "type":"string" - }, - "port":{ - "type":"integer", - "minimum":0, - "maximum":65535 - }, - "external-port":{ - "type":"integer", - "minimum":0, - "maximum":65535 - }, - "transport":{ - "type":"string", - "enum":[ - "tcp", - "udp" - ] - }, - "ip-version":{ - "type":"string", - "enum":[ - "v4", - "v6" - ] - } - }, - "allOf":[ - { - "anyOf":[ - { - "required":[ - "domain" - ] - }, - { - "required":[ - "ip" - ] - } - ] - }, - { - "required":[ - "port" - ] - } - ], - "title":"Address" - } - } -} \ No newline at end of file diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_yaml_validator.py b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_yaml_validator.py deleted file mode 100644 index 9e2cadb99..000000000 --- a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/ddsrouter_yaml_validator.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# 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. - -"""DDS-Router YAML Validator tool.""" - -from ddsrouter_yaml_validator.parser import Parser -from ddsrouter_yaml_validator.validator import YamlValidator - - -def main(args=None): - """Validate a DDS-Router YAML configuration file.""" - parser = Parser() - args = parser.parse() - - validator = YamlValidator() - validator.validate(args.config_file, args.schema, args.recursive) - - -if __name__ == '__main__': - main() diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/full_example.yaml b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/full_example.yaml deleted file mode 100644 index 11554456c..000000000 --- a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/full_example.yaml +++ /dev/null @@ -1,90 +0,0 @@ -version: v5.0 # Required - -threads: 32 # Optional - -allowlist: -- name: rt/chatter # Required - type: std_msgs::msg::dds_::String_ - keyed: true - -blocklist: -- name: rt/chatter # Required - type: std_msgs::msg::dds_::String_ - keyed: true - -builtin-topics: -- name: rt/chatter # Required - type: std_msgs::msg::dds_::String_ # Required - -- name: custom_topic # Required - type: custom_topic_type # Required - -topics: - - name: rt/chatter - qos: - keyed: true - - -participants: -- name: participant0 # Required - kind: echo # Required - -- name: participant1 # Required - kind: simple # Required - domain: 1 - -- name: participant2 - kind: discovery-server - discovery-server-guid: # Required - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe # Required guid or id - id: 0 # Required guid or id - ros-discovery-server: true - listening-addresses: # Required listening-addresses or connection-addresses - - ip: 127.0.0.1 # Required ip or domain - domain: localhost # Required ip or domain - port: 11667 # Required - transport: udp - ip-version: ipv4 - connection-addresses: # Required listening-addresses or connection-addresses - - discovery-server-guid: # Required - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe # Required guid or id - id: 0 # Required guid or id - ros-discovery-server: true - addresses: # Required - - ip: 127.0.0.1 # Required ip or domain - domain: localhost # Required ip or domain - port: 11667 # Required - transport: udp - ip-version: ipv4 - tls: - ca: ca.crt # Required - password: ddsrouterpass # If "password" present, "private_key" and "cert" required - private_key: ddsrouter.key # If "private_key" present, "password" and "cert" required - cert: ddsrouter.crt # If "cert" present, "password" and "private_key" required - dh_params: dh_params.pem - -- name: participant3 - kind: wan - discovery-server-guid: # Required - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe # Required guid or id - id: 0 # Required guid or id - ros-discovery-server: true - listening-addresses: # Required listening-addresses or connection-addresses - - ip: ::1 # Required ip or domain - domain: localhost # Required ip or domain - port: 11667 - transport: tcp - ip-version: ipv6 - connection-addresses: # Required listening-addresses or connection-addresses - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe # Required guid or id - id: 0 # Required guid or id - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 # Required ip or domain - domain: localhost # Required ip or domain - port: 11667 - transport: tcp - ip-version: ipv4 - tls: - ca: ca.crt # Required diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/parser.py b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/parser.py deleted file mode 100644 index 2a7c85063..000000000 --- a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/parser.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# 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. - -"""Argument parser for DDS-Router YAML Validator tool.""" - -import argparse -import os - - -class Parser: - """DDS-Router YAML Validator argument parser.""" - - def parse(self): - """Parse configuration and schema path arguments.""" - parser = argparse.ArgumentParser( - description='Validate DDS-Router configuration file.' - ) - parser.add_argument( - '-c', - '--config-file', - required=True, - help='YAML file or directory with files used to configure' - 'DDS-Router', - ) - parser.add_argument( - '-r', - '--recursive', - action='store_true', - default=False, - help='Whether to perform recursive search when --config-file' - ' refers to a directory (default: false)', - ) - parser.add_argument( - '-s', - '--schema', - default=os.path.join( - os.environ['COLCON_PREFIX_PATH'], - 'ddsrouter_yaml_validator/share/ddsrouter_yaml_validator/' - 'ddsrouter_config_schema.json', - ), - help='JSON schema used to perform validation', - ) - return parser.parse_args() diff --git a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/validator.py b/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/validator.py deleted file mode 100644 index 201b702e1..000000000 --- a/tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/validator.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# 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. - -"""DDS-Router YAML Validator class container.""" - -import json -import os - -import jsonschema - -import yaml - - -class YamlValidator: - """ - Used to validate DDS-Router YAML configuration files against a schema. - - It exposes a static method for this purpose. - DDS-Router configurations are YAML files, and the schema is in JSON format. - """ - - def validate(self, config_path, schema_path, recursive=True, logout=True): - """Validate configuration file or files under a directory.""" - if not self.__is_json(schema_path): - print( - 'The given schema {} is not a JSON file.'.format( - os.path.basename(schema_path) - ) - ) - return - - if os.path.isdir(config_path): - ret = True - visited_dirs = [] - for root, dirs, files in os.walk(config_path): - print(f'Scanning directory {root}') - if root not in visited_dirs: - visited_dirs.append(root) - for f in files: - if self.__is_yaml(f): - ret = ret and self.__validate_config_file( - os.path.join(root, f), schema_path, logout) - if not recursive: - break - return ret - else: - if self.__is_yaml(config_path): - return self.__validate_config_file( - config_path, schema_path, logout) - else: - print( - 'The given config file {} is not a YAML file.'.format( - os.path.basename(config_path))) - - def __validate_config_file(self, config_file_path, schema_path, - logout=True): - """Validate DDS-Router configuration file.""" - with open(schema_path) as json_file: - schema = json.load(json_file) - with open(config_file_path) as yaml_file: - config_yaml = yaml.safe_load(yaml_file) - config_json = json.loads(json.dumps(config_yaml)) - try: - jsonschema.validate(config_json, schema) - except jsonschema.exceptions.ValidationError as exception: - if logout: - print(exception) - return False - - if logout: - print(os.path.basename(config_file_path), - 'is a valid DDS-Router configuration file.') - return True - - def __is_json(self, file): - """ - Check if a file is a JSON file. - - :param file: The input file - :return: True if the file is an JSON file, False if not. - """ - return os.path.splitext(str(file))[-1] == '.json' - - def __is_yaml(self, file): - """ - Check if a file is a YAML file. - - :param file: The input file - :return: True if the file is an YAML file, False if not. - """ - ext = os.path.splitext(str(file))[-1] - return ext == '.yaml' or ext == '.yml' diff --git a/tools/ddsrouter_yaml_validator/package.xml b/tools/ddsrouter_yaml_validator/package.xml deleted file mode 100644 index a82d62fe0..000000000 --- a/tools/ddsrouter_yaml_validator/package.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - ddsrouter_yaml_validator - 3.0.0 - Tool used for validating DDS-Router configuration files - Raúl Sánchez-Mateos - Javier París - Juan López - Apache License, Version 2.0 - - python3-pytest - - - ament_python - - diff --git a/tools/ddsrouter_yaml_validator/resource/ddsrouter_yaml_validator b/tools/ddsrouter_yaml_validator/resource/ddsrouter_yaml_validator deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/ddsrouter_yaml_validator/setup.cfg b/tools/ddsrouter_yaml_validator/setup.cfg deleted file mode 100644 index 3c1f99b9e..000000000 --- a/tools/ddsrouter_yaml_validator/setup.cfg +++ /dev/null @@ -1,4 +0,0 @@ -[develop] -script_dir=$base/bin -[install] -install_scripts=$base/bin diff --git a/tools/ddsrouter_yaml_validator/setup.py b/tools/ddsrouter_yaml_validator/setup.py deleted file mode 100644 index ac4df8466..000000000 --- a/tools/ddsrouter_yaml_validator/setup.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Setup file to install ddsrouter_yaml_validator module.""" -from setuptools import setup - - -package_name = 'ddsrouter_yaml_validator' - -setup( - name=package_name, - version='3.0.0', - packages=[package_name], - data_files=[ - ('share/ament_index/resource_index/packages', - ['resource/' + package_name]), - ('share/' + package_name, ['package.xml']), - ('share/' + package_name, [package_name + '/ddsrouter_config_schema.json']), - ('share/' + package_name, [package_name + '/full_example.yaml']) - ], - install_requires=['setuptools'], - zip_safe=True, - maintainer='eprosima', - maintainer_email='juanlopez@eprosima.com', - description='Tool used for validating DDS-Router configuration files', - license='Apache License, Version 2.0', - tests_require=['pytest'], - test_suite='tests', - entry_points={ - 'console_scripts': [ - 'ddsrouter_yaml_validator = ddsrouter_yaml_validator.ddsrouter_yaml_validator:main', - ], - }, -) diff --git a/tools/ddsrouter_yaml_validator/tests/__init__.py b/tools/ddsrouter_yaml_validator/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tools/ddsrouter_yaml_validator/tests/ddsrouter_yaml_validator_test.py b/tools/ddsrouter_yaml_validator/tests/ddsrouter_yaml_validator_test.py deleted file mode 100644 index 9210ccac7..000000000 --- a/tools/ddsrouter_yaml_validator/tests/ddsrouter_yaml_validator_test.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# 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. - -"""DDS-Router YAML Validator tests.""" - -import os - -from ddsrouter_yaml_validator.validator import YamlValidator - - -# Move to project root level -os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../../..') - -SCHEMA_PATH = 'tools/ddsrouter_yaml_validator/ddsrouter_yaml_validator/' \ - 'ddsrouter_config_schema.json' - -VALID_CONFIGURATION_FILES = [ - 'resources/configurations/examples', - 'docs/resources/getting_started'] - -INVALID_CONFIGURATION_FILES = [ - 'tools/ddsrouter_yaml_validator/tests/invalid_configuration_files'] - - -def test_valid_yamls(): - """Assert given configuration files are valid.""" - validator = YamlValidator() - for valid_files_dir in VALID_CONFIGURATION_FILES: - for root, dirs, files in os.walk(valid_files_dir): - for file in files: - file_path = os.path.join(root, file) - assert validator.validate(file_path, SCHEMA_PATH, logout=False), 'Test error: ' + file_path - - -def test_invalid_yamls(): - """Assert given configuration files are invalid.""" - validator = YamlValidator() - for invalid_files_dir in INVALID_CONFIGURATION_FILES: - assert not validator.validate( - invalid_files_dir, SCHEMA_PATH, logout=False), 'Negative test error: ' + invalid_files_dir diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_ip_nor_domain.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_ip_nor_domain.yaml deleted file mode 100644 index a00717b0d..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_ip_nor_domain.yaml +++ /dev/null @@ -1,35 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: discovery_participant - kind: discovery-server - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - listening-addresses: - - port: 11667 - transport: udp - ip-version: v4 - connection-addresses: - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: udp - ip-version: v4 diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_port.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_port.yaml deleted file mode 100644 index 2bf6c27ab..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/address_no_port.yaml +++ /dev/null @@ -1,36 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: discovery_participant - kind: discovery-server - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - listening-addresses: - - ip: 127.0.0.1 - domain: localhost - transport: udp - ip-version: v4 - connection-addresses: - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: udp - ip-version: v4 diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_name.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_name.yaml deleted file mode 100644 index 359c42c87..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_name.yaml +++ /dev/null @@ -1,14 +0,0 @@ -version: v5.0 - -builtin-topics: - - type: HelloWorld - - -participants: - - - name: SimpleParticipant - kind: local - domain: 0 - - - name: EchoParticipant - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_type.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_type.yaml deleted file mode 100644 index 443ba8b47..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/builtin_topic_no_type.yaml +++ /dev/null @@ -1,14 +0,0 @@ -version: v5.0 - -builtin-topics: - - name: HelloWorldTopic - - -participants: - - - name: SimpleParticipant - kind: local - domain: 0 - - - name: EchoParticipant - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_discovery_server_guid.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_discovery_server_guid.yaml deleted file mode 100644 index 576723c2c..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_discovery_server_guid.yaml +++ /dev/null @@ -1,33 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: discovery_participant - kind: discovery-server - listening-addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: udp - ip-version: v4 - connection-addresses: - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: udp - ip-version: v4 diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_listening_nor_connection_addresses.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_listening_nor_connection_addresses.yaml deleted file mode 100644 index 4c3452940..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/ds_participant_no_listening_nor_connection_addresses.yaml +++ /dev/null @@ -1,20 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: discovery_participant - kind: discovery-server - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/filter_topic_no_name.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/filter_topic_no_name.yaml deleted file mode 100644 index 9dfbcae2d..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/filter_topic_no_name.yaml +++ /dev/null @@ -1,14 +0,0 @@ -version: v5.0 - -allowlist: - - type: HelloWorld - - -participants: - - - name: SimpleParticipant - kind: local - domain: 0 - - - name: EchoParticipant - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/initial_peers_no_addresses.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/initial_peers_no_addresses.yaml deleted file mode 100644 index ede89094a..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/initial_peers_no_addresses.yaml +++ /dev/null @@ -1,16 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: ip_participant - kind: initial-peers diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_kind.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_kind.yaml deleted file mode 100644 index 9b4daad29..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_kind.yaml +++ /dev/null @@ -1,16 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: SimpleParticipant - domain: 0 - - - name: EchoParticipant - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_name.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_name.yaml deleted file mode 100644 index e16f500a7..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_participant_name.yaml +++ /dev/null @@ -1,16 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: SimpleParticipant - kind: local - domain: 0 - - - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_version.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_version.yaml deleted file mode 100644 index 722484f38..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/no_version.yaml +++ /dev/null @@ -1,15 +0,0 @@ -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: SimpleParticipant - kind: local - domain: 0 - - - name: EchoParticipant - kind: echo diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_ca_no_private_key_provided_cert.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_ca_no_private_key_provided_cert.yaml deleted file mode 100644 index 8080c1a63..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_ca_no_private_key_provided_cert.yaml +++ /dev/null @@ -1,40 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: wan_participant - kind: wan - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - listening-addresses: - - ip: ::1 - domain: localhost - port: 11667 - transport: tcp - ip-version: v6 - connection-addresses: - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: tcp - ip-version: v4 - tls: - ca: ca.crt - cert: ddsrouter.crt diff --git a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_no_ca.yaml b/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_no_ca.yaml deleted file mode 100644 index 0129aca70..000000000 --- a/tools/ddsrouter_yaml_validator/tests/invalid_configuration_files/tls_no_ca.yaml +++ /dev/null @@ -1,42 +0,0 @@ -version: v5.0 - -allowlist: - - name: HelloWorldTopic - type: HelloWorld - - name: rt/chatter - type: std_msgs::msg::dds_::String_ - - -participants: - - - name: EchoParticipant - kind: echo - - - name: wan_participant - kind: wan - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - listening-addresses: - - ip: ::1 - domain: localhost - port: 11667 - transport: tcp - ip-version: v6 - connection-addresses: - - discovery-server-guid: - guid: 01.0f.00.00.00.00.00.00.00.00.ca.fe - id: 0 - ros-discovery-server: true - addresses: - - ip: 127.0.0.1 - domain: localhost - port: 11667 - transport: tcp - ip-version: v4 - tls: - password: ddsrouterpass - private_key: ddsrouter.key - cert: ddsrouter.crt - dh_params: dh_params.pem From b991cc126de55c8f84bfb4c237381d5f7a353c8c Mon Sep 17 00:00:00 2001 From: tempate Date: Wed, 24 Apr 2024 13:39:28 +0200 Subject: [PATCH 3/5] Always clear log consumers before exiting Signed-off-by: tempate --- tools/ddsrouter_tool/src/cpp/main.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index 86a0dc7a6..00ad21e97 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -46,6 +46,8 @@ using namespace eprosima; using namespace eprosima::ddsrouter; +int exit(const ui::ProcessReturnCode& code); + int main( int argc, char** argv) @@ -59,15 +61,15 @@ int main( if (arg_parse_result == ui::ProcessReturnCode::help_argument) { - return static_cast(ui::ProcessReturnCode::success); + return exit(ui::ProcessReturnCode::success); } else if (arg_parse_result == ui::ProcessReturnCode::version_argument) { - return static_cast(ui::ProcessReturnCode::success); + return exit(ui::ProcessReturnCode::success); } else if (arg_parse_result != ui::ProcessReturnCode::success) { - return static_cast(arg_parse_result); + return exit(arg_parse_result); } // Check file is in args, else get the default file @@ -87,7 +89,8 @@ int main( EPROSIMA_LOG_ERROR( DDSROUTER_ARGS, "File '" << commandline_args.file_path << "' does not exist or it is not accessible."); - return static_cast(ui::ProcessReturnCode::required_argument_failed); + + return exit(ui::ProcessReturnCode::required_argument_failed); } logUser(DDSROUTER_EXECUTION, "Starting DDS Router Tool execution."); @@ -274,23 +277,27 @@ int main( "Error Loading DDS Router Configuration from file " << commandline_args.file_path << ". Error message:\n " << e.what()); - return static_cast(ui::ProcessReturnCode::execution_failed); + + return exit(ui::ProcessReturnCode::execution_failed); } catch (const eprosima::utils::InitializationException& e) { EPROSIMA_LOG_ERROR(DDSROUTER_ERROR, "Error Initializing DDS Router. Error message:\n " << e.what()); - return static_cast(ui::ProcessReturnCode::execution_failed); + + return exit(ui::ProcessReturnCode::execution_failed); } logUser(DDSROUTER_EXECUTION, "Finishing DDS Router Tool execution correctly."); - // Force print every log before closing - eprosima::utils::Log::Flush(); + return exit(ui::ProcessReturnCode::success); +} +int exit(const ui::ProcessReturnCode& code) +{ // Delete the consumers before closing eprosima::utils::Log::ClearConsumers(); - return static_cast(ui::ProcessReturnCode::success); + return static_cast(code); } From d7269f1cde19ba309a7c7f7a6d827d005be8dde9 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 25 Apr 2024 10:03:01 +0200 Subject: [PATCH 4/5] Register a temporary log consumer to log warnings while parsing the YAML Signed-off-by: tempate --- tools/ddsrouter_tool/src/cpp/main.cpp | 71 +++++++++++++++------------ 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index 00ad21e97..29cc21ebc 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -47,6 +48,7 @@ using namespace eprosima; using namespace eprosima::ddsrouter; int exit(const ui::ProcessReturnCode& code); +void register_log_consumers(const ddspipe::core::DdsPipeLogConfiguration& configuration); int main( int argc, @@ -120,6 +122,12 @@ int main( commandline_args.timeout)); } + // Register the LogConsumers with the CommandLine configuration to log the YAML configuration errors. + ddspipe::core::DdsPipeLogConfiguration log_configuration; + log_configuration.set(utils::VerbosityKind::Warning); + + register_log_consumers(log_configuration); + ///// // DDS Router Initialization @@ -128,37 +136,8 @@ int main( yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(commandline_args.file_path, &commandline_args); - // Debug - { - const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration; - - // Remove every consumer - eprosima::utils::Log::ClearConsumers(); - - // Activate log with verbosity, as this will avoid running log thread with not desired kind - eprosima::utils::Log::SetVerbosity(log_configuration.verbosity); - - // Stdout Log Consumer - if (log_configuration.stdout_enable) - { - eprosima::utils::Log::RegisterConsumer( - std::make_unique(&log_configuration)); - } - - // DDS Log Consumer - if (log_configuration.publish.enable) - { - eprosima::utils::Log::RegisterConsumer( - std::make_unique(&log_configuration)); - } - - // NOTE: - // It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled - // in non debug or with LOG_NO_INFO=ON. - // This is the easiest way to allow to see Warnings and Errors from Fast DDS. - // Change it when Log Module is independent and with more extensive API. - // eprosima::utils::Log::SetCategoryFilter(std::regex("(DDSROUTER)")); - } + // Register the LogConsumers with their actual configuration + register_log_consumers(router_configuration.ddspipe_configuration.log_configuration); // Load XML profiles ddspipe::participants::XmlHandler::load_xml(router_configuration.xml_configuration); @@ -301,3 +280,33 @@ int exit(const ui::ProcessReturnCode& code) return static_cast(code); } + +void register_log_consumers(const ddspipe::core::DdsPipeLogConfiguration& configuration) +{ + // Remove every consumer + utils::Log::ClearConsumers(); + + // Activate log with verbosity, as this will avoid running log thread with not desired kind + utils::Log::SetVerbosity(configuration.verbosity); + + // Stdout Log Consumer + if (configuration.stdout_enable) + { + utils::Log::RegisterConsumer( + std::make_unique(&configuration)); + } + + // DDS Log Consumer + if (configuration.publish.enable) + { + utils::Log::RegisterConsumer( + std::make_unique(&configuration)); + } + + // NOTE: + // It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled + // in non debug or with LOG_NO_INFO=ON. + // This is the easiest way to allow to see Warnings and Errors from Fast DDS. + // Change it when Log Module is independent and with more extensive API. + // utils::Log::SetCategoryFilter(std::regex("(DDSROUTER)")); +} From 24e642278703f64a943147a3a064ab4f165e3f53 Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 26 Apr 2024 10:14:03 +0200 Subject: [PATCH 5/5] Overwrite some DdsPipe validation methods Signed-off-by: tempate --- .../src/cpp/YamlReader_configuration.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index bb1044870..c7e048613 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -37,6 +37,20 @@ namespace eprosima { namespace ddspipe { namespace yaml { +template <> +bool YamlValidator::validate( + const Yaml& yml, + const YamlReaderVersion& /* version */) +{ + // The method is rewritten to provide a specific validation of the DDS Router's MonitorConfiguration: + // i.e. the DDS Router's MonitorConfiguration doesn't have a status. + static const std::set tags{ + MONITOR_DOMAIN_TAG, + MONITOR_TOPICS_TAG}; + + return YamlValidator::validate_tags(yml, tags); +} + template <> void YamlReader::fill( ddsrouter::core::SpecsConfiguration& object,