vnf_generic: Fix str object has no attribute items 05/43505/1
authorDino Madarang <dinox.madarang@intel.com>
Thu, 28 Sep 2017 18:10:28 +0000 (18:10 +0000)
committerRoss Brattain <ross.b.brattain@intel.com>
Thu, 28 Sep 2017 19:46:07 +0000 (12:46 -0700)
When an IP range is specified in src_ip/dst_ip like:
src_ip:
   - '152.16.100.180-152.16.100.181'
yardstick would return str object has no attribute items error.
This change will return the IP range as is if type is str.

Change-Id: I3b097777f0d85b0600207157bebba18987ea2275
Signed-off-by: Dino Simeon Madarang <dinox.madarang@intel.com>
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
yardstick/benchmark/scenarios/networking/vnf_generic.py

index fa9b854..5b15dac 100644 (file)
@@ -361,6 +361,12 @@ class TestNetworkServiceTestCase(unittest.TestCase):
     def test___init__(self):
         assert self.topology
 
+    def test__get_ip_flow_range_string(self):
+        self.scenario_cfg["traffic_options"]["flow"] = \
+            self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
+        result = '152.16.100.2-152.16.100.254'
+        self.assertEqual(result, self.s._get_ip_flow_range('152.16.100.2-152.16.100.254'))
+
     def test__get_ip_flow_range(self):
         self.scenario_cfg["traffic_options"]["flow"] = \
             self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
index 450f83f..355b698 100644 (file)
@@ -140,8 +140,15 @@ class NetworkServiceTestCase(base.Scenario):
 
     def _get_ip_flow_range(self, ip_start_range):
 
+        # IP range is specified as 'x.x.x.x-y.y.y.y'
+        if isinstance(ip_start_range, six.string_types):
+            return ip_start_range
+
         node_name, range_or_interface = next(iter(ip_start_range.items()), (None, '0.0.0.0'))
-        if node_name is not None:
+        if node_name is None:
+            # we are manually specifying the range
+            ip_addr_range = range_or_interface
+        else:
             node = self.context_cfg["nodes"].get(node_name, {})
             try:
                 # the ip_range is the interface name
@@ -163,9 +170,6 @@ class NetworkServiceTestCase(base.Scenario):
                 LOG.warning("Only single IP in range %s", ipaddr)
                 # fall back to single IP range
                 ip_addr_range = ip
-        else:
-            # we are manually specifying the range
-            ip_addr_range = range_or_interface
         return ip_addr_range
 
     def _get_traffic_flow(self):