NFVBENCH-193: Correct a critical bug introduced in commit NFVBENCH-192
[nfvbench.git] / nfvbench / chaining.py
index b9ed48b..ed2f309 100644 (file)
@@ -245,6 +245,7 @@ class ChainNetwork(object):
         self.reuse = False
         self.network = None
         self.vlan = None
+        self.router_name = None
         if manager.config.l3_router and hasattr(network_config, 'router_name'):
             self.router_name = network_config.router_name
         try:
@@ -278,7 +279,7 @@ class ChainNetwork(object):
                 return item_field[index]
             except IndexError:
                 raise ChainException("List %s is too short for chain index %d" %
-                                     (str(item_field), index))
+                                     (str(item_field), index)) from IndexError
         # single value is configured
         if auto_index:
             return item_field + index
@@ -924,7 +925,10 @@ class Chain(object):
         if port_index:
             # this will pick the last item in array
             port_index = -1
-        return self.networks[port_index].get_vlan()
+        # This string filters networks connected to TG, in case of
+        # l3-router feature we have 4 networks instead of 2
+        networks = [x for x in self.networks if not x.router_name]
+        return networks[port_index].get_vlan()
 
     def get_vxlan(self, port_index):
         """Get the VXLAN id on a given port.
@@ -1191,7 +1195,8 @@ class ChainManager(object):
             self.vlans = [self._check_list('vlans[0]', self.config.vlans[0], re_vlan),
                           self._check_list('vlans[1]', self.config.vlans[1], re_vlan)]
         except IndexError:
-            raise ChainException('vlans parameter is mandatory. Set valid value in config file')
+            raise ChainException(
+                'vlans parameter is mandatory. Set valid value in config file') from IndexError
 
     def _get_dest_macs_from_config(self):
         re_mac = "[0-9a-fA-F]{2}([-:])[0-9a-fA-F]{2}(\\1[0-9a-fA-F]{2}){4}$"