cnti-testcatalog / testsuite

📞📱☎️📡🌐 Cloud Native Telecom Initiative (CNTI) Test Catalog is a tool to check for and provide feedback on the use of K8s + cloud native best practices in networking applications and platforms
https://wiki.lfnetworking.org/display/LN/Test+Catalog
Apache License 2.0
173 stars 71 forks source link

config: CNF installation (2.1) Transformer for old version of config #2147

Closed svteb closed 5 days ago

svteb commented 2 weeks ago

IMPORTANT

To speed up the development of the #2120 epic we are currently experimenting with a different approach to pull requests. This pull request has been created anew from a different branch, if you want to check the already existing discussion around it, view the old #2133.

Description

The transformer transforms the old config according to the structure proposed in #2129.

Notes

  1. To allow for some input validation, the v1 config was reimplemented as class in config_v1.cr.
  2. Certain arguments are found in cnf-testsuite.yml files spread across the samples and examples that are unused anywhere in the code, these are still parsed but ignored to avoid too much manual intervention in later stages.
  3. A new task has been added to allow for transformation, users can execute it by calling this command:

./cnf-testsuite transform_config OLD_FILE_PATH NEW_FILE_PATH

  1. The ConfigTransformer class found in config_transformer.cr automatically detects the version of the old config and transforms it to the latest version (currently only v1 -> v2), but allows for future extendibility.
  2. Upon determining the version of the old config, the main transform function is called which does the actual transformation in code (through use of Hashes and YAML::Any).
  3. The transform function uses the appropriate transformation rules (V1ToV2Transformation class in v1_to_v2_transformation.cr file)
  4. To make future extension of transformation rules easier, the function process_data has been added (TransformationBase class in transformation.cr file), this function converts the underlying hashes and arrays to the YAML::Any type and removes any nil branches so they don't clutter the final output.
  5. After the transformation is done the result can be printed to either String or dumped to a file through the serialize_to_string and serialize_to_file functions.
  6. Most edge cases have been resolved through the use of exceptions and their catching, giving users a readable output in case of any errors.

Issues:

Refs: #2130

How has this been tested:

Types of changes:

Checklist:

Documentation

Code Review

Issue