Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix repo sync not executing on any task failure #684

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

jeffkala
Copy link
Contributor

@jeffkala jeffkala commented Dec 7, 2023

fixes issues seen in NB2.0 installs where if any backup/intended fails out of all devices selected that the repo commit, push never executes.
More details in : #657 (comment)

@itdependsnetworks
Copy link
Contributor

I was thinking something like

class GoldenConfigJobMixin(Job):  # pylint: disable=abstract-method
    """Reused mixin to be able to reuse common celery primitives in all GC jobs."""


    def before_start(self, repo_types, *args, **data):
        """Ensure repos before tasks runs."""
        self.logger.debug(f"Repository types to sync: {', '.join(repo_types)}")
        for repo in self.Meta.repos:
            self.logger.debug(f"Refreshing repositories of type {repo}.")
            # repo_obj = some_magic_to_get_repo  <---- update
            current_repos = get_refreshed_repos(job_obj=self, repo_type=repo, data=data)

    def after_return(self, job_type, *args):
        """Commit and Push each repo after job is completed."""
        now = make_aware(datetime.now())
        for repo in self.Meta.repos:
            self.logger.debug(f"Pushing {job_type} results to repo %s.", repo.base_url)
            repo.commit_with_added(f"{job_type} JOB {now}")
            repo.push()



class BackupJob(GoldenConfigJobMixin, FormEntry):
    """Job to to run the backup job."""

    class Meta:
        """Meta object boilerplate for backup configurations."""

        name = "Backup Configurations"
        description = "Backup the configurations of your network devices."
        has_sensitive_variables = False
        repos = ["backup"]  <---- key piece

    def run(self, *args, **data):
        """Run config backup process."""
        self.logger.debug("Starting config backup nornir play.")
        config_backup(self.job_result, self.logger.getEffectiveLevel(), data)

@jeffkala jeffkala merged commit f8d106a into develop Dec 11, 2023
15 checks passed
@jeffkala jeffkala deleted the jkala-2.0-jobs branch December 11, 2023 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants