-
Notifications
You must be signed in to change notification settings - Fork 681
/
config_sonic_basedon_testbed.yml
407 lines (338 loc) · 15.4 KB
/
config_sonic_basedon_testbed.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# This Playbook run time generate matching configuration file for SONiC switch(Minigraph) based on a specific testbed topology specified in testbed.csv
# When user call testbed-cli to deploy a testbed topology, use this playbook to generate matching SONiC minigraph file and deploy it into SONiC switch under test.
# Or when you know your topology name, you may use this playbook alone to generate a minigraph matching your topology name without deploy it.
#
# VM Topologies are defined inside of vars/ directory in files vars/topo_{{ topology_name}}.yml
# Every topology should have a name to distinct one topology from another on the server
# Every topology contains a ptf container which will be used as placeholder for the injected interfaces from VMs, or direct connections to PTF host
# VMs inventory file is also required to have all VMs ready for generating the minigraph file
# VMs inventory is in file 'veos'
#
# Template files for generating minigraph.xml are defined in template/topo directory
#
# To generate and deploy minigraph for SONiC switch matching the VM topology please use following command
# ansible-playbook -i lab config_sonic_basedon_testbed.yml -l sonic_dut_name -e vm_base=VM0300 -e topo=t0 [-e deploy=true -e save=true]
# ansible-playbook -i lab config_sonic_basedon_testbed.yml -l sonic_dut_name -e testbed_name=vms1-1 [-e deploy=true -e save=true]
# Parameters
# -l str-msn2700-01 - the sonic_dut_name you are going to generate minigraph for
# -e vm_base=VM0300 - the VM name which is used to as base to calculate VM name for this set
# -e topo=t0 - the name of topology to generate minigraph file
# -e testbed_name=vms1-1 - the testbed name specified in testbed.csv file
# (if you give 'testbed_name' option, will use info from testbed and ignore topo and vm_base options)
# -e vm_file=veos - the virtual machine file name
# -e deploy=True - if deploy the newly generated minigraph to the targent DUT, default is false if not defined
# -e save=True - if save the newly generated minigraph to the targent DUT as starup-config, default is false if not defined
#
# After minigraph.xml is generated, the playbook will replace the original minigraph file under ansible/minigraph/ with the newly generated minigraph file for the SONiC device.
# The playbook will based on deploy=True or False to deside if load the SONiC device with new minigraph or not.
# If deploy=true, the playbook will apply the newly generated minigraph to the SONiC switch
# If save=true, the playbook will save the newly generated minigraph to SONiC switch as startup-config
#
####################################################################################################################################################################################
- hosts: sonic
gather_facts: no
tasks:
- block:
- name: set default testbed file
set_fact:
testbed_file: testbed.csv
when: testbed_file is not defined
- name: Gathering testbed information
test_facts: testbed_name="{{ testbed_name }}" testbed_file="{{ testbed_file }}"
delegate_to: localhost
- fail: msg="The DUT you are trying to run test does not belongs to this testbed"
when: inventory_hostname not in testbed_facts['duts']
- name: Set default num_asic
set_fact:
num_asics: 1
when: num_asics is not defined
- name: Set default dut index
set_fact:
dut_index: "{{ testbed_facts['duts_map'][inventory_hostname]|int }}"
- name: set testbed_type
set_fact:
topo: "{{ testbed_facts['topo'] }}"
- name: set vm
set_fact:
vm_base: "{{ testbed_facts['vm_base'] }}"
when: "testbed_facts['vm_base'] != ''"
when: testbed_name is defined
- topo_facts: topo={{ topo }} hwsku={{ hwsku }}
delegate_to: localhost
- name: find interface name mapping and individual interface speed if defined from dut
port_alias: hwsku="{{ hwsku }}" cardtype="{{ cardtype }}"
when: deploy is defined and deploy|bool == true
- name: find interface name mapping and individual interface speed if defined with local data
port_alias: hwsku="{{ hwsku }}" num_asic="{{ num_asics }}" cardtype="{{ cardtype }}"
delegate_to: localhost
when: deploy is not defined or deploy|bool == false
- name: find and generate ASIC infomation
fabric_info:
hwsku: "{{ hwsku }}"
num_asic: "{{ num_asic }}"
asics_host_pfx: "{{ asics_host_ip }}"
asics_host_pfx6: "{{ asics_host_ipv6 }}"
when: deploy is defined and deploy|bool == true
- name: find all enabled host_interfaces
set_fact:
host_if_indexes: "{{ vm_topo_config['host_interfaces_by_dut'][dut_index|int] | difference(vm_topo_config['disabled_host_interfaces_by_dut'][dut_index|int]) }}"
- name: find all vlan interface names for T0 topology
set_fact:
vlan_intfs: "{{ vlan_intfs|default([])}} + ['{{ port_alias[item] }}' ]"
with_items: "{{ host_if_indexes }}"
when: "('host_interfaces_by_dut' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"
- name: set default dualtor facts
set_fact:
dual_tor_facts: {}
when: "'dualtor' not in topo"
- name: gather dual ToR information
dual_tor_facts:
hostname: "{{ inventory_hostname }}"
testbed_facts: "{{ testbed_facts }}"
hostvars: "{{ hostvars }}"
vm_config: "{{ vm_topo_config }}"
port_alias: "{{ port_alias }}"
vlan_intfs: "{{ vlan_intfs }}"
delegate_to: localhost
when: "'dualtor' in topo"
- name: set default vm file path
set_fact:
vm_file: veos
when: vm_file is not defined
- set_fact:
VM_topo: "{% if 'ptf' in topo %}False{% else %}True{% endif %}"
remote_dut: "{{ ansible_ssh_host }}"
- name: gather testbed VM informations
testbed_vm_info: base_vm={{ testbed_facts['vm_base'] }} topo={{ testbed_facts['topo'] }} vm_file={{ vm_file }}
delegate_to: localhost
when: "VM_topo | bool"
- name: find all vlan configurations for T0 topology
vlan_config:
vm_topo_config: "{{ vm_topo_config }}"
port_alias: "{{ port_alias }}"
vlan_config: "{{ vlan_config | default(None) }}"
delegate_to: localhost
when: "('host_interfaces_by_dut' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"
- name: find downlink portchannel configuration for T0 topology
set_fact:
portchannel_config: "{{ vm_topo_config['DUT']['portchannel_config'] | default({})}}"
delegate_to: localhost
when: "('host_interfaces_by_dut' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"
- name: find any tunnel configurations
tunnel_config:
vm_topo_config: "{{ vm_topo_config }}"
tunnel_config: "{{ tunnel_config | default(None) }}"
delegate_to: localhost
- name: find all interface indexes mapping connecting to VM
set_fact:
interface_to_vms: "{{ interface_to_vms|default([]) + [ {'name': item.key, 'ports': item.value['interface_indexes'][dut_index|int] }] }}"
with_dict: "{{ vm_topo_config['vm'] }}"
- name: find all interface indexes connecting to VM
set_fact:
ifindex_to_vms: "{{ ifindex_to_vms|default([]) }} + {{ item.value['interface_indexes'][dut_index|int] }}"
with_dict: "{{ vm_topo_config['vm'] }}"
- name: find all interface names
set_fact:
intf_names: "{{ intf_names | default({}) | combine({item.0.name: intf_names[item.0.name]|default([]) + [ port_alias[item.1]] }) }}"
with_subelements:
- "{{ interface_to_vms }}"
- "ports"
# create map of VM to asic interface names
- name: find all interface asic names
set_fact:
vm_asic_ifnames: "{{ vm_asic_ifnames | default({}) | combine({item.0.name: vm_asic_ifnames[item.0.name]|default([]) + [ front_panel_asic_ifnames[item.1]] }) }}"
with_subelements:
- "{{ interface_to_vms }}"
- "ports"
when: front_panel_asic_ifnames != []
- name: create minigraph file in ansible minigraph folder
template: src=templates/minigraph_template.j2
dest=minigraph/{{ inventory_hostname}}.{{ topo }}.xml
delegate_to: localhost
when: local_minigraph is defined and local_minigraph|bool == true
- block:
- name: Init telemetry keys
set_fact:
server_key_t: ""
server_cer_t: ""
dsmsroot_key_t: ""
dsmsroot_cer_t: ""
dir_path_t: ""
subject_server: ""
subject_client: ""
- name: read server key
set_fact:
server_key_t: "{{ telemetry_certs['server_key'] }}"
when: telemetry_certs['server_key'] is defined
- name: read server cer
set_fact:
server_cer_t: "{{ telemetry_certs['server_cer'] }}"
when: telemetry_certs['server_cer'] is defined
- name: read dsmsroot key
set_fact:
dsmsroot_key_t: "{{ telemetry_certs['dsmsroot_key'] }}"
when: telemetry_certs['dsmsroot_key'] is defined
- name: read dsmsroot cer
set_fact:
dsmsroot_cer_t: "{{ telemetry_certs['dsmsroot_cer'] }}"
when: telemetry_certs['dsmsroot_cer'] is defined
- name: read directory path
set_fact:
dir_path_t: "{{ telemetry_certs['dir_path'] }}"
when: telemetry_certs['dir_path'] is defined
- name: read server subject
set_fact:
subject_server: "{{ telemetry_certs['subject_server'] }}"
when: telemetry_certs['subject_server'] is defined
- name: read client subject
set_fact:
subject_client: "{{ telemetry_certs['subject_client'] }}"
when: telemetry_certs['subject_client'] is defined
- include_tasks: deploy_certs.yml
vars:
dir_path: "{{ dir_path_t }}"
server_crt: "{{ server_cer_t }}"
server_key: "{{ server_key_t }}"
dsmsroot_cer: "{{ dsmsroot_cer_t }}"
dsmsroot_key: "{{ dsmsroot_key_t }}"
cert_subject: "{{ subject_server }}"
root_subject: "{{ subject_client }}"
when: deploy is defined and deploy|bool == true
- block:
- name: Init restapi keys
set_fact:
server_key_t: ""
server_crt_t: ""
dir_path_t: ""
subject_t: ""
- name: read server key
set_fact:
server_key_t: "{{ restapi_certs['server_key'] }}"
when: restapi_certs['server_key'] is defined
- name: read server crt
set_fact:
server_crt_t: "{{ restapi_certs['server_crt'] }}"
when: restapi_certs['server_crt'] is defined
- name: read subject
set_fact:
subject_t: "{{ restapi_certs['subject'] }}"
when: restapi_certs['subject'] is defined
- name: read directory path
set_fact:
dir_path_t: "{{ restapi_certs['dir_path'] }}"
when: restapi_certs['dir_path'] is defined
- include_tasks: deploy_certs.yml
vars:
dir_path: "{{ dir_path_t }}"
server_crt: "{{ server_crt_t }}"
server_key: "{{ server_key_t }}"
cert_subject: "{{ subject_t }}"
when: deploy is defined and deploy|bool == true
- block:
- name: saved original minigraph file in SONiC DUT(ignore errors when file doesnot exist)
shell: mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.xml.orig
become: true
ignore_errors: true
- name: create new minigraph file for SONiC device
template: src=templates/minigraph_template.j2
dest=/etc/sonic/minigraph.xml
become: true
- name: Test if configlet script exist
stat:
path: vars/configlet/{{ topo }}/apply_clet.sh
register: stat_result
delegate_to: localhost
- name: debug print stat_result
debug:
msg: Stat result is {{ stat_result }}
- name: Copy corresponding configlet files if exist
copy: src=vars/configlet/{{ topo }}/
dest=/etc/sonic/
become: true
when: stat_result.stat.exists is defined and stat_result.stat.exists
- name: Init account key and proxy
set_fact:
core_key: ""
core_proxy: ""
- name: Test if core_analyzer.rc.json exists
stat:
path: /etc/sonic/core_analyzer.rc.json
register: rc_stat
- name: read account key
set_fact:
core_key: "{{ corefile_uploader['azure_sonic_core_storage']['account_key'] }}"
when: rc_stat.stat.exists is defined and rc_stat.stat.exists and corefile_uploader['azure_sonic_core_storage']['account_key'] is defined
- name: read https proxy
set_fact:
core_proxy: "{{ corefile_uploader['env']['https_proxy'] }}"
when: rc_stat.stat.exists is defined and rc_stat.stat.exists and corefile_uploader['env']['https_proxy'] is defined
- name: Put secret in core_analyzer.rc.json
lineinfile:
name: /etc/sonic/core_analyzer.rc.json
regexp: '(^.*)account_key'
line: '\1account_key": "{{ core_key }}",'
backrefs: yes
become: true
when: core_key != ""
- name: Put https-proxy in core_analyzer.rc.json
lineinfile:
name: /etc/sonic/core_analyzer.rc.json
regexp: '(^.*)https_proxy'
line: '\1https_proxy": "{{ core_proxy }}"'
backrefs: yes
become: true
when: core_proxy != ""
- name: enable core uploader service
become: true
command: systemctl enable core_uploader.service
when: core_key != ""
- name: start core uploader service
become: true
command: systemctl start core_uploader.service
when: core_key != ""
- name: Replace snmp community string
lineinfile:
name: /etc/sonic/snmp.yml
regexp: '^snmp_rocommunity:'
line: 'snmp_rocommunity: {{ snmp_rocommunity }}'
become: true
- name: disable automatic minigraph update if we are deploying new minigraph into SONiC
lineinfile:
name: /etc/sonic/updategraph.conf
regexp: '^enabled='
line: 'enabled=false'
become: true
register: updategraph_conf
- name: restart automatic minigraph update service
become: true
service:
name: updategraph
state: restarted
when: updategraph_conf.changed
- name: docker status
shell: docker ps
register: docker_status
- debug: msg={{ docker_status.stdout_lines }}
- name: start topology service for multi-asic platform
become: true
shell: systemctl start topology.service
when: start_topo_service is defined and start_topo_service|bool == true
- name: execute cli "config load_minigraph -y" to apply new minigraph
become: true
shell: config load_minigraph -y
- name: execute cli "config bgp startup all" to bring up all bgp sessions for test
become: true
shell: config bgp startup all
- name: execute configlet application script, which applies configlets in strict order.
become: true
shell: bash "/etc/sonic/apply_clet.sh"
when: stat_result.stat.exists is defined and stat_result.stat.exists
- name: execute cli "config save -y" to save current minigraph as startup-config
become: true
shell: config save -y
when: save is defined and save|bool == true
- name: cleanup all cached facts
shell: python ../tests/common/cache/facts_cache.py
delegate_to: localhost
ignore_errors: true
when: deploy is defined and deploy|bool == true