コード例 #1
0
    def test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
        mock_ssh(ssh)

        mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'}

        prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
        prox_approx_vnf.ssh_helper = mock.MagicMock(
            **{"execute.return_value": (0, "", ""), "bin_path": ""})
        prox_approx_vnf.setup_helper._setup_resources = mock.MagicMock()
        prox_approx_vnf.setup_helper._find_used_drivers = mock.MagicMock()
        prox_approx_vnf.setup_helper.used_drivers = {}
        prox_approx_vnf.setup_helper.bound_pci = []
        prox_approx_vnf._run_prox = mock.MagicMock(return_value=0)
        prox_approx_vnf.resource_helper = mock.MagicMock()
        prox_approx_vnf.resource_helper.get_process_args.return_value = {
                    '-e': '',
                    '-t': '',
                }, 'configs/l3-gen-2.cfg', '/root/dppd-PROX-v035/build/prox'

        prox_approx_vnf.copy_to_target = mock.MagicMock()
        prox_approx_vnf.upload_prox_config = mock.MagicMock()
        prox_approx_vnf.generate_prox_config_file = mock.MagicMock()
        prox_approx_vnf.q_out.put("PROX started")
        prox_approx_vnf.WAIT_TIME = 0

        # if process it still running exitcode will be None
        expected = 0, None
        result = prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
        self.assertIn(result, expected)
コード例 #2
0
    def test__build_pipeline_kwargs(self, ssh, mock_context, *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'}
        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")
        udp_replay_approx_vnf.scenario_helper = ScenarioHelper(name='vnf__1')
        udp_replay_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG

        udp_replay_approx_vnf._build_pipeline_kwargs()

        self.assertEqual(
            udp_replay_approx_vnf.pipeline_kwargs, {
                'config': '(0,0,1),(1,0,2)',
                'cpu_mask_hex': '0x7',
                'hw_csum': '',
                'port_mask_hex': '0x3',
                'tool_path': 'tool_path',
                'whitelist': '0000:00:0.1 -w 0000:00:0.3'
            })
コード例 #3
0
    def test_run_vpe(self, ssh, _):
        mock_ssh(ssh)

        vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
        vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML)
        vpe_approx_vnf.vnf_cfg = {
            'lb_config': 'SW',
            'lb_count': 1,
            'worker_config': '1C/1T',
            'worker_threads': 1,
        }
        vpe_approx_vnf.scenario_helper.scenario_cfg = {
            'options': {
                NAME: {
                    'traffic_type': '4',
                    'topology': 'nsb_test_case.yaml',
                    'vnf_config': 'vpe_config',
                }
            }
        }
        vpe_approx_vnf.topology = "nsb_test_case.yaml"
        vpe_approx_vnf.nfvi_type = "baremetal"
        vpe_approx_vnf._provide_config_file = mock.Mock()
        vpe_approx_vnf._build_config = mock.MagicMock()

        self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock)
        self.assertIsInstance(vpe_approx_vnf.ssh_helper, mock.Mock)
        self.assertIsNone(vpe_approx_vnf._run())
コード例 #4
0
    def test__vnf_up_post(self, ssh, mock_time):
        mock_ssh(ssh)
        prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
        prox_approx_vnf.resource_helper = resource_helper = mock.Mock()

        prox_approx_vnf._vnf_up_post()
        self.assertEqual(resource_helper.up_post.call_count, 1)
コード例 #5
0
    def test_collect_kpi(self, ssh, mock_time):
        mock_ssh(ssh)

        resource_helper = mock.MagicMock()
        resource_helper.execute.return_value = list(range(12))
        resource_helper.collect_collectd_kpi.return_value = {
            'core': {
                'result': 234
            }
        }

        prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
        prox_approx_vnf.resource_helper = resource_helper

        expected = {
            'packets_in': 7,
            'packets_dropped': 1,
            'packets_fwd': 6,
            'collect_stats': {
                'core': {
                    'result': 234
                }
            },
        }
        result = prox_approx_vnf.collect_kpi()
        self.assertEqual(result, expected)
