forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestbed_add_vm_topology.yml
172 lines (142 loc) · 7.17 KB
/
testbed_add_vm_topology.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
# This Playbook add a topology to a server
#
# Topologies are defined inside of vars/ directorie in files vars/topo_{{ topology_name}}.yml
# This file contains three structures:
# - topology
# - configuration property
# - configuration
#
# topology key contains a dictionary of hostnames with 'vm_offset' and 'vlans' keys in it.
# 'vm_offset' is used to map current hostname vm_set VM to server VM (like ARISTA01T0 -> VM0300).
# This offset is used on VM_base
# 'vlans' is a list of vlan offsets which helps us to calculate vlan numbers which will be connected to Eth1/1..Eth1/8 interfaces.
# These offsets are used with vlan_base
#
# 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
#
# To add a topology please use following command
# ANSIBLE_SCP_IF_SSH=y ansible-playbook -i veos testbed_add_vm_topology.yml --vault-password-file=~/.password -l server_3 -e vm_set_name=first -e dut_name=str-msn2700-01 -e VM_base=VM0300 -e ptf_ip=10.255.0.255/23 -e topo=t0 -e ptf_imagename="docker_ptf"
#
# Parameters
# -l server_3 - this playbook have to be limited to run only on one server
# -e vm_set_name=first - the name of vm_set
# -e duts_name=str-msn2700-01 - the name of target duts
# -e VM_base=VM0300 - the VM name which is used to as base to calculate VM name for this set
# -e ptf_ip=10.255.0.255/23 - the ip address and prefix of ptf container mgmt interface
# -e ptf_ipv6=fec0::ffff:afa:1/64 - the ipv6 address and prefix of ptf container mgmt interface
# -e topo=t0 - the name of removed topo
# -e ptf_imagename=docker-ptf - name of a docker-image which will be used for the ptf docker container
# -e vm_type=veos|ceos|vsonic
# -e netns_mgmt_ip=10.255.0.254/23 - the ip address and prefix of netns mgmt interface, only for dualtor topo with ports in active-active cable type
- hosts: servers:&vm_host
gather_facts: no
pre_tasks:
- set_fact: ansible_user="{{ vm_host_user }}"
when:
- vm_host_user is defined
- vm_host_user != 'use_own_value'
- set_fact: ansible_password="{{ vm_host_password }}"
when:
- vm_host_password is defined
- vm_host_password != 'use_own_value'
- set_fact: ansible_become_password="{{ vm_host_become_password }}"
when:
- vm_host_become_password is defined
- vm_host_become_password != 'use_own_value'
- name: Check for a single host
fail: msg="Please use -l server_X to limit this playbook to one host"
when: play_hosts|length != 1
- name: Check that variable testbed_name is defined
fail: msg="Define testbed_name variable with -e testbed_name=something"
when: testbed_name is not defined
- name: Check that variable vm_set_name is defined
fail: msg="Define vm_set_name variable with -e vm_set_name=something"
when: vm_set_name is not defined
- name: Check that variable duts_name is defined
fail: msg="Define duts_name variable with -e duts_name=something"
when: duts_name is not defined
- name: Check that variable VM_base is defined
fail: msg="Define VM_base variable with -e VM_base=something"
when: VM_base is not defined
- name: Check that variable ptf_ip is defined
fail: msg="Define ptf ip variable with -e ptf_ip=something"
when: ptf_ip is not defined
- name: Check that variable ptf_ipv6 is defined
fail: msg="Define ptf ipv6 variable with -e ptf_ipv6=something"
when: ptf_ipv6 is not defined
- name: Check that variable topo is defined
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined
- set_fact:
base_topo: "{{ topo.split('_') | first }}"
- name: Check that topo is a known topology
fail: msg="Unknown topology {{ topo }}"
when: base_topo not in topologies
- name: Check that variable ptf_imagename is defined
fail: msg="Define ptf_imagename variable with -e ptf_imagename=something"
when: ptf_imagename is not defined
- name: Load docker variables
include_vars: "vars/docker_registry.yml"
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"
- name: Read duts minigraph
conn_graph_facts:
host: "{{ duts_name }}"
delegate_to: localhost
when: duts_name.split(',')|length == 1
- name: Read duts minigraph
conn_graph_facts:
hosts: "{{ duts_name.split(',') }}"
delegate_to: localhost
when: duts_name.split(',')|length > 1
roles:
- { role: vm_set, action: 'stop_sonic_vm', when force_stop_sonic_vm is defined }
- { role: vm_set, action: 'start_sonic_vm' }
- { role: vm_set, action: 'start_sid' }
- { role: vm_set, action: 'start_8000e_sonic' }
- { role: vm_set, action: 'add_topo' }
- hosts: servers:&eos
gather_facts: no
serial: "{{ eos_batch_size | default(0) | int }}"
pre_tasks:
- block:
- name: Check that variable topo is defined
fail: msg="Define topo variable with -e topo=something"
when: topo is not defined
- set_fact:
base_topo: "{{ topo.split('_') | first }}"
- name: Require VMs as CEOS by default
set_fact:
vm_type: "ceos"
when: vm_type is not defined
- name: Check if it is a known topology
fail: msg="Unknown topology {{ topo }}"
when: base_topo not in topologies
- name: Check that variable VM_base is defined
fail: msg="Define VM_base variable with -e VM_base=something"
when: VM_base is not defined
- name: Load topo variables
include_vars: "vars/topo_{{ topo }}.yml"
- name: Find current server group
set_fact: current_server={{ group_names | extract_by_prefix('server_') }}
- name: Extract VM names from the inventory
set_fact: VM_hosts={{ groups[current_server] | filter_by_prefix('VM') | sort }}
when: VM_base|length > 0
- name: Generate vm list of target VMs
set_fact: VM_targets={{ VM_hosts | filter_vm_targets(topology['VMs'], VM_base, dut_interfaces | default("")) }}
when:
- topology['VMs'] is defined
- VM_base|length > 0
run_once: True
delegate_to: localhost
roles:
- { role: eos, when: topology.VMs is defined and VM_targets is defined and inventory_hostname in VM_targets and (vm_type == "veos" or vm_type == "ceos" ) } # If the vm_type is eos based, role eos will be executed in any case, and when will evaluate with every task
- { role: sonic, when: topology.VMs is defined and VM_targets is defined and inventory_hostname in VM_targets and (vm_type == "vsonic" ) } # If the vm_type is sonic based, role sonic will be executed in any case, and when will evaluate with every task
- { role: cisco, when: topology.VMs is defined and VM_targets is defined and inventory_hostname in VM_targets and (vm_type == "vcisco" ) } # If the vm_type is cisco based, role cisco will be executed in any case, and when will evaluate with every task
- hosts: servers:&vm_host
gather_facts: no
tasks:
- name: Integrated traffic generator
include_tasks: testbed_integrate_traffic_generator.yml
when: topo == "wan-3link-tg"