From 506cb996649cb4adcd896829dad9ea2991a3567b Mon Sep 17 00:00:00 2001 From: Justin Drew <2396364+jdrew82@users.noreply.github.com> Date: Fri, 4 Aug 2023 09:34:07 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Ensure=20that=20config=20?= =?UTF-8?q?contexts=20and=20schemas=20are=20updated=20when=20GitRepo=20is?= =?UTF-8?q?=20refreshed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nautobot_golden_config/jobs.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nautobot_golden_config/jobs.py b/nautobot_golden_config/jobs.py index 36e3b450..4b07c99f 100644 --- a/nautobot_golden_config/jobs.py +++ b/nautobot_golden_config/jobs.py @@ -4,7 +4,11 @@ from datetime import datetime from nautobot.dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Platform, Rack, RackGroup, Region, Site -from nautobot.extras.datasources.git import ensure_git_repository +from nautobot.extras.datasources.git import ( + ensure_git_repository, + refresh_git_config_contexts, + refresh_git_config_context_schemas, +) from nautobot.extras.jobs import BooleanVar, Job, MultiObjectVar, ObjectVar from nautobot.extras.models import DynamicGroup, GitRepository, Status, Tag from nautobot.tenancy.models import Tenant, TenantGroup @@ -46,10 +50,17 @@ def get_refreshed_repos(job_obj, repo_type, data=None): def update_config_context_repos(job_obj): """Simple helper method to update all configured Config Context git repositories.""" - repos = GitRepository.objects.filter(provided_contents__icontains="extras.configcontext") - for repo in repos: + config_context_repos = GitRepository.objects.filter(provided_contents__icontains="extras.configcontext") + for repo in config_context_repos: job_obj.log_debug(f"Pulling config context repo {repo.name}.") ensure_git_repository(repository_record=repo, job_result=job_obj.job_result) + refresh_git_config_contexts(repository_record=repo, job_result=job_obj.job_result) + schema_repos = GitRepository.objects.filter(provided_contents__icontains="extras.configcontextschema") + for repo in schema_repos: + # to ensure we aren't syncing the git repo multiple times unnecessarily, check if it's already in previous group + if repo not in config_context_repos: + ensure_git_repository(repository_record=repo, job_result=job_obj.job_result) + refresh_git_config_context_schemas(repository_record=repo, job_result=job_obj.job_result) def commit_check(method):