summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen.py118
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen_dpdk.py5
-rw-r--r--yardstick/ssh.py12
-rw-r--r--yardstick/tests/unit/benchmark/runner/test_duration.py39
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py91
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py18
-rw-r--r--yardstick/tests/unit/common/test_utils.py110
-rw-r--r--yardstick/tests/unit/test_ssh.py19
8 files changed, 257 insertions, 155 deletions
diff --git a/yardstick/benchmark/scenarios/networking/pktgen.py b/yardstick/benchmark/scenarios/networking/pktgen.py
index d1d500ff6..c78108adb 100644
--- a/yardstick/benchmark/scenarios/networking/pktgen.py
+++ b/yardstick/benchmark/scenarios/networking/pktgen.py
@@ -112,18 +112,14 @@ class Pktgen(base.Scenario):
def _get_vnic_driver_name(self):
cmd = "readlink /sys/class/net/%s/device/driver" % self.vnic_name
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
return os.path.basename(stdout.strip())
def _is_irqbalance_disabled(self):
"""Did we disable irqbalance already in the guest?"""
is_disabled = False
cmd = "grep ENABLED /etc/default/irqbalance"
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
if "0" in stdout:
is_disabled = True
@@ -132,49 +128,35 @@ class Pktgen(base.Scenario):
def _disable_irqbalance(self):
cmd = "sudo sed -i -e 's/ENABLED=\"1\"/ENABLED=\"0\"/g' " \
"/etc/default/irqbalance"
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
cmd = "sudo service irqbalance stop"
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
cmd = "sudo service irqbalance disable"
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
def _setup_irqmapping_ovs(self, queue_number):
cmd = "grep 'virtio0-input.0' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'"
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo 1 | sudo tee /proc/irq/%s/smp_affinity" % (int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
cmd = "grep 'virtio0-output.0' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'"
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo 1 | sudo tee /proc/irq/%s/smp_affinity" % (int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
if queue_number == 1:
return
@@ -186,44 +168,32 @@ class Pktgen(base.Scenario):
cmd = "grep 'virtio0-input.%s' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'" % (i)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo %s | sudo tee /proc/irq/%s/smp_affinity" \
% (smp_affinity_mask, int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
cmd = "grep 'virtio0-output.%s' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'" % (i)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo %s | sudo tee /proc/irq/%s/smp_affinity" \
% (smp_affinity_mask, int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
def _setup_irqmapping_sriov(self, queue_number):
cmd = "grep '%s-TxRx-0' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'" % self.vnic_name
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo 1 | sudo tee /proc/irq/%s/smp_affinity" % (int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
if queue_number == 1:
return
@@ -234,24 +204,18 @@ class Pktgen(base.Scenario):
cmd = "grep '%s-TxRx-%s' /proc/interrupts |" \
"awk '{match($0,/ +[0-9]+/)} " \
"{print substr($1,RSTART,RLENGTH-1)}'" % (self.vnic_name, i)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
cmd = "echo %s | sudo tee /proc/irq/%s/smp_affinity" \
% (smp_affinity_mask, int(stdout))
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
def _get_sriov_queue_number(self):
"""Get queue number from server as both VMs are the same"""
cmd = "grep %s-TxRx- /proc/interrupts | wc -l" % self.vnic_name
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
return int(stdout)
def _get_available_queue_number(self):
@@ -259,9 +223,7 @@ class Pktgen(base.Scenario):
cmd = "sudo ethtool -l %s | grep Combined | head -1 |" \
"awk '{printf $2}'" % self.vnic_name
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
return int(stdout)
def _get_usable_queue_number(self):
@@ -269,9 +231,7 @@ class Pktgen(base.Scenario):
cmd = "sudo ethtool -l %s | grep Combined | tail -1 |" \
"awk '{printf $2}'" % self.vnic_name
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
return int(stdout)
def _enable_ovs_multiqueue(self):
@@ -282,10 +242,8 @@ class Pktgen(base.Scenario):
cmd = "sudo ethtool -L %s combined %s" % \
(self.vnic_name, available_queue_number)
LOG.debug("Executing command: %s", cmd)
- status, _, stderr = self.server.execute(cmd)
- status, _, stderr = self.client.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd)
+ self.client.run(cmd)
return available_queue_number
def _iptables_setup(self):
@@ -294,9 +252,7 @@ class Pktgen(base.Scenario):
"sudo iptables -A INPUT -p udp --dport 1000:%s -j DROP" \
% (1000 + self.number_of_ports)
LOG.debug("Executing command: %s", cmd)
- status, _, stderr = self.server.execute(cmd, timeout=SSH_TIMEOUT)
- if status:
- raise RuntimeError(stderr)
+ self.server.run(cmd, timeout=SSH_TIMEOUT)
def _iptables_get_result(self):
"""Get packet statistics from server"""
@@ -304,9 +260,7 @@ class Pktgen(base.Scenario):
"awk '/dpts:1000:%s/ {{printf \"%%s\", $1}}'" \
% (1000 + self.number_of_ports)
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.server.execute(cmd)
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.server.execute(cmd, raise_on_error=True)
return int(stdout)
def run(self, result):
@@ -356,10 +310,8 @@ class Pktgen(base.Scenario):
duration, queue_number, pps)
LOG.debug("Executing command: %s", cmd)
- status, stdout, stderr = self.client.execute(cmd, timeout=SSH_TIMEOUT)
-
- if status:
- raise RuntimeError(stderr)
+ _, stdout, _ = self.client.execute(cmd, raise_on_error=True,
+ timeout=SSH_TIMEOUT)
result.update(jsonutils.loads(stdout))
diff --git a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
index 1b018f52a..efb7d8b5d 100644
--- a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
+++ b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
@@ -113,10 +113,7 @@ cat ~/result.log -vT \
{print substr($0,RSTART,RLENGTH)}' \
|grep -v ^$ |awk '{if ($2 != 0) print $2}'\
"""
- client_status, client_stdout, client_stderr = self.client.execute(cmd)
-
- if client_status:
- raise RuntimeError(client_stderr)
+ _, client_stdout, _ = self.client.execute(cmd, raise_on_error=True)
avg_latency = 0
if client_stdout:
diff --git a/yardstick/ssh.py b/yardstick/ssh.py
index 6b5e6faf4..e6a26ab6b 100644
--- a/yardstick/ssh.py
+++ b/yardstick/ssh.py
@@ -348,12 +348,14 @@ class SSH(object):
raise exceptions.SSHError(error_msg=details)
return exit_status
- def execute(self, cmd, stdin=None, timeout=3600):
+ def execute(self, cmd, stdin=None, timeout=3600, raise_on_error=False):
"""Execute the specified command on the server.
- :param cmd: Command to be executed.
- :param stdin: Open file to be sent on process stdin.
- :param timeout: Timeout for execution of the command.
+ :param cmd: (str) Command to be executed.
+ :param stdin: (StringIO) Open file to be sent on process stdin.
+ :param timeout: (int) Timeout for execution of the command.
+ :param raise_on_error: (bool) If True, then an SSHError will be raised
+ when non-zero exit code.
:returns: tuple (exit_status, stdout, stderr)
"""
@@ -362,7 +364,7 @@ class SSH(object):
exit_status = self.run(cmd, stderr=stderr,
stdout=stdout, stdin=stdin,
- timeout=timeout, raise_on_error=False)
+ timeout=timeout, raise_on_error=raise_on_error)
stdout.seek(0)
stderr.seek(0)
return exit_status, stdout.read(), stderr.read()
diff --git a/yardstick/tests/unit/benchmark/runner/test_duration.py b/yardstick/tests/unit/benchmark/runner/test_duration.py
new file mode 100644
index 000000000..21e3874b8
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/runner/test_duration.py
@@ -0,0 +1,39 @@
+##############################################################################
+# Copyright (c) 2018 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
+##############################################################################
+
+import mock
+import unittest
+import multiprocessing
+import os
+
+from yardstick.benchmark.runners import duration
+
+
+class DurationRunnerTest(unittest.TestCase):
+ def setUp(self):
+ self.scenario_cfg = {
+ 'runner': {'interval': 0, "duration": 0},
+ 'type': 'some_type'
+ }
+
+ @mock.patch.object(os, 'getpid')
+ @mock.patch.object(multiprocessing, 'Process')
+ def test__run_benchmark_called_with(self, mock_multiprocessing_process,
+ mock_os_getpid):
+ mock_os_getpid.return_value = 101
+
+ runner = duration.DurationRunner({})
+ benchmark_cls = mock.Mock()
+ runner._run_benchmark(benchmark_cls, 'my_method', self.scenario_cfg,
+ {})
+ mock_multiprocessing_process.assert_called_once_with(
+ name='Duration-some_type-101',
+ target=duration._worker_process,
+ args=(runner.result_queue, benchmark_cls, 'my_method',
+ self.scenario_cfg, {}, runner.aborted, runner.output_queue))
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
index ea0deab3e..4016f5055 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
@@ -56,11 +56,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.number_of_ports = args['options']['number_of_ports']
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
-
p._iptables_setup()
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ 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)
@@ -75,8 +73,8 @@ class PktgenTestCase(unittest.TestCase):
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)
+ mock_ssh.SSH.from_node().run.side_effect = y_exc.SSHError
+ self.assertRaises(y_exc.SSHError, p._iptables_setup)
def test_pktgen_successful_iptables_get_result(self, mock_ssh):
@@ -89,12 +87,14 @@ class PktgenTestCase(unittest.TestCase):
p.number_of_ports = args['options']['number_of_ports']
mock_ssh.SSH.from_node().execute.return_value = (0, '150000', '')
- p._iptables_get_result()
+ result = p._iptables_get_result()
+ expected_result = 150000
+ self.assertEqual(result, expected_result)
mock_ssh.SSH.from_node().execute.assert_called_with(
"sudo iptables -L INPUT -vnx |"
"awk '/dpts:1000:%s/ {{printf \"%%s\", $1}}'"
- % 1010)
+ % 1010, raise_on_error=True)
def test_pktgen_unsuccessful_iptables_get_result(self, mock_ssh):
@@ -107,8 +107,8 @@ class PktgenTestCase(unittest.TestCase):
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_get_result)
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
+ self.assertRaises(y_exc.SSHError, p._iptables_get_result)
def test_pktgen_successful_no_sla(self, mock_ssh):
@@ -192,8 +192,8 @@ class PktgenTestCase(unittest.TestCase):
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)
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
+ self.assertRaises(y_exc.SSHError, p.run, result)
def test_pktgen_get_vnic_driver_name(self, mock_ssh):
args = {
@@ -214,9 +214,9 @@ class PktgenTestCase(unittest.TestCase):
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._get_vnic_driver_name)
+ self.assertRaises(y_exc.SSHError, p._get_vnic_driver_name)
def test_pktgen_get_sriov_queue_number(self, mock_ssh):
args = {
@@ -237,9 +237,9 @@ class PktgenTestCase(unittest.TestCase):
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._get_sriov_queue_number)
+ self.assertRaises(y_exc.SSHError, p._get_sriov_queue_number)
def test_pktgen_get_available_queue_number(self, mock_ssh):
args = {
@@ -250,11 +250,11 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '4', '')
- p._get_available_queue_number()
+ self.assertEqual(p._get_available_queue_number(), 4)
mock_ssh.SSH.from_node().execute.assert_called_with(
"sudo ethtool -l eth0 | grep Combined | head -1 |"
- "awk '{printf $2}'")
+ "awk '{printf $2}'", raise_on_error=True)
def test_pktgen_unsuccessful_get_available_queue_number(self, mock_ssh):
args = {
@@ -263,9 +263,9 @@ class PktgenTestCase(unittest.TestCase):
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._get_available_queue_number)
+ self.assertRaises(y_exc.SSHError, p._get_available_queue_number)
def test_pktgen_get_usable_queue_number(self, mock_ssh):
args = {
@@ -276,11 +276,11 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '1', '')
- p._get_usable_queue_number()
+ 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}'")
+ "awk '{printf $2}'", raise_on_error=True)
def test_pktgen_unsuccessful_get_usable_queue_number(self, mock_ssh):
args = {
@@ -289,9 +289,9 @@ class PktgenTestCase(unittest.TestCase):
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._get_usable_queue_number)
+ self.assertRaises(y_exc.SSHError, p._get_usable_queue_number)
def test_pktgen_enable_ovs_multiqueue(self, mock_ssh):
args = {
@@ -333,12 +333,12 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ 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(RuntimeError, p._enable_ovs_multiqueue)
+ self.assertRaises(y_exc.SSHError, p._enable_ovs_multiqueue)
def test_pktgen_setup_irqmapping_ovs(self, mock_ssh):
args = {
@@ -352,7 +352,7 @@ class PktgenTestCase(unittest.TestCase):
p._setup_irqmapping_ovs(4)
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ mock_ssh.SSH.from_node().run.assert_called_with(
"echo 8 | sudo tee /proc/irq/10/smp_affinity")
def test_pktgen_setup_irqmapping_ovs_1q(self, mock_ssh):
@@ -367,7 +367,7 @@ class PktgenTestCase(unittest.TestCase):
p._setup_irqmapping_ovs(1)
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ mock_ssh.SSH.from_node().run.assert_called_with(
"echo 1 | sudo tee /proc/irq/10/smp_affinity")
def test_pktgen_unsuccessful_setup_irqmapping_ovs(self, mock_ssh):
@@ -378,9 +378,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._setup_irqmapping_ovs, 4)
+ self.assertRaises(y_exc.SSHError, p._setup_irqmapping_ovs, 4)
def test_pktgen_unsuccessful_setup_irqmapping_ovs_1q(self, mock_ssh):
args = {
@@ -390,9 +390,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._setup_irqmapping_ovs, 1)
+ self.assertRaises(y_exc.SSHError, p._setup_irqmapping_ovs, 1)
def test_pktgen_setup_irqmapping_sriov(self, mock_ssh):
args = {
@@ -406,7 +406,7 @@ class PktgenTestCase(unittest.TestCase):
p._setup_irqmapping_sriov(2)
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ mock_ssh.SSH.from_node().run.assert_called_with(
"echo 2 | sudo tee /proc/irq/10/smp_affinity")
def test_pktgen_setup_irqmapping_sriov_1q(self, mock_ssh):
@@ -421,7 +421,7 @@ class PktgenTestCase(unittest.TestCase):
p._setup_irqmapping_sriov(1)
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ mock_ssh.SSH.from_node().run.assert_called_with(
"echo 1 | sudo tee /proc/irq/10/smp_affinity")
def test_pktgen_unsuccessful_setup_irqmapping_sriov(self, mock_ssh):
@@ -432,9 +432,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._setup_irqmapping_sriov, 2)
+ self.assertRaises(y_exc.SSHError, p._setup_irqmapping_sriov, 2)
def test_pktgen_unsuccessful_setup_irqmapping_sriov_1q(self, mock_ssh):
args = {
@@ -444,9 +444,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._setup_irqmapping_sriov, 1)
+ self.assertRaises(y_exc.SSHError, p._setup_irqmapping_sriov, 1)
def test_pktgen_is_irqbalance_disabled(self, mock_ssh):
args = {
@@ -457,10 +457,11 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
- p._is_irqbalance_disabled()
+ result = p._is_irqbalance_disabled()
+ self.assertFalse(result)
mock_ssh.SSH.from_node().execute.assert_called_with(
- "grep ENABLED /etc/default/irqbalance")
+ "grep ENABLED /etc/default/irqbalance", raise_on_error=True)
def test_pktgen_unsuccessful_is_irqbalance_disabled(self, mock_ssh):
args = {
@@ -469,9 +470,9 @@ class PktgenTestCase(unittest.TestCase):
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().execute.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._is_irqbalance_disabled)
+ self.assertRaises(y_exc.SSHError, p._is_irqbalance_disabled)
def test_pktgen_disable_irqbalance(self, mock_ssh):
args = {
@@ -481,11 +482,11 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ mock_ssh.SSH.from_node().run.return_value = (0, '', '')
p._disable_irqbalance()
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ mock_ssh.SSH.from_node().run.assert_called_with(
"sudo service irqbalance disable")
def test_pktgen_unsuccessful_disable_irqbalance(self, mock_ssh):
@@ -496,9 +497,9 @@ class PktgenTestCase(unittest.TestCase):
p.server = mock_ssh.SSH.from_node()
p.client = mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ mock_ssh.SSH.from_node().run.side_effect = y_exc.SSHError
- self.assertRaises(RuntimeError, p._disable_irqbalance)
+ self.assertRaises(y_exc.SSHError, p._disable_irqbalance)
def test_pktgen_multiqueue_setup_ovs(self, mock_ssh):
args = {
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
index b141591f7..bcd417830 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
@@ -165,7 +165,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
self.assertRaises(y_exc.SLAValidationError, p.run, result)
- def test_pktgen_dpdk_unsuccessful_script_error(self):
+ def test_pktgen_dpdk_run_unsuccessful_get_port_mac(self):
args = {
'options': {'packetsize': 60},
@@ -177,3 +177,19 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
+
+ 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)
diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py
index 31b10e6da..6e7a0bfc4 100644
--- a/yardstick/tests/unit/common/test_utils.py
+++ b/yardstick/tests/unit/common/test_utils.py
@@ -19,14 +19,14 @@ from six.moves import configparser
import time
import unittest
-import yardstick
from yardstick import ssh
from yardstick.common import constants
from yardstick.common import utils
from yardstick.common import exceptions
+from yardstick.tests.unit import base as ut_base
-class IterSubclassesTestCase(unittest.TestCase):
+class IterSubclassesTestCase(ut_base.BaseUnitTestCase):
# Disclaimer: this class is a modified copy from
# rally/tests/unit/common/plugin/test_discover.py
# Copyright 2015: Mirantis Inc.
@@ -47,7 +47,7 @@ class IterSubclassesTestCase(unittest.TestCase):
self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
-class ImportModulesFromPackageTestCase(unittest.TestCase):
+class ImportModulesFromPackageTestCase(ut_base.BaseUnitTestCase):
@mock.patch('yardstick.common.utils.os.walk')
def test_import_modules_from_package_no_mod(self, mock_walk):
@@ -72,7 +72,7 @@ class ImportModulesFromPackageTestCase(unittest.TestCase):
mock_import_module.assert_called_once_with('bar.baz')
-class GetParaFromYaml(unittest.TestCase):
+class GetParaFromYaml(ut_base.BaseUnitTestCase):
@mock.patch('yardstick.common.utils.os.environ.get')
def test_get_param_para_not_found(self, get_env):
@@ -96,7 +96,7 @@ class GetParaFromYaml(unittest.TestCase):
return file_path
-class CommonUtilTestCase(unittest.TestCase):
+class CommonUtilTestCase(ut_base.BaseUnitTestCase):
def setUp(self):
self.data = {
@@ -186,14 +186,14 @@ class CommonUtilTestCase(unittest.TestCase):
self.assertEqual(mock_open.call_count, mock_open_call_count)
-class TestMacAddressToHex(unittest.TestCase):
+class TestMacAddressToHex(ut_base.BaseUnitTestCase):
def test_mac_address_to_hex_list(self):
self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
-class TranslateToStrTestCase(unittest.TestCase):
+class TranslateToStrTestCase(ut_base.BaseUnitTestCase):
def test_translate_to_str_unicode(self):
input_str = u'hello'
@@ -219,7 +219,7 @@ class TranslateToStrTestCase(unittest.TestCase):
self.assertIs(input_value, result)
-class TestParseCpuInfo(unittest.TestCase):
+class TestParseCpuInfo(ut_base.BaseUnitTestCase):
def test_single_socket_no_hyperthread(self):
cpuinfo = """\
@@ -804,7 +804,7 @@ power management:
self.assertEqual(sockets, [0, 1])
-class ChangeObjToDictTestCase(unittest.TestCase):
+class ChangeObjToDictTestCase(ut_base.BaseUnitTestCase):
def test_change_obj_to_dict(self):
class A(object):
@@ -817,7 +817,7 @@ class ChangeObjToDictTestCase(unittest.TestCase):
self.assertEqual(obj_r, obj_s)
-class SetDictValueTestCase(unittest.TestCase):
+class SetDictValueTestCase(ut_base.BaseUnitTestCase):
def test_set_dict_value(self):
input_dic = {
@@ -827,7 +827,7 @@ class SetDictValueTestCase(unittest.TestCase):
self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
-class RemoveFileTestCase(unittest.TestCase):
+class RemoveFileTestCase(ut_base.BaseUnitTestCase):
def test_remove_file(self):
try:
@@ -837,7 +837,83 @@ class RemoveFileTestCase(unittest.TestCase):
self.assertTrue(isinstance(e, OSError))
-class TestUtils(unittest.TestCase):
+class ParseIniFileTestCase(ut_base.BaseUnitTestCase):
+
+ def setUp(self):
+ self._mock_config_parser_type = mock.patch.object(configparser,
+ 'ConfigParser')
+ self.mock_config_parser_type = self._mock_config_parser_type.start()
+ self.addCleanup(self._stop_mocks)
+
+ def _stop_mocks(self):
+ self._mock_config_parser_type.stop()
+
+ def test_parse_ini_file(self):
+ defaults = {'default1': 'value1',
+ 'default2': 'value2'}
+ s1 = {'key1': 'value11',
+ 'key2': 'value22'}
+ s2 = {'key1': 'value123',
+ 'key2': 'value234'}
+
+ mock_config_parser = mock.Mock()
+ self.mock_config_parser_type.return_value = mock_config_parser
+ mock_config_parser.read.return_value = True
+ mock_config_parser.sections.return_value = ['s1', 's2']
+ mock_config_parser.items.side_effect = iter([
+ defaults.items(),
+ s1.items(),
+ s2.items(),
+ ])
+
+ expected = {'DEFAULT': defaults,
+ 's1': s1,
+ 's2': s2}
+ result = utils.parse_ini_file('my_path')
+ self.assertDictEqual(expected, result)
+
+ @mock.patch.object(utils, 'logger')
+ def test_parse_ini_file_missing_section_header(self, *args):
+ mock_config_parser = mock.Mock()
+ self.mock_config_parser_type.return_value = mock_config_parser
+ mock_config_parser.read.side_effect = (
+ configparser.MissingSectionHeaderError(
+ mock.Mock(), 321, mock.Mock()))
+
+ with self.assertRaises(configparser.MissingSectionHeaderError):
+ utils.parse_ini_file('my_path')
+
+ def test_parse_ini_file_no_file(self):
+ mock_config_parser = mock.Mock()
+ self.mock_config_parser_type.return_value = mock_config_parser
+ mock_config_parser.read.return_value = False
+ with self.assertRaises(RuntimeError):
+ utils.parse_ini_file('my_path')
+
+ def test_parse_ini_file_no_default_section_header(self):
+ s1 = {'key1': 'value11',
+ 'key2': 'value22'}
+ s2 = {'key1': 'value123',
+ 'key2': 'value234'}
+
+ mock_config_parser = mock.Mock()
+ self.mock_config_parser_type.return_value = mock_config_parser
+ mock_config_parser.read.return_value = True
+ mock_config_parser.sections.return_value = ['s1', 's2']
+ mock_config_parser.items.side_effect = iter([
+ configparser.NoSectionError(mock.Mock()),
+ s1.items(),
+ s2.items(),
+ ])
+
+ expected = {'DEFAULT': {},
+ 's1': s1,
+ 's2': s2}
+ result = utils.parse_ini_file('my_path')
+ self.assertDictEqual(expected, result)
+
+
+class TestUtils(ut_base.BaseUnitTestCase):
@mock.patch('yardstick.common.utils.os.makedirs')
def test_makedirs(self, *_):
@@ -992,7 +1068,7 @@ class TestUtils(unittest.TestCase):
utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
-class TestUtilsIpAddrMethods(unittest.TestCase):
+class TestUtilsIpAddrMethods(ut_base.BaseUnitTestCase):
GOOD_IP_V4_ADDRESS_STR_LIST = [
u'0.0.0.0',
@@ -1119,7 +1195,7 @@ class TestUtilsIpAddrMethods(unittest.TestCase):
self.assertEqual(utils.ip_to_hex(value), value)
-class SafeDecodeUtf8TestCase(unittest.TestCase):
+class SafeDecodeUtf8TestCase(ut_base.BaseUnitTestCase):
@unittest.skipIf(six.PY2,
'This test should only be launched with Python 3.x')
@@ -1130,7 +1206,7 @@ class SafeDecodeUtf8TestCase(unittest.TestCase):
self.assertEqual('this is a byte array', out)
-class ReadMeminfoTestCase(unittest.TestCase):
+class ReadMeminfoTestCase(ut_base.BaseUnitTestCase):
MEMINFO = (b'MemTotal: 65860500 kB\n'
b'MemFree: 28690900 kB\n'
@@ -1156,7 +1232,7 @@ class ReadMeminfoTestCase(unittest.TestCase):
self.assertEqual(self.MEMINFO_DICT, output)
-class TimerTestCase(unittest.TestCase):
+class TimerTestCase(ut_base.BaseUnitTestCase):
def test__getattr(self):
with utils.Timer() as timer:
@@ -1186,7 +1262,7 @@ class TimerTestCase(unittest.TestCase):
self.assertEqual(2, len(iterations))
-class WaitUntilTrueTestCase(unittest.TestCase):
+class WaitUntilTrueTestCase(ut_base.BaseUnitTestCase):
def test_no_timeout(self):
self.assertIsNone(utils.wait_until_true(lambda: True,
diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py
index 5cf1e50a0..b727e821d 100644
--- a/yardstick/tests/unit/test_ssh.py
+++ b/yardstick/tests/unit/test_ssh.py
@@ -238,6 +238,25 @@ class SSHTestCase(unittest.TestCase):
self.assertEqual("stdout fake data", stdout)
self.assertEqual("stderr fake data", stderr)
+ @mock.patch("yardstick.ssh.six.moves.StringIO")
+ def test_execute_raise_on_error_passed(self, mock_string_io):
+ mock_string_io.side_effect = stdio = [mock.Mock(), mock.Mock()]
+ stdio[0].read.return_value = "stdout fake data"
+ stdio[1].read.return_value = "stderr fake data"
+ with mock.patch.object(self.test_client, "run", return_value=0) \
+ as mock_run:
+ status, stdout, stderr = self.test_client.execute(
+ "cmd",
+ stdin="fake_stdin",
+ timeout=43,
+ raise_on_error=True)
+ mock_run.assert_called_once_with(
+ "cmd", stdin="fake_stdin", stdout=stdio[0],
+ stderr=stdio[1], timeout=43, raise_on_error=True)
+ self.assertEqual(0, status)
+ self.assertEqual("stdout fake data", stdout)
+ self.assertEqual("stderr fake data", stderr)
+
@mock.patch("yardstick.ssh.time")
def test_wait_timeout(self, mock_time):
mock_time.time.side_effect = [1, 50, 150]