Fix exception handling ixload
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_vfw_vnf.py
index ffb5cd6..efbb7a8 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.common import utils
-
-
-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.vfw_vnf import FWApproxVnf
-    from yardstick.network_services.nfvi.resource import ResourceProfile
-    from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxSetupEnvHelper
+from yardstick.benchmark.contexts import base as ctx_base
+from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxVnf
+from yardstick.network_services.nfvi.resource import ResourceProfile
+from yardstick.network_services.vnf_generic.vnf.vfw_vnf import FWApproxSetupEnvHelper
+from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
 
 
 TEST_FILE_YAML = 'nsb_test_case.yaml'
@@ -241,7 +232,7 @@ class TestFWApproxVnf(unittest.TestCase):
 
     def test___init__(self, *args):
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
         self.assertIsNone(vfw_approx_vnf._vnf_process)
 
     STATS = """\
@@ -259,12 +250,15 @@ pipeline>
 """  # noqa
 
     @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)
-
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
+        vfw_approx_vnf.scenario_helper.scenario_cfg = {
+            'nodes': {vfw_approx_vnf.name: "mock"}
+        }
         vfw_approx_vnf.q_in = mock.MagicMock()
         vfw_approx_vnf.q_out = mock.MagicMock()
         vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -273,6 +267,7 @@ pipeline>
             **{'collect_kpi.return_value': {"core": {}}})
         vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
         result = {
+            'physical_node': 'mock_node',
             'packets_dropped': 0,
             'packets_fwd': 6007180,
             'packets_in': 6007180,
@@ -286,7 +281,7 @@ pipeline>
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
         vfw_approx_vnf.q_in = mock.MagicMock()
         vfw_approx_vnf.q_out = mock.MagicMock()
         vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -298,7 +293,7 @@ pipeline>
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
         vfw_approx_vnf.q_in = mock.MagicMock()
         vfw_approx_vnf.q_out = mock.MagicMock()
         vfw_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
@@ -318,7 +313,7 @@ pipeline>
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
         vfw_approx_vnf._build_config = mock.MagicMock()
         vfw_approx_vnf.queue_wrapper = mock.MagicMock()
         vfw_approx_vnf.ssh_helper = mock.MagicMock()
@@ -334,14 +329,13 @@ pipeline>
         vfw_approx_vnf.ssh_helper.run.assert_called_once()
 
     @mock.patch.object(utils, 'find_relative_file')
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.vfw_vnf.YangModel")
-    @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)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        vfw_approx_vnf = FWApproxVnf(name, vnfd)
+        vfw_approx_vnf = FWApproxVnf(name, vnfd, 'task_id')
         vfw_approx_vnf.ssh_helper = ssh
         vfw_approx_vnf.deploy_helper = mock.MagicMock()
         vfw_approx_vnf.resource_helper = mock.MagicMock()
@@ -363,12 +357,15 @@ class TestFWApproxSetupEnvHelper(unittest.TestCase):
         ssh_helper = mock.Mock()
         scenario_helper = mock.Mock()
         scenario_helper.vnf_cfg = {'lb_config': 'HW'}
+        scenario_helper.options = {}
         scenario_helper.all_options = {}
 
         vfw_approx_setup_helper = FWApproxSetupEnvHelper(vnfd_helper, ssh_helper, scenario_helper)
+        vfw_approx_setup_helper.get_flows_config = mock.Mock()
 
         vfw_approx_setup_helper.ssh_helper.provision_tool = mock.Mock(return_value='tool_path')
         vfw_approx_setup_helper.ssh_helper.all_ports = mock.Mock()
         vfw_approx_setup_helper.vnfd_helper.port_nums = mock.Mock(return_value=[0, 1])
         expected = 'sudo tool_path -p 0x3 -f /tmp/vfw_config -s /tmp/vfw_script  --hwlb 3'
         self.assertEqual(vfw_approx_setup_helper.build_config(), expected)
+        vfw_approx_setup_helper.get_flows_config.assert_called_once()