forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_sonic_basedon_testbed.yml
851 lines (710 loc) · 31.8 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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# 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 target DUT, default is false if not defined
# -e save=True - if save the newly generated minigraph to the target DUT as startup-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 decide 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.yaml
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 ptf image name
set_fact:
ptf_image: "{{ testbed_facts['ptf_image_name'] }}"
- name: check if testbed is an ixia testbed
set_fact:
is_ixia_testbed: "{{ true if ptf_image == 'docker-keysight-api-server' else false }}"
- name: set vm
set_fact:
vm_base: "{% if 'vm_base' in testbed_facts and testbed_facts['vm_base'] != '' %}{{ testbed_facts['vm_base'] }}{% else %}''{% endif %}"
when: testbed_name is defined
- name: find supervisor dut of testbed
set_fact:
sup_dut: "{{ item | default(None) }}"
when: hostvars[item]['card_type'] is defined and hostvars[item]['card_type'] == 'supervisor'
loop: "{{ testbed_facts['duts'] }}"
- name: Get asics_present of supervisor dut
set_fact:
asics_present: "{{ hostvars[sup_dut]['asics_present'] | default([]) }}"
when: sup_dut is defined and hostvars[sup_dut]['asics_present'] is defined
- topo_facts: topo={{ topo }} hwsku={{ hwsku }} testbed_name={{ testbed_name | default(None) }} asics_present={{ asics_present | default([]) }} card_type={{ card_type | default('fixed') }}
delegate_to: localhost
- name: get connection graph if defined for dut (ignore any errors)
conn_graph_facts: host="{{ inventory_hostname }}" ignore_errors=true
delegate_to: localhost
ignore_errors: true
- name: find interface name mapping and individual interface speed if defined from dut
port_alias:
hwsku: "{{ hwsku }}"
card_type: "{{ card_type | default('fixed') }}"
hostname: "{{ inventory_hostname | default('') }}"
switchids: "{{ switchids | default([]) }}"
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 }}"
card_type: "{{ card_type | default('fixed') }}"
hostname: "{{ inventory_hostname | default('') }}"
switchids: "{{ switchids | default([]) }}"
slotid: "{{ slot_num | default(None) }}"
delegate_to: localhost
when: deploy is not defined or deploy|bool == false
- name: find and generate fabric ASIC information
fabric_info:
num_fabric_asic: "{{ num_fabric_asics | default(0) }}"
asics_host_basepfx: "{{ asics_host_ip | default(None) }}"
asics_host_basepfx6: "{{ asics_host_ipv6 | default(None) }}"
delegate_to: localhost
- name: set all VoQ system ports information
set_fact:
all_sysports: "{{ all_sysports | default( [] ) + hostvars[item]['sysports'] }}"
when: hostvars[item]['sysports'] is defined
loop: "{{ ansible_play_batch }}"
- name: set all v4 Inband Ip information for iBGP chassis voq
set_fact:
all_inbands: "{{ all_inbands | default( {} ) | combine( { item : hostvars[item]['voq_inband_ip']}) }}"
when: hostvars[item]['voq_inband_ip'] is defined
loop: "{{ ansible_play_batch }}"
- name: set all v6 Inband Ip information for iBGP chassis voq
set_fact:
all_inbands_ipv6: "{{ all_inbands_ipv6 | default( {} ) | combine( { item : hostvars[item]['voq_inband_ipv6']}) }}"
when: hostvars[item]['voq_inband_ipv6'] is defined
loop: "{{ ansible_play_batch }}"
- name: set all Loopback4096 information for iBGP chassis
set_fact:
all_loopback4096: "{{ all_loopback4096 | default( {} ) | combine( { item : hostvars[item]['loopback4096_ip']}) }}"
when: hostvars[item]['loopback4096_ip'] is defined
loop: "{{ ansible_play_batch }}"
- name: set all Loopback4096 ipv6 information for iBGP chassis
set_fact:
all_loopback4096_ipv6: "{{ all_loopback4096_ipv6 | default( {} ) | combine( { item : hostvars[item]['loopback4096_ipv6']}) }}"
when: hostvars[item]['loopback4096_ipv6'] is defined
loop: "{{ ansible_play_batch }}"
- name: set all slot information for chassis
set_fact:
all_slots: "{{ all_slots | default( {} ) | combine( { item : hostvars[item]['slot_num']}) }}"
when: hostvars[item]['slot_num'] is defined
loop: "{{ ansible_play_batch }}"
- 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: {}
mux_cable_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 }}"
vlan_config: "{{ vlan_config | default(None) }}"
delegate_to: localhost
when: "'dualtor' in topo or 'cable' in topo"
- name: gather mux cable information
mux_cable_facts:
topo_name: "{{ topo }}"
vlan_config: "{{ vlan_config | default(None) }}"
delegate_to: localhost
when: "'dualtor' in topo"
- name: generate y_cable simulator driver
include_tasks: dualtor/config_simulated_y_cable.yml
vars:
restart_pmon: no
when: "'dualtor' in topo"
- name: gather hwsku for LeafRouter that supports dualtor deployment
set_fact:
hwsku_list_dualtor_t1: "['ACS-MSN4600C', 'Arista-7260CX3-C64']"
- name: enable tunnel_qos_remap for T1 in dualtor deployment
set_fact:
enable_tunnel_qos_remap: true
when: "(('leafrouter' == (vm_topo_config['dut_type'] | lower)) or ('backendleafrouter' == (vm_topo_config['dut_type'] | lower))) and (hwsku in hwsku_list_dualtor_t1) and not (is_ixia_testbed)"
- name: gather hwsku that supports ComputeAI deployment
set_fact:
hwsku_list_compute_ai: "['Cisco-8111-O64', 'Cisco-8111-O32', 'Cisco-8122-O64', 'Cisco-8122-O64S2', 'Cisco-8122-O128']"
- name: enable ComputeAI deployment
set_fact:
enable_compute_ai_deployment: true
when: "(hwsku in hwsku_list_compute_ai) and not (is_ixia_testbed)"
- 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 information
testbed_vm_info: base_vm={{ testbed_facts['vm_base'] if 'vm_base' in testbed_facts else "" }} topo={{ testbed_facts['topo'] }} vm_file={{ vm_file }} servers_info={{ testbed_facts['servers'] | default({}) }}
delegate_to: localhost
when: "(VM_topo | bool) and ('cable' not in topo)"
- 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'] }}"
when: "'cable' not in topo"
- 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'] }}"
when: "'cable' not in topo"
- 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 | default([]) }}"
- "ports"
when: "'cable' not in topo"
# 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]] }) }}"
vm_asic_ids: "{{ vm_asic_ids | default({}) | combine({item.0.name: vm_asic_ids[item.0.name]|default([]) + [ front_panel_asic_ifs_asic_id[item.1]] }) }}"
with_subelements:
- "{{ interface_to_vms | default([]) }}"
- "ports"
when: front_panel_asic_ifnames != []
- block:
- name: Create new dictionary for my slot
set_fact:
new_asic_topo_config : "{{ new_asic_topo_config | default( { slot_num : asic_topo_config.slot0 }) }}"
- name: set asic_topo_config to new dictionary
set_fact:
asic_topo_config: "{{ new_asic_topo_config }}"
when: switch_type is defined and switch_type == 'voq' and slot_num is defined and asic_topo_config|length > 0
- 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
- name: Set docker proxy
block:
- name: Ensures /etc/systemd/system/docker.service.d dir exists
file:
path: /etc/systemd/system/docker.service.d
state: directory
recurse: yes
- name: Render docker proxy config
template:
src: 'templates/docker_http_proxy.j2'
dest: '/etc/systemd/system/docker.service.d/http-proxy.conf'
force: yes
- name: restart docker service, let docker proxy takes effect
systemd:
state: restarted
daemon_reload: yes
name: docker
- name: Wait 60s for docker containers to restart
pause:
seconds: 60
become: true
when: proxy_env is defined and deploy is defined and deploy|bool == true
- name: Enable PTF tacacs server by default
set_fact:
use_ptf_tacacs_server: true
tacacs_enabled_by_default: true
when: use_ptf_tacacs_server is not defined
- debug: msg="use_ptf_tacacs_server {{ use_ptf_tacacs_server }}"
- block:
- name: Load variables from topology file for topo_{{ topo }}.yml
include_vars: "vars/topo_{{ topo }}.yml"
- name: saved original minigraph file in SONiC DUT(ignore errors when file does not exist)
shell: mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.xml.orig
become: true
ignore_errors: true
when: init_cfg_profile is not defined
- name: Update TACACS server address to PTF IP
set_fact:
tacacs_servers: ["{{ testbed_facts['multi_servers_tacacs_ip'] if 'multi_servers_tacacs_ip' in testbed_facts else testbed_facts['ptf_ip'] }}"]
when: use_ptf_tacacs_server is defined and use_ptf_tacacs_server|bool == true
- debug: msg="tacacs_servers {{ tacacs_servers }}"
- name: create new minigraph file for SONiC device
template: src=templates/minigraph_template.j2
dest=/etc/sonic/minigraph.xml
become: true
when: init_cfg_profile is not defined
- block:
- name: Load variables from vars/init_cfg_profiles.yml
include_vars: "vars/init_cfg_profiles.yml"
- name: set cfg_profile to {{ init_cfg_profile }}
set_fact:
cfg_profile: "{{ init_cfg_profile }}"
- name: Set actual configuration value based on cfg_profile key
set_fact:
actual_config: "{{ lookup('vars', cfg_profile) }}"
- name: Debug actual configuration value
debug:
msg: "The actual configuration value is: {{ actual_config }}"
- name: Copy over config_db.json from file system for {{ cfg_profile }}
copy :
src: "{{ actual_config }}"
dest: /tmp/config_db.json
when: cfg_profile is defined
- name: Overwrite config_db.json
shell: cat /tmp/config_db.json > /etc/sonic/config_db.json
become: yes
when: init_cfg_profile is defined
- 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
when: init_cfg_profile is not defined
- 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
register: result
retries: 3
delay: 10
until: result is not failed
- name: Cleanup /etc/sonic folder before loading new minigraph
block:
- name: Ensure /etc/sonic/acl.json is deleted
become: true
file:
path: /etc/sonic/acl.json
state: absent
- name: Ensure /etc/sonic/port_config.json is deleted
become: true
file:
path: /etc/sonic/port_config.json
state: absent
- name: find interface name mapping
port_alias:
hwsku: "{{ hwsku }}"
when: topo == "mx"
- name: Copy dhcp_server config hwsku {{ hwsku }}
copy: src=golden_config_db/dhcp_server_mx.json
dest=/tmp/dhcp_server.json
become: true
when: topo == "mx"
- name: Copy smartswitch config
copy: src=golden_config_db/smartswitch_t1-28-lag.json
dest=/tmp/smartswitch.json
become: true
when: topo == "t1-28-lag"
- name: Generate golden_config_db.json
generate_golden_config_db:
topo_name: "{{ topo }}"
port_index_map: "{{ port_index_map | default({}) }}"
become: true
when: "'t2' not in topo"
- name: Copy macsec profile json to dut
copy: src=../tests/common/macsec/profile.json
dest=/tmp/profile.json
become: true
when: "('t2' in topo) and (enable_macsec is defined)"
- name: Copy golden_config_db_t2 template to DUT
copy: src=templates/golden_config_db_t2.j2
dest=/tmp/golden_config_db_t2.j2
become: true
when: "('t2' in topo) and (enable_macsec is defined)"
- name: Generate golden_config_db.json for t2
generate_golden_config_db:
topo_name: "{{ topo }}"
macsec_profile: "{{ macsec_profile }}"
num_asics: "{{ num_asics }}"
become: true
when: "('t2' in topo) and (enable_macsec is defined)"
- name: Use minigraph case
block:
- name: execute cli "config load_minigraph --override_config -y" to apply new minigraph
become: true
shell: config load_minigraph --override_config -y
register: load_minigraph_result
failed_when:
- load_minigraph_result.rc != 0
- "'no such option: --override_config' not in load_minigraph_result.stderr"
- name: execute cli "config load_minigraph -y" to apply new minigraph
become: true
shell: config load_minigraph -y
when: "'no such option: --override_config' in load_minigraph_result.stderr"
- name: remove DSCP_TO_TC_MAP for {{ hwsku }}. Some platform doesn't support this configuration
become: true
shell: redis-cli -n 4 del "DSCP_TO_TC_MAP|AZURE"
when:
- hwsku is defined
- hwsku == 'cisco-8101-p4-32x100-vs'
when: init_cfg_profile is not defined
- name: SONiC config reload to pick up config_db.json
command: config reload -y
become: yes
when: init_cfg_profile is defined
- name: Wait for switch to become reachable again
become: false
local_action: wait_for
args:
host: "{{ ansible_host }}"
port: 22
state: started
search_regex: "OpenSSH_[\\w\\.]+ Debian"
delay: 10
timeout: 600
changed_when: false
- name: Check if chrony exists
service: name=chrony
register: chrony_service
- name: Sync DUT system time with NTP server with ntpd
block:
- name: Wait for ntp.service restart after reload minigraph
become: true
service: name=ntp state=started
- name: Stop ntp.service on DUT
become: true
service: name=ntp state=stopped
- name: Sync DUT system time with NTP server
become: true
command: ntpd -gq
ignore_errors: true
async: 60
poll: 10
- name: Set the RTC from the system time
become: true
command: hwclock --systohc
ignore_errors: true
- name: Start ntp.service on DUT
become: true
service: name=ntp state=restarted enabled=true
when: chrony_service.status.LoadState == "not-found"
- name: Sync DUT system time with NTP server with chrony
block:
- name: Wait for chrony.service restart after reload minigraph
become: true
service: name=chrony state=started
- name: Stop chrony.service on DUT
become: true
service: name=chrony state=stopped
- name: Sync DUT system time with NTP server
become: true
command: chronyd -F 1 -q
ignore_errors: true
async: 60
poll: 10
- name: Start chrony.service on DUT
become: true
service: name=chrony state=restarted enabled=true
when: chrony_service.status.LoadState != "not-found"
- name: config static route for trex traffic passthrough
become: true
command: "{{ item }}"
with_items:
- config route add prefix 48.0.0.0/8 nexthop 10.0.0.59
- config route add prefix 16.0.0.0/8 nexthop 10.0.0.57
when: topo == "wan-3link-tg"
- name: execute cli "config bgp startup all" to bring up all bgp sessions for test
become: true
shell: config bgp startup all
- name: Configure TACACS
become: true
shell: "{{ tacacs_config_cmd }}"
loop:
- config tacacs passkey {{ tacacs_passkey }}
- config tacacs authtype pap
- config aaa authentication login tacacs+
loop_control:
loop_var: tacacs_config_cmd
ignore_errors: true
when: tacacs_enabled_by_default is defined and tacacs_enabled_by_default|bool == true
- block:
- name: Configure TACACS with PTF TACACS server
become: true
shell: "{{ tacacs_config_cmd }}"
loop:
- config tacacs authtype login
- config aaa authorization tacacs+
- config aaa accounting "tacacs+ local"
loop_control:
loop_var: tacacs_config_cmd
ignore_errors: true
- name: Configure TACACS with PTF TACACS server for MX
become: true
shell: config aaa authorization "tacacs+ local"
when: topo == "mx"
when: use_ptf_tacacs_server is defined and use_ptf_tacacs_server|bool == true
- 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
- block:
- name: create isis config file for SONiC device
template: src=templates/isis_config.j2
dest=/etc/sonic/isis_config.json
become: true
- name: active isis config
become: true
shell: sonic-cfggen -j /etc/sonic/isis_config.json -w
#will remove below task, after isisd issue got fixed
- name: restart bgp container
become: true
shell: docker restart bgp
when: topo == "wan-ecmp" or topo == "wan-pub-isis"
- block:
- name: set the default grpc credential file path
set_fact:
grpc_credential_file: /etc/sonic/grpc_secrets.json
- name: check if grpc credential file exists
stat:
path: "{{ grpc_credential_file }}"
register: stat_result
- block:
- name: collect initial grpc credentials
slurp:
path: "{{ grpc_credential_file }}"
register: grpc_credential_content
- name: parse initial grpc credentials
set_fact:
grpc_secrets_before: "{{ grpc_credential_content.content | b64decode | from_json }}"
- name: use insecure grpc for testing
shell: "sed -E -i 's/\"type\": \"secure\"/\"type\": \"insecure\"/' {{ grpc_credential_file }}"
become: true
- name: collect current grpc credentials
slurp:
path: "{{ grpc_credential_file }}"
register: grpc_credential_content
- name: parse current grpc credentials
set_fact:
grpc_secrets_after: "{{ grpc_credential_content.content | b64decode | from_json }}"
- name: show original grpc setting
debug:
var: grpc_secrets_before
- name: show new grpc setting
debug:
var: grpc_secrets_after
- name: restart the pmon service
service:
name: pmon
state: restarted
become: true
when: stat_result.stat.exists
when: "'dualtor-mixed' in topo or 'dualtor-aa' in topo"
- 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: remove running golden config file if exists
become: True
file: path=/etc/sonic/running_golden_config.json
state=absent
- name: remove running golden config files for all the asics if exists
become: True
file: path=/etc/sonic/running_golden_config{{ item }}.json
state=absent
with_sequence: start=0 end={{ num_asics - 1 }}
when: num_asics > 1
- name: cleanup all cached facts
shell: python ../tests/common/cache/facts_cache.py
delegate_to: localhost
ignore_errors: true
# In pr https://github.com/sonic-net/sonic-buildimage/pull/12109, it decrease the sshd timeout
# which may cause timeout when executing `generate_dump -s yesterday`.
# Increase this time during deploying minigraph
- name: Reset sshd timeout
become: True
shell: sed -i "s/^ClientAliveInterval [0-9].*/ClientAliveInterval 900/g" /etc/ssh/sshd_config && systemctl restart sshd
when: deploy is defined and deploy|bool == true