Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ansible/config_sonic_basedon_testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@
testbed_file: testbed.csv
when: testbed_file is not defined

- name: Set default dut index
set_fact:
dut_index: 0
when: dut_index 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: testbed_facts['duts'][dut_index] != inventory_hostname
when: inventory_hostname not in testbed_facts['duts']

- name: Set default dut index
set_fact:
dut_index: "{{ testbed_facts['duts_map'][inventory_hostname]|int }}"

- name: set testbed_type
set_fact:
Expand Down Expand Up @@ -85,30 +84,30 @@

- name: find all enabled host_interfaces
set_fact:
host_if_indexes: "{{ vm_topo_config['host_interfaces'] | difference(vm_topo_config['disabled_host_interfaces']) }}"
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' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"
when: "('host_interfaces_by_dut' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"

- 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' in vm_topo_config) and ('tor' in vm_topo_config['dut_type'] | lower)"
when: "('host_interfaces_by_dut' 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'] }) }}"
interface_to_vms: "{{ interface_to_vms|default({}) | combine({ item.key: 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']}}"
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
Expand Down Expand Up @@ -163,7 +162,7 @@
mode: '0755'
become: true

# {{ server_cer }}/ streamingtelemetryserver.cer need to be copied on PTFDocker and renamed as dsmsroot.cer
# {{ server_cer }}/ streamingtelemetryserver.cer need to be copied on PTFDocker and renamed as dsmsroot.cer
- name: Generate server cert using openssl.
command: openssl req \
-x509 \
Expand All @@ -172,7 +171,7 @@
-newkey rsa:2048 \
-keyout "{{ server_key }}"
-subj "/CN=ndastreamingservertest"
-out "{{ server_cer }}"
-out "{{ server_cer }}"
become: true

# {{ dsmsroot_cer }}/ dsmsroot.cer need to be copied on PTFDocker and renamed as streamingtelemetryclient.cer
Expand Down
6 changes: 6 additions & 0 deletions ansible/lab
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ sonic_s6000:
vlab-04:
ansible_host: 10.250.0.107
ansible_hostv6: fec0::ffff:afa:7
vlab-05:
ansible_host: 10.250.0.110
ansible_hostv6: fec0::ffff:afa:a
vlab-06:
ansible_host: 10.250.0.111
ansible_hostv6: fec0::ffff:afa:b

sonic_s6100:
vars:
Expand Down
2 changes: 2 additions & 0 deletions ansible/library/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def main():
device_port_vlans = []
device_vlan_range = []
device_vlan_list = []
device_vlan_map_list = {}
for hostname in hostnames:
dev = lab_graph.get_host_device_info(hostname)
if dev is None:
Expand All @@ -337,6 +338,7 @@ def main():
if host_vlan:
device_vlan_range.append(host_vlan["VlanRange"])
device_vlan_list.append(host_vlan["VlanList"])
device_vlan_map_list[hostname] = host_vlan["VlanList"]
device_port_vlans.append(lab_graph.get_host_port_vlans(hostname))
results = {k: v for k, v in locals().items()
if (k.startswith("device_") and v)}
Expand Down
1 change: 1 addition & 0 deletions ansible/library/test_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def read_testbed_topo(self):
line['ptf_netmask_v6'] = str(ptfaddress.netmask)

line['duts'] = line['dut'].translate(string.maketrans("", ""), "[] ").split(';')
line['duts_map'] = {dut:line['duts'].index(dut) for dut in line['duts']}
del line['dut']

