Skip to content

Commit

Permalink
Added the integration tests for the configurating templates, exportin…
Browse files Browse the repository at this point in the history
…g the templates and importing the templates (#70)
  • Loading branch information
madhansansel authored Dec 16, 2024
2 parents 99c6226 + befc3e0 commit e445cbe
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/integration/ccc_template_management/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
testcase: "*"
1 change: 1 addition & 0 deletions tests/integration/ccc_template_management/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dependencies: []
34 changes: 34 additions & 0 deletions tests/integration/ccc_template_management/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: collect ccc test cases
find:
paths: "{{ role_path }}/tests"
patterns: "{{ testcase }}.yml"
connection: local
register: ccc_cases
tags: sanity

- debug:
msg: "CCC Cases: {{ ccc_cases }}"

- set_fact:
test_cases:
files: "{{ ccc_cases.files }}"
tags: sanity

- debug:
msg: "Test Cases: {{ test_cases }}"

- name: set test_items
set_fact:
test_items: "{{ test_cases.files | map(attribute='path') | list }}"
tags: sanity

- debug:
msg: "Test Items: {{ test_items }}"

- name: run test cases (connection=httpapi)
include_tasks: "{{ test_case_to_run }}"
loop: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
tags: sanity
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"name": "test_template",
"tags": [],
"author": "admin",
"deviceTypes": [
{
"productFamily": "Switches and Hubs"
}
],
"softwareType": "IOS",
"softwareVariant": "XE",
"templateContent": "hostname cat9k-1\\n",
"templateParams": [],
"rollbackTemplateParams": [],
"composite": false,
"containingTemplates": [],
"language": "VELOCITY",
"promotedTemplateContent": "hostname cat9k-1\\n",
"promotedTemplateParams": [],
"customParamsOrder": false,
"createTime": 1719914895959,
"lastUpdateTime": 1719914895959,
"latestVersionTime": 1719914896486,
"validationErrors": {
"templateErrors": [],
"rollbackTemplateErrors": [],
"templateId": "10a9a332-44f8-419e-8274-45ad74a38e9b",
"templateVersion": null
},
"noOfConflicts": 0,
"projectAssociated": true,
"documentDatabase": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
- debug: msg="Starting export template and project test"
- debug: msg="Role Path {{ role_path }}"

- block:
- name: Load vars and declare dnac vars
include_vars:
file: "{{ role_path }}/vars/vars_export_template_and_project.yml"
name: vars_map
vars:
dnac_login: &dnac_login
dnac_host: "{{ dnac_host }}"
dnac_username: "{{ dnac_username }}"
dnac_password: "{{ dnac_password }}"
dnac_verify: "{{ dnac_verify }}"
dnac_port: "{{ dnac_port }}"
dnac_version: "{{ dnac_version }}"
dnac_debug: "{{ dnac_debug }}"
dnac_log: true
dnac_log_level: DEBUG
config_verify: true

# - debug:
# msg: "{{ vars_map.create_template_details }}"

# - debug:
# msg: "{{ vars_map.export_project_details }}"

# - debug:
# msg: "{{ vars_map.export_template_details }}"

#############################################
# Pre Tests Clean Up #
#############################################

- name: Create template before test
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: merged
config:
- "{{ item }}"
loop: "{{ vars_map.template_details }}"

#############################################
# EXPORT PROJECT #
#############################################

- name: Export project from export_project_details
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: merged
config:
- "{{ item }}"
register: result_export_project
loop: "{{ vars_map.export_project_details }}"
tags: merged

# - name: Debug item
# debug:
# var: item
# loop: "{{ result_export_project.results }}"
# when: result_export_project is defined

- name: Assert export of project
assert:
that:
- item.changed == true
loop: "{{ result_export_project.results }}"
when: result_export_project is defined

#############################################
# EXPORT TEMPLATE #
#############################################

- name: Export template from export_template_details
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: merged
config:
- "{{ item }}"
register: result_export_template
loop: "{{ vars_map.export_template_details }}"
tags: merged

# - name: Debug item
# debug:
# var: item
# loop: "{{ result_export_template.results }}"
# when: result_export_template is defined

- name: Assert export of template
assert:
that:
- item.changed == true
loop: "{{ result_export_template.results }}"
when: result_export_template is defined

#############################################
# POST TEST CLEAN UP #
#############################################

# - name: Pause for 10 seconds after each updation
# pause:
# seconds: 10

- name: Delete template after test
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: deleted
config:
- "{{ item }}"
loop: "{{ vars_map.template_details }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
- debug: msg="Starting import template and project test"
- debug: msg="Role Path {{ role_path }}"

- block:
- name: Load vars and declare dnac vars
include_vars:
file: "{{ role_path }}/vars/vars_import_template_and_project.yml"
name: vars_map
vars:
dnac_login: &dnac_login
dnac_host: "{{ dnac_host }}"
dnac_username: "{{ dnac_username }}"
dnac_password: "{{ dnac_password }}"
dnac_verify: "{{ dnac_verify }}"
dnac_port: "{{ dnac_port }}"
dnac_version: "{{ dnac_version }}"
dnac_debug: "{{ dnac_debug }}"
dnac_log: true
dnac_log_level: DEBUG
config_verify: true

# - debug:
# msg: "{{ vars_map.template_details }}"

# - debug:
# msg: "{{ vars_map.project_details }}"

# - debug:
# msg: "{{ vars_map.import_template_details }}"

# - debug:
# msg: "{{ vars_map.import_project_details }}"

#############################################
# Pre Tests Clean Up #
#############################################

- name: Clean up template before test
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: deleted
config:
- "{{ item }}"
loop: "{{ vars_map.template_details }}"

# - name: Clean up project before test
# cisco.dnac.template_workflow_manager:
# <<: *dnac_login
# state: deleted
# config:
# - "{{ item }}"
# loop: "{{ vars_map.project_details }}"

# #############################################
# # IMPORT PROJECT #
# #############################################

# - name: Import project from import_project_details
# cisco.dnac.template_workflow_manager:
# <<: *dnac_login
# state: merged
# config:
# - "{{ item }}"
# register: result_import_project
# loop: "{{ vars_map.import_project_details }}"
# tags: merged

# # - name: Debug item
# # debug:
# # var: item
# # loop: "{{ result_import_project.results }}"
# # when: result_import_project is defined

# - name: Assert import project
# assert:
# that:
# - item.changed == true
# - "'imported the project' in item.response[2].import.response.importProject"
# loop: "{{ result_import_project.results }}"
# when: result_import_project is defined

#############################################
# IMPORT TEMPLATE #
#############################################

- name: Import template from import_template_details
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: merged
config:
- "{{ item }}"
register: result_import_template
loop: "{{ vars_map.import_template_details }}"
tags: merged

# - name: Debug item
# debug:
# var: item
# loop: "{{ result_import_template.results }}"
# when: result_import_template is defined

- name: Assert import template
assert:
that:
- item.changed == true
- "'imported the templates' in item.response[2].import.response.importTemplate"
loop: "{{ result_import_template.results }}"
when: result_import_template is defined

#############################################
# Pre Tests Clean Up #
#############################################

- name: Clean up template before test
cisco.dnac.template_workflow_manager:
<<: *dnac_login
state: deleted
config:
- "{{ item }}"
loop: "{{ vars_map.template_details }}"

# - name: Clean up project before test
# cisco.dnac.template_workflow_manager:
# <<: *dnac_login
# state: deleted
# config:
# - "{{ item }}"
# loop: "{{ vars_map.project_details }}"
Loading

0 comments on commit e445cbe

Please sign in to comment.