forked from cisco-en-programmability/dnacenter-ansible
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Merged
madhansansel
merged 10 commits into
cisco-en-programmability:main
from
syed-khadeerahmed:new_swim_workflow_feature
Dec 10, 2024
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0cfd71
code is in progress for the SWIM bugs
syed-khadeerahmed 137d752
Swim Bug fixed
syed-khadeerahmed e9e022c
swim 2 bugs fixed
syed-khadeerahmed f2602f2
Merge branch 'main' of https://github.com/cisco-en-programmability/ca…
syed-khadeerahmed 0c71afb
sanity fixed
syed-khadeerahmed 97ca090
sanity fixed
syed-khadeerahmed 565f59e
sanity fixed
syed-khadeerahmed 607f1ef
review comments compleated
syed-khadeerahmed 04b8db5
review comments compleated
syed-khadeerahmed 95bca51
review comments fixed
syed-khadeerahmed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,6 +586,7 @@ class Swim(DnacBase): | |
def __init__(self, module): | ||
super().__init__(module) | ||
self.supported_states = ["merged"] | ||
self.images_to_import, self.existing_images = [], [] | ||
|
||
def validate_input(self): | ||
""" | ||
|
@@ -1373,6 +1374,7 @@ def get_diff_import(self): | |
self.log(name) | ||
if self.is_image_exist(name): | ||
existing_images.append(name) | ||
self.existing_images.append(name) | ||
self.log("Image '{0}' already exists in Cisco Catalyst Center, skipping import.".format(name), "INFO") | ||
else: | ||
images_to_import.append(name) | ||
|
@@ -1457,7 +1459,7 @@ def get_diff_import(self): | |
if "completed successfully" in task_details.get("progress", "").lower(): | ||
if images_to_import: | ||
images_to_import_str = ", ".join(images_to_import) | ||
|
||
self.images_to_import.append(images_to_import_str) | ||
self.result['changed'] = True | ||
self.status = "success" | ||
self.msg = "Swim Image(s) {0} imported successfully".format(images_to_import_str) | ||
|
@@ -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"): | ||
self.status = "failed" | ||
self.result['changed'] = False | ||
self.msg = ("Tagging image {0} golden for site {1} for family {2} for device deviceTag" | ||
" - {3} Failed".format(image_name, site_name, device_family, device_role)) | ||
self.result['msg'] = self.msg | ||
self.result['response'] = self.msg | ||
self.log(self.msg, "ERROR") | ||
break | ||
else: | ||
if not task_details.get("isError") and 'successful' in task_details.get("progress"): | ||
self.status = "success" | ||
|
@@ -1689,6 +1700,7 @@ def get_diff_tagging(self): | |
self.result['response'] = self.msg | ||
self.log(self.msg, "INFO") | ||
break | ||
|
||
elif task_details.get("isError"): | ||
failure_reason = task_details.get("failureReason", "") | ||
if failure_reason and "An inheritted tag cannot be un-tagged" in failure_reason: | ||
|
@@ -2315,6 +2327,45 @@ def verify_diff_merged(self, config): | |
|
||
return self | ||
|
||
def update_swim_profile_messages(self): | ||
""" | ||
Verify the merged status (Importing/Tagging/Distributing/Activating) of the SWIM Image in devices in Cisco Catalyst Center. | ||
Args: | ||
- self (object): An instance of a class used for interacting with Cisco Catalyst Center. | ||
Return: | ||
- self (object): An instance of a class used for interacting with Cisco Catalyst Center. | ||
Description: | ||
This method checks the merged status of a configuration in Cisco Catalyst Center by retrieving the current state | ||
(have) and desired state (want) of the configuration. It logs the current and desired states, and validates whether | ||
the specified SWIM operation (Importing, Tagging, Distributing, or Activating) has been successfully performed or not. | ||
""" | ||
|
||
if self.images_to_import or self.existing_images: | ||
imported_images_str = ", ".join(self.images_to_import) | ||
skipped_images_str = ", ".join(self.existing_images) | ||
|
||
messages = [] | ||
|
||
if skipped_images_str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we opimize the logic?
|
||
if imported_images_str: | ||
messages.append("Image(s) {0} were skipped as they already exist in Cisco Catalyst Center.".format(skipped_images_str)) | ||
messages.append("Images {0} have been imported successfully.".format(imported_images_str)) | ||
else: | ||
messages.append("Image(s) {0} were skipped as they already exist in Cisco Catalyst Center." | ||
"No new images were imported.".format(skipped_images_str)) | ||
elif imported_images_str: | ||
messages.append("Image(s) {0} have been imported successfully into Cisco Catalyst Center.".format(imported_images_str)) | ||
else: | ||
messages.append("No images were imported.") | ||
|
||
self.msg = " ".join(messages) | ||
|
||
self.result['msg'] = self.msg | ||
self.result['response'] = self.msg | ||
self.log(self.msg, "INFO") | ||
|
||
return self | ||
|
||
|
||
def main(): | ||
""" main entry point for module execution | ||
|
@@ -2361,7 +2412,7 @@ def main(): | |
ccc_swims.get_diff_state_apply[state](config).check_return_status() | ||
if config_verify: | ||
ccc_swims.verify_diff_state_apply[state](config).check_return_status() | ||
|
||
ccc_swims.update_swim_profile_messages() | ||
module.exit_json(**ccc_swims.result) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,26 +256,26 @@ | |
# Delete Device # | ||
############################################# | ||
|
||
- name: Delete device | ||
cisco.dnac.inventory_workflow_manager: | ||
<<: *dnac_login | ||
state: deleted | ||
config: | ||
- "{{ item }}" | ||
loop: "{{ vars_map.delete_devices }}" | ||
register: result_device_deleted | ||
# - name: Delete device | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented lines... |
||
# cisco.dnac.inventory_workflow_manager: | ||
# <<: *dnac_login | ||
# state: deleted | ||
# config: | ||
# - "{{ item }}" | ||
# loop: "{{ vars_map.delete_devices }}" | ||
# register: result_device_deleted | ||
|
||
# - name: Debug item | ||
# debug: | ||
# var: item | ||
# loop: "{{ result_device_deleted.results }}" | ||
# when: result_device_deleted is defined | ||
# # - name: Debug item | ||
# # debug: | ||
# # var: item | ||
# # loop: "{{ result_device_deleted.results }}" | ||
# # when: result_device_deleted is defined | ||
|
||
- name: Assert device deletion success | ||
assert: | ||
that: | ||
- result_device_deleted.changed == true | ||
when: result_device_deleted is defined | ||
# - name: Assert device deletion success | ||
# assert: | ||
# that: | ||
# - result_device_deleted.changed == true | ||
# when: result_device_deleted is defined | ||
|
||
############################################# | ||
# PAUSE # | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.... >>>>>>>>>>
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..