Create a SampleVNF MQ consumer class
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_router_vnf.py
index 5574c67..ad74145 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
 
-from yardstick.tests import STL_MOCKS
 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
-
-
-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.router_vnf import RouterVNF
+from yardstick.benchmark.contexts import base as ctx_base
+from yardstick.network_services.vnf_generic.vnf.router_vnf import RouterVNF
 
 
 TEST_FILE_YAML = 'nsb_test_case.yaml'
@@ -207,22 +199,32 @@ class TestRouterVNF(unittest.TestCase):
 
     def test___init__(self):
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        router_vnf = RouterVNF(name, vnfd)
+        router_vnf = RouterVNF(name, vnfd, 'task_id')
         self.assertIsNone(router_vnf._vnf_process)
 
     def test_get_stats(self):
         stats = RouterVNF.get_stats(self.IP_SHOW_STATS_OUTPUT)
         self.assertDictEqual(stats, self.STATS)
 
+    @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
     @mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.time")
     @mock.patch(SSH_HELPER)
-    def test_collect_kpi(self, ssh, _):
+    def test_collect_kpi(self, ssh, *args):
         m = mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        router_vnf = RouterVNF(name, vnfd)
+        router_vnf = RouterVNF(name, vnfd, 'task_id')
+        router_vnf.scenario_helper.scenario_cfg = {
+            'nodes': {router_vnf.name: "mock"}
+        }
         router_vnf.ssh_helper = m
-        result = {'packets_dropped': 0, 'packets_fwd': 0, 'packets_in': 0, 'link_stats': {}}
+        result = {
+            'physical_node': 'mock_node',
+            'packets_dropped': 0,
+            'packets_fwd': 0,
+            'packets_in': 0,
+            'link_stats': {}
+        }
         self.assertEqual(result, router_vnf.collect_kpi())
 
     @mock.patch(SSH_HELPER)
@@ -230,18 +232,18 @@ class TestRouterVNF(unittest.TestCase):
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        router_vnf = RouterVNF(name, vnfd)
+        router_vnf = RouterVNF(name, vnfd, 'task_id')
         router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
         router_vnf._run()
         router_vnf.ssh_helper.drop_connection.assert_called_once()
 
-    @mock.patch("yardstick.network_services.vnf_generic.vnf.router_vnf.Context")
+    @mock.patch.object(ctx_base, 'Context')
     @mock.patch(SSH_HELPER)
-    def test_instantiate(self, ssh, _):
+    def test_instantiate(self, ssh, *args):
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        router_vnf = RouterVNF(name, vnfd)
+        router_vnf = RouterVNF(name, vnfd, 'task_id')
         router_vnf.WAIT_TIME = 0
         router_vnf.INTERFACE_WAIT = 0
         self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
@@ -254,7 +256,7 @@ class TestRouterVNF(unittest.TestCase):
         mock_ssh(ssh)
 
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        router_vnf = RouterVNF(name, vnfd)
+        router_vnf = RouterVNF(name, vnfd, 'task_id')
         router_vnf._vnf_process = mock.MagicMock()
         router_vnf._vnf_process.terminate = mock.Mock()
         self.assertIsNone(router_vnf.terminate())