コード例 #6
0
    def test_collect_kpi_sa_running(self, ssh, _):
        mock_ssh(ssh)

        resource = mock.Mock(autospec=ResourceProfile)
        resource.check_if_sa_running.return_value = 0, '1234'
        resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}

        vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
        vpe_approx_vnf.q_in = mock.MagicMock()
        vpe_approx_vnf.q_out = mock.MagicMock()
        vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
        vpe_approx_vnf.resource_helper.resource = resource

        expected = {
            'pkt_in_down_stream': 0,
            'pkt_in_up_stream': 0,
            'pkt_drop_down_stream': 0,
            'pkt_drop_up_stream': 0,
            'collect_stats': {
                'core': {
                    'foo': 234
                }
            },
        }
        self.assertEqual(vpe_approx_vnf.collect_kpi(), expected)
コード例 #7
0
 def test_collect_kpi(self, ssh):
     mock_ssh(ssh)
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
     trex_traffic_gen.resource_helper._queue.put({})
     result = trex_traffic_gen.collect_kpi()
     self.assertEqual({}, result)
コード例 #8
0
    def test_instantiate_error(self, ssh):
        mock_ssh(ssh, exec_result=(1, "", ""))

        mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
        mock_traffic_profile.get_traffic_definition.return_value = "64"
        mock_traffic_profile.params = self.TRAFFIC_PROFILE

        trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
        trex_traffic_gen.resource_helper = mock.MagicMock()
        scenario_cfg = {
            "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
            "nodes": [
                "tg_1",
                "vnf_1",
            ],
            "topology": 'nsb_test_case.yaml',
            '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,
                    },
                },
            },
        }
        trex_traffic_gen.instantiate(scenario_cfg, {})
コード例 #9
0
    def test__generate_trex_cfg(self, ssh, _):
        mock_ssh(ssh)

        trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
        trex_traffic_gen.ssh_helper = mock.MagicMock()
        trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
        self.assertIsNone(trex_traffic_gen.resource_helper.generate_cfg())
コード例 #10
0
    def test_instantiate(self, ssh):
        mock_ssh(ssh)

        mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
        mock_traffic_profile.get_traffic_definition.return_value = "64"
        mock_traffic_profile.params = self.TRAFFIC_PROFILE

        trex_traffic_gen = TrexTrafficGenRFC('vnf1', self.VNFD_0)
        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()

        scenario_cfg = {
            "tc": "tc_baremetal_rfc2544_ipv4_1flow_64B",
            "topology": 'nsb_test_case.yaml',
            '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
                    },
                },
            },
        }
        tg_rfc2544_trex.WAIT_TIME = 3
        scenario_cfg.update({"nodes": ["tg_1", "vnf_1"]})
        self.assertIsNone(trex_traffic_gen.instantiate(scenario_cfg, {}))
コード例 #11
0
    def test_build_config(self, mock_mul, mock_context, mock_config, mock_open,
                          ssh, _):
        mock_ssh(ssh)
        vpe_approx_vnf = VpeApproxSetupEnvHelper(mock.MagicMock(),
                                                 mock.MagicMock,
                                                 mock.MagicMock)
        vpe_approx_vnf.tc_file_name = get_file_abspath(TEST_FILE_YAML)
        vpe_approx_vnf.generate_port_pairs = mock.Mock()
        vpe_approx_vnf.vnf_cfg = {
            'lb_config': 'SW',
            'lb_count': 1,
            'worker_config': '1C/1T',
            'worker_threads': 1,
        }
        vpe_approx_vnf.scenario_helper.scenario_cfg = {
            'options': {
                NAME: {
                    'traffic_type': '4',
                    'topology': 'nsb_test_case.yaml',
                    'vnf_config': 'vpe_config',
                }
            }
        }
        vpe_approx_vnf.topology = "nsb_test_case.yaml"
        vpe_approx_vnf.nfvi_type = "baremetal"
        vpe_approx_vnf._provide_config_file = mock.Mock()

        vpe_approx_vnf.ssh_helper = mock.MagicMock()
        vpe_approx_vnf.scenario_helper = mock.MagicMock()
        vpe_approx_vnf.ssh_helper.bin_path = mock.Mock()
        vpe_approx_vnf.ssh_helper.upload_config_file = mock.MagicMock()
        self.assertIsNone(vpe_approx_vnf._build_vnf_ports())
        self.assertIsNotNone(vpe_approx_vnf.build_config())
コード例 #12
0
 def test_terminate(self, ssh):
     mock_ssh(ssh)
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
     trex_traffic_gen.ssh_helper = mock.MagicMock()
     trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
     self.assertIsNone(trex_traffic_gen.terminate())
コード例 #13
0
 def test_vnf_execute(self, ssh, _):
     mock_ssh(ssh)
     vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
     vpe_approx_vnf.q_in = mock.MagicMock()
     vpe_approx_vnf.q_out = mock.MagicMock()
     vpe_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
     self.assertEqual(vpe_approx_vnf.vnf_execute("quit", 0), '')
コード例 #14
0
 def test__connect_client(self, ssh):
     mock_ssh(ssh)
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
     client = mock.Mock(autospec=STLClient)
     client.connect = mock.Mock(return_value=0)
     self.assertIsNotNone(trex_traffic_gen.resource_helper._connect(client))
コード例 #15
0
ファイル: test_tg_ping.py プロジェクト: warmwm/yardstick-ha
 def test_collect_kpi(self, ssh):
     mock_ssh(ssh, exec_result=(0, "success", ""))
     ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
     ping_traffic_gen._queue = Queue()
     ping_traffic_gen._queue.put({})
     ping_traffic_gen.collect_kpi()
     self.assertEqual(ping_traffic_gen._result, {})
コード例 #16
0
 def test__start_server(self, ssh):
     mock_ssh(ssh)
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     trex_traffic_gen = TrexTrafficGen(NAME, vnfd)
     trex_traffic_gen.ssh_helper = mock.MagicMock()
     trex_traffic_gen.resource_helper.ssh_helper = mock.MagicMock()
     trex_traffic_gen.scenario_helper.scenario_cfg = {}
     self.assertIsNone(trex_traffic_gen._start_server())
コード例 #17
0
    def test_terminate(self, ssh, _):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        router_vnf = RouterVNF(name, vnfd)
        router_vnf._vnf_process = mock.MagicMock()
        router_vnf._vnf_process.terminate = mock.Mock()
        self.assertIsNone(router_vnf.terminate())
コード例 #18
0
    def test_collect_kpi(self, ssh, mock_time):
        mock_ssh(ssh)

        prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
        prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock(
            **{"check_if_sa_running.return_value": [False]})
        prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
        self.assertEqual({}, prox_traffic_gen.collect_kpi())
コード例 #19
0
    def test_run_router(self, ssh):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        router_vnf = RouterVNF(name, vnfd)
        router_vnf.scenario_helper.scenario_cfg = self.scenario_cfg
        router_vnf._run()
        router_vnf.ssh_helper.drop_connection.assert_called_once()
コード例 #20
0
    def test_collect_kpi(self, ssh, mock_time):
        mock_ssh(ssh)

        prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
        prox_traffic_gen._vnf_wrapper.resource = mock.Mock(
            autospec=ResourceProfile)
        prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
        self.assertEqual({}, prox_traffic_gen.collect_kpi())
コード例 #21
0
    def test_terminate(self, ssh, _):
        mock_ssh(ssh)

        vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
        vpe_approx_vnf._vnf_process = mock.MagicMock()
        vpe_approx_vnf._resource_collect_stop = mock.Mock()
        vpe_approx_vnf.resource_helper = mock.MagicMock()

        self.assertIsNone(vpe_approx_vnf.terminate())
