netdevops / hier_config

Hierarchical Configuration
MIT License
128 stars 24 forks source link

feat: preserve tags for negated lines in config_to_get_to #126

Open Frazew opened 8 months ago

Frazew commented 8 months ago

Summary

This PR introduces the ability to selectively generate snippets of remediation configuration based on tags

Changes

The only significant change is that when negating a line in the remediation configuration (_config_to_get_to_left), we preserve the tags that were previously set on the now-negated HConfigChild.

Example

(note: this is mostly verbatim from the docstring written in the test case)

Consider the case where we want to selectively remediate only parts of a configuration, we have two options:

  1. filter the generated and running configurations by tags, and create the remediation: this will work almost as expected but will fail spectacularly for some edge cases (see below)
  2. create the remediation from the generated and running configurations, and then filter by tags on the remediation (which, as I have only just noticed, is available in remediation_config_filtered_text)

Option (1) can fail in the following example scenario:

This happens because the generated configuration is completely empty once it is filtered: it does not contain this neighbor, hence it does not contain anything!

The right (?) approach is therefore to compute the remediation configuration and only filter it afterwards, which requires that we are able to tag it properly. remediation_config_filtered_text will re-run tagging on the remediation configuration, but this implies that our tags must also match remediation configurations (with its negations and other necessary artifacts). I believe that copying the tags to the remediation configuration when negating lines actually makes more sense.

Notes