def test_listen_traffic(self, mock_ixnextgen):
     with mock.patch("yardstick.ssh.SSH") as ssh:
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "", ""))
         ssh.from_node.return_value = ssh_mock
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
         self.assertEqual(None, ixnet_traffic_gen.listen_traffic({}))
 def test_collect_kpi(self, mock_ixnextgen):
     with mock.patch("yardstick.ssh.SSH") as ssh:
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "", ""))
         ssh.from_node.return_value = ssh_mock
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
         ixnet_traffic_gen.data = {}
         restult = ixnet_traffic_gen.collect_kpi()
         self.assertEqual({}, restult)
 def test___init__(self, *args):
     with mock.patch("yardstick.ssh.SSH") as ssh:
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "", ""))
         ssh.from_node.return_value = ssh_mock
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         # NOTE(ralonsoh): check the object returned.
         IxiaTrafficGen(NAME, vnfd)
 def test_instantiate(self, *args):
     with mock.patch("yardstick.ssh.SSH") as ssh:
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "", ""))
         ssh_mock.run = \
             mock.Mock(return_value=(0, "", ""))
         ssh.from_node.return_value = ssh_mock
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
         scenario_cfg = {'tc': "nsb_test_case", "topology": "",
                         'ixia_profile': "ixload.cfg"}
         scenario_cfg.update({'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}}
                                          }})
         ixnet_traffic_gen.topology = ""
         ixnet_traffic_gen.get_ixobj = mock.MagicMock()
         ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
         ixnet_traffic_gen._ixia_traffic_gen._connect = mock.Mock()
         self.assertRaises(
             IOError,
             ixnet_traffic_gen.instantiate(scenario_cfg, {}))
 def test_terminate(self, mock_ixnextgen):
     with mock.patch("yardstick.ssh.SSH") as ssh:
         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "", ""))
         ssh.from_node.return_value = ssh_mock
         ixnet_traffic_gen = IxiaTrafficGen(NAME, vnfd)
         ixnet_traffic_gen._terminated = mock.MagicMock()
         ixnet_traffic_gen._terminated.value = 0
         ixnet_traffic_gen._ixia_traffic_gen = mock.MagicMock()
         ixnet_traffic_gen._ixia_traffic_gen.ix_stop_traffic = mock.Mock()
         ixnet_traffic_gen._traffic_process = mock.MagicMock()
         ixnet_traffic_gen._traffic_process.terminate = mock.Mock()
         self.assertEqual(None, ixnet_traffic_gen.terminate())
    def test_traffic_runner(self, mock_ixnextgen, mock_ssh, mock_time):
        mock_traffic_profile = mock.Mock(autospec=TrafficProfile)
        mock_traffic_profile.get_traffic_definition.return_value = "64"
        mock_traffic_profile.params = self.TRAFFIC_PROFILE

        mock_ssh_instance = mock.Mock(autospec=mock_ssh.SSH)
        mock_ssh_instance.execute.return_value = 0, "", ""
        mock_ssh_instance.run.return_value = 0, "", ""

        mock_ssh.from_node.return_value = mock_ssh_instance

        vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
        vnfd["mgmt-interface"].update(
            {'tg-config': {
                "ixchassis": "1.1.1.1",
                "py_bin_path": "/root",
            }})

        samples = {}
        name = ''
        for ifname in range(1):
            name = "xe{}".format(ifname)
            samples[name] = {
                "Rx_Rate_Kbps": 20,
                "Tx_Rate_Kbps": 20,
                "Rx_Rate_Mbps": 10,
                "Tx_Rate_Mbps": 10,
                "RxThroughput": 10,
                "TxThroughput": 10,
                "Valid_Frames_Rx": 1000,
                "Frames_Tx": 1000,
                "in_packets": 1000,
                "out_packets": 1000,
            }

        samples.update({"CurrentDropPercentage": 0.0})

        last_res = [
            0,
            {
                "Rx_Rate_Kbps": [20, 20],
                "Tx_Rate_Kbps": [20, 20],
                "Rx_Rate_Mbps": [10, 10],
                "Tx_Rate_Mbps": [10, 10],
                "CurrentDropPercentage": [0, 0],
                "RxThroughput": [10, 10],
                "TxThroughput": [10, 10],
                "Frames_Tx": [1000, 1000],
                "in_packets": [1000, 1000],
                "Valid_Frames_Rx": [1000, 1000],
                "out_packets": [1000, 1000],
            },
        ]

        mock_traffic_profile.execute.return_value = ['Completed', samples]
        mock_traffic_profile.get_drop_percentage.return_value = [
            'Completed', samples
        ]

        sut = IxiaTrafficGen(name, vnfd)
        sut.tg_port_pairs = [[[0], [1]]]
        sut.vnf_port_pairs = [[[0], [1]]]
        sut.tc_file_name = self._get_file_abspath(TEST_FILE_YAML)
        sut.topology = ""

        sut.ssh_helper = mock.Mock()
        sut._traffic_process = mock.MagicMock()
        sut.generate_port_pairs = mock.Mock()

        sut._ixia_traffic_gen = mock.MagicMock()
        sut._ixia_traffic_gen.ix_get_statistics.return_value = last_res

        sut.resource_helper.client = mock.MagicMock()
        sut.resource_helper.client_started = mock.MagicMock()
        sut.resource_helper.client_started.value = 1

        sut.scenario_helper.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,
                    },
                },
            },
            'ixia_profile': '/path/to/profile',
            'task_path': '/path/to/task'
        }

        with mock.patch(
                'yardstick.benchmark.scenarios.networking.vnf_generic.open',
                create=True) as mock_open:
            mock_open.return_value = mock.MagicMock()
            result = sut._traffic_runner(mock_traffic_profile)
            self.assertIsNone(result)
 def test__check_status(self, mock_ix_nextgen):
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     sut = IxiaTrafficGen('vnf1', vnfd)
     sut._check_status()
 def test_scale(self, mock_ix_nextgen):
     vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
     sut = IxiaTrafficGen('vnf1', vnfd)
     sut.scale()