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

New swim workflow feature #57

Conversation

syed-khadeerahmed
Copy link
Collaborator

@syed-khadeerahmed syed-khadeerahmed commented Dec 9, 2024

Description

Please include a summary of the changes and the related issue. Also, include relevant motivation and context.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • All the sanity checks have been completed and the sanity test cases have been executed

Ansible Best Practices

  • Tasks are idempotent (can be run multiple times without changing state)
  • Variables and secrets are handled securely (e.g., using ansible-vault or environment variables)
  • Playbooks are modular and reusable
  • Handlers are used for actions that need to run on change

Documentation

  • All options and parameters are documented clearly.
  • Examples are provided and tested.
  • Notes and limitations are clearly stated.

Screenshots (if applicable)

Notes to Reviewers


messages = []

if skipped_images_str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we opimize the logic?

        messages = []

        if skipped_images_str:
            messages.append("Image(s) {0} were skipped as they already exist in Cisco Catalyst Center.".format(skipped_images_str))

        if imported_images_str:
            messages.append("Image(s) {0} have been imported successfully into Cisco Catalyst Center.".format(imported_images_str))
        elif not skipped_images_str:
            messages.append("No images were imported.")

- "{{ item }}"
loop: "{{ vars_map.delete_devices }}"
register: result_device_deleted
# - name: Delete device
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented lines...

@@ -1679,6 +1681,15 @@ def get_diff_tagging(self):
self.result['response'] = self.msg
self.log(self.msg, "INFO")
break
elif task_details.get("isError"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting isError, progress, failure_reason from task_details used in multiple places.
Can't we get the vaules, store and use it?

<<< Sample Code, modify the code based on your logic.... >>>>>>>>>>

device_family = tagging_details.get("device_image_family_name")
device_role = tagging_details.get("device_role", "ALL")
site_name = tagging_details.get("site_name", "Global")

while True:
    task_details = self.get_task_details(task_id)
    is_error = task_details.get("isError")
    progress = task_details.get("progress", "")
    failure_reason = task_details.get("failureReason", "")

    if is_error:
        if not tag_image_golden and "An inheritted tag cannot be un-tagged" in failure_reason:
            self.msg = failure_reason
        else:
            action = "Tagging" if tag_image_golden else "Un-Tagging"
            self.msg = (
                "{0} image {1} golden for site {2} for family {3} for device role {4} failed."
                .format(action, image_name, site_name, device_family, device_role)
            )
        self.status = "failed"
        self.result['changed'] = False
        self.result['msg'] = self.msg
        self.log(self.msg, "ERROR")
        break

    if "successful" in progress:
        action = "Tagging" if tag_image_golden else "Un-Tagging"
        self.msg = (
            "{0} image {1} golden for site {2} for family {3} for device role {4} successful."
            .format(action, image_name, site_name, device_family, device_role)
        )
        self.status = "success"
        self.result['changed'] = True
        self.result['msg'] = self.msg
        self.log(self.msg, "INFO")
        break

return self

What happens if not is_error, and not successful in progress? Do we sleep for some time? Is it needed to be in while loop to do tag and untag an image? If we still need to check "while" loop, then add sleep and do checks for default times and break from the loop..

@madhansansel madhansansel merged commit 2de3c0d into cisco-en-programmability:main Dec 10, 2024
8 of 10 checks passed
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