Skip to content

Commit

Permalink
Closes #668 - Removed unneeded lookup for GoldenConfigSetting (#685)
Browse files Browse the repository at this point in the history
* Closes #668 - Removed unneeded lookup for GoldenConfigSetting

* Fix flake8

---------

Co-authored-by: Jeremy White <[email protected]>
  • Loading branch information
itdependsnetworks and whitej6 authored Dec 13, 2023
1 parent f8d106a commit cc647ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on: # yamllint disable-line rule:truthy rule:comments
branches:
- "main"
- "develop"
- "ltm-1.6"
tags:
- "v*"
pull_request: ~
Expand Down
6 changes: 6 additions & 0 deletions docs/admin/release_notes/version_1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
- Add functionality to compliance result to provide a Remediation plan.
- Supports Nautobot >=1.6.1,<2.0.0.

## v1.6.3 - 2023-10

### Fixed

- [#668](https://github.com/nautobot/nautobot-plugin-golden-config/issue/668) - Removed unneeded lookup for GoldenConfigSetting

## v1.6.2 - 2023-09

### Fixed
Expand Down
12 changes: 8 additions & 4 deletions nautobot_golden_config/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, Q
from django.urls import reverse
from nautobot.dcim.models import Device
from nautobot.extras.plugins import PluginTemplateExtension
from nautobot_golden_config.models import ConfigCompliance, GoldenConfig
from nautobot_golden_config.utilities.constant import CONFIG_FEATURES, ENABLE_COMPLIANCE
from nautobot_golden_config.utilities.helper import get_device_to_settings_map


class ConfigComplianceDeviceCheck(PluginTemplateExtension): # pylint: disable=abstract-method
Expand All @@ -21,6 +19,8 @@ def get_device(self):
def right_page(self):
"""Content to add to the configuration compliance."""
comp_obj = ConfigCompliance.objects.filter(device=self.get_device()).values("rule__feature__name", "compliance")
if not comp_obj:
return ""
extra_context = {
"compliance": comp_obj,
"device": self.get_device(),
Expand Down Expand Up @@ -72,6 +72,8 @@ def right_page(self):
.order_by("rule__feature__name")
.values("rule__feature__name", "compliant", "non_compliant")
)
if not comp_obj:
return ""
extra_context = {"compliance": comp_obj, "template_type": "location"}
return self.render(
"nautobot_golden_config/content_template.html",
Expand All @@ -92,13 +94,13 @@ def right_page(self):
"""Content to add to the configuration compliance."""
device = self.get_device()
golden_config = GoldenConfig.objects.filter(device=device).first()
settings = get_device_to_settings_map(queryset=Device.objects.filter(id=device.id))
if not golden_config:
return ""
extra_context = {
"device": self.get_device(), # device,
"golden_config": golden_config,
"template_type": "device-configs",
"config_features": CONFIG_FEATURES,
"matched_config_setting": settings.get(device.id, False),
}
return self.render(
"nautobot_golden_config/content_template.html",
Expand Down Expand Up @@ -128,6 +130,8 @@ def right_page(self):
.order_by("rule__feature__name")
.values("rule__feature__name", "compliant", "non_compliant")
)
if not comp_obj:
return ""
extra_context = {"compliance": comp_obj, "template_type": "location"}
return self.render(
"nautobot_golden_config/content_template.html",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<th>Config</th>
</tr>
</thead>
{% if matched_config_setting %}
<tbody>
{% if config_features.compliance and golden_config.compliance_config %}
<tr>
Expand Down Expand Up @@ -118,7 +117,6 @@
</tr>
{% endif %}
</tbody>
{% endif %}
</table>
</div>
{% endif %}
Expand Down

0 comments on commit cc647ca

Please sign in to comment.