Skip to content

Commit 1be530f

Browse files
Feat(cv_deploy): Add variables to match missing cv_workflow options (#6725)
Co-authored-by: Claus Holbech <[email protected]>
1 parent 12a71f5 commit 1be530f

7 files changed

Lines changed: 534 additions & 4 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
- name: "{{ test_id | upper }} Converge - cv_change_control_requested_state = pending approval"
3+
hosts: SITE1_FABRIC
4+
connection: local
5+
gather_facts: false
6+
vars:
7+
cv_server: "{{ lookup('env', 'CV_SERVER') }}"
8+
cv_token: "{{ lookup('env', 'CV_ACCESS_TOKEN') }}"
9+
proxy_host: "{{ lookup('env', 'CV_PROXY_HOST') | default('', true) }}"
10+
proxy_port: "{{ lookup('env', 'CV_PROXY_PORT') | default(3128, true) | int }}"
11+
proxy_username: "{{ lookup('env', 'CV_PROXY_USERNAME') | default('', true) }}"
12+
proxy_password: "{{ lookup('env', 'CV_PROXY_PASSWORD') | default('', true) }}"
13+
cv_verify_certs: "{{ lookup('env', 'CV_VERIFY_CERTS') | default(true, true) | bool }}"
14+
cv_skip_missing_devices: true
15+
eos_config_dir: "{{ playbook_dir }}/intended/configs/test_configs"
16+
structured_dir: "{{ playbook_dir }}/intended/structured_configs/test_configs"
17+
intended_tag_device: avd-ci-leaf1
18+
intended_tags: "{{ lookup('file', structured_dir ~ '/' ~ intended_tag_device ~ '.yml')| from_yaml }}"
19+
test_id: "cc-requested-state-pending"
20+
cv_common_pattern: "avd_cv-deploy_{{ test_id }}"
21+
22+
tasks:
23+
- name: "{{ test_id | upper }} Banner"
24+
tags: ["{{ test_id }}"]
25+
run_once: true
26+
ansible.builtin.debug:
27+
msg:
28+
- "{{ ('#' * (31 + test_id | length))[:100] }}"
29+
- "### STARTING MOLECULE TEST {{ test_id[:69] | upper }} ###"
30+
- "{{ ('#' * (31 + test_id | length))[:100] }}"
31+
32+
- name: "{{ test_id | upper }} {{ 'Read' if lookup('env', 'MOLECULE_EXECUTION_ID') else 'Generate' }} molecule execution ID"
33+
tags: ["{{ test_id }}"]
34+
run_once: true
35+
ansible.builtin.set_fact:
36+
r: "{{ lookup('env', 'MOLECULE_EXECUTION_ID') or lookup('password', '/dev/null chars=ascii_lowercase,digits length=4') }}"
37+
38+
- name: "{{ test_id | upper }} Code block to provision CVP with AVD configuration"
39+
tags: ["{{ test_id }}"]
40+
run_once: true
41+
delegate_to: localhost
42+
43+
block:
44+
45+
- name: "(BLOCK) {{ test_id | upper }} Banner"
46+
tags: ["{{ test_id }}"]
47+
run_once: true
48+
ansible.builtin.debug:
49+
msg:
50+
- "### ENGAGE CV_DEPLOY ROLE TO PUSH CONFIGURATION FOR {{ test_id[:69] | upper }} ###"
51+
52+
- name: "(BLOCK) {{ test_id | upper }} Provision with cv_change_control_requested_state = pending approval"
53+
tags: ["{{ test_id }}"]
54+
run_once: true
55+
delegate_to: localhost
56+
ansible.builtin.import_role:
57+
name: arista.avd.cv_deploy
58+
vars:
59+
cv_workspace_name: "{{ cv_common_pattern }}_{{ r }}_converge"
60+
cv_workspace_description: "{{ (cv_common_pattern + '_' + r + '_converge') | upper }}"
61+
cv_change_control_name: "{{ cv_common_pattern }}_{{ r }}_converge"
62+
cv_change_control_description: "{{ (cv_common_pattern + '_' + r + '_converge') | upper }}"
63+
cv_register_detailed_results: true
64+
cv_submit_workspace_force: true
65+
# Should be ignored
66+
cv_run_change_control: true
67+
cv_change_control_requested_state: "pending approval"
68+
69+
- name: "(BLOCK) {{ test_id | upper }} Check CVP returns"
70+
tags: ["{{ test_id }}"]
71+
run_once: true
72+
ansible.builtin.assert:
73+
that:
74+
# Workspace
75+
- cv_deploy_results.workspace.state == "submitted"
76+
# Change control
77+
- cv_deploy_results.change_control.name == cv_change_control_name
78+
- cv_deploy_results.change_control.description == cv_change_control_description
79+
- cv_deploy_results.change_control.requested_state == "pending approval"
80+
- cv_deploy_results.change_control.state == "pending approval"
81+
vars:
82+
cv_change_control_name: "{{ cv_common_pattern }}_{{ r }}_converge"
83+
cv_change_control_description: "{{ (cv_common_pattern + '_' + r + '_converge') | upper }}"
84+
85+
always:
86+
87+
- name: "(ALWAYS) {{ test_id | upper }} Display CVP detailed result"
88+
tags: ["{{ test_id }}"]
89+
run_once: true
90+
ansible.builtin.debug:
91+
var: cv_deploy_results
92+
93+
- name: "(ALWAYS) {{ test_id | upper }} Cleanup orphan CC"
94+
tags: ["{{ test_id }}"]
95+
run_once: true
96+
ansible.legacy.uri:
97+
url: https://{{ cv_server }}/api/resources/changecontrol/v1/ChangeControlConfig?key.id={{ cv_deploy_results.change_control.id }}
98+
use_proxy: "{{ true if proxy_host and proxy_port else false }}"
99+
validate_certs: "{{ cv_verify_certs }}"
100+
return_content: true
101+
headers:
102+
Accept: "application/json"
103+
Content-Type: "application/json"
104+
Authorization: "Bearer {{ lookup('env', 'CV_ACCESS_TOKEN') }}"
105+
method: DELETE
106+
body_format: json
107+
force_basic_auth: true
108+
timeout: 10
109+
register: cvp_abandon_cc_result
110+
until: cvp_abandon_cc_result.status == 200
111+
retries: 3
112+
delay: 3
113+
ignore_errors: true
114+
when: cv_deploy_results.change_control.state | lower in ['pending approval', 'approved']
115+
# Set HTTPS_PROXY environment variable scoped for this task only
116+
environment:
117+
https_proxy: >-
118+
http://{{ (proxy_username and proxy_password) | ternary(proxy_username ~ ':' ~ proxy_password ~ '@', '') }}{{ proxy_host }}:{{ proxy_port }}
119+
120+
- name: "(ALWAYS) {{ test_id | upper }} Banner"
121+
tags: ["{{ test_id }}"]
122+
run_once: true
123+
ansible.builtin.debug:
124+
msg:
125+
- "### ENGAGE CV_DEPLOY ROLE TO CLEANUP AFTER {{ test_id[:69] | upper }} ###"
126+
127+
- name: "(ALWAYS) {{ test_id | upper }} Cleanup"
128+
tags: ["{{ test_id }}"]
129+
run_once: true
130+
delegate_to: localhost
131+
ansible.builtin.import_role:
132+
name: arista.avd.cv_deploy
133+
vars:
134+
cv_workspace_name: "{{ cv_common_pattern }}_{{ r }}_cleanup"
135+
cv_workspace_description: "{{ (cv_common_pattern + '_' + r + '_cleanup') | upper }}"
136+
cv_change_control_name: "{{ cv_common_pattern }}_{{ r }}_cleanup"
137+
cv_change_control_description: "{{ (cv_common_pattern + '_' + r + '_cleanup') | upper }}"
138+
cv_register_detailed_results: true
139+
cv_devices: "{{ ansible_play_hosts_all }}"
140+
eos_config_dir: "{{ playbook_dir }}/intended/configs/base_configs"
141+
structured_dir: "{{ playbook_dir }}/intended/structured_configs/base_configs"
142+
cv_submit_workspace_force: true
143+
cv_run_change_control: true

ansible_collections/arista/avd/extensions/molecule/cv_deploy/converge.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
- name: Test Provisions with Workspace Pending
66
import_playbook: workspace_pending.yml
77

8+
- name: Test Workspace Requested State = built
9+
import_playbook: workspace_requested_state.yml
10+
11+
- name: Test Workspace custom ID
12+
import_playbook: workspace_id.yml
13+
814
- name: Test Workspace Force True
915
import_playbook: workspace_force_true.yml
1016

@@ -17,6 +23,9 @@
1723
- name: Test Change Control False
1824
import_playbook: cc_false.yml
1925

26+
- name: Test Change Control Requested State = pending approval
27+
import_playbook: cc_requested_state.yml
28+
2029
- name: Test cv_deploy with devices with uniquely set serial_numbers and system_mac_addresses
2130
import_playbook: no_duplicated_devices.yml
2231

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
- name: "{{ test_id | upper }} Converge - cv_workspace_id"
3+
hosts: SITE1_FABRIC
4+
connection: local
5+
gather_facts: false
6+
vars:
7+
cv_server: "{{ lookup('env', 'CV_SERVER') }}"
8+
cv_token: "{{ lookup('env', 'CV_ACCESS_TOKEN') }}"
9+
proxy_host: "{{ lookup('env', 'CV_PROXY_HOST') | default('', true) }}"
10+
proxy_port: "{{ lookup('env', 'CV_PROXY_PORT') | default(3128, true) | int }}"
11+
proxy_username: "{{ lookup('env', 'CV_PROXY_USERNAME') | default('', true) }}"
12+
proxy_password: "{{ lookup('env', 'CV_PROXY_PASSWORD') | default('', true) }}"
13+
cv_verify_certs: "{{ lookup('env', 'CV_VERIFY_CERTS') | default(true, true) | bool }}"
14+
cv_skip_missing_devices: true
15+
eos_config_dir: "{{ playbook_dir }}/intended/configs/test_configs"
16+
structured_dir: "{{ playbook_dir }}/intended/structured_configs/test_configs"
17+
intended_tag_device: avd-ci-leaf1
18+
intended_tags: "{{ lookup('file', structured_dir ~ '/' ~ intended_tag_device ~ '.yml')| from_yaml }}"
19+
test_id: "ws-custom-id"
20+
cv_common_pattern: "avd_cv-deploy_{{ test_id }}"
21+
22+
tasks:
23+
- name: "{{ test_id | upper }} Banner"
24+
tags: ["{{ test_id }}"]
25+
run_once: true
26+
ansible.builtin.debug:
27+
msg:
28+
- "{{ ('#' * (31 + test_id | length))[:100] }}"
29+
- "### STARTING MOLECULE TEST {{ test_id[:69] | upper }} ###"
30+
- "{{ ('#' * (31 + test_id | length))[:100] }}"
31+
32+
- name: "{{ test_id | upper }} {{ 'Read' if lookup('env', 'MOLECULE_EXECUTION_ID') else 'Generate' }} molecule execution ID"
33+
tags: ["{{ test_id }}"]
34+
run_once: true
35+
ansible.builtin.set_fact:
36+
r: "{{ lookup('env', 'MOLECULE_EXECUTION_ID') or lookup('password', '/dev/null chars=ascii_lowercase,digits length=4') }}"
37+
38+
- name: "{{ test_id | upper }} Code block to provision CVP with AVD configuration"
39+
tags: ["{{ test_id }}"]
40+
run_once: true
41+
delegate_to: localhost
42+
43+
block:
44+
45+
- name: "(BLOCK) {{ test_id | upper }} Banner"
46+
tags: ["{{ test_id }}"]
47+
run_once: true
48+
ansible.builtin.debug:
49+
msg:
50+
- "### ENGAGE CV_DEPLOY ROLE TO PUSH CONFIGURATION FOR {{ test_id[:69] | upper }} ###"
51+
52+
- name: "(BLOCK) {{ test_id | upper }} Provision with cv_workspace_id"
53+
run_once: true
54+
delegate_to: localhost
55+
ansible.builtin.import_role:
56+
name: arista.avd.cv_deploy
57+
vars:
58+
cv_workspace_name: "{{ cv_common_pattern }}_{{ r }}_converge"
59+
cv_workspace_description: "{{ (cv_common_pattern + '_' + r + '_converge') | upper }}"
60+
cv_workspace_id: "avd-ci-ws-{{ r }}"
61+
cv_change_control_name: "{{ cv_common_pattern }}_{{ r }}_converge"
62+
cv_change_control_description: "{{ (cv_common_pattern + '_' + r + '_converge') | upper }}"
63+
cv_register_detailed_results: true
64+
cv_submit_workspace: false
65+
66+
- name: "(BLOCK) {{ test_id | upper }} Check CVP returns"
67+
tags: ["{{ test_id }}"]
68+
run_once: true
69+
ansible.builtin.assert:
70+
that:
71+
# workspace
72+
- cv_deploy_results.workspace.id == cv_workspace_id
73+
- cv_deploy_results.workspace.name == cv_workspace_name
74+
- cv_deploy_results.workspace.state == "built"
75+
- cv_deploy_results.workspace.requested_state == "built"
76+
vars:
77+
cv_workspace_id: "avd-ci-ws-{{ r }}"
78+
cv_workspace_name: "{{ cv_common_pattern }}_{{ r }}_converge"
79+
80+
always:
81+
82+
- name: "(ALWAYS) {{ test_id | upper }} Display CVP detailed result"
83+
tags: ["{{ test_id }}"]
84+
run_once: true
85+
ansible.builtin.debug:
86+
var: cv_deploy_results
87+
88+
- name: "(ALWAYS) {{ test_id | upper }} Cleanup orphan workspace"
89+
tags: ["{{ test_id }}"]
90+
run_once: true
91+
ansible.legacy.uri:
92+
url: https://{{ cv_server }}/api/resources/workspace/v1/WorkspaceConfig/some
93+
use_proxy: "{{ true if proxy_host and proxy_port else false }}"
94+
validate_certs: "{{ cv_verify_certs }}"
95+
return_content: true
96+
headers:
97+
Accept: "application/json"
98+
Content-Type: "application/json"
99+
Authorization: "Bearer {{ lookup('env', 'CV_ACCESS_TOKEN') }}"
100+
method: POST
101+
body_format: json
102+
body:
103+
{
104+
"values": [
105+
{
106+
"key": {
107+
"workspaceId": "{{ cv_deploy_results.workspace.id }}"
108+
},
109+
"request": "REQUEST_ABANDON",
110+
"requestParams": {
111+
"requestId": "{{ r }}"
112+
}
113+
}
114+
]
115+
}
116+
force_basic_auth: true
117+
timeout: 10
118+
register: cvp_abandon_workspace_result
119+
until: cvp_abandon_workspace_result.status == 200
120+
retries: 3
121+
delay: 3
122+
ignore_errors: true
123+
when: |
124+
cv_deploy_results.workspace.id is not none and
125+
cv_deploy_results.workspace.id | length > 0 and
126+
cv_deploy_results.workspace.state | default('') != "abandoned"
127+
# Set HTTPS_PROXY environment variable scoped for this task only
128+
environment:
129+
https_proxy: >-
130+
http://{{ (proxy_username and proxy_password) | ternary(proxy_username ~ ':' ~ proxy_password ~ '@', '') }}{{ proxy_host }}:{{ proxy_port }}
131+
132+
- name: "(ALWAYS) {{ test_id | upper }} Banner"
133+
tags: ["{{ test_id }}"]
134+
run_once: true
135+
ansible.builtin.debug:
136+
msg:
137+
- "### ENGAGE CV_DEPLOY ROLE TO CLEANUP AFTER {{ test_id[:69] | upper }} ###"
138+
139+
- name: "(ALWAYS) {{ test_id | upper }} Cleanup"
140+
tags: ["{{ test_id }}"]
141+
run_once: true
142+
delegate_to: localhost
143+
ansible.builtin.import_role:
144+
name: arista.avd.cv_deploy
145+
vars:
146+
cv_workspace_name: "{{ cv_common_pattern }}_{{ r }}_cleanup"
147+
cv_workspace_description: "{{ (cv_common_pattern + '_' + r + '_cleanup') | upper }}"
148+
cv_change_control_name: "{{ cv_common_pattern }}_{{ r }}_cleanup"
149+
cv_change_control_description: "{{ (cv_common_pattern + '_' + r + '_cleanup') | upper }}"
150+
cv_register_detailed_results: true
151+
cv_devices: "{{ ansible_play_hosts_all }}"
152+
eos_config_dir: "{{ playbook_dir }}/intended/configs/base_configs"
153+
structured_dir: "{{ playbook_dir }}/intended/structured_configs/base_configs"
154+
cv_submit_workspace_force: true
155+
cv_run_change_control: true

0 commit comments

Comments
 (0)