self.testbed_topo[line['conf-name']] = line
Expand Down
137 changes: 117 additions & 20 deletions ansible/library/topo_facts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import os
import traceback
import ipaddr as ipaddress
import ipaddress
import csv
from operator import itemgetter
from itertools import groupby
Expand All @@ -19,6 +19,45 @@
required: True
'''

def parse_vm_vlan_port(vlan):
"""
parse vm vlan port

old format (non multi-dut): vlan_index
new format (multi-dut): dut_index.vlan_index@ptf_index

"""
if isinstance(vlan, int):
dut_index = 0
vlan_index = vlan
ptf_index = vlan
else:
m = re.match("(\d+)\.(\d+)@(\d+)", vlan)
(dut_index, vlan_index, ptf_index) = (int(m.group(1)), int(m.group(2)), int(m.group(3)))

return (dut_index, vlan_index, ptf_index)

def parse_host_interfaces(hifs):
"""
parse host interfaces

old format (non multi-dut): vlan_index
new format (multi-dut): dut_index.vlan_index,dut_index.vlan_index
"""

if isinstance(hifs, int):
dut_index = 0
vlan_index = int(hifs)

return [(dut_index, vlan_index)]

ret = []
for hif in hifs.split(','):
(dut_index, port_index) = [int(x) for x in hif.split('.')]
ret.append((dut_index, port_index))

return ret

class ParseTestbedTopoinfo():
'''
Parse topology yml file
Expand All @@ -36,6 +75,7 @@ def get_topo_config(self, topo_name):
topo_name = re.sub(CLET_SUFFIX + "$", "", topo_name)
topo_filename = 'vars/topo_' + topo_name + '.yml'
vm_topo_config = dict()
po_map = [None] * 16 # maximum 16 port channel interfaces

### read topology definition
if not os.path.isfile(topo_filename):
Expand All @@ -45,43 +85,99 @@ def get_topo_config(self, topo_name):
topo_definition = yaml.load(f)

### parse topo file specified in vars/ to reverse as dut config
dut_num = 1
if 'dut_num' in topo_definition['topology']:
dut_num = topo_definition['topology']['dut_num']
vm_topo_config['dut_num'] = dut_num

if 'VMs' in topo_definition['topology']:
dut_asn = topo_definition['configuration_properties']['common']['dut_asn']
vm_topo_config['dut_asn'] = dut_asn
vm_topo_config['dut_type'] = topo_definition['configuration_properties']['common']['dut_type']
vmconfig = dict()
for vm in topo_definition['topology']['VMs']:
vmconfig[vm] = dict()
vmconfig[vm]['intfs'] = []
vmconfig[vm]['intfs'] = [[] for i in range(dut_num)]
vmconfig[vm]['properties']=topo_definition['configuration'][vm]['properties']
vmconfig[vm]['interface_indexes'] = topo_definition['topology']['VMs'][vm]['vlans']
vmconfig[vm]['bgp_asn'] = topo_definition['configuration'][vm]['bgp']['asn']
vmconfig[vm]['interface_indexes'] = [[] for i in range(dut_num)]
for vlan in topo_definition['topology']['VMs'][vm]['vlans']:
(dut_index, vlan_index, _) = parse_vm_vlan_port(vlan)
vmconfig[vm]['interface_indexes'][dut_index].append(vlan_index)

# physical interface
for intf in topo_definition['configuration'][vm]['interfaces']:
if 'Ethernet' in intf:
dut_index = 0
if 'dut_index' in topo_definition['configuration'][vm]['interfaces'][intf]:
dut_index = topo_definition['configuration'][vm]['interfaces'][intf]['dut_index']
if 'lacp' in topo_definition['configuration'][vm]['interfaces'][intf]:
po_map[topo_definition['configuration'][vm]['interfaces'][intf]['lacp']] = dut_index

vmconfig[vm]['intfs'][dut_index].append(intf)

# ip interface
vmconfig[vm]['ip_intf'] = [None] * dut_num
vmconfig[vm]['peer_ipv4'] = [None] * dut_num
vmconfig[vm]['ipv4mask'] = [None] * dut_num
vmconfig[vm]['peer_ipv6'] = [None] * dut_num
vmconfig[vm]['ipv6mask'] = [None] * dut_num


for intf in topo_definition['configuration'][vm]['interfaces']:
dut_index = 0
if 'Ethernet' in intf:
if 'dut_index' in topo_definition['configuration'][vm]['interfaces'][intf]:
dut_index = topo_definition['configuration'][vm]['interfaces'][intf]['dut_index']
elif 'Port-Channel' in intf:
m = re.search("(\d+)", intf)
dut_index = po_map[int(m.group(1))]