コード例 #22
0
    def test__run_traffic_once(self, ssh, *_):
        mock_ssh(ssh)

        mock_traffic_profile = mock.MagicMock(
            autospec=TrafficProfile,
            **{'get_drop_percentage.return_value': {}})
        sut = TrexRfcResourceHelper(mock.MagicMock(), mock.MagicMock())
        sut.client = mock.MagicMock()
        sut._run_traffic_once(mock_traffic_profile)
コード例 #23
0
 def test_instantiate(self, ssh):
     mock_ssh(ssh, spec=VnfSshHelper, exec_result=(0, "success", ""))
     ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
     ping_traffic_gen.setup_helper.ssh_helper = mock.MagicMock(
         **{"execute.return_value": (0, "", "")})
     self.assertIsInstance(ping_traffic_gen.ssh_helper, mock.Mock)
     self.assertEqual(ping_traffic_gen._result, {})
     self.assertIsNone(ping_traffic_gen.instantiate({}, {}))
     self.assertIsNotNone(ping_traffic_gen._result)
コード例 #24
0
 def test_wait_for_instantiate_panic(self, ssh, mock_time):
     mock_ssh(ssh, exec_result=(1, "", ""))
     prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
     prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True})
     prox_approx_vnf._run_prox = mock.Mock(return_value=0)
     prox_approx_vnf.WAIT_TIME = 0
     prox_approx_vnf.q_out.put("PANIC")
     with self.assertRaises(RuntimeError):
         prox_approx_vnf.wait_for_instantiate()
コード例 #25
0
    def test_vnf_execute_command(self, ssh, mock_time, mock_process):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        cgnapt_approx_vnf = CgnaptApproxVnf(name, vnfd)
        cgnapt_approx_vnf.q_in = mock.MagicMock()
        cgnapt_approx_vnf.q_out = mock.MagicMock()
        cgnapt_approx_vnf.q_out.qsize = mock.Mock(return_value=0)
        cmd = "quit"
        self.assertEqual("", cgnapt_approx_vnf.vnf_execute(cmd))
コード例 #26
0
    def test_terminate(self, ssh, mock_socket, mock_time):
        mock_ssh(ssh)
        prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
        prox_approx_vnf._vnf_process = mock.MagicMock()
        prox_approx_vnf._vnf_process.terminate = mock.Mock()
        prox_approx_vnf.ssh_helper = mock.MagicMock()
        prox_approx_vnf.setup_helper = mock.Mock()
        prox_approx_vnf.resource_helper = mock.MagicMock()

        self.assertIsNone(prox_approx_vnf.terminate())
コード例 #27
0
    def test_get_stats(self, ssh, *args):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        vfw_approx_vnf = FWApproxVnf(name, vnfd)
        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)
        vfw_approx_vnf.vnf_execute = mock.Mock(return_value=self.STATS)
        self.assertEqual(self.STATS, vfw_approx_vnf.get_stats())
コード例 #28
0
    def test_instantiate(self, ssh, _):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        router_vnf = RouterVNF(name, vnfd)
        router_vnf.WAIT_TIME = 0
        router_vnf.INTERFACE_WAIT = 0
        self.scenario_cfg.update({"nodes": {"vnf__1": ""}})
        self.assertIsNone(
            router_vnf.instantiate(self.scenario_cfg, self.context_cfg))
コード例 #29
0
    def test_run_udp_replay(self, ssh, _):
        mock_ssh(ssh)

        udp_replay_approx_vnf = UdpReplayApproxVnf(NAME, self.VNFD_0)
        udp_replay_approx_vnf._build_config = mock.MagicMock()
        udp_replay_approx_vnf.queue_wrapper = mock.MagicMock()

        udp_replay_approx_vnf._run()

        udp_replay_approx_vnf.ssh_helper.run.assert_called_once()
コード例 #30
0
    def test_vnf_execute_command(self, ssh, *args):
        mock_ssh(ssh)

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        vfw_approx_vnf = FWApproxVnf(name, vnfd)
        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)
        cmd = "quit"
        self.assertEqual(vfw_approx_vnf.vnf_execute(cmd), "")