Merge "Allow to see steady state status in the yardstick logs"
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_tg_rfc2544_trex.py
index 9531b90..a5b9f25 100644 (file)
@@ -15,6 +15,8 @@
 import mock
 import unittest
 
+from yardstick.benchmark import contexts
+from yardstick.benchmark.contexts import base as ctx_base
 from yardstick.network_services.traffic_profile import base as tp_base
 from yardstick.network_services.vnf_generic.vnf import sample_vnf
 from yardstick.network_services.vnf_generic.vnf import tg_rfc2544_trex
@@ -28,13 +30,14 @@ class TestTrexRfcResouceHelper(unittest.TestCase):
         mock_traffic_profile.config.duration = 3
         mock_traffic_profile.execute_traffic.return_value = ('fake_ports',
                                                              'port_pg_id_map')
-        mock_traffic_profile.get_drop_percentage.return_value = 'percentage'
+        mock_traffic_profile.get_drop_percentage.return_value = (True,
+                                                                 'percentage')
         rfc_rh = tg_rfc2544_trex.TrexRfcResourceHelper(mock_setup_helper)
         rfc_rh.TRANSIENT_PERIOD = 0
         rfc_rh.rfc2544_helper = mock.Mock()
 
         with mock.patch.object(rfc_rh, '_get_samples') as mock_get_samples:
-            rfc_rh._run_traffic_once(mock_traffic_profile)
+            self.assertTrue(rfc_rh._run_traffic_once(mock_traffic_profile))
 
         mock_traffic_profile.execute_traffic.assert_called_once_with(rfc_rh)
         mock_traffic_profile.stop_traffic.assert_called_once_with(rfc_rh)
@@ -205,7 +208,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
         ],
         'context': {
             'nfvi_type': 'baremetal',
-            'type': 'Node',
+            'type': contexts.CONTEXT_NODE,
             'name': 'yardstick',
             'file': '/etc/yardstick/nodes/pod.yaml',
         },
@@ -221,15 +224,31 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
         self._mock_ssh_helper.stop()
 
     def test___init__(self):
-        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
+        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
+            'vnf1', self.VNFD_0, 'task_id')
         self.assertIsNotNone(trex_traffic_gen.resource_helper._terminated.value)
 
-    def test_instantiate(self):
+    @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
+    def test_collect_kpi(self, *args):
+        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
+            'vnf1', self.VNFD_0, 'task_id')
+        trex_traffic_gen.scenario_helper.scenario_cfg = {
+            'nodes': {trex_traffic_gen.name: "mock"}
+        }
+        expected = {
+            'physical_node': 'mock_node',
+            'collect_stats': {},
+        }
+        self.assertEqual(trex_traffic_gen.collect_kpi(), expected)
+
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+    def test_instantiate(self, *args):
         mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
         mock_traffic_profile.get_traffic_definition.return_value = "64"
         mock_traffic_profile.params = self.TRAFFIC_PROFILE
 
-        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
+        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
+            'vnf1', self.VNFD_0, 'task_id')
         trex_traffic_gen._start_server = mock.Mock(return_value=0)
         trex_traffic_gen.resource_helper = mock.MagicMock()
         trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
@@ -255,23 +274,25 @@ class TestTrexTrafficGenRFC(unittest.TestCase):
             },
         }
         tg_rfc2544_trex.WAIT_TIME = 3
-        scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
+        scenario_cfg.update({"nodes": {"tg_1": {}, "vnf1": {}}})
         self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
 
-    def test_instantiate_error(self):
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server', return_value='fake_context')
+    def test_instantiate_error(self, *args):
         mock_traffic_profile = mock.Mock(autospec=tp_base.TrafficProfile)
         mock_traffic_profile.get_traffic_definition.return_value = "64"
         mock_traffic_profile.params = self.TRAFFIC_PROFILE
 
-        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC('vnf1', self.VNFD_0)
+        trex_traffic_gen = tg_rfc2544_trex.TrexTrafficGenRFC(
+            'vnf1', self.VNFD_0, 'task_id')
         trex_traffic_gen.resource_helper = mock.MagicMock()
         trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
         scenario_cfg = {
             "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
-            "nodes": [
-                "tg_1",
-                "vnf_1",
-            ],
+            "nodes": {
+                "tg_1": {},
+                "vnf1": {}
+            },
             "topology": 'nsb_test_case.yaml',
             'options': {
                 'packetsize': 64,