nautobot / nautobot-app-golden-config

Golden Configuration App for Nautobot.
https://docs.nautobot.com/projects/golden-config/en/latest/
Other
98 stars 56 forks source link

Golden Config Jobs no longer detects repository types #759

Closed apast0r closed 3 months ago

apast0r commented 4 months ago

Environment

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

glennmatthews commented 4 months ago

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.

apast0r commented 4 months ago

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()
glennmatthews commented 4 months ago

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

glennmatthews commented 4 months ago

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