aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
blob: c2e35af759d93e06e908b77e5160350cb8b8edde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment 
##############################################################################
# Copyright (c) 2017 Nokia and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
#!/usr/bin/env python

# Unittest for yardstick.benchmark.scenarios.networking.pktgen.PktgenDPDK

from __future__ import absolute_import
import unittest

from oslo_serialization import jsonutils
import mock

from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput


@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh')
class PktgenDPDKTestCase(unittest.TestCase):

    def setUp(self):
        self.ctx = {
            'host': {
                'ip': '172.16.0.137',
                'user': 'root',
                'key_filename': 'mykey.key'
            },
            'target': {
                'ip': '172.16.0.138',
                'user': 'root',
                'key_filename': 'mykey.key',
            }
        }

        self._mock_time = mock.patch(
            'yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time')
        self.mock_time = self._mock_time.start()

        self.addCleanup(self._cleanup)

    def _cleanup(self):
        self._mock_time.stop()

    def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
        p.setup()

        mock_ssh.SSH().execute.return_value = (0, '', '')
        self.assertIsNotNone(p.server)
        self.assertIsNotNone(p.client)
        self.assertTrue(p.setup_done)

    def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh):
        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
        }

        result = {}

        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)

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

        mock_dpdk_result = mock.Mock()
        mock_dpdk_result.return_value = 149300
        p._dpdk_get_result = mock_dpdk_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149776, "flows": 110}'
        mock_ssh.SSH().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_dpdk_throughput_successful_sla(self, mock_ssh):
        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
            'sla': {'max_ppm': 10000}
        }
        result = {}

        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)

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

        mock_dpdk_result = mock.Mock()
        mock_dpdk_result.return_value = 149300
        p._dpdk_get_result = mock_dpdk_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149776, "flows": 110}'
        mock_ssh.SSH().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_dpdk_throughput_unsuccessful_sla(self, mock_ssh):
        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
            'sla': {'max_ppm': 1000}
        }
        result = {}

        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)

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

        mock_dpdk_result = mock.Mock()
        mock_dpdk_result.return_value = 149300
        p._dpdk_get_result = mock_dpdk_result

        sample_output = '{"packets_per_second": 9753, "errors": 0, \
            "packets_sent": 149776, "flows": 110}'
        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
        self.assertRaises(AssertionError, p.run, result)

    def test_pktgen_dpdk_throughput_unsuccessful_script_error(
            self, mock_ssh):
        args = {
            'options': {'packetsize': 60, 'number_of_ports': 10},
            'sla': {'max_ppm': 1000}
        }
        result = {}

        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)

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

        mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, p.run, result)

    def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
        p.server = mock_ssh.SSH()

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

        p._is_dpdk_setup("server")

        mock_ssh.SSH().execute.assert_called_with(
            "ip a | grep eth1 2>/dev/null")

    def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
        p.server = mock_ssh.SSH()
        p.client = mock_ssh.SSH()

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

        p.dpdk_setup()

        self.assertTrue(p.dpdk_setup_done)

    def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh):
        args = {
            'options': {'packetsize': 60},
        }
        p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
        p.server = mock_ssh.SSH()
        p.client = mock_ssh.SSH()

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

        p._dpdk_get_result()

        mock_ssh.SSH().execute.assert_called_with(
            "sudo /dpdk/destdir/bin/dpdk-procinfo -- --stats-reset > /dev/null 2>&1")


def main():
    unittest.main()


if __name__ == '__main__':
    main()