1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from yardstick.benchmark.scenarios.networking import nstat
16 @mock.patch('yardstick.benchmark.scenarios.networking.nstat.ssh')
17 class NstatTestCase(unittest.TestCase):
22 "ip": "192.168.50.28",
24 "key_filename": "mykey.key"
28 def test_nstat_successful_setup(self, mock_ssh):
30 n = nstat.Nstat({}, self.ctx)
33 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
34 self.assertIsNotNone(n.client)
35 self.assertTrue(n.setup_done)
37 def test_nstat_successful_no_sla(self, mock_ssh):
45 n = nstat.Nstat(args, self.ctx)
48 sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n' # pylint: disable=line-too-long
50 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
53 expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
54 "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
55 "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
56 "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
57 "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
58 "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
59 self.assertEqual(result, expected_result)
61 def test_nstat_successful_sla(self, mock_ssh):
67 "IP_datagram_error_rate": 0.1
73 n = nstat.Nstat(args, self.ctx)
76 sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n' # pylint: disable=line-too-long
78 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
81 expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
82 "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
83 "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
84 "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
85 "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
86 "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
87 self.assertEqual(result, expected_result)
89 def test_nstat_unsuccessful_cmd_error(self, mock_ssh):
95 "IP_datagram_error_rate": 0.1
101 n = nstat.Nstat(args, self.ctx)
104 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
105 self.assertRaises(RuntimeError, n.run, result)