nautobot-app-golden-config icon indicating copy to clipboard operation
nautobot-app-golden-config copied to clipboard

Golden Config Jobs no longer detects repository types

Open apast0r opened this issue 3 months ago • 4 comments

Environment

  • Python version: 3.11.9
  • Nautobot version: 2.2.3
  • nautobot-golden-config version: 2.0.4

Expected Behavior

When a Job is launched, it should detect which kind of repos to sync.

imagen

Observed Behavior

When a Job is launched, it can't detect any kind of repo:

imagen

Steps to Reproduce

  1. Enable any kind of Job from Golden Configuration
  2. Launch the job
  3. It finish with no errors, but it doesn't sync with the repos.

imagen

apast0r avatar May 08 '24 15:05 apast0r

Appears to be due to an unintended change in the Job().name value in Nautobot 2.2.3. We'll see about restoring the pre-2.2.3 behavior.

glennmatthews avatar May 08 '24 21:05 glennmatthews

Hi @glennmatthews , thanks for the quick response.

Leaving aside the change to the Job().name function, Why not move the logic to each Job definition? The Job should know which type of repo to use.

Replace this:

def get_repo_types_for_job(job_name):
    """Logic to determine which repo_types are needed based on job + plugin settings."""
    repo_types = []
    if constant.ENABLE_BACKUP and job_name == "nautobot_golden_config.jobs.BackupJob":
        repo_types.extend(["backup_repository"])
    if constant.ENABLE_INTENDED and job_name == "nautobot_golden_config.jobs.IntendedJob":
        repo_types.extend(["jinja_repository", "intended_repository"])
    if constant.ENABLE_COMPLIANCE and job_name == "nautobot_golden_config.jobs.ComplianceJob":
        repo_types.extend(["intended_repository", "backup_repository"])
    if "All" in job_name:
        repo_types.extend(["backup_repository", "jinja_repository", "intended_repository"])
    return repo_types

Whit this:

class BackupJob(GoldenConfigJobMixin, FormEntry):
    """Job to to run the backup job."""
    repo_types = ["backup_repository"]

class IntendedJob(GoldenConfigJobMixin, FormEntry):
    """Job to to run generation of intended configurations."""
    repo_types = ["jinja_repository", "intended_repository"]

class ComplianceJob(GoldenConfigJobMixin, FormEntry):
    """Job to to run the compliance engine."""
    repo_types = ["intended_repository", "backup_repository"]

class AllGoldenConfig(GoldenConfigJobMixin):
    """Job to to run all three jobs against a single device."""

    device = ObjectVar(model=Device, required=True)
    debug = BooleanVar(description="Enable for more verbose debug logging")
    repo_types = ["backup_repository", "jinja_repository", "intended_repository"]

class AllDevicesGoldenConfig(GoldenConfigJobMixin, FormEntry):
    """Job to to run all three jobs against multiple devices."""
    repo_types = ["backup_repository", "jinja_repository", "intended_repository"]

Then change this line:

gitrepo_types = list(set(get_repo_types_for_job(job.name)))

To this:

gitrepo_types = job.repo_types.copy()

apast0r avatar May 09 '24 06:05 apast0r

Sounds sensible to me. My priority was to unblock existing deployments but I agree that that looks like a desirable refactor.

glennmatthews avatar May 09 '24 12:05 glennmatthews

Forwarding back to golden-config to be fixed there instead.

glennmatthews avatar May 09 '24 15:05 glennmatthews