Merge "Add 8 port topology file for agnostic vnf with ixia tg"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / networking / test_vnf_generic.py
index 49578b3..90248d1 100644 (file)
@@ -405,7 +405,6 @@ class TestNetworkServiceTestCase(unittest.TestCase):
     def test___get_traffic_flow(self):
         self.scenario_cfg["traffic_options"]["flow"] = \
             self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
-        self.scenario_cfg["options"] = {}
         self.scenario_cfg['options'] = {
             'flow': {
                 'src_ip': [
@@ -421,11 +420,10 @@ class TestNetworkServiceTestCase(unittest.TestCase):
                 'public_ip': ['1.1.1.1'],
             },
         }
-        # NOTE(ralonsoh): check the expected output. This test could be
-        # incorrect
-        # result = {'flow': {'dst_ip0': '152.16.40.2-152.16.40.254',
-        #                    'src_ip0': '152.16.100.2-152.16.100.254'}}
-        self.assertEqual({'flow': {}}, self.s._get_traffic_flow())
+        expected_flow = {'flow': {'dst_ip_0': '152.16.40.2-152.16.40.254',
+                                  'public_ip_0': '1.1.1.1',
+                                  'src_ip_0': '152.16.100.2-152.16.100.254'}}
+        self.assertEqual(expected_flow, self.s._get_traffic_flow())
 
     def test___get_traffic_flow_error(self):
         self.scenario_cfg["traffic_options"]["flow"] = \
@@ -631,7 +629,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
     @mock.patch.object(vnfdgen, 'generate_vnfd')
     def test__fill_traffic_profile(self, mock_generate, mock_tprofile_get):
         fake_tprofile = mock.Mock()
-        fake_vnfd = mock.Mock()
+        fake_vnfd = mock.MagicMock()
         with mock.patch.object(self.s, '_get_traffic_profile',
                                return_value=fake_tprofile) as mock_get_tp:
             mock_generate.return_value = fake_vnfd
@@ -648,6 +646,22 @@ class TestNetworkServiceTestCase(unittest.TestCase):
             )
             mock_tprofile_get.assert_called_once_with(fake_vnfd)
 
+    @mock.patch.object(base.TrafficProfile, 'get')
+    @mock.patch.object(vnfdgen, 'generate_vnfd')
+    def test__fill_traffic_profile2(self, mock_generate, mock_tprofile_get):
+        fake_tprofile = mock.Mock()
+        fake_vnfd = {}
+        with mock.patch.object(self.s, '_get_traffic_profile',
+                               return_value=fake_tprofile) as mock_get_tp:
+            mock_generate.return_value = fake_vnfd
+
+            self.s.scenario_cfg["options"] = {"traffic_config": {"duration": 99899}}
+            self.s._fill_traffic_profile()
+            mock_get_tp.assert_called_once()
+            self.assertIn("traffic_profile", fake_vnfd)
+            self.assertIn("duration", fake_vnfd["traffic_profile"])
+            self.assertEqual(99899, fake_vnfd["traffic_profile"]["duration"])
+
     @mock.patch.object(utils, 'open_relative_file')
     def test__get_topology(self, mock_open_path):
         self.s.scenario_cfg['topology'] = 'fake_topology'