Merge "Bugfix: ha test case criteria pass when sla not pass"
[yardstick.git] / tests / unit / network_services / vnf_generic / vnf / test_tg_trex.py
index 65370df..9d1ce15 100644 (file)
@@ -20,6 +20,8 @@ from __future__ import absolute_import
 import unittest
 import mock
 
+SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
+
 from tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
 from tests.unit import STL_MOCKS
 
@@ -112,16 +114,197 @@ class TestTrexTrafficGen(unittest.TestCase):
             "traffic_type": "FixedTraffic",
             "frame_rate": 100,  # pps
             "flow_number": 10,
-            "frame_size": 64}}
+            "frame_size": 64
+        },
+    }
+
+    SCENARIO_CFG = {
+        "options": {
+            "packetsize": 64,
+            "traffic_type": 4,
+            "rfc2544": {
+                "allowed_drop_rate": "0.8 - 1",
+            },
+            "vnf__1": {
+                "rules": "acl_1rule.yaml",
+                "vnf_config": {
+                    "lb_config": "SW",
+                    "lb_count": 1,
+                    "worker_config": "1C/1T",
+                    "worker_threads": 1,
+                }
+            }
+        },
+        "task_id": "a70bdf4a-8e67-47a3-9dc1-273c14506eb7",
+        "tc": "tc_ipv4_1Mflow_64B_packetsize",
+        "runner": {
+            "object": "NetworkServiceTestCase",
+            "interval": 35,
+            "output_filename": "/tmp/yardstick.out",
+            "runner_id": 74476, "duration": 400,
+            "type": "Duration"
+        },
+        "traffic_profile": "ipv4_throughput_acl.yaml",
+        "traffic_options": {
+            "flow": "ipv4_Packets_acl.yaml",
+            "imix": "imix_voice.yaml"
+        },
+        "type": "ISB",
+        "nodes": {
+            "tg__2": "trafficgen_2.yardstick",
+            "tg__1": "trafficgen_1.yardstick",
+            "vnf__1": "vnf.yardstick"
+        },
+        "topology": "udpreplay-tg-topology-baremetal.yaml"
+    }
+
+    CONTEXT_CFG = {
+        "nodes": {
+            "vnf__1": {
+                "vnfd-id-ref": "vnf__1",
+                "ip": "1.2.1.1",
+                "interfaces": {
+                    "xe0": {
+                        "local_iface_name": "ens786f0",
+                        "vld_id": "private",
+                        "netmask": "255.255.255.0",
+                        "vpci": "0000:05:00.0",
+                        "local_ip": "152.16.100.19",
+                        "driver": "i40e",
+                        "dst_ip": "152.16.100.20",
+                        "local_mac": "00:00:00:00:00:02",
+                        "dst_mac": "00:00:00:00:00:04",
+                        "dpdk_port_num": 0
+                    },
+                    "xe1": {
+                        "local_iface_name": "ens786f1",
+                        "vld_id": "public",
+                        "netmask": "255.255.255.0",
+                        "vpci": "0000:05:00.1",
+                        "local_ip": "152.16.40.19",
+                        "driver": "i40e",
+                        "dst_ip": "152.16.40.20",
+                        "local_mac": "00:00:00:00:00:01",
+                        "dst_mac": "00:00:00:00:00:03",
+                        "dpdk_port_num": 1
+                    }
+                },
+                "host": "1.2.1.1",
+                "user": "root",
+                "nd_route_tbl": [
+                    {
+                        "netmask": "112",
+                        "if": "xe0",
+                        "gateway": "0064:ff9b:0:0:0:0:9810:6414",
+                        "network": "0064:ff9b:0:0:0:0:9810:6414"
+                    },
+                    {
+                        "netmask": "112",
+                        "if": "xe1",
+                        "gateway": "0064:ff9b:0:0:0:0:9810:2814",
+                        "network": "0064:ff9b:0:0:0:0:9810:2814"
+                    }
+                ],
+                "password": "r00t",
+                "VNF model": "udp_replay.yaml",
+                "name": "vnf.yardstick",
+                "member-vnf-index": "2",
+                "routing_table": [
+                    {
+                        "netmask": "255.255.255.0",
+                        "if": "xe0",
+                        "gateway": "152.16.100.20",
+                        "network": "152.16.100.20"
+                    },
+                    {
+                        "netmask": "255.255.255.0",
+                        "if": "xe1",
+                        "gateway": "152.16.40.20",
+                        "network": "152.16.40.20"
+                    }
+                ],
+                "role": "vnf"
+            },
+            "trafficgen_2.yardstick": {
+                "member-vnf-index": "3",
+                "role": "TrafficGen",
+                "name": "trafficgen_2.yardstick",
+                "vnfd-id-ref": "tg__2",
+                "ip": "1.2.1.1",
+                "interfaces": {
+                    "xe0": {
+                        "local_iface_name": "ens513f0",
+                        "vld_id": "public",
+                        "netmask": "255.255.255.0",
+                        "vpci": "0000:02:00.0",
+                        "local_ip": "152.16.40.20",
+                        "driver": "ixgbe",
+                        "dst_ip": "152.16.40.19",
+                        "local_mac": "00:00:00:00:00:03",
+                        "dst_mac": "00:00:00:00:00:01",
+                        "dpdk_port_num": 0
+                    },
+                    "xe1": {
+                        "local_iface_name": "ens513f1",
+                        "netmask": "255.255.255.0",
+                        "network": "202.16.100.0",
+                        "local_ip": "202.16.100.20",
+                        "driver": "ixgbe",
+                        "local_mac": "00:1e:67:d0:60:5d",
+                        "vpci": "0000:02:00.1",
+                        "dpdk_port_num": 1
+                    }
+                },
+                "password": "r00t",
+                "VNF model": "l3fwd_vnf.yaml",
+                "user": "root"
+            },
+            "trafficgen_1.yardstick": {
+                "member-vnf-index": "1",
+                "role": "TrafficGen",
+                "name": "trafficgen_1.yardstick",
+                "vnfd-id-ref": "tg__1",
+                "ip": "1.2.1.1",
+                "interfaces": {
+                    "xe0": {
+                        "local_iface_name": "ens785f0",
+                        "vld_id": "private",
+                        "netmask": "255.255.255.0",
+                        "vpci": "0000:05:00.0",
+                        "local_ip": "152.16.100.20",
+                        "driver": "i40e",
+                        "dst_ip": "152.16.100.19",
+                        "local_mac": "00:00:00:00:00:04",
+                        "dst_mac": "00:00:00:00:00:02",
+                        "dpdk_port_num": 0
+                    },
+                    "xe1": {
+                        "local_ip": "152.16.100.21",
+                        "driver": "i40e",
+                        "vpci": "0000:05:00.1",
+                        "dpdk_port_num": 1,
+                        "local_iface_name": "ens785f1",
+                        "netmask": "255.255.255.0",
+                        "local_mac": "00:00:00:00:00:01"
+                    }
+                },
+                "password": "r00t",
+                "VNF model": "tg_rfc2544_tpl.yaml",
+                "user": "root"
+            }
+        }
+    }
+
+
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test___init__(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
         self.assertIsInstance(trex_traffic_gen.resource_helper, TrexResourceHelper)
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_collect_kpi(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -130,14 +313,14 @@ class TestTrexTrafficGen(unittest.TestCase):
         result = trex_traffic_gen.collect_kpi()
         self.assertEqual({}, result)
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_listen_traffic(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
         self.assertIsNone(trex_traffic_gen.listen_traffic({}))
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_instantiate(self, ssh):
         mock_ssh(ssh)
 
@@ -150,9 +333,11 @@ class TestTrexTrafficGen(unittest.TestCase):
         trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=1)
         trex_traffic_gen.ssh_helper = mock.MagicMock()
         trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
-        self.assertIsNone(trex_traffic_gen.instantiate({}, {}))
+        trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
 
-    @mock.patch("yardstick.ssh.SSH")
+        self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
+
+    @mock.patch(SSH_HELPER)
     def test_instantiate_error(self, ssh):
         mock_ssh(ssh, exec_result=(1, "", ""))
 
@@ -164,9 +349,10 @@ class TestTrexTrafficGen(unittest.TestCase):
         trex_traffic_gen._tg_process._is_alive = mock.Mock(return_value=0)
         trex_traffic_gen.ssh_helper = mock.MagicMock()
         trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
-        self.assertIsNone(trex_traffic_gen.instantiate({}, {}))
+        trex_traffic_gen.setup_helper.setup_vnf_environment = mock.MagicMock()
+        self.assertIsNone(trex_traffic_gen.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG))
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test__start_server(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -175,7 +361,7 @@ class TestTrexTrafficGen(unittest.TestCase):
         trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
         self.assertIsNone(trex_traffic_gen._start_server())
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test__traffic_runner(self, ssh):
         mock_ssh(ssh)
 
@@ -195,7 +381,7 @@ class TestTrexTrafficGen(unittest.TestCase):
         self.sut.resource_helper.QUEUE_WAIT_TIME = 0
         self.sut._traffic_runner(mock_traffic_profile)
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test__generate_trex_cfg(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -203,7 +389,7 @@ class TestTrexTrafficGen(unittest.TestCase):
         trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
         self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_run_traffic(self, ssh):
         mock_ssh(ssh)
 
@@ -221,21 +407,14 @@ class TestTrexTrafficGen(unittest.TestCase):
         self.sut._traffic_process.terminate()
         self.assertIsNotNone(result)
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_scale(self, ssh):
         mock_ssh(ssh, exec_result=(1, "", ""))
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
         trex_traffic_gen.scale('')
 
-    @mock.patch("yardstick.ssh.SSH")
-    def test_setup_vnf_environment(self, ssh):
-        mock_ssh(ssh, exec_result=(1, "", ""))
-        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
-        trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
-        self.assertIsNone(trex_traffic_gen.setup_helper.setup_vnf_environment())
-
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test_terminate(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
@@ -244,7 +423,7 @@ class TestTrexTrafficGen(unittest.TestCase):
         trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
         self.assertIsNone(trex_traffic_gen.terminate())
 
-    @mock.patch("yardstick.ssh.SSH")
+    @mock.patch(SSH_HELPER)
     def test__connect_client(self, ssh):
         mock_ssh(ssh)
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]