if 'ipv4' in topo_definition['configuration'][vm]['interfaces'][intf] and ('loopback' not in intf.lower()):
(vmconfig[vm]['peer_ipv4'], vmconfig[vm]['ipv4mask']) = topo_definition['configuration'][vm]['interfaces'][intf]['ipv4'].split('/')
vmconfig[vm]['ip_intf'] = intf
(peer_ipv4, ipv4_mask) = topo_definition['configuration'][vm]['interfaces'][intf]['ipv4'].split('/')
vmconfig[vm]['peer_ipv4'][dut_index] = peer_ipv4
vmconfig[vm]['ipv4mask'][dut_index] = ipv4_mask
vmconfig[vm]['ip_intf'][dut_index] = intf
if 'ipv6' in topo_definition['configuration'][vm]['interfaces'][intf] and ('loopback' not in intf.lower()):
(ipv6_addr, vmconfig[vm]['ipv6mask']) = topo_definition['configuration'][vm]['interfaces'][intf]['ipv6'].split('/')
vmconfig[vm]['ip_intf'] = intf
vmconfig[vm]['peer_ipv6'] = ipv6_addr.upper()
if 'Ethernet' in intf:
vmconfig[vm]['intfs'].append(intf)
for ip in topo_definition['configuration'][vm]['bgp']['peers'][dut_asn]:
if ip[0:5].upper() in vmconfig[vm]['peer_ipv4'].upper():
vmconfig[vm]['bgp_ipv4'] = ip.upper()
if ip[0:5].upper() in vmconfig[vm]['peer_ipv6'].upper():
vmconfig[vm]['bgp_ipv6'] = ip.upper()
(ipv6_addr, ipv6_mask) = topo_definition['configuration'][vm]['interfaces'][intf]['ipv6'].split('/')
vmconfig[vm]['peer_ipv6'][dut_index] = ipv6_addr.upper()
vmconfig[vm]['ipv6mask'][dut_index] = ipv6_mask
vmconfig[vm]['ip_intf'][dut_index] = intf

# bgp
vmconfig[vm]['bgp_ipv4'] = [None] * dut_num
vmconfig[vm]['bgp_ipv6'] = [None] * dut_num
vmconfig[vm]['bgp_asn'] = topo_definition['configuration'][vm]['bgp']['asn']
for ipstr in topo_definition['configuration'][vm]['bgp']['peers'][dut_asn]:
ip = ipaddress.ip_address(ipstr.decode('utf8'))
for dut_index in range(0, dut_num):
if ip.version == 4:
ipsubnet_str = vmconfig[vm]['peer_ipv4'][dut_index]+'/'+vmconfig[vm]['ipv4mask'][dut_index]
ipsubnet = ipaddress.ip_interface(ipsubnet_str.decode('utf8'))
if ip in ipsubnet.network:
vmconfig[vm]['bgp_ipv4'][dut_index] = ipstr.upper()
elif ip.version == 6:
ipsubnet_str = vmconfig[vm]['peer_ipv6'][dut_index]+'/'+vmconfig[vm]['ipv6mask'][dut_index]
ipsubnet = ipaddress.ip_interface(ipsubnet_str.decode('utf8'))
if ip in ipsubnet.network:
vmconfig[vm]['bgp_ipv6'][dut_index] = ipstr.upper()

vm_topo_config['vm'] = vmconfig

vm_topo_config['host_interfaces_by_dut'] = [[] for i in range(dut_num)]
if 'host_interfaces' in topo_definition['topology']:
vm_topo_config['host_interfaces'] = topo_definition['topology']['host_interfaces']
else:
vm_topo_config['host_interfaces'] = []
for host_if in topo_definition['topology']['host_interfaces']:
hifs = parse_host_interfaces(host_if)
for hif in hifs:
vm_topo_config['host_interfaces_by_dut'][hif[0]].append(hif[1])

vm_topo_config['disabled_host_interfaces_by_dut'] = [[] for i in range(dut_num)]
if 'disabled_host_interfaces' in topo_definition['topology']:
vm_topo_config['disabled_host_interfaces'] = topo_definition['topology']['disabled_host_interfaces']
else:
vm_topo_config['disabled_host_interfaces'] = []
for host_if in topo_definition['topology']['disabled_host_interfaces']:
hifs = parse_host_interfaces(host_if)
for hif in hifs:
vm_topo_config['disabled_host_interfaces_by_dut'][hif[0]].append(hif[1])

if 'DUT' in topo_definition['topology']:
vm_topo_config['DUT'] = topo_definition['topology']['DUT']
Expand All @@ -91,6 +187,7 @@ def get_topo_config(self, topo_name):
self.vm_topo_config = vm_topo_config
return vm_topo_config


def main():
module = AnsibleModule(
argument_spec=dict(
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/eos/templates/dualtor-leaf.j2
Loading