diff options
Diffstat (limited to 'tests/unit/benchmark')
26 files changed, 838 insertions, 359 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py index 6899a0af6..6090356b6 100644 --- a/tests/unit/benchmark/contexts/standalone/test_model.py +++ b/tests/unit/benchmark/contexts/standalone/test_model.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (c) 2016-2017 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,72 +12,157 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Unittest for yardstick.benchmark.contexts.standalone.model - - -from __future__ import absolute_import +import copy import os import unittest -import errno import mock -from yardstick.common import constants as consts +from xml.etree import ElementTree + from yardstick.benchmark.contexts.standalone.model import Libvirt -from yardstick.benchmark.contexts.standalone.model import StandaloneContextHelper from yardstick.benchmark.contexts.standalone import model -from yardstick.network_services.utils import PciAddress +from yardstick.network_services import utils +XML_SAMPLE = """<?xml version="1.0"?> +<domain type="kvm"> + <devices> + </devices> +</domain> +""" + +XML_SAMPLE_INTERFACE = """<?xml version="1.0"?> +<domain type="kvm"> + <devices> + <interface> + </interface> + </devices> +</domain> +""" + class ModelLibvirtTestCase(unittest.TestCase): + def setUp(self): + self.xml = ElementTree.ElementTree( + element=ElementTree.fromstring(XML_SAMPLE)) + self.pci_address_str = '0001:04:03.2' + self.pci_address = utils.PciAddress(self.pci_address_str) + self.mac = '00:00:00:00:00:01' + self._mock_write_xml = mock.patch.object(ElementTree.ElementTree, + 'write') + self.mock_write_xml = self._mock_write_xml.start() + + self.addCleanup(self._cleanup) + + def _cleanup(self): + self._mock_write_xml.stop() + def test_check_if_vm_exists_and_delete(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) + ssh_mock.execute = mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - result = Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock) - self.assertIsNone(result) + # NOTE(ralonsoh): this test doesn't cover function execution. + model.Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock) def test_virsh_create_vm(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) + ssh_mock.execute = mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - result = Libvirt.virsh_create_vm(ssh_mock, "vm_0") - self.assertIsNone(result) + # NOTE(ralonsoh): this test doesn't cover function execution. + model.Libvirt.virsh_create_vm(ssh_mock, "vm_0") def test_virsh_destroy_vm(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) + ssh_mock.execute = mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - result = Libvirt.virsh_destroy_vm("vm_0", ssh_mock) - self.assertIsNone(result) - - @mock.patch('yardstick.benchmark.contexts.standalone.model.ET') - def test_add_interface_address(self, mock_et): - pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) - result = Libvirt.add_interface_address("<interface/>", pci_address) - self.assertIsNotNone(result) - - @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt.add_interface_address') - @mock.patch('yardstick.benchmark.contexts.standalone.model.ET') - def test_add_ovs_interfaces(self, mock_et, mock_add_interface_address): - pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) - result = Libvirt.add_ovs_interface("/usr/local", 0, "0000:00:04.0", - "00:00:00:00:00:01", "xml") - self.assertIsNone(result) - - @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt.add_interface_address') - @mock.patch('yardstick.benchmark.contexts.standalone.model.ET') - def test_add_sriov_interfaces(self, mock_et, mock_add_interface_address): - pci_address = PciAddress.parse_address("0000:00:04.0", multi_line=True) - result = Libvirt.add_sriov_interfaces("0000:00:05.0", "0000:00:04.0", - "00:00:00:00:00:01", "xml") - self.assertIsNone(result) + # NOTE(ralonsoh): this test doesn't cover function execution. + model.Libvirt.virsh_destroy_vm("vm_0", ssh_mock) + + def test_add_interface_address(self): + xml = ElementTree.ElementTree( + element=ElementTree.fromstring(XML_SAMPLE_INTERFACE)) + interface = xml.find('devices').find('interface') + result = model.Libvirt._add_interface_address(interface, self.pci_address) + self.assertEqual('pci', result.get('type')) + self.assertEqual('0x{}'.format(self.pci_address.domain), + result.get('domain')) + self.assertEqual('0x{}'.format(self.pci_address.bus), + result.get('bus')) + self.assertEqual('0x{}'.format(self.pci_address.slot), + result.get('slot')) + self.assertEqual('0x{}'.format(self.pci_address.function), + result.get('function')) + + def test_add_ovs_interfaces(self): + xml_input = mock.Mock() + with mock.patch.object(ElementTree, 'parse', return_value=self.xml) \ + as mock_parse: + xml = copy.deepcopy(self.xml) + mock_parse.return_value = xml + model.Libvirt.add_ovs_interface( + '/usr/local', 0, self.pci_address_str, self.mac, xml_input) + mock_parse.assert_called_once_with(xml_input) + self.mock_write_xml.assert_called_once_with(xml_input) + interface = xml.find('devices').find('interface') + self.assertEqual('vhostuser', interface.get('type')) + mac = interface.find('mac') + self.assertEqual(self.mac, mac.get('address')) + source = interface.find('source') + self.assertEqual('unix', source.get('type')) + self.assertEqual('/usr/local/var/run/openvswitch/dpdkvhostuser0', + source.get('path')) + self.assertEqual('client', source.get('mode')) + _model = interface.find('model') + self.assertEqual('virtio', _model.get('type')) + driver = interface.find('driver') + self.assertEqual('4', driver.get('queues')) + host = driver.find('host') + self.assertEqual('off', host.get('mrg_rxbuf')) + self.assertIsNotNone(interface.find('address')) + + def test_add_sriov_interfaces(self): + xml_input = mock.Mock() + with mock.patch.object(ElementTree, 'parse', return_value=self.xml) \ + as mock_parse: + xml = copy.deepcopy(self.xml) + mock_parse.return_value = xml + vm_pci = '0001:05:04.2' + model.Libvirt.add_sriov_interfaces( + vm_pci, self.pci_address_str, self.mac, xml_input) + mock_parse.assert_called_once_with(xml_input) + self.mock_write_xml.assert_called_once_with(xml_input) + interface = xml.find('devices').find('interface') + self.assertEqual('yes', interface.get('managed')) + self.assertEqual('hostdev', interface.get('type')) + mac = interface.find('mac') + self.assertEqual(self.mac, mac.get('address')) + source = interface.find('source') + source_address = source.find('address') + self.assertIsNotNone(source.find('address')) + + self.assertEqual('pci', source_address.get('type')) + self.assertEqual('0x' + self.pci_address_str.split(':')[0], + source_address.get('domain')) + self.assertEqual('0x' + self.pci_address_str.split(':')[1], + source_address.get('bus')) + self.assertEqual('0x' + self.pci_address_str.split(':')[2].split('.')[0], + source_address.get('slot')) + self.assertEqual('0x' + self.pci_address_str.split(':')[2].split('.')[1], + source_address.get('function')) + + interface_address = interface.find('address') + self.assertEqual('pci', interface_address.get('type')) + self.assertEqual('0x' + vm_pci.split(':')[0], + interface_address.get('domain')) + self.assertEqual('0x' + vm_pci.split(':')[1], + interface_address.get('bus')) + self.assertEqual('0x' + vm_pci.split(':')[2].split('.')[0], + interface_address.get('slot')) + self.assertEqual('0x' + vm_pci.split(':')[2].split('.')[1], + interface_address.get('function')) def test_create_snapshot_qemu(self): result = "/var/lib/libvirt/images/0.qcow2" @@ -88,15 +171,17 @@ class ModelLibvirtTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - image = Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") + image = model.Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") self.assertEqual(image, result) - @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.pin_vcpu_for_perf") - @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.create_snapshot_qemu") - @mock.patch('yardstick.benchmark.contexts.standalone.model.open') - @mock.patch('yardstick.benchmark.contexts.standalone.model.write_file') - def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu, - mock_pin_vcpu_for_perf): + @mock.patch.object(model.Libvirt, 'pin_vcpu_for_perf') + @mock.patch.object(model.Libvirt, 'create_snapshot_qemu') + def test_build_vm_xml(self, mock_create_snapshot_qemu, + *args): + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + cfg_file = 'test_config_file.cfg' + self.addCleanup(os.remove, cfg_file) result = [4] with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -105,7 +190,7 @@ class ModelLibvirtTestCase(unittest.TestCase): ssh.return_value = ssh_mock mock_create_snapshot_qemu.return_value = "0.img" - status = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0) + status = model.Libvirt.build_vm_xml(ssh_mock, {}, cfg_file, 'vm_0', 0) self.assertEqual(status[0], result[0]) def test_update_interrupts_hugepages_perf(self): @@ -114,18 +199,22 @@ class ModelLibvirtTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - status = Libvirt.update_interrupts_hugepages_perf(ssh_mock) - self.assertIsNone(status) + # NOTE(ralonsoh): 'update_interrupts_hugepages_perf' always return + # None, this check is trivial. + #status = Libvirt.update_interrupts_hugepages_perf(ssh_mock) + #self.assertIsNone(status) + Libvirt.update_interrupts_hugepages_perf(ssh_mock) @mock.patch("yardstick.benchmark.contexts.standalone.model.CpuSysCores") - @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.update_interrupts_hugepages_perf") - def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_CpuSysCores): + @mock.patch.object(model.Libvirt, 'update_interrupts_hugepages_perf') + def test_pin_vcpu_for_perf(self, *args): + # NOTE(ralonsoh): test mocked methods/variables. with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4) + status = Libvirt.pin_vcpu_for_perf(ssh_mock, 4) self.assertIsNotNone(status) class StandaloneContextHelperTestCase(unittest.TestCase): @@ -148,7 +237,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase): } def setUp(self): - self.helper = StandaloneContextHelper() + self.helper = model.StandaloneContextHelper() def test___init__(self): self.assertIsNone(self.helper.file_path) @@ -159,8 +248,9 @@ class StandaloneContextHelperTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(1, "a", "")) ssh.return_value = ssh_mock - status = StandaloneContextHelper.install_req_libs(ssh_mock) - self.assertIsNone(status) + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + model.StandaloneContextHelper.install_req_libs(ssh_mock) def test_get_kernel_module(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -168,19 +258,22 @@ class StandaloneContextHelperTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(1, "i40e", "")) ssh.return_value = ssh_mock - status = StandaloneContextHelper.get_kernel_module(ssh_mock, "05:00.0", None) - self.assertEqual(status, "i40e") + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + model.StandaloneContextHelper.get_kernel_module( + ssh_mock, "05:00.0", None) - @mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper.get_kernel_module') + @mock.patch.object(model.StandaloneContextHelper, 'get_kernel_module') def test_get_nic_details(self, mock_get_kernel_module): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "i40e ixgbe", "")) + ssh_mock.execute = mock.Mock(return_value=(1, "i40e ixgbe", "")) ssh.return_value = ssh_mock mock_get_kernel_module.return_value = "i40e" - status = StandaloneContextHelper.get_nic_details(ssh_mock, self.NETWORKS, "dpdk-devbind.py") - self.assertIsNotNone(status) + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + model.StandaloneContextHelper.get_nic_details( + ssh_mock, self.NETWORKS, 'dpdk-devbind.py') def test_get_virtual_devices(self): pattern = "PCI_SLOT_NAME=0000:05:00.0" @@ -189,8 +282,10 @@ class StandaloneContextHelperTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(1, pattern, "")) ssh.return_value = ssh_mock - status = StandaloneContextHelper.get_virtual_devices(ssh_mock, "0000:00:05.0") - self.assertIsNotNone(status) + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + model.StandaloneContextHelper.get_virtual_devices( + ssh_mock, '0000:00:05.0') def _get_file_abspath(self, filename): curr_path = os.path.dirname(os.path.abspath(__file__)) @@ -204,40 +299,50 @@ class StandaloneContextHelperTestCase(unittest.TestCase): def test_parse_pod_file(self): self.helper.file_path = self._get_file_abspath("dummy") - self.assertRaises(IOError, self.helper.parse_pod_file, self.helper.file_path) + self.assertRaises(IOError, self.helper.parse_pod_file, + self.helper.file_path) self.helper.file_path = self._get_file_abspath(self.NODE_SAMPLE) - self.assertRaises(TypeError, self.helper.parse_pod_file, self.helper.file_path) + self.assertRaises(TypeError, self.helper.parse_pod_file, + self.helper.file_path) self.helper.file_path = self._get_file_abspath(self.NODE_SRIOV_SAMPLE) self.assertIsNotNone(self.helper.parse_pod_file(self.helper.file_path)) def test_get_mac_address(self): - status = StandaloneContextHelper.get_mac_address() + status = model.StandaloneContextHelper.get_mac_address() self.assertIsNotNone(status) @mock.patch('yardstick.ssh.SSH') - def test_get_mgmt_ip(self, mock_ssh): + def test_get_mgmt_ip(self, *args): + # NOTE(ralonsoh): test mocked methods/variables. with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "1.2.3.4 00:00:00:00:00:01", "")) + ssh_mock.execute = mock.Mock( + return_value=(1, "1.2.3.4 00:00:00:00:00:01", "")) ssh.return_value = ssh_mock - status = StandaloneContextHelper.get_mgmt_ip(ssh_mock, "00:00:00:00:00:01", "1.1.1.1/24", {}) + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. + status = model.StandaloneContextHelper.get_mgmt_ip( + ssh_mock, "00:00:00:00:00:01", "1.1.1.1/24", {}) self.assertIsNotNone(status) @mock.patch('yardstick.ssh.SSH') - def test_get_mgmt_ip_no(self, mock_ssh): + def test_get_mgmt_ip_no(self, *args): + # NOTE(ralonsoh): test mocked methods/variables. with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(1, "", "")) ssh.return_value = ssh_mock - + # NOTE(ralonsoh): this test doesn't cover function execution. This test + # should also check mocked function calls. model.WAIT_FOR_BOOT = 0 - status = StandaloneContextHelper.get_mgmt_ip(ssh_mock, "99", "1.1.1.1/24", {}) + status = model.StandaloneContextHelper.get_mgmt_ip( + ssh_mock, "99", "1.1.1.1/24", {}) self.assertIsNone(status) + class ServerTestCase(unittest.TestCase): NETWORKS = { @@ -257,6 +362,7 @@ class ServerTestCase(unittest.TestCase): 'cidr': '152.16.40.10/24', 'gateway_ip': '152.16.100.20'} } + def setUp(self): self.server = model.Server() @@ -282,7 +388,8 @@ class ServerTestCase(unittest.TestCase): 'xe1': ['public_0'], } } - status = self.server.generate_vnf_instance({}, self.NETWORKS, "1.1.1.1/24", 'vm_0', vnf, '00:00:00:00:00:01') + status = self.server.generate_vnf_instance( + {}, self.NETWORKS, '1.1.1.1/24', 'vm_0', vnf, '00:00:00:00:00:01') self.assertIsNotNone(status) class OvsDeployTestCase(unittest.TestCase): @@ -312,14 +419,17 @@ class OvsDeployTestCase(unittest.TestCase): self.assertIsNotNone(self.ovs_deploy.connection) @mock.patch('yardstick.benchmark.contexts.standalone.model.os') - def test_prerequisite(self, mock_ssh): + def test_prerequisite(self, *args): + # NOTE(ralonsoh): this test should check mocked function calls. self.ovs_deploy.helper = mock.Mock() self.assertIsNone(self.ovs_deploy.prerequisite()) @mock.patch('yardstick.benchmark.contexts.standalone.model.os') - def test_prerequisite(self, mock_ssh): + def test_prerequisite_2(self, *args): + # NOTE(ralonsoh): this test should check mocked function calls. Rename + # this test properly. self.ovs_deploy.helper = mock.Mock() - self.ovs_deploy.connection.execute = \ - mock.Mock(return_value=(1, "1.2.3.4 00:00:00:00:00:01", "")) + self.ovs_deploy.connection.execute = mock.Mock( + return_value=(1, '1.2.3.4 00:00:00:00:00:01', '')) self.ovs_deploy.prerequisite = mock.Mock() self.assertIsNone(self.ovs_deploy.ovs_deploy()) diff --git a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py index 5d1b0421c..e39ecf4f2 100644 --- a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py +++ b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py @@ -17,12 +17,9 @@ from __future__ import absolute_import import os import unittest -import errno import mock -from yardstick.common import constants as consts from yardstick.benchmark.contexts.standalone import ovs_dpdk -from yardstick.network_services.utils import PciAddress class OvsDpdkContextTestCase(unittest.TestCase): @@ -68,7 +65,7 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.helper = mock_helper self.ovs_dpdk.vnf_node = mock_server self.assertIsNone(self.ovs_dpdk.file_path) - self.assertEqual(self.ovs_dpdk.first_run, True) + self.assertTrue(self.ovs_dpdk.first_run) def test_init(self): self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}]) @@ -149,12 +146,9 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.assertRaises(Exception, self.ovs_dpdk.check_ovs_dpdk_env) @mock.patch('yardstick.ssh.SSH') - def test_deploy(self, mock_ssh): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock + def test_deploy(self, ssh_mock): + ssh_mock.execute.return_value = (0, "a", "") + self.ovs_dpdk.vm_deploy = False self.assertIsNone(self.ovs_dpdk.deploy()) @@ -168,22 +162,21 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.setup_ovs_bridge_add_flows = mock.Mock(return_value={}) self.ovs_dpdk.setup_ovs_dpdk_context = mock.Mock(return_value={}) self.ovs_dpdk.wait_for_vnfs_to_start = mock.Mock(return_value={}) + # TODO(elfoley): This test should check states/sideeffects instead of + # output. self.assertIsNone(self.ovs_dpdk.deploy()) - @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt') + @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt') @mock.patch('yardstick.ssh.SSH') - def test_undeploy(self, mock_ssh, mock_libvirt): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock + def test_undeploy(self, ssh_mock, _): + ssh_mock.execute.return_value = (0, "a", "") + self.ovs_dpdk.vm_deploy = False self.assertIsNone(self.ovs_dpdk.undeploy()) self.ovs_dpdk.vm_deploy = True - self.ovs_dpdk.connection = ssh_mock self.ovs_dpdk.vm_names = ['vm_0', 'vm_1'] + self.ovs_dpdk.connection = ssh_mock self.ovs_dpdk.drivers = ['vm_0', 'vm_1'] self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock() self.ovs_dpdk.networks = self.NETWORKS @@ -326,8 +319,8 @@ class OvsDpdkContextTestCase(unittest.TestCase): self.ovs_dpdk.get_vf_datas = mock.Mock(return_value="") self.assertIsNone(self.ovs_dpdk.configure_nics_for_ovs_dpdk()) - @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt') - def test__enable_interfaces(self, mock_add_ovs_interface): + @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt.add_ovs_interface') + def test__enable_interfaces(self, _): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -343,7 +336,7 @@ class OvsDpdkContextTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt') @mock.patch('yardstick.benchmark.contexts.standalone.model.Server') - def test_setup_ovs_dpdk_context(self, mock_server, mock_libvirt): + def test_setup_ovs_dpdk_context(self, _, mock_libvirt): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -372,6 +365,6 @@ class OvsDpdkContextTestCase(unittest.TestCase): mock_libvirt.build_vm_xml = mock.Mock(return_value=[6, "00:00:00:00:00:01"]) self.ovs_dpdk._enable_interfaces = mock.Mock(return_value="") mock_libvirt.virsh_create_vm = mock.Mock(return_value="") - mock_libvirt.pin_vcpu_for_perf= mock.Mock(return_value="") + mock_libvirt.pin_vcpu_for_perf = mock.Mock(return_value="") self.ovs_dpdk.vnf_node.generate_vnf_instance = mock.Mock(return_value={}) self.assertIsNotNone(self.ovs_dpdk.setup_ovs_dpdk_context()) diff --git a/tests/unit/benchmark/contexts/standalone/test_sriov.py b/tests/unit/benchmark/contexts/standalone/test_sriov.py index 50ae5fe13..7f11a7d59 100644 --- a/tests/unit/benchmark/contexts/standalone/test_sriov.py +++ b/tests/unit/benchmark/contexts/standalone/test_sriov.py @@ -17,12 +17,10 @@ from __future__ import absolute_import import os import unittest -import errno import mock -from yardstick.common import constants as consts +from yardstick import ssh from yardstick.benchmark.contexts.standalone import sriov -from yardstick.network_services.utils import PciAddress class SriovContextTestCase(unittest.TestCase): @@ -66,23 +64,23 @@ class SriovContextTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.contexts.standalone.sriov.Libvirt') @mock.patch('yardstick.benchmark.contexts.standalone.model.Server') def test___init__(self, mock_helper, mock_libvirt, mock_server): + # pylint: disable=unused-argument + # NOTE(ralonsoh): this test doesn't cover function execution. + # The pylint exception should be removed. self.sriov.helper = mock_helper self.sriov.vnf_node = mock_server self.assertIsNone(self.sriov.file_path) - self.assertEqual(self.sriov.first_run, True) + self.assertTrue(self.sriov.first_run) def test_init(self): self.sriov.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}]) self.assertIsNone(self.sriov.init(self.ATTRS)) - @mock.patch('yardstick.ssh.SSH') + @mock.patch.object(ssh, 'SSH', return_value=(0, "a", "")) def test_deploy(self, mock_ssh): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - + # pylint: disable=unused-argument + # NOTE(ralonsoh): this test doesn't cover function execution. + # The pylint exception should be removed. self.sriov.vm_deploy = False self.assertIsNone(self.sriov.deploy()) @@ -94,20 +92,16 @@ class SriovContextTestCase(unittest.TestCase): self.sriov.wait_for_vnfs_to_start = mock.Mock(return_value={}) self.assertIsNone(self.sriov.deploy()) - @mock.patch('yardstick.ssh.SSH') + @mock.patch.object(ssh, 'SSH', return_value=(0, "a", "")) @mock.patch('yardstick.benchmark.contexts.standalone.sriov.Libvirt') def test_undeploy(self, mock_libvirt, mock_ssh): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - + # pylint: disable=unused-argument + # NOTE(ralonsoh): the pylint exception should be removed. self.sriov.vm_deploy = False self.assertIsNone(self.sriov.undeploy()) self.sriov.vm_deploy = True - self.sriov.connection = ssh_mock + self.sriov.connection = mock_ssh self.sriov.vm_names = ['vm_0', 'vm_1'] self.sriov.drivers = ['vm_0', 'vm_1'] self.assertIsNone(self.sriov.undeploy()) @@ -246,27 +240,27 @@ class SriovContextTestCase(unittest.TestCase): self.sriov.drivers = [] self.sriov.networks = self.NETWORKS self.sriov.helper.get_mac_address = mock.Mock(return_value="") - self.sriov.get_vf_data = mock.Mock(return_value="") + self.sriov._get_vf_data = mock.Mock(return_value="") self.assertIsNone(self.sriov.configure_nics_for_sriov()) + @mock.patch.object(ssh, 'SSH', return_value=(0, "a", "")) @mock.patch('yardstick.benchmark.contexts.standalone.sriov.Libvirt') - def test__enable_interfaces(self, mock_libvirt): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock + def test__enable_interfaces(self, mock_libvirt, mock_ssh): + # pylint: disable=unused-argument + # NOTE(ralonsoh): the pylint exception should be removed. self.sriov.vm_deploy = True - self.sriov.connection = ssh_mock + self.sriov.connection = mock_ssh self.sriov.vm_names = ['vm_0', 'vm_1'] self.sriov.drivers = [] self.sriov.networks = self.NETWORKS - self.sriov.get_vf_data = mock.Mock(return_value="") + self.sriov._get_vf_data = mock.Mock(return_value="") self.assertIsNone(self.sriov._enable_interfaces(0, 0, ["private_0"], 'test')) @mock.patch('yardstick.benchmark.contexts.standalone.model.Server') @mock.patch('yardstick.benchmark.contexts.standalone.sriov.Libvirt') def test_setup_sriov_context(self, mock_libvirt, mock_server): + # pylint: disable=unused-argument + # NOTE(ralonsoh): the pylint exception should be removed. with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -296,7 +290,7 @@ class SriovContextTestCase(unittest.TestCase): self.sriov.vnf_node.generate_vnf_instance = mock.Mock(return_value={}) self.assertIsNotNone(self.sriov.setup_sriov_context()) - def test_get_vf_data(self): + def test__get_vf_data(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -318,5 +312,7 @@ class SriovContextTestCase(unittest.TestCase): } } self.sriov.networks = self.NETWORKS - self.sriov.helper.get_virtual_devices = mock.Mock(return_value={"0000:00:01.0": ""}) - self.assertIsNotNone(self.sriov.get_vf_data("", "0000:00:01.0", "00:00:00:00:00:01", "if0")) + self.sriov.helper.get_virtual_devices = mock.Mock( + return_value={'0000:00:01.0': ''}) + self.assertIsNotNone(self.sriov._get_vf_data( + '0000:00:01.0', '00:00:00:00:00:01', 'if0')) diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index 223d64060..f2e725df2 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -119,8 +119,12 @@ class HeatContextTestCase(unittest.TestCase): "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b") mock_template.add_security_group.assert_called_with("foo-secgroup") # mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None) - mock_template.add_router.assert_called_with("bar-fool-network-router", netattrs["external_network"], "bar-fool-network-subnet") - mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", "bar-fool-network-router", "bar-fool-network-subnet") + mock_template.add_router.assert_called_with("bar-fool-network-router", + netattrs["external_network"], + "bar-fool-network-subnet") + mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", + "bar-fool-network-router", + "bar-fool-network-subnet") @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_attrs_get(self, mock_template): diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py index 48ee01cf0..53b035b82 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -282,6 +282,178 @@ class ServerTestCase(unittest.TestCase): scheduler_hints='hints', availability_zone='zone') + def test_override_ip(self): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': [ + {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, + ], + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.interfaces = { + "xe0": { + "local_ip": "1.2.3.4", + "netmask": "255.255.255.0", + }, + "xe1": { + "local_ip": "1.2.3.5", + "netmask": "255.255.255.0" + } + } + test_server.network_ports = network_ports + + test_server.override_ip("uplink_0", {"port": "xe0"}) + self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"]) + + def test_override_ip_multiple(self): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': [ + {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, + {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, + ], + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.interfaces = { + "xe0": { + "local_ip": "1.2.3.4", + "netmask": "255.255.255.0", + }, + "xe1": { + "local_ip": "1.2.3.5", + "netmask": "255.255.255.0" + } + } + test_server.network_ports = network_ports + test_server.override_ip("uplink_0", {"port": "xe0"}) + self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"]) + + def test_override_ip_mixed(self): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': [ + 'xe0', + {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, + ], + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.interfaces = { + "xe0": { + "local_ip": "1.2.3.4", + "netmask": "255.255.255.0", + }, + "xe1": { + "local_ip": "1.2.3.5", + "netmask": "255.255.255.0" + } + } + test_server.network_ports = network_ports + test_server.override_ip("uplink_0", {"port": "xe0"}) + self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][1]["xe0"]) + + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + def test__add_instance_with_ip_override_invalid_syntax(self, mock_template): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': 'xe0', + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.network_ports = network_ports + context = type("Context", (object,), {}) + # can't use Mock because Mock.name is reserved + context.name = "context" + networks = [model.Network(n, context, {}) for n in network_ports] + + with self.assertRaises(SyntaxError): + test_server._add_instance(mock_template, 'some-server', + networks, 'hints') + + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + def test__add_instance_with_ip_override(self, mock_template): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': [ + {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, + ], + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.network_ports = network_ports + context = type("Context", (object,), {}) + # can't use Mock because Mock.name is reserved + context.name = "context" + networks = [model.Network(n, context, {}) for n in network_ports] + + test_server._add_instance(mock_template, 'some-server', + networks, 'hints') + self.assertEqual(test_server.ports, { + 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}], + 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}], + 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'}] + }) + + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + def test__add_instance_with_multiple_ip_override(self, mock_template): + network_ports = { + 'mgmt': ['mgmt'], + 'uplink_0': [ + {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, + {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, + ], + 'downlink_0': [ + {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, + ], + } + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + } + test_server = model.Server('foo', self.mock_context, attrs) + test_server.network_ports = network_ports + context = type("Context", (object,), {}) + # can't use Mock because Mock.name is reserved + context.name = "context" + networks = [model.Network(n, context, {}) for n in network_ports] + + test_server._add_instance(mock_template, 'some-server', + networks, 'hints') + self.assertEqual(test_server.ports, { + 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}], + 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}], + 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'}, + # this is not an error, we can produce this, it is left to Heat + # to detect duplicate ports and error + {'port': 'xe0', 'stack_name': 'some-server-xe0-port'}] + }) + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_with_user_data(self, mock_template): user_data = "USER_DATA" diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py index 6a9b3b157..b84cef23c 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py @@ -19,30 +19,26 @@ import unittest from yardstick.benchmark.scenarios.availability.monitor import monitor_command -@mock.patch( - 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' - '.subprocess') +@mock.patch('subprocess.check_output') class ExecuteShellTestCase(unittest.TestCase): - def test__fun_execute_shell_command_successful(self, mock_subprocess): + def test__fun_execute_shell_command_successful(self, mock_subprocess_check_output): cmd = "env" - mock_subprocess.check_output.return_value = (0, 'unittest') - exitcode, output = monitor_command._execute_shell_command(cmd) + mock_subprocess_check_output.return_value = (0, 'unittest') + exitcode, _ = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, 0) @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG') def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, - mock_subprocess): + mock_subprocess_check_output): cmd = "env" - mock_subprocess.check_output.side_effect = RuntimeError - exitcode, output = monitor_command._execute_shell_command(cmd) + mock_subprocess_check_output.side_effect = RuntimeError + exitcode, _ = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, -1) mock_log.error.assert_called_once() -@mock.patch( - 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' - '.subprocess') +@mock.patch('subprocess.check_output') class MonitorOpenstackCmdTestCase(unittest.TestCase): def setUp(self): @@ -59,24 +55,24 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): 'sla': {'max_outage_time': 5} } - def test__monitor_command_monitor_func_successful(self, mock_subprocess): + def test__monitor_command_monitor_func_successful(self, mock_subprocess_check_output): instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10}) instance.setup() - mock_subprocess.check_output.return_value = (0, 'unittest') + mock_subprocess_check_output.return_value = (0, 'unittest') ret = instance.monitor_func() - self.assertEqual(ret, True) + self.assertTrue(ret) instance._result = {"outage_time": 0} instance.verify_SLA() @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG') - def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess): - mock_subprocess.check_output.return_value = (1, 'unittest') + def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess_check_output): + mock_subprocess_check_output.return_value = (1, 'unittest') instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10}) instance.setup() - mock_subprocess.check_output.side_effect = RuntimeError + mock_subprocess_check_output.side_effect = RuntimeError ret = instance.monitor_func() - self.assertEqual(ret, False) + self.assertFalse(ret) mock_log.error.assert_called_once() instance._result = {"outage_time": 10} instance.verify_SLA() @@ -84,12 +80,13 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): @mock.patch( 'yardstick.benchmark.scenarios.availability.monitor.monitor_command' '.ssh') - def test__monitor_command_ssh_monitor_successful(self, mock_ssh, - mock_subprocess): + def test__monitor_command_ssh_monitor_successful(self, mock_ssh, mock_subprocess_check_output): + mock_subprocess_check_output.return_value = (0, 'unittest') self.config["host"] = "node1" instance = monitor_command.MonitorOpenstackCmd( self.config, self.context, {"nova-api": 10}) instance.setup() mock_ssh.SSH.from_node().execute.return_value = (0, "0", '') ret = instance.monitor_func() + self.assertTrue(ret) diff --git a/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/tests/unit/benchmark/scenarios/availability/test_serviceha.py index 4ae508958..97d534894 100644 --- a/tests/unit/benchmark/scenarios/availability/test_serviceha.py +++ b/tests/unit/benchmark/scenarios/availability/test_serviceha.py @@ -18,9 +18,6 @@ import unittest from yardstick.benchmark.scenarios.availability import serviceha -@mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor') -@mock.patch( - 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker') class ServicehaTestCase(unittest.TestCase): def setUp(self): @@ -51,27 +48,32 @@ class ServicehaTestCase(unittest.TestCase): sla = {"outage_time": 5} self.args = {"options": options, "sla": sla} - def test__serviceha_setup_run_successful(self, mock_attacker, + @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor') + @mock.patch( + 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker') + def test__serviceha_setup_run_successful(self, _, mock_monitor): p = serviceha.ServiceHA(self.args, self.ctx) p.setup() - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) mock_monitor.MonitorMgr().verify_SLA.return_value = True ret = {} p.run(ret) p.teardown() -""" - def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor): - p = serviceha.ServiceHA(self.args, self.ctx) p.setup() - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) - result = {} - result["outage_time"] = 10 - mock_monitor.Monitor().get_result.return_value = result +# def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor): +# p = serviceha.ServiceHA(self.args, self.ctx) - ret = {} - self.assertRaises(AssertionError, p.run, ret) -""" +# p.setup() +# self.assertTrue(p.setup_done) +# +# result = {} +# result["outage_time"] = 10 +# mock_monitor.Monitor().get_result.return_value = result + +# ret = {} +# self.assertRaises(AssertionError, p.run, ret) diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py index 0974f385a..548efe91b 100644 --- a/tests/unit/benchmark/scenarios/availability/test_util.py +++ b/tests/unit/benchmark/scenarios/availability/test_util.py @@ -16,36 +16,43 @@ import unittest from yardstick.benchmark.scenarios.availability import util -@mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess') + class ExecuteShellTestCase(unittest.TestCase): def setUp(self): self.param_config = {'serviceName': '@serviceName', 'value': 1} self.intermediate_variables = {'@serviceName': 'nova-api'} self.std_output = '| id | 1 |' - self.cmd_config = {'cmd':'ls','param':'-a'} + self.cmd_config = {'cmd': 'ls', 'param': '-a'} + + self._mock_subprocess = mock.patch.object(util, 'subprocess') + self.mock_subprocess = self._mock_subprocess.start() + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_subprocess.stop() - def test_util_build_command_shell(self,mock_subprocess): + def test_util_build_command_shell(self): result = util.build_shell_command(self.param_config, True, self.intermediate_variables) - self.assertEqual("nova-api" in result, True) + self.assertIn("nova-api", result) - def test_read_stdout_item(self,mock_subprocess): - result = util.read_stdout_item(self.std_output,'id') - self.assertEquals('1',result) + def test_read_stdout_item(self): + result = util.read_stdout_item(self.std_output, 'id') + self.assertEqual('1', result) - def test_buildshellparams(self,mock_subprocess): - result = util.buildshellparams(self.cmd_config,True) - self.assertEquals('/bin/bash -s {0} {1}', result) + def test_buildshellparams(self): + result = util.buildshellparams(self.cmd_config, True) + self.assertEqual('/bin/bash -s {0} {1}', result) - def test__fun_execute_shell_command_successful(self, mock_subprocess): + def test__fun_execute_shell_command_successful(self): cmd = "env" - mock_subprocess.check_output.return_value = (0, 'unittest') - exitcode, output = util.execute_shell_command(cmd) + self.mock_subprocess.check_output.return_value = (0, 'unittest') + exitcode, _ = util.execute_shell_command(cmd) self.assertEqual(exitcode, 0) - def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess): + def test__fun_execute_shell_command_fail_cmd_exception(self): cmd = "env" - mock_subprocess.check_output.side_effect = RuntimeError - exitcode, output = util.execute_shell_command(cmd) + self.mock_subprocess.check_output.side_effect = RuntimeError + exitcode, _ = util.execute_shell_command(cmd) self.assertEqual(exitcode, -1) diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py index dc52a80c7..51ffd2488 100644 --- a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py +++ b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py @@ -74,7 +74,7 @@ class CyclictestTestCase(unittest.TestCase): c.setup() self.assertIsNotNone(c.guest) self.assertIsNotNone(c.host) - self.assertEqual(c.setup_done, True) + self.assertTrue(c.setup_done) def test_cyclictest_successful_no_sla(self, mock_ssh): result = {} diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py index 1f0ff3c29..fb55b809f 100644 --- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py +++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py @@ -71,7 +71,7 @@ class QemuMigrateTestCase(unittest.TestCase): q.setup() self.assertIsNotNone(q.host) - self.assertEqual(q.setup_done, True) + self.assertTrue(q.setup_done) def test_qemu_migrate_successful_no_sla(self, mock_ssh): result = {} diff --git a/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py b/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py new file mode 100644 index 000000000..c428e1fb8 --- /dev/null +++ b/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd 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 +############################################################################## + +# Unittest for yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.SpecCPUforVM + +from __future__ import absolute_import + +import unittest + +import mock + +from yardstick.benchmark.scenarios.compute import spec_cpu_for_vm + + +@mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu_for_vm.ssh') +class SpecCPUforVMTestCase(unittest.TestCase): + + def setUp(self): + self.ctx = { + 'host': { + 'ip': '172.16.0.137', + 'user': 'root', + 'key_filename': "mykey.key" + } + } + + self.result = {} + + def test_spec_cpu_successful_setup(self, mock_ssh): + + options = { + "SPECint_benchmark": "perlbench", + "runspec_tune": "all", + "output_format": "all", + "runspec_iterations": "1", + "runspec_size": "test" + } + args = {"options": options} + s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx) + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + + s.setup() + self.assertIsNotNone(s.client) + self.assertTrue(s.setup_done, True) + + def test_spec_cpu_successful__run_no_sla(self, mock_ssh): + + options = { + "SPECint_benchmark": "perlbench", + "runspec_tune": "all", + "output_format": "all" + } + args = {"options": options} + s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx) + + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().get.return_value = (0, '', '') + s.run(self.result) + expected_result = {'SPEC_CPU_result': ''} + self.assertEqual(self.result, expected_result) + + def test_spec_cpu_unsuccessful_script_error(self, mock_ssh): + options = { + "benchmark_subset": "int" + } + args = {"options": options} + s = spec_cpu_for_vm.SpecCPUforVM(args, self.ctx) + + mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') + self.assertRaises(RuntimeError, s.run, self.result) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/tests/unit/benchmark/scenarios/compute/test_unixbench.py index 7d071e91c..fec355b45 100644 --- a/tests/unit/benchmark/scenarios/compute/test_unixbench.py +++ b/tests/unit/benchmark/scenarios/compute/test_unixbench.py @@ -40,7 +40,7 @@ class UnixbenchTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(u.client) - self.assertEqual(u.setup_done, True) + self.assertTrue(u.setup_done) def test_unixbench_successful_no_sla(self, mock_ssh): diff --git a/tests/unit/benchmark/scenarios/dummy/test_dummy.py b/tests/unit/benchmark/scenarios/dummy/test_dummy.py index 560675d09..bc5131806 100644 --- a/tests/unit/benchmark/scenarios/dummy/test_dummy.py +++ b/tests/unit/benchmark/scenarios/dummy/test_dummy.py @@ -24,11 +24,11 @@ class DummyTestCase(unittest.TestCase): self.assertIsNone(self.test_context.scenario_cfg) self.assertIsNone(self.test_context.context_cfg) - self.assertEqual(self.test_context.setup_done, False) + self.assertFalse(self.test_context.setup_done) def test_run(self): result = {} self.test_context.run(result) self.assertEqual(result["hello"], "yardstick") - self.assertEqual(self.test_context.setup_done, True) + self.assertTrue(self.test_context.setup_done) diff --git a/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py index bdf1e66e5..1dd461d41 100644 --- a/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py +++ b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py @@ -14,7 +14,8 @@ from yardstick.benchmark.scenarios.lib.check_numa_info import CheckNumaInfo class CheckNumaInfoTestCase(unittest.TestCase): - @mock.patch('yardstick.benchmark.scenarios.lib.check_numa_info.CheckNumaInfo._check_vm2_status') + @mock.patch( + 'yardstick.benchmark.scenarios.lib.check_numa_info.CheckNumaInfo._check_vm2_status') def test_check_numa_info(self, mock_check_vm2): scenario_cfg = {'info1': {}, 'info2': {}} obj = CheckNumaInfo(scenario_cfg, {}) @@ -37,7 +38,7 @@ class CheckNumaInfoTestCase(unittest.TestCase): scenario_cfg = {'info1': info1, 'info2': info2} obj = CheckNumaInfo(scenario_cfg, {}) status = obj._check_vm2_status(info1, info2) - self.assertEqual(status, True) + self.assertTrue(status) def test_check_vm2_status_length_gt_1(self): info1 = { @@ -55,7 +56,7 @@ class CheckNumaInfoTestCase(unittest.TestCase): scenario_cfg = {'info1': info1, 'info2': info2} obj = CheckNumaInfo(scenario_cfg, {}) status = obj._check_vm2_status(info1, info2) - self.assertEqual(status, False) + self.assertFalse(status) def test_check_vm2_status_length_not_in_set(self): info1 = { @@ -73,7 +74,7 @@ class CheckNumaInfoTestCase(unittest.TestCase): scenario_cfg = {'info1': info1, 'info2': info2} obj = CheckNumaInfo(scenario_cfg, {}) status = obj._check_vm2_status(info1, info2) - self.assertEqual(status, False) + self.assertFalse(status) def main(): diff --git a/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/tests/unit/benchmark/scenarios/lib/test_create_volume.py index fc633139e..ef2c0ccaf 100644 --- a/tests/unit/benchmark/scenarios/lib/test_create_volume.py +++ b/tests/unit/benchmark/scenarios/lib/test_create_volume.py @@ -9,28 +9,79 @@ import unittest import mock -from yardstick.benchmark.scenarios.lib.create_volume import CreateVolume +import yardstick.benchmark.scenarios.lib.create_volume class CreateVolumeTestCase(unittest.TestCase): + def setUp(self): + self._mock_cinder_client = mock.patch( + 'yardstick.common.openstack_utils.get_cinder_client') + self.mock_cinder_client = self._mock_cinder_client.start() + self._mock_glance_client = mock.patch( + 'yardstick.common.openstack_utils.get_glance_client') + self.mock_glance_client = self._mock_glance_client.start() + self.addCleanup(self._stop_mock) + + self.scenario_cfg = { + "options" : + { + 'volume_name': 'yardstick_test_volume_01', + 'size': '256', + 'image': 'cirros-0.3.5' + } + } + + self.scenario = ( + yardstick.benchmark.scenarios.lib.create_volume.CreateVolume( + scenario_cfg=self.scenario_cfg, + context_cfg={})) + + def _stop_mock(self): + self._mock_cinder_client.stop() + self._mock_glance_client.stop() + + def test_init(self): + self.mock_cinder_client.return_value = "All volumes are equal" + self.mock_glance_client.return_value = "Images are more equal" + + expected_vol_name = self.scenario_cfg["options"]["volume_name"] + expected_vol_size = self.scenario_cfg["options"]["size"] + expected_im_name = self.scenario_cfg["options"]["image"] + expected_im_id = None + + scenario = ( + yardstick.benchmark.scenarios.lib.create_volume.CreateVolume( + scenario_cfg=self.scenario_cfg, + context_cfg={})) + + self.assertEqual(expected_vol_name, scenario.volume_name) + self.assertEqual(expected_vol_size, scenario.volume_size) + self.assertEqual(expected_im_name, scenario.image_name) + self.assertEqual(expected_im_id, scenario.image_id) + self.assertEqual("All volumes are equal", scenario.cinder_client) + self.assertEqual("Images are more equal", scenario.glance_client) + + def test_setup(self): + self.assertFalse(self.scenario.setup_done) + self.scenario.setup() + self.assertTrue(self.scenario.setup_done) + @mock.patch('yardstick.common.openstack_utils.create_volume') @mock.patch('yardstick.common.openstack_utils.get_image_id') - @mock.patch('yardstick.common.openstack_utils.get_cinder_client') - @mock.patch('yardstick.common.openstack_utils.get_glance_client') - def test_create_volume(self, mock_get_glance_client, mock_get_cinder_client, mock_image_id, mock_create_volume): - options = { - 'volume_name': 'yardstick_test_volume_01', - 'size': '256', - 'image': 'cirros-0.3.5' - } - args = {"options": options} - obj = CreateVolume(args, {}) - obj.run({}) - self.assertTrue(mock_create_volume.called) - self.assertTrue(mock_image_id.called) - self.assertTrue(mock_get_glance_client.called) - self.assertTrue(mock_get_cinder_client.called) + def test_run(self, mock_image_id, mock_create_volume): + self.scenario.run() + + mock_image_id.assert_called_once() + mock_create_volume.assert_called_once() + + @mock.patch.object( + yardstick.benchmark.scenarios.lib.create_volume.CreateVolume, 'setup') + def test_run_no_setup(self, scenario_setup): + self.scenario.setup_done = False + self.scenario.run() + scenario_setup.assert_called_once() + def main(): unittest.main() diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf.py b/tests/unit/benchmark/scenarios/networking/test_netperf.py index d0f862fb5..d82a00931 100755 --- a/tests/unit/benchmark/scenarios/networking/test_netperf.py +++ b/tests/unit/benchmark/scenarios/networking/test_netperf.py @@ -48,7 +48,7 @@ class NetperfTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_netperf_successful_no_sla(self, mock_ssh): diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py index 62874cc44..8be9bb94d 100755 --- a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py +++ b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py @@ -48,7 +48,7 @@ class NetperfNodeTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_netperf_node_successful_no_sla(self, mock_ssh): diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py index fe44cfdf4..4b58e06c1 100644 --- a/tests/unit/benchmark/scenarios/networking/test_nstat.py +++ b/tests/unit/benchmark/scenarios/networking/test_nstat.py @@ -19,6 +19,7 @@ import mock from yardstick.benchmark.scenarios.networking import nstat + @mock.patch('yardstick.benchmark.scenarios.networking.nstat.ssh') class NstatTestCase(unittest.TestCase): @@ -38,7 +39,7 @@ class NstatTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(n.client) - self.assertEqual(n.setup_done, True) + self.assertTrue(n.setup_done) def test_nstat_successful_no_sla(self, mock_ssh): @@ -51,17 +52,17 @@ class NstatTestCase(unittest.TestCase): n = nstat.Nstat(args, self.ctx) result = {} - 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' + 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 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') n.run(result) expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318, - "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2, - "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2, - "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319, - "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0, - "Icmp_message_error_rate": 0.0, "UdpInErrors": 0} + "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2, + "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2, + "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319, + "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0, + "Icmp_message_error_rate": 0.0, "UdpInErrors": 0} self.assertEqual(result, expected_result) def test_nstat_successful_sla(self, mock_ssh): @@ -79,17 +80,17 @@ class NstatTestCase(unittest.TestCase): n = nstat.Nstat(args, self.ctx) result = {} - 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' + 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 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') n.run(result) expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318, - "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2, - "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2, - "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319, - "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0, - "Icmp_message_error_rate": 0.0, "UdpInErrors": 0} + "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2, + "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2, + "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319, + "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0, + "Icmp_message_error_rate": 0.0, "UdpInErrors": 0} self.assertEqual(result, expected_result) def test_nstat_unsuccessful_cmd_error(self, mock_ssh): @@ -114,5 +115,6 @@ class NstatTestCase(unittest.TestCase): def main(): unittest.main() + if __name__ == '__main__': main() diff --git a/tests/unit/benchmark/scenarios/networking/test_ping6.py b/tests/unit/benchmark/scenarios/networking/test_ping6.py index ecce7cee5..d2be6f576 100644 --- a/tests/unit/benchmark/scenarios/networking/test_ping6.py +++ b/tests/unit/benchmark/scenarios/networking/test_ping6.py @@ -59,7 +59,7 @@ class PingTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '0', '') p.setup() - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh') def test_ping_successful_no_sla(self, mock_ssh): diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py index 3928aacde..005b53177 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py @@ -50,7 +50,7 @@ class PktgenTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_pktgen_successful_iptables_setup(self, mock_ssh): @@ -632,9 +632,13 @@ class PktgenTestCase(unittest.TestCase): 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} - } + '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() @@ -659,9 +663,13 @@ class PktgenTestCase(unittest.TestCase): 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} - } + 'options': { + 'packetsize': 60, + 'number_of_ports': 10, + 'duration': 20, + 'multiqueue': True}, + 'sla': { + 'max_ppm': 1}} result = {} p = pktgen.Pktgen(args, self.ctx) @@ -683,7 +691,7 @@ class PktgenTestCase(unittest.TestCase): mock_result3 = mock.Mock() mock_result3.return_value = 4 - p._enable_ovs_multiqueue = mock_result3 + p._enable_ovs_multiqueue = mock_result3 mock_result4 = mock.Mock() p._setup_irqmapping_ovs = mock_result4 @@ -704,9 +712,13 @@ class PktgenTestCase(unittest.TestCase): def test_pktgen_run_with_sriov_multiqueque(self, mock_ssh): args = { - 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True}, - 'sla': {'max_ppm': 1} - } + 'options': { + 'packetsize': 60, + 'number_of_ports': 10, + 'duration': 20, + 'multiqueue': True}, + 'sla': { + 'max_ppm': 1}} result = {} p = pktgen.Pktgen(args, self.ctx) @@ -739,8 +751,10 @@ class PktgenTestCase(unittest.TestCase): expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) + def main(): unittest.main() + if __name__ == '__main__': main() diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py index b4b87522c..c9eec4b94 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py @@ -20,8 +20,6 @@ import yardstick.common.utils as utils from yardstick.benchmark.scenarios.networking import pktgen_dpdk -@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.time') -@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh') class PktgenDPDKLatencyTestCase(unittest.TestCase): def setUp(self): @@ -39,7 +37,20 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): } } - def test_pktgen_dpdk_successful_setup(self, mock_ssh, mock_time): + self._mock_ssh = mock.patch( + 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh') + self.mock_ssh = self._mock_ssh.start() + self._mock_time = mock.patch( + 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.time') + self.mock_time = self._mock_time.start() + + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_ssh.stop() + self._mock_time.stop() + + def test_pktgen_dpdk_successful_setup(self): args = { 'options': {'packetsize': 60}, @@ -47,66 +58,66 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) p.setup() - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) - def test_pktgen_dpdk_successful_get_port_ip(self, mock_ssh, mock_time): + def test_pktgen_dpdk_successful_get_port_ip(self): args = { 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH.from_node() + p.server = self.mock_ssh.SSH.from_node() - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') utils.get_port_ip(p.server, "eth1") - mock_ssh.SSH.from_node().execute.assert_called_with( + self.mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ") - def test_pktgen_dpdk_unsuccessful_get_port_ip(self, mock_ssh, mock_time): + def test_pktgen_dpdk_unsuccessful_get_port_ip(self): args = { 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH.from_node() + p.server = self.mock_ssh.SSH.from_node() - mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1") - def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh, mock_time): + def test_pktgen_dpdk_successful_get_port_mac(self): args = { 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH.from_node() + p.server = self.mock_ssh.SSH.from_node() - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') utils.get_port_mac(p.server, "eth1") - mock_ssh.SSH.from_node().execute.assert_called_with( + self.mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ") - def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh, mock_time): + def test_pktgen_dpdk_unsuccessful_get_port_mac(self): args = { 'options': {'packetsize': 60}, } p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH.from_node() + p.server = self.mock_ssh.SSH.from_node() - mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1") - def test_pktgen_dpdk_successful_no_sla(self, mock_ssh, mock_time): + def test_pktgen_dpdk_successful_no_sla(self): args = { 'options': {'packetsize': 60}, @@ -116,7 +127,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) 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.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) # with python 3 we get float, might be due python division changes @@ -125,7 +136,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): delta = result['avg_latency'] - 132 self.assertLessEqual(delta, 1) - def test_pktgen_dpdk_successful_sla(self, mock_ssh, mock_time): + def test_pktgen_dpdk_successful_sla(self): args = { 'options': {'packetsize': 60}, @@ -136,13 +147,13 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): 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, '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') p.run(result) self.assertEqual(result, {"avg_latency": 100}) - def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh, mock_time): + def test_pktgen_dpdk_unsuccessful_sla(self): args = { 'options': {'packetsize': 60}, @@ -152,14 +163,14 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - p.server = mock_ssh.SSH.from_node() - p.client = mock_ssh.SSH.from_node() + p.server = self.mock_ssh.SSH.from_node() + p.client = self.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.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) - def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh, mock_time): + def test_pktgen_dpdk_unsuccessful_script_error(self): args = { 'options': {'packetsize': 60}, @@ -169,7 +180,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx) - mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py index d34097008..c2e35af75 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py @@ -20,7 +20,6 @@ from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh') -@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time') class PktgenDPDKTestCase(unittest.TestCase): def setUp(self): @@ -37,7 +36,16 @@ class PktgenDPDKTestCase(unittest.TestCase): } } - def test_pktgen_dpdk_throughput_successful_setup(self, mock__time, mock_ssh): + 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}, } @@ -47,9 +55,9 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, '', '') self.assertIsNotNone(p.server) self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) - def test_pktgen_dpdk_throughput_successful_no_sla(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, } @@ -75,7 +83,7 @@ class PktgenDPDKTestCase(unittest.TestCase): expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) - def test_pktgen_dpdk_throughput_successful_sla(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 10000} @@ -101,7 +109,7 @@ class PktgenDPDKTestCase(unittest.TestCase): expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) - def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 1000} @@ -122,7 +130,8 @@ class PktgenDPDKTestCase(unittest.TestCase): 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__time, mock_ssh): + def test_pktgen_dpdk_throughput_unsuccessful_script_error( + self, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 1000} @@ -137,7 +146,7 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) - def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -151,7 +160,7 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.assert_called_with( "ip a | grep eth1 2>/dev/null") - def test_pktgen_dpdk_throughput_dpdk_setup(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -163,9 +172,9 @@ class PktgenDPDKTestCase(unittest.TestCase): p.dpdk_setup() - self.assertEqual(p.dpdk_setup_done, True) + self.assertTrue(p.dpdk_setup_done) - def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock__time, mock_ssh): + def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -180,8 +189,10 @@ class PktgenDPDKTestCase(unittest.TestCase): 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() diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py index cbbfc2b34..be8ac55d0 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py @@ -66,7 +66,7 @@ class VsperfTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_vsperf_teardown(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) @@ -77,10 +77,10 @@ class VsperfTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) p.teardown() - self.assertEqual(p.setup_done, False) + self.assertFalse(p.setup_done) def test_vsperf_run_ok(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py index 5759f0a90..fbe3ed804 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py @@ -27,7 +27,6 @@ from yardstick.benchmark.scenarios.networking import vsperf_dpdk @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.subprocess') -@mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh') class VsperfDPDKTestCase(unittest.TestCase): def setUp(self): @@ -63,7 +62,16 @@ class VsperfDPDKTestCase(unittest.TestCase): } } - def test_vsperf_dpdk_setup(self, mock_ssh, mock_subprocess): + self._mock_ssh = mock.patch( + 'yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh') + self.mock_ssh = self._mock_ssh.start() + + self.addCleanup(self._cleanup) + + def _cleanup(self): + self._mock_ssh.stop() + + def test_vsperf_dpdk_setup(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -71,9 +79,9 @@ class VsperfDPDKTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) - def test_vsperf_dpdk_teardown(self, mock_ssh, mock_subprocess): + def test_vsperf_dpdk_teardown(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -81,12 +89,12 @@ class VsperfDPDKTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) p.teardown() - self.assertEqual(p.setup_done, False) + self.assertFalse(p.setup_done) - def test_vsperf_dpdk_is_dpdk_setup_no(self, mock_ssh, mock_subprocess): + def test_vsperf_dpdk_is_dpdk_setup_no(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -94,15 +102,15 @@ class VsperfDPDKTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # is_dpdk_setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') result = p._is_dpdk_setup() - self.assertEqual(result, False) + self.assertFalse(result) - def test_vsperf_dpdk_is_dpdk_setup_yes(self, mock_ssh, mock_subprocess): + def test_vsperf_dpdk_is_dpdk_setup_yes(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -110,16 +118,16 @@ class VsperfDPDKTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # is_dpdk_setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') result = p._is_dpdk_setup() - self.assertEqual(result, True) + self.assertTrue(result) - @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') - def test_vsperf_dpdk_dpdk_setup_first(self, mock_time, mock_ssh, mock_subprocess): + @mock.patch('time.sleep') + def test_vsperf_dpdk_dpdk_setup_first(self, _, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks @@ -127,61 +135,61 @@ class VsperfDPDKTestCase(unittest.TestCase): p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # is_dpdk_setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') p.dpdk_setup() - self.assertEqual(p._is_dpdk_setup(), False) - self.assertEqual(p.dpdk_setup_done, True) + self.assertFalse(p._is_dpdk_setup()) + self.assertTrue(p.dpdk_setup_done) - @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') - def test_vsperf_dpdk_dpdk_setup_next(self, mock_time, mock_ssh, mock_subprocess): + @mock.patch('time.sleep') + def test_vsperf_dpdk_dpdk_setup_next(self, _, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) p.dpdk_setup() - self.assertEqual(p._is_dpdk_setup(), True) - self.assertEqual(p.dpdk_setup_done, True) + self.assertTrue(p._is_dpdk_setup()) + self.assertTrue(p.dpdk_setup_done) - @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') - def test_vsperf_dpdk_dpdk_setup_fail(self, mock_time, mock_ssh, mock_subprocess): + @mock.patch('time.sleep') + def test_vsperf_dpdk_dpdk_setup_fail(self, _, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - mock_ssh.SSH.from_node().execute.return_value = (1, '', '') - self.assertEqual(p.setup_done, True) + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.assertTrue(p.setup_done) self.assertRaises(RuntimeError, p.dpdk_setup) - @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time') - def test_vsperf_dpdk_run_ok(self, mock_time, mock_ssh, mock_subprocess): + @mock.patch('time.sleep') + def test_vsperf_dpdk_run_ok(self, _, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # run() specific mocks mock_subprocess.call().execute.return_value = None - mock_ssh.SSH.from_node().execute.return_value = ( + self.mock_ssh.SSH.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') result = {} @@ -189,42 +197,41 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(result['throughput_rx_fps'], '14797660.000') - def test_vsperf_dpdk_run_falied_vsperf_execution(self, mock_ssh, - mock_subprocess): + def test_vsperf_dpdk_run_falied_vsperf_execution(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # run() specific mocks mock_subprocess.call().execute.return_value = None mock_subprocess.call().execute.return_value = None - mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) - def test_vsperf_dpdk_run_falied_csv_report(self, mock_ssh, mock_subprocess): + def test_vsperf_dpdk_run_falied_csv_report(self, mock_subprocess): p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) # run() specific mocks mock_subprocess.call().execute.return_value = None mock_subprocess.call().execute.return_value = None - mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) diff --git a/tests/unit/benchmark/scenarios/parser/test_parser.py b/tests/unit/benchmark/scenarios/parser/test_parser.py index 59b98a092..ee2bbc07d 100644 --- a/tests/unit/benchmark/scenarios/parser/test_parser.py +++ b/tests/unit/benchmark/scenarios/parser/test_parser.py @@ -9,50 +9,67 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.parser.Parser - -from __future__ import absolute_import +import subprocess import unittest - import mock + from oslo_serialization import jsonutils from yardstick.benchmark.scenarios.parser import parser -@mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess') class ParserTestCase(unittest.TestCase): def setUp(self): - pass - - def test_parser_successful_setup(self, mock_subprocess): - - p = parser.Parser({}, {}) - mock_subprocess.call().return_value = 0 - p.setup() - self.assertEqual(p.setup_done, True) - - def test_parser_successful(self, mock_subprocess): args = { 'options': {'yangfile': '/root/yardstick/samples/yang.yaml', 'toscafile': '/root/yardstick/samples/tosca.yaml'}, } - p = parser.Parser(args, {}) + self.scenario = parser.Parser(scenario_cfg=args, context_cfg={}) + + self._mock_popen = mock.patch.object(subprocess, 'Popen') + self.mock_popen = self._mock_popen.start() + self._mock_call = mock.patch.object(subprocess, 'call') + self.mock_call = self._mock_call.start() + + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_popen.stop() + self._mock_call.stop() + + def test_setup_successful(self): + + self.mock_call.return_value = 0 + self.scenario.setup() + self.assertTrue(self.scenario.setup_done) + + def test_run_successful(self): + result = {} - mock_subprocess.call().return_value = 0 - sample_output = '{"yangtotosca": "success"}' - p.run(result) - expected_result = jsonutils.loads(sample_output) + self.mock_popen().returncode = 0 + + expected_result = jsonutils.loads('{"yangtotosca": "success"}') + + self.scenario.run(result) + self.assertEqual(result, expected_result) + + def test_run_fail(self): + result = {} + + self.mock_popen().returncode = 1 + expected_result = jsonutils.loads('{"yangtotosca": "fail"}') + + self.scenario.run(result) + self.assertEqual(result, expected_result) - def test_parser_teardown_successful(self, mock_subprocess): + def test_teardown_successful(self): - p = parser.Parser({}, {}) - mock_subprocess.call().return_value = 0 - p.teardown() - self.assertEqual(p.teardown_done, True) + self.mock_call.return_value = 0 + self.scenario.teardown() + self.assertTrue(self.scenario.teardown_done) def main(): diff --git a/tests/unit/benchmark/scenarios/storage/test_fio.py b/tests/unit/benchmark/scenarios/storage/test_fio.py index 17594b9f4..0cffea224 100644 --- a/tests/unit/benchmark/scenarios/storage/test_fio.py +++ b/tests/unit/benchmark/scenarios/storage/test_fio.py @@ -53,7 +53,7 @@ class FioTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_fio_job_file_successful_setup(self, mock_ssh): @@ -67,7 +67,7 @@ class FioTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') self.assertIsNotNone(p.client) - self.assertEqual(p.setup_done, True) + self.assertTrue(p.setup_done) def test_fio_successful_no_sla(self, mock_ssh): |