Skip to content
Merged
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
35 changes: 22 additions & 13 deletions ansible/roles/vm_set/library/vm_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
PTF_FP_IFACE_TEMPLATE = 'eth%d'
BACK_ROOT_END_IF_TEMPLATE = 'veth-bb-%s'
BACK_VM_END_IF_TEMPLATE = 'veth-bv-%s'
RETRIES = 3


class VMTopology(object):
Expand Down Expand Up @@ -405,7 +406,7 @@ def bind_phys_vlan(self, br_name, vlan_iface, injected_iface, vm_iface, disconne
if vlan_iface not in ports:
VMTopology.cmd('ovs-vsctl add-port %s %s' % (br_name, vlan_iface))

bindings = VMTopology.get_ovs_port_bindings(br_name)
bindings = VMTopology.get_ovs_port_bindings(br_name, vlan_iface)
vlan_iface_id = bindings[vlan_iface]
injected_iface_id = bindings[injected_iface]
vm_iface_id = bindings[vm_iface]
Expand Down Expand Up @@ -490,19 +491,27 @@ def get_ovs_br_ports(bridge):
out = VMTopology.cmd('ovs-vsctl list-ports %s' % bridge)
return set(out.split('\n'))


@staticmethod
def get_ovs_port_bindings(bridge):
out = VMTopology.cmd('ovs-ofctl show %s' % bridge)
lines = out.split('\n')
result = {}
for line in lines:
matched = re.match(r'^\s+(\S+)\((\S+)\):\s+addr:.+$', line)
if matched:
port_id = matched.group(1)
iface_name = matched.group(2)
result[iface_name] = port_id

return result
def get_ovs_port_bindings(bridge, vlan_iface = None):
# Vlan interface addition may take few secs to reflect in OVS Command,
# Let`s retry few times in that case.
for retries in range(RETRIES):
out = VMTopology.cmd('ovs-ofctl show %s' % bridge)
lines = out.split('\n')
result = {}
for line in lines:
matched = re.match(r'^\s+(\S+)\((\S+)\):\s+addr:.+$', line)
if matched:
port_id = matched.group(1)
iface_name = matched.group(2)
result[iface_name] = port_id
# Check if we have vlan_iface populated
if vlan_iface is None or vlan_iface in result:
return result
time.sleep(2*retries+1)
# Flow reaches here when vlan_iface not present in result
raise Exception("Can't find vlan_iface_id")

@staticmethod
def ifconfig(cmdline):
Expand Down