forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_sonic_basedon_testbed.yml
More file actions
executable file
·131 lines (109 loc) · 6.28 KB
/
Copy pathconfig_sonic_basedon_testbed.yml
File metadata and controls
executable file
·131 lines (109 loc) · 6.28 KB
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
# 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 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: Gathering testbed information
test_facts: testbed_name="{{ testbed_name }}"
connection: local
- fail: msg="The DUT you are trying to run test does not belongs to this testbed"
when: testbed_facts['dut'] != inventory_hostname
- 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 }}
connection: local
- 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'] }}"
testbed_vm_info: base_vm="{{vm_base}}" topo="{{topo}}"
connection: local
when: "VM_topo | bool"
- name: find interface name mapping and individual interface speed if defined
port_alias: hwsku="{{ hwsku }}"
- name: find all enabled host_interfaces
set_fact:
host_if_indexes: "{{ vm_topo_config['host_interfaces'] | difference(vm_topo_config['disabled_host_interfaces']) }}"
- 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' in vm_topo_config") and ("'tor' in vm_topo_config['dut_type'] | lower")
- name: find all interface indexes mapping connecting to VM
set_fact:
interface_to_vms: "{{ interface_to_vms|default({}) | combine({ item.key: item.value['interface_indexes'] }) }}"
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']}}"
with_dict: vm_topo_config['vm']
- name: find all interface names
set_fact:
intf_names: "{{ intf_names | default({}) | combine({item.key: port_alias[item.value[0]|int:item.value[-1]|int+1] }) }}"
with_dict: interface_to_vms
- name: create minigraph file in ansible minigraph folder
template: src=templates/minigraph_template.j2
dest=minigraph/{{ inventory_hostname}}.{{ topo }}.xml
connection: local
- 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: 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
- 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 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
when: deploy is defined and deploy|bool == true