Skip to content

Commit

Permalink
Fix issue where parser is not mapped when not matching netutils norma… (
Browse files Browse the repository at this point in the history
#744)

* Fix issue where parser is not mapped when not matching netutils normalized names
  • Loading branch information
itdependsnetworks authored Apr 4, 2024
1 parent 1bc4163 commit 0a8d9d5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion development/docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
entrypoint:
- "sh"
- "-c" # this is to evaluate the $NAUTOBOT_LOG_LEVEL from the env
- "nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL" ## $$ because of docker-compose
- "watchmedo auto-restart --directory './' --pattern '*.py' --recursive -- nautobot-server celery worker -l $$NAUTOBOT_LOG_LEVEL --events" ## $$ because of docker-compose
depends_on:
- "nautobot"
healthcheck:
Expand Down
6 changes: 4 additions & 2 deletions nautobot_golden_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from nautobot.extras.utils import extras_features
from nautobot.utilities.utils import serialize_object, serialize_object_v2
from netutils.config.compliance import feature_compliance
from netutils.lib_mapper import HIERCONFIG_LIB_MAPPER_REVERSE
from netutils.lib_mapper import HIERCONFIG_LIB_MAPPER_REVERSE, NETUTILSPARSER_LIB_MAPPER_REVERSE

from nautobot_golden_config.choices import ComplianceRuleConfigTypeChoice, ConfigPlanTypeChoice, RemediationTypeChoice
from nautobot_golden_config.utilities.constant import ENABLE_SOTAGG, PLUGIN_CFG
Expand Down Expand Up @@ -67,7 +67,9 @@ def _get_cli_compliance(obj):
"name": obj.rule,
}
feature.update({"section": obj.rule.match_config.splitlines()})
value = feature_compliance(feature, obj.actual, obj.intended, get_platform(obj.device.platform.slug))
_platform_slug = get_platform(obj.device.platform.slug)
netutils_os_parser = NETUTILSPARSER_LIB_MAPPER_REVERSE.get(_platform_slug, _platform_slug)
value = feature_compliance(feature, obj.actual, obj.intended, netutils_os_parser)
compliance = value["compliant"]
if compliance:
compliance_int = 1
Expand Down
11 changes: 7 additions & 4 deletions nautobot_golden_config/nornir_plays/config_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from nautobot_plugin_nornir.constants import NORNIR_SETTINGS
from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from netutils.config.compliance import _open_file_config, parser_map, section_config
from netutils.lib_mapper import NETUTILSPARSER_LIB_MAPPER_REVERSE
from nornir import InitNornir
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task
Expand Down Expand Up @@ -69,16 +70,18 @@ def get_config_element(rule, config, obj, logger):
config_element = config_json

elif rule["obj"].config_type == ComplianceRuleConfigTypeChoice.TYPE_CLI:
if get_platform(obj.platform.slug) not in parser_map.keys():
_platform_slug = get_platform(obj.platform.slug)
netutils_os_parser = NETUTILSPARSER_LIB_MAPPER_REVERSE.get(_platform_slug, _platform_slug)
if netutils_os_parser not in parser_map.keys():
logger.log_failure(
obj,
f"There is currently no CLI-config parser support for platform slug `{get_platform(obj.platform.slug)}`, preemptively failed.",
f"There is currently no CLI-config parser support for platform slug `{netutils_os_parser}`, preemptively failed.",
)
raise NornirNautobotException(
f"There is currently no CLI-config parser support for platform slug `{get_platform(obj.platform.slug)}`, preemptively failed."
f"There is currently no CLI-config parser support for platform slug `{netutils_os_parser}`, preemptively failed."
)

config_element = section_config(rule, config, get_platform(obj.platform.slug))
config_element = section_config(rule, config, netutils_os_parser)

else:
logger.log_failure(obj, f"There rule type ({rule['obj'].config_type}) is not recognized.")
Expand Down
Loading

0 comments on commit 0a8d9d5

Please sign in to comment.