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

fix flake8, pylint configs and issues, and update run_job.js #589

Merged
merged 4 commits into from
Sep 14, 2023
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
# E501: Line length is enforced by Black, so flake8 doesn't need to check it
# W503: Black disagrees with this rule, as does PEP 8; Black wins
ignore = E501, W503, F811, F401, F405, E203
ignore = E501, W503
6 changes: 2 additions & 4 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import sys

from django.utils.module_loading import import_string

from nautobot.core.settings import * # noqa: F403
from nautobot.core.settings_funcs import is_truthy, parse_redis_connection


#
# Misc. settings
#
Expand Down Expand Up @@ -200,7 +198,7 @@

# Modify django_jinja Environment for test cases
django_jinja_config = None
for template in TEMPLATES:
for template in TEMPLATES: # noqa: F405
if template["BACKEND"].startswith("django_jinja"):
django_jinja_config = template

Expand All @@ -213,4 +211,4 @@
jinja_options["undefined"] = "jinja2.StrictUndefined"

# Import filter function to have it register filter with django_jinja
from nautobot_golden_config.tests import jinja_filters # noqa: E402
from nautobot_golden_config.tests import jinja_filters # noqa: E402, F401
14 changes: 14 additions & 0 deletions docs/dev/dev_adr.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,17 @@ This function performs an additional permission validation, to check if the requ
Over time device(s) platform may change; whether this is a device refresh or full replacement. A Django `post_save` signal is used on the `ConfigCompliance` model and provides a reliable and efficient way to manage configuration compliance objects. This signal deletes any `ConfigCompliance` objects that don't match the current platform. This decision was made to avoid compliance reporting inconsistencies that can arise when outdated or irrelevant objects remain in the database which were generated with the previous platform.

This has a computational impact when updating a Device object's platform. This is similar to the computational impact of an SQL `cascade` option on a delete. This is largely unavoidable and should be limited in impact, such that it will only be the removal of the number of `ConfigCompliance` objects, which is no bigger than the number of `Config Features`, which is generally intended to be a small amount.

### Configuration Deployment and Remediation

Configuration remediation and deployments of any of the attributes based on the configuration compliance object are calculated based on the last run of the `ConfigCompliance` job. After a configuration deployment to fix any of these attributes (remediation, intended, missing) a new `ConfigCompliance` job must be run before all the compliance results will be updated.


### Manual ConfigPlans

When generating a manual `ConfigPlan` the Jinja2 template render has access to Django ORM methods like `.all()`, this also means that methods like `.delete()` can be called, the `render_template` functionality used by Golden Config inherits a Jinja2 Sandbox exception that will block unsafe calls. Golden Config will simply re-raise the exception `jinja2.exceptions.SecurityError: > is not safely callable`.


### Hidden Jobs and JobButtons

The configuration deployment and plans features of Golden Config come packaged with Jobs and JobButtons to execute the functionality. In order to to provide a repeatable and consistent behavior these Jobs and JobButtons are designed to only be executed via specialized views. They're not intended to be executed manually from the Jobs/JobButtons menus.
43 changes: 41 additions & 2 deletions docs/user/app_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,50 @@ Compliance requires Backups and Intended Configurations in order to be executed.

# Config Plans

Coming soon
Follow the steps below to get up and running for the configuration plans element of the plugin.

