diff options
Diffstat (limited to 'tests/unit/benchmark/contexts/standalone/test_model.py')
-rw-r--r-- | tests/unit/benchmark/contexts/standalone/test_model.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py index a8c54f193..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,9 +12,6 @@ # 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 @@ -24,9 +19,9 @@ import mock from xml.etree import ElementTree +from yardstick.benchmark.contexts.standalone.model import Libvirt from yardstick.benchmark.contexts.standalone import model from yardstick.network_services import utils -from yardstick.network_services.helpers import cpu XML_SAMPLE = """<?xml version="1.0"?> @@ -185,6 +180,8 @@ class ModelLibvirtTestCase(unittest.TestCase): *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) @@ -193,7 +190,7 @@ class ModelLibvirtTestCase(unittest.TestCase): ssh.return_value = ssh_mock mock_create_snapshot_qemu.return_value = "0.img" - status = model.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): @@ -202,21 +199,23 @@ class ModelLibvirtTestCase(unittest.TestCase): ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - # NOTE(ralonsoh): this test doesn't cover function execution. This test - # should also check mocked function calls. - model.Libvirt.update_interrupts_hugepages_perf(ssh_mock) - - @mock.patch.object(cpu.CpuSysCores, 'get_core_socket') - def test_pin_vcpu_for_perf(self, mock_get_core_socket): - mock_get_core_socket.return_value = { - 'cores_per_socket': 1, - 'thread_per_core': 1, - '0': [1, 2] - } - # NOTE(ralonsoh): this test doesn't cover function execution. This - # function needs more tests. - model.Libvirt.pin_vcpu_for_perf(mock.Mock()) - + # 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.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, 4) + self.assertIsNotNone(status) class StandaloneContextHelperTestCase(unittest.TestCase): @@ -268,8 +267,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase): 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" # NOTE(ralonsoh): this test doesn't cover function execution. This test @@ -317,6 +315,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase): @mock.patch('yardstick.ssh.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( @@ -330,6 +329,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase): @mock.patch('yardstick.ssh.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 = \ |