Beispiel #1
0
    def test_setup(self):
        scenario = pktgen_dpdk.PktgenDPDKLatency(self.scenario_cfg,
                                                 self.context_cfg)
        scenario.setup()

        self.assertIsNotNone(scenario.server)
        self.assertIsNotNone(scenario.client)
        self.assertTrue(scenario.setup_done)
Beispiel #2
0
    def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh, mock_time):

        args = {'options': {'packetsize': 60}, 'sla': {'max_latency': 100}}
        result = {}

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, p.run, result)
Beispiel #3
0
    def test_run_sla_error(self):
        self.scenario_cfg['sla'] = {'max_latency': 100}
        scenario = pktgen_dpdk.PktgenDPDKLatency(self.scenario_cfg,
                                                 self.context_cfg)

        sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
        self.mock_SSH.from_node().execute.return_value = (0, sample_output, '')

        with self.assertRaises(y_exc.SLAValidationError):
            scenario.run({})
Beispiel #4
0
    def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh):

        args = {
            'options': {'packetsize': 60},
        }

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
        p.server = mock_ssh.SSH()

        mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, p.get_port_mac, p.server, "eth1")
    def test_pktgen_dpdk_unsuccessful_get_port_ip(self):

        args = {
            'options': {'packetsize': 60},
        }

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
        p.server = self.mock_ssh.SSH.from_node()

        self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
Beispiel #6
0
    def test_pktgen_dpdk_successful_setup(self, mock_ssh):

        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
        p.setup()

        mock_ssh.SSH().execute.return_value = (0, '', '')
        self.assertIsNotNone(p.server)
        self.assertIsNotNone(p.client)
        self.assertEqual(p.setup_done, True)
Beispiel #7
0
    def test_run_sla(self):
        self.scenario_cfg['sla'] = {'max_latency': 100}
        scenario = pktgen_dpdk.PktgenDPDKLatency(self.scenario_cfg,
                                                 self.context_cfg)

        sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
        self.mock_SSH.from_node().execute.return_value = (0, sample_output, '')

        result = {}
        scenario.run(result)

        self.assertEqual(result, {"avg_latency": 100})
Beispiel #8
0
    def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh, mock_time):

        args = {'options': {'packetsize': 60}, 'sla': {'max_latency': 100}}
        result = {}

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
        mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
        self.assertRaises(AssertionError, p.run, result)
Beispiel #9
0
    def test_pktgen_dpdk_successful_sla(self, mock_ssh, mock_time):

        args = {'options': {'packetsize': 60}, 'sla': {'max_latency': 100}}
        result = {}

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
        mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')

        p.run(result)

        self.assertEqual(result, {"avg_latency": 100})
Beispiel #10
0
    def test_pktgen_dpdk_run_unsuccessful_script_error(self):
        args = {'options': {'packetsize': 60}}

        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        self.mock_ssh.SSH.from_node().execute.side_effect = ((0, '',
                                                              ''), (0, '', ''),
                                                             (0, '',
                                                              ''), (0, '', ''),
                                                             (0, '', ''),
                                                             y_exc.SSHError)
        self.assertRaises(y_exc.SSHError, p.run, {})
        self.assertEqual(self.mock_ssh.SSH.from_node().execute.call_count, 6)
Beispiel #11
0
    def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh):

        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
        p.server = mock_ssh.SSH()

        mock_ssh.SSH().execute.return_value = (0, '', '')

        p.get_port_mac(p.server, "eth1")

        mock_ssh.SSH().execute.assert_called_with(
            "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
Beispiel #12
0
    def test_pktgen_dpdk_successful_get_port_ip(self):

        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
        p.server = self.mock_ssh.SSH.from_node()

        self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')

        utils.get_port_ip(p.server, "eth1")

        self.mock_ssh.SSH.from_node().execute.assert_called_with(
            "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
Beispiel #13
0
    def test_pktgen_dpdk_successful_no_sla(self, mock_ssh):

        args = {
            'options': {
                'packetsize': 60
            },
        }

        result = {}
        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
        mock_ssh.SSH().execute.return_value = (0, sample_output, '')

        p.run(result)
        self.assertEqual(result, {"avg_latency": 132})
Beispiel #14
0
    def test_pktgen_dpdk_successful_no_sla(self, mock_ssh):

        args = {
            'options': {'packetsize': 60},
        }

        result = {}
        p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)

        sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
        mock_ssh.SSH().execute.return_value = (0, sample_output, '')

        p.run(result)
        # with python 3 we get float, might be due python division changes
        # AssertionError: {'avg_latency': 132.33333333333334} != {
        # 'avg_latency': 132}
        delta = result['avg_latency'] - 132
        self.assertLessEqual(delta, 1)
Beispiel #15
0
    def setUp(self):
        self.context_cfg = {
            'host': {
                'ip': '172.16.0.137',
                'user': '******',
                'key_filename': 'mykey.key'
            },
            'target': {
                'ip': '172.16.0.138',
                'user': '******',
                'key_filename': 'mykey.key',
                'ipaddr': '172.16.0.138'
            }
        }
        self.scenario_cfg = {'options': {'packetsize': 60}}

        self._mock_SSH = mock.patch.object(ssh, 'SSH')
        self.mock_SSH = self._mock_SSH.start()

        self._mock_time_sleep = mock.patch.object(time, 'sleep')
        self.mock_time_sleep = self._mock_time_sleep.start()

        self._mock_utils_get_port_ip = mock.patch.object(utils, 'get_port_ip')
        self.mock_utils_get_port_ip = self._mock_utils_get_port_ip.start()

        self._mock_utils_get_port_mac = mock.patch.object(
            utils, 'get_port_mac')
        self.mock_utils_get_port_mac = self._mock_utils_get_port_mac.start()

        self.mock_SSH.from_node().execute.return_value = (0, '', '')

        self.addCleanup(self._stop_mock)

        self.scenario = pktgen_dpdk.PktgenDPDKLatency(self.scenario_cfg,
                                                      self.context_cfg)
        self.scenario.server = self.mock_SSH.from_node()
        self.scenario.client = self.mock_SSH.from_node()