1. Enable the feature in the `PLUGIN_SETTINGS`. The configuration should have `"enable_plan": True` set in the `PLUGINS_CONFIG` dictionary for `nautobot_golden_config`.
2. Follow the steps in [Compliance](#compliance).
- Compliance is necessary if ConfigPlans will be generated utilizing any of the attributes provided by a Compliance object.
- This step may be skipped if only `manual` ConfigPlans are going to be generated.
3. Create a ConfigPlan

1. Navigate to `Golden Config -> Config Plans`
2. Click on `ADD` button.
3. Fill out the plan details and plan filters.
- The options dynamically change in the form based on the `plan type` selected.
- If the `plan type` is Intended, Remediation, Missing.
- Select the Compliance Features to use to generate the plan. If none are selected all features will be in scope.
- If the `plan type` is Manual.
- Create a manual plan to accomplish the goal. Note: Access to `obj` is available to dynamically populate fields via Jinja2 syntax.
4. Click `Generate`

> For in-depth details see [Navigating Config Plans](./app_feature_config_plans.md)

# Config Deploy

Coming soon
Follow the steps below to get up and running for the configuration deployment element of the plugin.

1. Enable the feature in the `PLUGIN_SETTINGS`. The configuration should have `"enable_deploy": True` set in the `PLUGINS_CONFIG` dictionary for `nautobot_golden_config`.
2. Follow the steps in [Config Plans](#config-plans).
3. Navigate to the specific ConfigPlan to deploy, or multi-select them from the ConfigPlan list view.
- If deploying from a specific ConfigPlan object. Click `Deploy` button and accept the warnings.
- If deploying from the ConfigPlan list view. Click `Deploy Selected` button and accept the warnings.
4. Interpret the results from the popup modal and navigate to the job result as needed for more details.

> Config Deployments utilize the dispatchers from nornir-nautobot just like the other functionality of Golden Config. See [Troubleshooting Dispatchers](./troubleshooting/troubleshoot_dispatchers.md) for more details.

# Config Remediation

Follow the steps below to get up and running for the configuration remediation element of the plugin.

1. Navigate to `Golden Config -> Compliance Rules`.
2. Select the rules in which you'd like to enable remediation on.
3. Edit the `Compliance Rule` and turn on the `Remediation` toggle button.
4. Run the `Compliance` job again which will generate the initial remediation plan for the feature.
5. Navigate to `Golden Config -> Config Compliance`, select the device and notice a remediation section is not present for the compliance details for the feature.

> For in-depth details see [Navigating Config Plans](./app_feature_remediation.md)

# Load Properties from Git

Expand Down
4 changes: 4 additions & 0 deletions docs/user/troubleshooting/troubleshoot_general.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ If none of these troubleshooting steps helped identify the problem please visit

- [Troubleshoot Credentials](./troubleshoot_credentials.md)
- [Troubleshoot Dispatchers](./troubleshoot_dispatchers.md)

### Detailed Diagrams

Golden config flow diagrams are available on the repositories [wiki](https://github.com/nautobot/nautobot-plugin-golden-config/wiki#diagrams).
2 changes: 1 addition & 1 deletion nautobot_golden_config/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
from nautobot_golden_config.nornir_plays.config_compliance import config_compliance
from nautobot_golden_config.nornir_plays.config_deployment import config_deployment
from nautobot_golden_config.nornir_plays.config_intended import config_intended
from nautobot_golden_config.utilities import constant
from nautobot_golden_config.utilities.config_plan import (
config_plan_default_status,
generate_config_set_from_compliance_feature,
generate_config_set_from_manual,
)
from nautobot_golden_config.utilities import constant
from nautobot_golden_config.utilities.git import GitRepo
from nautobot_golden_config.utilities.helper import get_job_filter

Expand Down
2 changes: 1 addition & 1 deletion nautobot_golden_config/migrations/0002_custom_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 3.1.3 on 2021-02-22 01:27

from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


def save_existing_sotagg_queries(apps, schema_editor):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from datetime import date

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import date
import logging
from datetime import date

from django.core.validators import ValidationError
from django.db import migrations

logger = logging.getLogger("nautobot")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Generated by Django 3.2.14 on 2022-07-11 14:18

from django.db import migrations, models
from django.db import migrations
from django.utils.text import slugify
import django.db.models.deletion


def create_dynamic_groups(apps, schedma_editor):
Expand Down
18 changes: 7 additions & 11 deletions nautobot_golden_config/nornir_plays/config_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@
import difflib
import logging
import os

from collections import defaultdict
from datetime import datetime

from netutils.config.compliance import parser_map, section_config, _open_file_config
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 nornir import InitNornir
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task

from nornir_nautobot.exceptions import NornirNautobotException
from nornir_nautobot.utils.logger import NornirLogger

from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from nautobot_plugin_nornir.constants import NORNIR_SETTINGS

from nautobot_golden_config.choices import ComplianceRuleConfigTypeChoice
from nautobot_golden_config.models import ComplianceRule, ConfigCompliance, GoldenConfig
from nautobot_golden_config.nornir_plays.processor import ProcessGoldenConfig
from nautobot_golden_config.utilities.db_management import close_threaded_db_connections
from nautobot_golden_config.models import ComplianceRule, ConfigCompliance, GoldenConfigSetting, GoldenConfig
from nautobot_golden_config.utilities.helper import (
get_device_to_settings_map,
get_job_filter,
verify_settings,
render_jinja_template,
get_json_config,
render_jinja_template,
verify_settings,
)
from nautobot_golden_config.nornir_plays.processor import ProcessGoldenConfig
from nautobot_golden_config.utilities.utils import get_platform


InventoryPluginRegister.register("nautobot-inventory", NautobotORMInventory)
LOGGER = logging.getLogger(__name__)

Expand Down
25 changes: 11 additions & 14 deletions nautobot_golden_config/nornir_plays/config_intended.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
"""Nornir job for generating the intended config."""
# pylint: disable=relative-beyond-top-level
import os
import logging

import os
from datetime import datetime
from nornir import InitNornir
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task

from django.template import engines
from jinja2.sandbox import SandboxedEnvironment

from nautobot_plugin_nornir.constants import NORNIR_SETTINGS
from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from nautobot_plugin_nornir.utils import get_dispatcher
from nornir import InitNornir
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task
from nornir_nautobot.exceptions import NornirNautobotException
from nornir_nautobot.plugins.tasks.dispatcher import dispatcher
from nornir_nautobot.utils.logger import NornirLogger

from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from nautobot_plugin_nornir.constants import NORNIR_SETTINGS
from nautobot_plugin_nornir.utils import get_dispatcher

from nautobot_golden_config.models import GoldenConfig
from nautobot_golden_config.nornir_plays.processor import ProcessGoldenConfig
from nautobot_golden_config.utilities.constant import PLUGIN_CFG
from nautobot_golden_config.utilities.db_management import close_threaded_db_connections
from nautobot_golden_config.models import GoldenConfigSetting, GoldenConfig
from nautobot_golden_config.utilities.graphql import graph_ql_query
from nautobot_golden_config.utilities.helper import (
get_device_to_settings_map,
get_job_filter,
verify_settings,
render_jinja_template,
verify_settings,
)
from nautobot_golden_config.utilities.graphql import graph_ql_query
from nautobot_golden_config.nornir_plays.processor import ProcessGoldenConfig

InventoryPluginRegister.register("nautobot-inventory", NautobotORMInventory)
LOGGER = logging.getLogger(__name__)
Expand Down
Loading