aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts/standalone/test_model.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark/contexts/standalone/test_model.py')
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_model.py75
1 files changed, 48 insertions, 27 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py
index 31ec2b7d1..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"?>
@@ -134,9 +129,9 @@ class ModelLibvirtTestCase(unittest.TestCase):
as mock_parse:
xml = copy.deepcopy(self.xml)
mock_parse.return_value = xml
- vf_pci = '0001:05:04.2'
+ vm_pci = '0001:05:04.2'
model.Libvirt.add_sriov_interfaces(
- self.pci_address_str, vf_pci, self.mac, xml_input)
+ 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')
@@ -145,8 +140,29 @@ class ModelLibvirtTestCase(unittest.TestCase):
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.assertIsNotNone(interface.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"
@@ -164,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)
@@ -172,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):
@@ -181,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):
@@ -247,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
@@ -296,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(
@@ -309,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 = \