示例#1
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_SSH.from_node().execute.return_value = (0, '', '')
        self.mock_SSH.from_node().run.return_value = 0

        self.addCleanup(self._stop_mock)

        self.scenario = pktgen.Pktgen(self.scenario_cfg, self.context_cfg)
        self.scenario.setup()
    def test_pktgen_run_with_setup_done(self, mock_ssh):
        args = {
            'options': {
                'packetsize': 60,
                'number_of_ports': 10,
                'duration': 20,
                'multiqueue': True
            },
            'sla': {
                'max_ppm': 1
            }
        }
        result = {}
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        p.setup_done = True
        p.multiqueue_setup_done = True

        mock_iptables_result = mock.Mock()
        mock_iptables_result.return_value = 149300
        p._iptables_get_result = mock_iptables_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149300, "flows": 110, "ppm": 0}'

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

        p.run(result)
        expected_result = jsonutils.loads(sample_output)
        expected_result["packets_received"] = 149300
        expected_result["packetsize"] = 60
        self.assertEqual(result, expected_result)
    def test_pktgen_successful_sla(self, mock_ssh):

        args = {
            'options': {
                'packetsize': 60,
                'number_of_ports': 10
            },
            'sla': {
                'max_ppm': 10000
            }
        }
        result = {}

        p = pktgen.Pktgen(args, self.ctx)

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

        mock_iptables_result = mock.Mock()
        mock_iptables_result.return_value = 149300
        p._iptables_get_result = mock_iptables_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149776, "packetsize": 60, "flows": 110, "ppm": 3179}'

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

        p.run(result)
        expected_result = jsonutils.loads(sample_output)
        expected_result["packets_received"] = 149300
        expected_result["packetsize"] = 60
        self.assertEqual(result, expected_result)
示例#4
0
    def test_run_with_sriov_multiqueque(self):
        scenario_cfg = {
            'options': {
                'packetsize': 60,
                'number_of_ports': 10,
                'duration': 20,
                'multiqueue': True
            },
            'sla': {
                'max_ppm': 1
            }
        }
        scenario = pktgen.Pktgen(scenario_cfg, self.context_cfg)
        scenario.setup()
        scenario._get_vnic_driver_name = mock.Mock(return_value="ixgbevf")
        scenario._get_sriov_queue_number = mock.Mock(return_value=2)
        scenario._setup_irqmapping_sriov = mock.Mock()
        scenario._iptables_get_result = mock.Mock(return_value=149300)

        sample_output = jsonutils.dumps({
            "packets_per_second": 9753,
            "errors": 0,
            "packets_sent": 149300,
            "flows": 110,
            "ppm": 0
        })
        self.mock_SSH.from_node().execute.return_value = (0, sample_output, '')

        result = {}
        scenario.run(result)

        expected_result = jsonutils.loads(sample_output)
        expected_result["packets_received"] = 149300
        expected_result["packetsize"] = 60
        self.assertEqual(result, expected_result)
    def test_pktgen_unsuccessful_sla(self, mock_ssh):

        args = {
            'options': {
                'packetsize': 60,
                'number_of_ports': 10
            },
            'sla': {
                'max_ppm': 1000
            }
        }
        result = {}

        p = pktgen.Pktgen(args, self.ctx)

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

        mock_iptables_result = mock.Mock()
        mock_iptables_result.return_value = 149300
        p._iptables_get_result = mock_iptables_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149776, "packetsize": 60, "flows": 110}'

        mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
        self.assertRaises(AssertionError, p.run, result)
    def test_pktgen_multiqueue_setup_ovs_1q(self, mock_ssh):
        args = {
            'options': {
                'packetsize': 60,
                'multiqueue': True
            },
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

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

        mock_result1 = mock.Mock()
        mock_result1.return_value = False
        p._is_irqbalance_disabled = mock_result1

        mock_result2 = mock.Mock()
        mock_result2.return_value = "virtio_net"
        p._get_vnic_driver_name = mock_result2

        mock_result3 = mock.Mock()
        mock_result3.return_value = 1
        p._get_usable_queue_number = mock_result3

        mock_result4 = mock.Mock()
        mock_result4.return_value = 1
        p._get_available_queue_number = mock_result4

        p.multiqueue_setup()

        self.assertEqual(p.queue_number, 1)
示例#7
0
    def test_pktgen_run_with_ovs_multiqueque(self, mock_ssh):
        args = {
            'options': {
                'packetsize': 60,
                'number_of_ports': 10,
                'duration': 20,
                'multiqueue': True},
            'sla': {
                'max_ppm': 1}}
        result = {}

        p = pktgen.Pktgen(args, self.ctx)

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

        p._get_vnic_driver_name = mock.Mock(return_value="virtio_net")
        p._get_usable_queue_number = mock.Mock(return_value=1)
        p._get_available_queue_number = mock.Mock(return_value=4)
        p._enable_ovs_multiqueue = mock.Mock(return_value=4)
        p._setup_irqmapping_ovs = mock.Mock()
        p._iptables_get_result = mock.Mock(return_value=149300)

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149300, "flows": 110, "ppm": 0}'
        mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')

        p.run(result)
        expected_result = jsonutils.loads(sample_output)
        expected_result["packets_received"] = 149300
        expected_result["packetsize"] = 60
        self.assertEqual(result, expected_result)
