Skip to content
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

Closes #81: Handle exceptions when calculating missing/extra commands in Configurator and improve error logging #88

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions netbox_config_diff/configurator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ async def _collect_one_diff(self, device: ConfiguratorDeviceDataClass) -> None:

device.diff = get_unified_diff(device.rendered_config, device.actual_config, device.name)
self.logger.add_diff(device.name, diff=device.diff)
device.missing = diff_network_config(
device.rendered_config, device.actual_config, PLATFORM_MAPPING[device.platform]
)
device.extra = diff_network_config(
device.actual_config, device.rendered_config, PLATFORM_MAPPING[device.platform]
)
try:
device.missing = diff_network_config(
device.rendered_config, device.actual_config, PLATFORM_MAPPING[device.platform]
)
device.extra = diff_network_config(
device.actual_config, device.rendered_config, PLATFORM_MAPPING[device.platform]
)
except Exception as e:
self.logger.log_warning(f"Unable to get missing/extra commands for {device.name}: {e}")
device.patch = get_remediation_commands(
device.name, device.platform, device.actual_config, device.rendered_config
)
Expand Down
6 changes: 3 additions & 3 deletions netbox_config_diff/configurator/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def _render_substituted_config(

replace_sections = [(name, re.search(pattern=pattern, string=source_config)) for name, pattern in substitutes]

rendered_config = ""
rendered_config = config_template
for name, replace_section in replace_sections:
if not replace_section:
msg = f"substitution pattern {name} was unable to find a match in the target config" " source"
msg = f"substitution pattern {name} was unable to find a match in the target configsource"
self.logger.critical(msg)
raise TemplateError(msg)

replace_group = replace_section.group()
rendered_config = config_template.replace(f"{{{{ {name} }}}}", replace_group)
rendered_config = rendered_config.replace(f"{{{{ {name} }}}}", replace_group)

# remove any totally empty lines (from bad regex, or just device spitting out lines w/
# nothing on it
Expand Down
Loading