Merge "Add test suite for scenario "opnfv_os-ovn-nofeature-ha""
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_udp_replay.py
index 05a0ead..56c971d 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 import unittest
 import mock
 import os
 
-from yardstick.tests import STL_MOCKS
 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
+from yardstick.benchmark.contexts import base as ctx_base
+from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
+from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
 
 
 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
 
-STLClient = mock.MagicMock()
-stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
-stl_patch.start()
-
-if stl_patch:
-    from yardstick.network_services.vnf_generic.vnf.udp_replay import UdpReplayApproxVnf
-    from yardstick.network_services.vnf_generic.vnf.sample_vnf import ScenarioHelper
-
-
 TEST_FILE_YAML = 'nsb_test_case.yaml'
 
-
 NAME = "vnf__1"
 
 
@@ -326,10 +317,12 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
     }
 
     def test___init__(self, *args):
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         self.assertIsNone(udp_replay_approx_vnf._vnf_process)
 
     @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
+    @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
     @mock.patch(SSH_HELPER)
     def test_collect_kpi(self, ssh, *args):
         mock_ssh(ssh)
@@ -340,22 +333,30 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
             "Port\t\tRx Packet\t\tTx Packet\t\tRx Pkt Drop\t\tTx Pkt Drop \r\n"\
             "0\t\t7374156\t\t7374136\t\t\t0\t\t\t0\r\n" \
             "1\t\t7374316\t\t7374315\t\t\t0\t\t\t0\r\n\r\nReplay>\r\r\nReplay>"
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, vnfd, 'task_id')
+        udp_replay_approx_vnf.scenario_helper.scenario_cfg = {
+            'nodes': {udp_replay_approx_vnf.name: "mock"}
+        }
         udp_replay_approx_vnf.q_in = mock.MagicMock()
         udp_replay_approx_vnf.q_out = mock.MagicMock()
         udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
         udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
         udp_replay_approx_vnf.get_stats = mock.Mock(return_value=get_stats_ret_val)
-
-        result = {'collect_stats': {}, 'packets_dropped': 0,
-                  'packets_fwd': 14748451, 'packets_in': 14748472}
+        result = {
+            'physical_node': 'mock_node',
+            'collect_stats': {},
+            'packets_dropped': 0,
+            'packets_fwd': 14748451,
+            'packets_in': 14748472
+        }
         self.assertEqual(result, udp_replay_approx_vnf.collect_kpi())
 
     @mock.patch(SSH_HELPER)
     def test_get_stats(self, ssh, *args):
         mock_ssh(ssh)
 
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf.q_in = mock.MagicMock()
         udp_replay_approx_vnf.q_out = mock.MagicMock()
         udp_replay_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -372,14 +373,19 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
         file_path = os.path.join(curr_path, filename)
         return file_path
 
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server')
     @mock.patch(SSH_HELPER)
-    def test__build_config(self, ssh, mock_context, *args):
+    def test__build_config(self, ssh, mock_get_ctx, *args):
         mock_ssh(ssh)
 
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        nfvi_context = mock.Mock()
+        nfvi_context.attrs = {'nfvi_type': 'baremetal'}
+        mock_get_ctx.return_value = nfvi_context
+
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
-        udp_replay_approx_vnf.nfvi_context = mock_context
+        udp_replay_approx_vnf.nfvi_context = mock_get_ctx
         udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
         udp_replay_approx_vnf.setup_helper.bound_pci = []
         udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
@@ -393,13 +399,17 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
         self.assertEqual(cmd_line, expected)
 
     @mock.patch('yardstick.network_services.vnf_generic.vnf.udp_replay.open')
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server')
     @mock.patch(SSH_HELPER)
-    def test__build_pipeline_kwargs(self, ssh, mock_context, *args):
+    def test__build_pipeline_kwargs(self, ssh, mock_get_ctx, *args):
         mock_ssh(ssh)
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
-        udp_replay_approx_vnf.nfvi_context = mock_context
-        udp_replay_approx_vnf.nfvi_context.attrs = {'nfvi_type': 'baremetal'}
+
+        nfvi_context = mock.Mock()
+        nfvi_context.attrs = {'nfvi_type': "baremetal"}
+        mock_get_ctx.return_value = nfvi_context
+
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf.setup_helper.bound_pci = ['0000:00:0.1', '0000:00:0.3']
         udp_replay_approx_vnf.all_ports = ["xe0", "xe1"]
         udp_replay_approx_vnf.ssh_helper.provision_tool = mock.MagicMock(return_value="tool_path")
@@ -421,7 +431,8 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
     def test_run_udp_replay(self, ssh, *args):
         mock_ssh(ssh)
 
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf._build_config = mock.MagicMock()
         udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()
         udp_replay_approx_vnf.scenario_helper = mock.MagicMock()
@@ -430,12 +441,13 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
 
         udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
 
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server')
     @mock.patch(SSH_HELPER)
     def test_instantiate(self, ssh, *args):
         mock_ssh(ssh)
 
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf.q_out.put("Replay>")
         udp_replay_approx_vnf.WAIT_TIME = 0
         udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()
@@ -449,11 +461,12 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
 
         self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
 
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
+    @mock.patch.object(ctx_base.Context, 'get_context_from_server')
     @mock.patch('yardstick.ssh.SSH')
     @mock.patch(SSH_HELPER)
     def test_instantiate_panic(self, *args):
-        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
+        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0,
+                                                   'task_id')
         udp_replay_approx_vnf.WAIT_TIME = 0
         udp_replay_approx_vnf.q_out.put("some text PANIC some text")
         udp_replay_approx_vnf.setup_helper.setup_vnf_environment = mock.Mock()