Skip to content

Commit

Permalink
Fix/skip test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcgill298 committed Sep 5, 2023
1 parent ff5e5a2 commit 914054c
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 282 deletions.
10 changes: 5 additions & 5 deletions nautobot_golden_config/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ def refresh_git_jinja(repository_record, job_result, delete=False): # pylint: d
"""Callback for gitrepository updates on Jinja Template repo."""
job_result.log(
"Successfully Pulled git repo",
level_choice=LogLevelChoices.LOG_SUCCESS,
level_choice=LogLevelChoices.LOG_DEBUG,
)


def refresh_git_intended(repository_record, job_result, delete=False): # pylint: disable=unused-argument
"""Callback for gitrepository updates on Intended Config repo."""
job_result.log(
"Successfully Pulled git repo",
level_choice=LogLevelChoices.LOG_SUCCESS,
level_choice=LogLevelChoices.LOG_DEBUG,
)


def refresh_git_backup(repository_record, job_result, delete=False): # pylint: disable=unused-argument
"""Callback for gitrepository updates on Git Backup repo."""
job_result.log(
"Successfully Pulled git repo",
level_choice=LogLevelChoices.LOG_SUCCESS,
level_choice=LogLevelChoices.LOG_DEBUG,
)


Expand Down Expand Up @@ -96,7 +96,7 @@ def refresh_git_gc_properties(repository_record, job_result, delete=False): # p

job_result.log(
"Successfully Completed sync of Golden Config properties",
level_choice=LogLevelChoices.LOG_SUCCESS,
level_choice=LogLevelChoices.LOG_DEBUG,
)


Expand Down Expand Up @@ -186,7 +186,7 @@ def update_git_gc_properties(golden_config_path, job_result, gc_config_item): #

job_result.log(
log_message,
level_choice=LogLevelChoices.LOG_SUCCESS,
level_choice=LogLevelChoices.LOG_DEBUG,
)

except MissingReference:
Expand Down
33 changes: 10 additions & 23 deletions nautobot_golden_config/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import django_filters
from django.db.models import Q

from nautobot.core.filters import MultiValueDateTimeFilter, TreeNodeMultipleChoiceFilter
from nautobot.dcim.models import Device, DeviceType, Manufacturer, Platform, Rack, RackGroup, Location
from nautobot.dcim.filters import DeviceFilterSet
from nautobot.extras.filters import StatusFilter
from nautobot.extras.filters import NautobotFilterSet
from nautobot.extras.models import Status, Role
from nautobot.tenancy.models import Tenant, TenantGroup
from nautobot.utilities.filters import TreeNodeMultipleChoiceFilter
from nautobot.utilities.filters import MultiValueDateTimeFilter

from nautobot_golden_config import models


# TODO: DeviceFilterSet has bugs in regards to Location in 2.0.0-rc.2
class GoldenConfigDeviceFilterSet(DeviceFilterSet): # pylint: disable=too-many-ancestors
"""Filter capabilities that extend the standard DeviceFilterSet."""

Expand Down Expand Up @@ -80,27 +81,13 @@ def _get_filter_lookup_dict(existing_filter):
to_field_name="slug",
label="Tenant (slug)",
)
region_id = TreeNodeMultipleChoiceFilter(
queryset=Location.objects.all(), # TODO: How does change to Location model affect this?
field_name="device__site__region=", # TODO: How does change to Location model affect this?
label="Region (ID)",
)
region = TreeNodeMultipleChoiceFilter(
queryset=Location.objects.all(), # TODO: How does change to Location model affect this?
field_name="device__site__region", # TODO: How does change to Location model affect this?
to_field_name="slug",
label="Region (slug)",
)
site_id = django_filters.ModelMultipleChoiceFilter(
field_name="device__site", # TODO: How does change to Location model affect this?
queryset=Location.objects.all(), # TODO: How does change to Location model affect this?
label="Site (ID)",
)
site = django_filters.ModelMultipleChoiceFilter(
field_name="device__site__slug", # TODO: How does change to Location model affect this?
queryset=Location.objects.all(), # TODO: How does change to Location model affect this?
to_field_name="slug",
label="Site name (slug)",
location = TreeNodeMultipleChoiceFilter(
# Not limiting to content_type=dcim.device to allow parent locations to be included
# i.e. include all sites in a Region, even though Region can't be assigned to a Device
queryset=Location.objects.all(),
field_name="device__location__id",
to_field_name="pk",
label="Location (ID)",
)
rack_group_id = TreeNodeMultipleChoiceFilter(
queryset=RackGroup.objects.all(),
Expand Down
20 changes: 13 additions & 7 deletions nautobot_golden_config/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=too-many-ancestors

from django import forms
from django.contrib.contenttypes.models import ContentType

import nautobot.extras.forms as extras_forms
import nautobot.core.forms as core_forms
Expand All @@ -19,8 +18,6 @@
class ConfigComplianceFilterForm(NautobotFilterForm):
"""Filter Form for ConfigCompliance instances."""

_device_ct = ContentType.objects.get_for_model(Device)

model = models.ConfigCompliance
# Set field order to be explicit
field_order = [
Expand Down Expand Up @@ -50,23 +47,32 @@ class ConfigComplianceFilterForm(NautobotFilterForm):
query_params={"group": "$tenant_group"},
)
location = core_forms.DynamicModelMultipleChoiceField(
queryset=Location.objects.filter(location_type__content_types=_device_ct), to_field_name="", required=False,
# Not limiting to query_params={"content_type": "dcim.device" to allow parent locations to be included
# i.e. include all sites in a Region, even though Region can't be assigned to a Device
queryset=Location.objects.all(),
to_field_name="pk",
required=False,
)
rack_group_id = core_forms.DynamicModelMultipleChoiceField(
queryset=RackGroup.objects.all(), required=False, label="Rack group", query_params={"location": "$location"} # TODO: Verify change to location works
queryset=RackGroup.objects.all(),
required=False,
label="Rack group",
query_params={"location": "$location"},
)
rack_id = core_forms.DynamicModelMultipleChoiceField(
queryset=Rack.objects.all(),
required=False,
label="Rack",
null_option="None",
query_params={
"location": "$location", # TODO: Verify change to location works
"location": "$location",
"group_id": "$rack_group_id",
},
)
role = core_forms.DynamicModelMultipleChoiceField(
queryset=Role.objects.all(), to_field_name="slug", required=False # TODO: Fix slug field, Test with change to Role model
queryset=Role.objects.all(),
to_field_name="slug",
required=False, # TODO: Fix slug field, Test with change to Role model
)
manufacturer = core_forms.DynamicModelMultipleChoiceField(
queryset=Manufacturer.objects.all(), to_field_name="slug", required=False, label="Manufacturer"
Expand Down
79 changes: 50 additions & 29 deletions nautobot_golden_config/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ def inner(obj, data, commit):
return inner


# TODO: Does changing region/site to location affect nornir jobs?


class FormEntry: # pylint disable=too-few-public-method
"""Class definition to use as Mixin for form definitions."""

tenant_group = MultiObjectVar(model=TenantGroup, required=False)
tenant = MultiObjectVar(model=Tenant, required=False)
region = MultiObjectVar(model=Location, required=False) # TODO: How does change to Location model affect this?
site = MultiObjectVar(model=Location, required=False) # TODO: How does change to Location model affect this?
location = MultiObjectVar(model=Location, required=False)
rack_group = MultiObjectVar(model=RackGroup, required=False)
rack = MultiObjectVar(model=Rack, required=False)
role = MultiObjectVar(model=Role, required=False) # TODO: How does change to Role model affect this?
Expand All @@ -81,10 +83,11 @@ class FormEntry: # pylint disable=too-few-public-method
class ComplianceJob(Job, FormEntry):
"""Job to to run the compliance engine."""

# TODO: Remove these as they are already defined via inheritence

tenant_group = FormEntry.tenant_group
tenant = FormEntry.tenant
region = FormEntry.region
site = FormEntry.site
location = FormEntry.location
rack_group = FormEntry.rack_group
rack = FormEntry.rack
role = FormEntry.role
Expand All @@ -103,17 +106,22 @@ class Meta:
description = "Run configuration compliance on your network infrastructure."

@commit_check
def run(self, data, commit): # pylint: disable=too-many-branches
# TODO: Fix pylint arguments-differ during Job 2.x migration
def run(self, data, commit): # pylint: disable=too-many-branches,arguments-differ
"""Run config compliance report script."""
# pylint: disable=unused-argument
self.log_debug("Starting compliance job.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Starting compliance job.") # pylint: disable=no-member

self.log_debug("Refreshing intended configuration git repository.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Refreshing intended configuration git repository.") # pylint: disable=no-member
get_refreshed_repos(job_obj=self, repo_type="intended_repository", data=data)
self.log_debug("Refreshing backup configuration git repository.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Refreshing backup configuration git repository.") # pylint: disable=no-member
get_refreshed_repos(job_obj=self, repo_type="backup_repository", data=data)

self.log_debug("Starting config compliance nornir play.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Starting config compliance nornir play.") # pylint: disable=no-member
config_compliance(self, data)


Expand All @@ -122,8 +130,7 @@ class IntendedJob(Job, FormEntry):

tenant_group = FormEntry.tenant_group
tenant = FormEntry.tenant
region = FormEntry.region
site = FormEntry.site
location = FormEntry.location
rack_group = FormEntry.rack_group
rack = FormEntry.rack
role = FormEntry.role
Expand All @@ -142,25 +149,33 @@ class Meta:
description = "Generate the configuration for your intended state."

@commit_check
def run(self, data, commit):
# TODO: Fix pylint arguments-differ,unused-argument during Job 2.x migration
def run(self, data, commit): # pylint: disable=arguments-differ,unused-argument
"""Run config generation script."""
self.log_debug("Starting intended job.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Starting intended job.") # pylint: disable=no-member

now = datetime.now()

self.log_debug("Pull Jinja template repos.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Pull Jinja template repos.") # pylint: disable=no-member
get_refreshed_repos(job_obj=self, repo_type="jinja_repository", data=data)

self.log_debug("Pull Intended config repos.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Pull Intended config repos.") # pylint: disable=no-member
# Instantiate a GitRepo object for each GitRepository in GoldenConfigSettings.
intended_repos = get_refreshed_repos(job_obj=self, repo_type="intended_repository", data=data)

self.log_debug("Building device settings mapping and running intended config nornir play.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug( # pylint: disable=no-member
"Building device settings mapping and running intended config nornir play."
)
config_intended(self, data)

# Commit / Push each repo after job is completed.
for intended_repo in intended_repos:
self.log_debug(f"Push new intended configs to repo {intended_repo.url}.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug(f"Push new intended configs to repo {intended_repo.url}.") # pylint: disable=no-member
intended_repo.commit_with_added(f"INTENDED CONFIG CREATION JOB - {now}")
intended_repo.push()

Expand All @@ -170,8 +185,7 @@ class BackupJob(Job, FormEntry):

tenant_group = FormEntry.tenant_group
tenant = FormEntry.tenant
region = FormEntry.region
site = FormEntry.site
location = FormEntry.location
rack_group = FormEntry.rack_group
rack = FormEntry.rack
role = FormEntry.role
Expand All @@ -190,23 +204,29 @@ class Meta:
description = "Backup the configurations of your network devices."

@commit_check
def run(self, data, commit):
# TODO: Fix pylint arguments-differ,unused-argument during Job 2.x migration
def run(self, data, commit): # pylint: disable=arguments-differ,unused-argument
"""Run config backup process."""
self.log_debug("Starting backup job.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Starting backup job.") # pylint: disable=no-member
now = datetime.now()
self.log_debug("Pull Backup config repo.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Pull Backup config repo.") # pylint: disable=no-member

# Instantiate a GitRepo object for each GitRepository in GoldenConfigSettings.
backup_repos = get_refreshed_repos(job_obj=self, repo_type="backup_repository", data=data)

self.log_debug(f"Starting backup jobs to the following repos: {backup_repos}")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug(f"Starting backup jobs to the following repos: {backup_repos}") # pylint: disable=no-member

self.log_debug("Starting config backup nornir play.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug("Starting config backup nornir play.") # pylint: disable=no-member
config_backup(self, data)

# Commit / Push each repo after job is completed.
for backup_repo in backup_repos:
self.log_debug(f"Pushing Backup config repo {backup_repo.url}.")
# TODO: Fix pylint no-member during Job 2.x migration
self.log_debug(f"Pushing Backup config repo {backup_repo.url}.") # pylint: disable=no-member
backup_repo.commit_with_added(f"BACKUP JOB {now}")
backup_repo.push()

Expand All @@ -224,7 +244,8 @@ class Meta:
description = "Process to run all Golden Configuration jobs configured."

@commit_check
def run(self, data, commit):
# TODO: Fix pylint arguments-differ,unused-argument during Job 2.x migration
def run(self, data, commit): # pylint: disable=arguments-differ,unused-argument
"""Run all jobs."""
if ENABLE_INTENDED:
IntendedJob().run.__func__(self, data, True) # pylint: disable=too-many-function-args
Expand All @@ -239,8 +260,7 @@ class AllDevicesGoldenConfig(Job):

tenant_group = FormEntry.tenant_group
tenant = FormEntry.tenant
region = FormEntry.region
site = FormEntry.site
location = FormEntry.location
rack_group = FormEntry.rack_group
rack = FormEntry.rack
role = FormEntry.role
Expand All @@ -259,7 +279,8 @@ class Meta:
description = "Process to run all Golden Configuration jobs configured against multiple devices."

@commit_check
def run(self, data, commit):
# TODO: Fix pylint arguments-differ,unused-argument during Job 2.x migration
def run(self, data, commit): # pylint: disable=arguments-differ,unused-argument
"""Run all jobs."""
if ENABLE_INTENDED:
IntendedJob().run.__func__(self, data, True) # pylint: disable=too-many-function-args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def create_dynamic_groups(apps, schedma_editor):
name = f"GoldenConfigSetting {i.name} scope"
d_group = model.objects.create(
name=name,
slug=slugify(name),
filter=i.scope,
content_type=content_type,
description="Automatically generated for nautobot_golden_config version 1.2.0.",
Expand Down
Loading

0 comments on commit 914054c

Please sign in to comment.