Skip to content

Reduce the number of ifconfig calls made in add_topo #19119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 23 additions & 8 deletions ansible/roles/vm_set/library/vm_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def __init__(self, vm_names, vm_properties, fp_mtu, max_fp_num, topo, worker,
def init(self, vm_set_name, vm_base, duts_fp_ports, duts_name, ptf_exists=True, check_bridge=True):
self.vm_set_name = vm_set_name
self.duts_name = duts_name
self._is_multi_duts = True if len(self.duts_name) > 1 else False

if ptf_exists:
self.pid = VMTopology.get_pid(PTF_NAME_TEMPLATE % vm_set_name)
Expand Down Expand Up @@ -286,13 +287,28 @@ def init(self, vm_set_name, vm_base, duts_fp_ports, duts_name, ptf_exists=True,
self.VMs[k] = v

if check_bridge:
for hostname, attrs in self.VMs.items():
vmname = self.vm_names[self.vm_base_index +
attrs['vm_offset']]
vm_bridges = self.get_vm_bridges(vmname)
if len(attrs['vlans']) > len(vm_bridges):
raise Exception("Wrong vlans parameter for hostname %s, vm %s. Too many vlans. Maximum is %d"
% (hostname, vmname, len(vm_bridges)))
if self._is_multi_duts:
for hostname, attrs in self.VMs.items():
vmname = self.vm_names[self.vm_base_index + attrs['vm_offset']]
vm_bridges = self.get_vm_bridges(vmname)
if len(attrs['vlans']) > len(vm_bridges):
raise Exception("Wrong vlans parameter for hostname %s, vm %s. Too many vlans. Maximum is %d"
% (hostname, vmname, len(vm_bridges)))
# The approach below offers a vast speed improvement for performing check_bridge (particularly for
# topologies with a large number of interfaces, but it does not work for multi-dut approaches such as
# dualtor, hence why the former approach is preserved above for that case.
else:
intf_names = [intf['ifname'] for intf in json.loads(VMTopology.cmd('ip -j addr'))]
for hostname, attrs in self.VMs.items():
vmname = self.vm_names[self.vm_base_index + attrs['vm_offset']]
vm_bridge_regx = OVS_FP_BRIDGE_REGEX % vmname
num_intfs = 0
for intf_name in intf_names:
if re.search(vm_bridge_regx, intf_name):
num_intfs += 1
if len(attrs['vlans']) > num_intfs:
raise Exception("Wrong vlans parameter for hostname %s, vm %s. Too many vlans. Maximum is %d"
% (hostname, vmname, num_intfs))

self.VM_LINKs = {}
if 'VM_LINKs' in self.topo:
Expand All @@ -304,7 +320,6 @@ def init(self, vm_set_name, vm_base, duts_fp_ports, duts_name, ptf_exists=True,
for k, v in self.topo['OVS_LINKs'].items():
self.OVS_LINKs[k] = v

self._is_multi_duts = True if len(self.duts_name) > 1 else False
# For now distinguish a cable topology since it does not contain any vms and there are two ToR's
self._is_cable = True if len(
self.duts_name) > 1 and 'VMs' not in self.topo else False
Expand Down
Loading