示例#8
0
    def test_pktgen_unsuccessful_is_irqbalance_disabled(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError

        self.assertRaises(y_exc.SSHError, p._is_irqbalance_disabled)
示例#9
0
    def test_pktgen_unsuccessful_get_usable_queue_number(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError

        self.assertRaises(y_exc.SSHError, p._get_usable_queue_number)
示例#10
0
    def test_pktgen_unsuccessful_is_irqbalance_disabled(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.return_value = (1, '', '')

        self.assertRaises(RuntimeError, p._is_irqbalance_disabled)
示例#11
0
    def test_pktgen_unsuccessful_get_usable_queue_number(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.return_value = (1, '', '')

        self.assertRaises(RuntimeError, p._get_usable_queue_number)
示例#12
0
    def test_pktgen_unsuccessful_setup_irqmapping_sriov_1q(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError

        self.assertRaises(y_exc.SSHError, p._setup_irqmapping_sriov, 1)
示例#13
0
    def test_pktgen_get_sriov_queue_number(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

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

        p.queue_number = p._get_sriov_queue_number()
        self.assertEqual(p.queue_number, 2)
示例#14
0
    def test_pktgen_get_vnic_driver_name(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

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

        vnic_driver_name = p._get_vnic_driver_name()
        self.assertEqual(vnic_driver_name, 'ixgbevf')
示例#15
0
    def test_pktgen_unsuccessful_setup_irqmapping_sriov_1q(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().execute.return_value = (1, '', '')

        self.assertRaises(RuntimeError, p._setup_irqmapping_sriov, 1)
示例#16
0
    def test_pktgen_successful_setup(self, mock_ssh):

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

        mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
        self.assertIsNotNone(p.server)
        self.assertIsNotNone(p.client)
        self.assertTrue(p.setup_done)
示例#17
0
    def test_pktgen_unsuccessful_iptables_setup(self, mock_ssh):

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

        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.number_of_ports = args['options']['number_of_ports']

        mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, p._iptables_setup)
示例#18
0
    def test_pktgen_unsuccessful_iptables_setup(self, mock_ssh):

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

        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.number_of_ports = args['options']['number_of_ports']

        mock_ssh.SSH.from_node().run.side_effect = y_exc.SSHError
        self.assertRaises(y_exc.SSHError, p._iptables_setup)
示例#19
0
    def test_pktgen_is_irqbalance_disabled(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

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

        p._is_irqbalance_disabled()

        mock_ssh.SSH.from_node().execute.assert_called_with(
            "grep ENABLED /etc/default/irqbalance")
示例#20
0
    def test_pktgen_get_usable_queue_number(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

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

        self.assertEqual(p._get_usable_queue_number(), 1)

        mock_ssh.SSH.from_node().execute.assert_called_with(
            "sudo ethtool -l eth0 | grep Combined | tail -1 |"
            "awk '{printf $2}'", raise_on_error=True)
示例#21
0
    def test_pktgen_disable_irqbalance(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().run.return_value = (0, '', '')

        p._disable_irqbalance()

        mock_ssh.SSH.from_node().run.assert_called_with(
            "sudo service irqbalance disable")
示例#22
0
    def test_pktgen_get_available_queue_number(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()

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

        p._get_available_queue_number()

        mock_ssh.SSH.from_node().execute.assert_called_with(
            "sudo ethtool -l eth0 | grep Combined | head -1 |"
            "awk '{printf $2}'")
示例#23
0
    def test_pktgen_unsuccessful_enable_ovs_multiqueue(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

        mock_ssh.SSH.from_node().run.side_effect = y_exc.SSHError

        p._get_usable_queue_number = mock.Mock(return_value=1)
        p._get_available_queue_number = mock.Mock(return_value=4)

        self.assertRaises(y_exc.SSHError, p._enable_ovs_multiqueue)
示例#24
0
    def test_pktgen_setup_irqmapping_sriov_1q(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

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

        p._setup_irqmapping_sriov(1)

        mock_ssh.SSH.from_node().run.assert_called_with(
            "echo 1 | sudo tee /proc/irq/10/smp_affinity")
示例#25
0
    def test_pktgen_unsuccessful_script_error(self, mock_ssh):

        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
            'sla': {'max_ppm': 1000}
        }
        result = {}

        p = pktgen.Pktgen(args, self.ctx)

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

        mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
        self.assertRaises(y_exc.SSHError, p.run, result)
示例#26
0
    def test_pktgen_successful_iptables_setup(self, mock_ssh):

        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.number_of_ports = args['options']['number_of_ports']

        p._iptables_setup()

        mock_ssh.SSH.from_node().run.assert_called_with(
            "sudo iptables -F; "
            "sudo iptables -A INPUT -p udp --dport 1000:%s -j DROP"
            % 1010, timeout=60)
示例#27
0
    def test_pktgen_enable_ovs_multiqueue_1q(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

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

        p._get_usable_queue_number = mock.Mock(return_value=1)
        p._get_available_queue_number = mock.Mock(return_value=1)

        p.queue_number = p._enable_ovs_multiqueue()
        self.assertEqual(p.queue_number, 1)
示例#28
0
    def test_pktgen_unsuccessful_script_error(self, mock_ssh):

        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
            'sla': {'max_ppm': 1000}
        }
        result = {}

        p = pktgen.Pktgen(args, self.ctx)

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

        mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, p.run, result)
示例#29
0
    def test_run_unsuccessful_sla(self):
        self.scenario_cfg['sla'] = {'max_ppm': 1000}
        scenario = pktgen.Pktgen(self.scenario_cfg, self.context_cfg)
        scenario.setup()
        scenario._iptables_get_result = mock.Mock(return_value=149300)
        sample_output = jsonutils.dumps({
            "packets_per_second": 9753,
            "errors": 0,
            "packets_sent": 149776,
            "packetsize": 60,
            "flows": 110
        })
        self.mock_SSH.from_node().execute.return_value = (0, sample_output, '')

        with self.assertRaises(y_exc.SLAValidationError):
            scenario.run({})
示例#30
0
    def test_pktgen_multiqueue_setup_sriov_1q(self, mock_ssh):
        args = {
            'options': {'packetsize': 60, 'multiqueue': True},
        }
        p = pktgen.Pktgen(args, self.ctx)
        p.server = mock_ssh.SSH.from_node()
        p.client = mock_ssh.SSH.from_node()

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

        p._is_irqbalance_disabled = mock.Mock(return_value=False)
        p._get_vnic_driver_name = mock.Mock(return_value="ixgbevf")

        p.multiqueue_setup()

        self.assertEqual(p.queue_number, 1)