| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 7 |
ansible.builtin.fail: |
| 8 |
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 9 |
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 10 |
|
| 11 |
- name: ensure tenant does not exist for tests to kick off |
| 12 |
cisco.aci.aci_tenant: &aci_tenant_absent |
| 13 |
host: "{{ aci_hostname }}" |
| 14 |
username: "{{ aci_username }}" |
| 15 |
password: "{{ aci_password }}" |
| 16 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 17 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 18 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 19 |
output_level: debug |
| 20 |
state: absent |
| 21 |
tenant: ansible_test |
| 22 |
|
| 23 |
- name: Verify Cloud and Non-Cloud Sites in use. |
| 24 |
ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml |
| 25 |
|
| 26 |
- name: create a snapshot |
| 27 |
cisco.aci.aci_config_snapshot: &create_snapshot |
| 28 |
<<: *aci_tenant_absent |
| 29 |
state: present |
| 30 |
tenant: "{{ fakevar | default(omit) }}" |
| 31 |
export_policy: anstest |
| 32 |
|
| 33 |
- name: create a tenant - use for rollback |
| 34 |
cisco.aci.aci_tenant: &aci_tenant |
| 35 |
<<: *create_snapshot |
| 36 |
export_policy: "{{ fakevar | default(omit) }}" |
| 37 |
tenant: ansible_test |
| 38 |
register: tenant_present |
| 39 |
|
| 40 |
- name: create a new snapshot |
| 41 |
cisco.aci.aci_config_snapshot: |
| 42 |
<<: *create_snapshot |
| 43 |
register: create_snapshot_annotation_check |
| 44 |
|
| 45 |
- name: waiting for snapshot to be finished before querying |
| 46 |
ansible.builtin.pause: |
| 47 |
seconds: 10 |
| 48 |
|
| 49 |
- name: get snapshots |
| 50 |
cisco.aci.aci_config_snapshot: |
| 51 |
<<: *create_snapshot |
| 52 |
state: query |
| 53 |
register: snapshots |
| 54 |
|
| 55 |
- name: Execute tasks only for non-cloud sites |
| 56 |
when: query_cloud.current != [] |
| 57 |
block: |
| 58 |
|
| 59 |
|
| 60 |
- name: verify only one snapshot is returned |
| 61 |
ansible.builtin.assert: |
| 62 |
that: |
| 63 |
- snapshots.current.0.configSnapshotCont.children | length == 1 |
| 64 |
|
| 65 |
- name: Execute tasks only for non-cloud sites |
| 66 |
when: query_cloud.current == [] |
| 67 |
block: |
| 68 |
|
| 69 |
- name: sort snapshot list |
| 70 |
ansible.builtin.set_fact: |
| 71 |
sorted_snapshots: '{{ snapshots.current.0.configSnapshotCont.children | sort(attribute="configSnapshot.attributes.createTime", reverse=True) }}' |
| 72 |
|
| 73 |
- name: Uninstall lxml for error checking |
| 74 |
ansible.builtin.pip: &lxml |
| 75 |
name: lxml |
| 76 |
state: absent |
| 77 |
ignore_errors: true |
| 78 |
|
| 79 |
- name: Uninstall xmljson for error checking |
| 80 |
ansible.builtin.pip: &xmljson |
| 81 |
name: xmljson |
| 82 |
state: absent |
| 83 |
ignore_errors: true |
| 84 |
|
| 85 |
- name: compare snapshots |
| 86 |
cisco.aci.aci_config_rollback: &preview_rollback |
| 87 |
<<: *create_snapshot |
| 88 |
state: preview |
| 89 |
compare_export_policy: anstest |
| 90 |
compare_snapshot: "{{ sorted_snapshots[0].configSnapshot.attributes.name }}" |
| 91 |
snapshot: "{{ sorted_snapshots[1].configSnapshot.attributes.name }}" |
| 92 |
register: rollback_preview_xml |
| 93 |
|
| 94 |
- name: Install lxml |
| 95 |
ansible.builtin.pip: |
| 96 |
<<: *lxml |
| 97 |
state: present |
| 98 |
ignore_errors: true |
| 99 |
|
| 100 |
- name: Install xmljson |
| 101 |
ansible.builtin.pip: |
| 102 |
<<: *xmljson |
| 103 |
state: present |
| 104 |
ignore_errors: true |
| 105 |
|
| 106 |
- name: compare snapshots |
| 107 |
cisco.aci.aci_config_rollback: |
| 108 |
<<: *preview_rollback |
| 109 |
register: rollback_preview_json |
| 110 |
|
| 111 |
- name: compare snapshots with wrong compare_snapshot (error) |
| 112 |
cisco.aci.aci_config_rollback: |
| 113 |
<<: *preview_rollback |
| 114 |
compare_snapshot: wrong_snap |
| 115 |
ignore_errors: true |
| 116 |
register: err_rollback_preview_json |
| 117 |
|
| 118 |
- name: rollback to snapshot with missing parameters |
| 119 |
cisco.aci.aci_config_rollback: &aci_rollback |
| 120 |
<<: *create_snapshot |
| 121 |
state: rollback |
| 122 |
snapshot: "{{ sorted_snapshots[1].configSnapshot.attributes.name }}" |
| 123 |
ignore_errors: true |
| 124 |
register: rollback_missing_param |
| 125 |
|
| 126 |
- name: rollback to not existing snapshot for "tar.gz" append and "run-" removal testing |
| 127 |
cisco.aci.aci_config_rollback: |
| 128 |
<<: *aci_rollback |
| 129 |
snapshot: "not-existing-snapshot.tar.gz" |
| 130 |
import_policy: anstest |
| 131 |
import_type: replace |
| 132 |
import_mode: atomic |
| 133 |
register: not_existing_rollback |
| 134 |
ignore_errors: true |
| 135 |
|
| 136 |
- name: rollback to snapshot |
| 137 |
cisco.aci.aci_config_rollback: |
| 138 |
<<: *aci_rollback |
| 139 |
import_policy: anstest |
| 140 |
import_type: replace |
| 141 |
import_mode: atomic |
| 142 |
register: rollback_rollback |
| 143 |
|
| 144 |
- name: pause execution to let rollback take effect |
| 145 |
ansible.builtin.pause: |
| 146 |
seconds: 15 |
| 147 |
|
| 148 |
- name: ensure tenant doesn't exist after rollback |
| 149 |
cisco.aci.aci_tenant: |
| 150 |
<<: *aci_tenant_absent |
| 151 |
register: tenant_removed |
| 152 |
|
| 153 |
- debug: |
| 154 |
msg: '{{ rollback_preview_json }}' |
| 155 |
|
| 156 |
- name: rollback assertions |
| 157 |
ansible.builtin.assert: |
| 158 |
that: |
| 159 |
- rollback_preview_xml is not changed |
| 160 |
- '"ansible_test" in rollback_preview_xml.preview' |
| 161 |
- '"created" in rollback_preview_xml.preview' |
| 162 |
- '"snapshots.diff.xml" in rollback_preview_xml.url' |
| 163 |
- err_rollback_preview_json.status == 400 |
| 164 |
- err_rollback_preview_json.response == "HTTP Error 400{{":"}} Bad Request" |
| 165 |
- rollback_preview_json is not changed |
| 166 |
- rollback_preview_json.preview.polUni.children[0].fvTenant.attributes.name == 'ansible_test' |
| 167 |
- rollback_preview_json.preview.polUni.children[0].fvTenant.attributes.status == 'created' |
| 168 |
- '"snapshots.diff.xml" in rollback_preview_json.url' |
| 169 |
- rollback_missing_param is failed |
| 170 |
- 'rollback_missing_param.msg == "state is rollback but all of the following are missing: import_policy"' |
| 171 |
- rollback_rollback is changed |
| 172 |
- '"ce2_" in rollback_rollback.sent.configImportP.attributes.fileName' |
| 173 |
- '".tar.gz" in rollback_rollback.sent.configImportP.attributes.fileName' |
| 174 |
- '"ce2_" in rollback_rollback.proposed.configImportP.attributes.fileName' |
| 175 |
- '".tar.gz" in rollback_rollback.proposed.configImportP.attributes.fileName' |
| 176 |
- '"fabric/configimp-anstest.json" in rollback_rollback.url' |
| 177 |
- tenant_removed is not changed |
| 178 |
- tenant_removed.previous == [] |
| 179 |
- create_snapshot_annotation_check.current.0.configExportP.attributes.annotation == 'orchestrator:ansible' |