Skip to content

Hier Config V3 Upgrade #902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Hier Config V3 Upgrade #902

wants to merge 7 commits into from

Conversation

jtdub
Copy link

@jtdub jtdub commented Feb 27, 2025

What's Changed

This pull requests updates hier_config from 2.2.2 to 3.2.2. This hier_config migration across major revisions required a refactor of the hier_config implementation in Golden Config. All this occurs under the hood and will not change the remediation experience for the user.

To Do

  • Update hier-config in pyproject.toml.
  • Update hier_config implementation in models.py.
  • Update documentation to reflect the location of current hier config documentation.
  • Add change log.
  • Add remediation tests.

@jtdub jtdub self-assigned this Feb 27, 2025
@jtdub jtdub marked this pull request as draft February 27, 2025 00:06
@jtdub jtdub changed the title WIP | Hier Config V3 Upgrade Hier Config V3 Upgrade Feb 27, 2025
@jtdub jtdub marked this pull request as ready for review February 27, 2025 00:53
@jtdub jtdub marked this pull request as draft February 27, 2025 21:33
@jtdub jtdub marked this pull request as ready for review February 28, 2025 01:12
@@ -177,32 +178,39 @@ def _verify_get_custom_compliance_data(compliance_details):

def _get_hierconfig_remediation(obj):
"""Returns the remediating config."""
hierconfig_os = obj.device.platform.network_driver_mappings["hier_config"]
hierconfig_os = obj.device.platform.network_driver_mappings.get("hier_config")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing the hier config v3 update, I noticed that if the network_driver_mappings wasn't created, because of an unsupported driver, then this would cause an exception that isn't handled. By changing this to .get, it produces a default value of None, which would cause the ValidationError below and handled appropriately.

if not hierconfig_os:
raise ValidationError(f"platform {obj.network_driver} is not supported by hierconfig.")
raise ValidationError(f"platform {obj.device.platform.network_driver} is not supported by hierconfig.")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this function, I noticed that obj.network_driver is not the correct syntax, it should be obj.device.platform.network_driver. This would cause a separate exception that is not handled.


try:
remediation_setting_obj = RemediationSetting.objects.get(platform=obj.rule.platform)
except Exception as err: # pylint: disable=broad-except:
raise ValidationError(f"Platform {obj.network_driver} has no Remediation Settings defined.") from err
raise ValidationError(
f"Platform {obj.device.platform.network_driver} has no Remediation Settings defined."
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing this function, I noticed that obj.network_driver is not the correct syntax, it should be obj.device.platform.network_driver. This would cause a separate exception that is not handled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemediationSetting is set per Platform, so probably we don't need network_driver here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The network driver is specifically used to map to a hier config driver in netutils.

@@ -177,32 +178,39 @@ def _verify_get_custom_compliance_data(compliance_details):

def _get_hierconfig_remediation(obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to document and standardize and document inputs in this method


try:
remediation_setting_obj = RemediationSetting.objects.get(platform=obj.rule.platform)
except Exception as err: # pylint: disable=broad-except:
raise ValidationError(f"Platform {obj.network_driver} has no Remediation Settings defined.") from err
raise ValidationError(
f"Platform {obj.device.platform.network_driver} has no Remediation Settings defined."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemediationSetting is set per Platform, so probably we don't need network_driver here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants