Skip to content

Commit

Permalink
Merge pull request #739 from nautobot/prep-2.0.3
Browse files Browse the repository at this point in the history
prepping 2.0.3 release
  • Loading branch information
itdependsnetworks authored Mar 14, 2024
2 parents 8daf92f + f0b4c73 commit af9926e
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 111 deletions.
1 change: 1 addition & 0 deletions changes/736.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a boolean job parameter `fail_job_on_task_failure` which will determine whether a single task failure anywhere in the job-result should result in job-result status of failed vs successful.
1 change: 1 addition & 0 deletions changes/736.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes repo push and commit not executing if a exception was raised on any task inside a job.
1 change: 1 addition & 0 deletions changes/739.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prep release v2.0.3
2 changes: 1 addition & 1 deletion development/towncrier_template.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{% if render_title %}
## [v{{ versiondata.version }} ({{ versiondata.date }})]({{ cookiecutter.repo_url }}/releases/tag/v{{ versiondata.version}})
## [v{{ versiondata.version }} ({{ versiondata.date }})](https://github.com/nautobot/nautobot-app-golden-config/releases/tag/v{{ versiondata.version}})

{% endif %}
{% for section, _ in sections.items() %}
Expand Down
11 changes: 11 additions & 0 deletions docs/admin/release_notes/version_2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
!!! note
Please see [migrating guide](../migrating_to_v2.md) for details on migration.


## v2.0.3 2024-03

### Added

- [#736](https://github.com/nautobot/nautobot-app-golden-config/issues/736) - Add a boolean job parameter `fail_job_on_task_failure` which will determine whether a single task failure anywhere in the job-result should result in job-result status of failed vs successful.

### Fixed

- [#736](https://github.com/nautobot/nautobot-app-golden-config/issues/736) - Fixes repo push and commit not executing if a exception was raised on any task inside a job.

## v2.0.2 - 2024-03

### Added
Expand Down
40 changes: 25 additions & 15 deletions nautobot_golden_config/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,28 @@ def gc_repo_wrapper(self, *args, **kwargs):
)
current_repos = get_refreshed_repos(job_obj=self, repo_types=gitrepo_types, data=self.qs)
# This is where the specific jobs run method runs via this decorator.
func(self, *args, **kwargs)
now = make_aware(datetime.now())
self.logger.debug(
f"Finished the {self.Meta.name} job execution.",
extra={"grouping": "GC After Run"},
)
if current_repos:
for _, repo in current_repos.items():
if repo["to_commit"]:
self.logger.debug(
f"Pushing {self.Meta.name} results to repo {repo['repo_obj'].base_url}.",
extra={"grouping": "GC Repo Commit and Push"},
)
repo["repo_obj"].commit_with_added(f"{self.Meta.name.upper()} JOB {now}")
repo["repo_obj"].push()
try:
func(self, *args, **kwargs)
except Exception as error: # pylint: disable=broad-exception-caught
error_msg = f"`E3001:` General Exception handler, original error message ```{error}```"
# Raise error only if the job kwarg (checkbox) is selected to do so on the job execution form.
if kwargs["fail_job_on_task_failure"]:
raise NornirNautobotException(error_msg) from error
finally:
now = make_aware(datetime.now())
self.logger.debug(
f"Finished the {self.Meta.name} job execution.",
extra={"grouping": "GC After Run"},
)
if current_repos:
for _, repo in current_repos.items():
if repo["to_commit"]:
self.logger.debug(
f"Pushing {self.Meta.name} results to repo {repo['repo_obj'].base_url}.",
extra={"grouping": "GC Repo Commit and Push"},
)
repo["repo_obj"].commit_with_added(f"{self.Meta.name.upper()} JOB {now}")
repo["repo_obj"].push()

return gc_repo_wrapper

Expand Down Expand Up @@ -161,6 +168,9 @@ class FormEntry: # pylint disable=too-few-public-method
label="Device Status",
)
debug = BooleanVar(description="Enable for more verbose debug logging")
fail_job_on_task_failure = BooleanVar(
description="If any device in the tasks list fails, fail the entire job result."
)


class GoldenConfigJobMixin(Job): # pylint: disable=abstract-method
Expand Down
58 changes: 25 additions & 33 deletions nautobot_golden_config/nornir_plays/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
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 nautobot_golden_config.models import ConfigRemove, ConfigReplace, 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.utilities.helper import ( # get_device_to_settings_map,; get_job_filter,
from nautobot_golden_config.utilities.helper import (
dispatch_params,
render_jinja_template,
verify_settings,
Expand Down Expand Up @@ -103,36 +102,29 @@ def config_backup(job_result, log_level, qs, device_to_settings_map):
if not replace_regex_dict.get(regex.platform.network_driver):
replace_regex_dict[regex.platform.network_driver] = []
replace_regex_dict[regex.platform.network_driver].append({"replace": regex.replace, "regex": regex.regex})
try:
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir backup tasks.")
nr_with_processors.run(
task=run_backup,
name="BACKUP CONFIG",
logger=logger,
device_to_settings_map=device_to_settings_map,
remove_regex_dict=remove_regex_dict,
replace_regex_dict=replace_regex_dict,
)
logger.debug("Completed configuration from devices.")

except Exception as error:
error_msg = f"`E3001:` General Exception handler, original error message ```{error}```"
logger.error(error_msg)
raise NornirNautobotException(error_msg) from error

},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir backup tasks.")
nr_with_processors.run(
task=run_backup,
name="BACKUP CONFIG",
logger=logger,
device_to_settings_map=device_to_settings_map,
remove_regex_dict=remove_regex_dict,
replace_regex_dict=replace_regex_dict,
)
logger.debug("Completed configuration from devices.")
logger.debug("Completed configuration backup job for devices.")
52 changes: 22 additions & 30 deletions nautobot_golden_config/nornir_plays/config_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,35 +177,27 @@ def config_compliance(job_result, log_level, qs, device_to_settings_map):

for settings in set(device_to_settings_map.values()):
verify_settings(logger, settings, ["backup_path_template", "intended_path_template"])

try:
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir compliance tasks.")
nr_with_processors.run(
task=run_compliance,
name="RENDER COMPLIANCE TASK GROUP",
logger=logger,
device_to_settings_map=device_to_settings_map,
rules=rules,
)

except Exception as error:
error_msg = f"`E3001:` General Exception handler, original error message ```{error}```"
logger.error(error_msg)
raise NornirNautobotException(error_msg) from error

},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir compliance tasks.")
nr_with_processors.run(
task=run_compliance,
name="RENDER COMPLIANCE TASK GROUP",
logger=logger,
device_to_settings_map=device_to_settings_map,
rules=rules,
)
logger.debug("Completed compliance job for devices.")
55 changes: 24 additions & 31 deletions nautobot_golden_config/nornir_plays/config_intended.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,35 +110,28 @@ def config_intended(job_result, log_level, job_class_instance, qs, device_to_set

# Retrieve filters from the Django jinja template engine
jinja_env = get_django_env()

try:
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
"plugin": "nautobot-inventory",
"options": {
"credentials_class": NORNIR_SETTINGS.get("credentials"),
"params": NORNIR_SETTINGS.get("inventory_params"),
"queryset": qs,
"defaults": {"now": now},
},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir render config tasks.")
# Run the Nornir Tasks
nr_with_processors.run(
task=run_template,
name="RENDER CONFIG",
logger=logger,
device_to_settings_map=device_to_settings_map,
job_class_instance=job_class_instance,
jinja_env=jinja_env,
)

except Exception as error:
error_msg = f"`E3001:` General Exception handler, original error message ```{error}```"
logger.error(error_msg)
raise NornirNautobotException(error_msg) from error
},
) as nornir_obj:
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

logger.debug("Run nornir render config tasks.")
# Run the Nornir Tasks
nr_with_processors.run(
task=run_template,
name="RENDER CONFIG",
logger=logger,
device_to_settings_map=device_to_settings_map,
job_class_instance=job_class_instance,
jinja_env=jinja_env,
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nautobot-golden-config"
version = "2.0.2"
version = "2.0.3"
description = "An app for configuration on nautobot"
authors = ["Network to Code, LLC <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit af9926e

Please sign in to comment.