diff options
author | Emma Foley <emma.l.foley@intel.com> | 2017-11-29 22:56:21 +0000 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-02-12 16:57:56 +0000 |
commit | ba4e9e6e47bd10ecc803bab920178ea973c2fa86 (patch) | |
tree | 54576c199cabe8ccc29d04eedfe0e4f88b2bd598 /tests/unit/benchmark/contexts/standalone | |
parent | babe3cc2882e19c6dafdbf41d502d7ba5560635a (diff) |
Move tests: unit/benchmark
* Fix pylint errors
* Add TODOs
Some errors are ignored locally, as they were a symptom of other problems.
These issues have been flagged with a TODO, and should be fixed later.
Change-Id: I30eb4b0aafe0575d0cddbc946108291f21a98ed8
Jira: YARDSTICK-837
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/benchmark/contexts/standalone')
8 files changed, 0 insertions, 1273 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/__init__.py b/tests/unit/benchmark/contexts/standalone/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/unit/benchmark/contexts/standalone/__init__.py +++ /dev/null diff --git a/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml deleted file mode 100644 index 2e501a6af..000000000 --- a/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml +++ /dev/null @@ -1,37 +0,0 @@ -############################################################################## -# 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 -############################################################################## -nodes: -- - name: node1 - role: Controller - ip: 10.229.47.137 - user: root - key_filename: /root/.yardstick_key -- - name: node1 - role: Controller - ip: 10.229.47.138 - user: root - key_filename: /root/.yardstick_key - -- - name: node5 - role: Sriov - ip: 10.229.47.140 - user: root - password: password - key_filename: /root/.yardstick_key - -- - name: node5 - role: OvsDpdk - ip: 10.229.47.140 - user: root - password: password - key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/standalone/nodes_ovs_dpdk_sample.yaml b/tests/unit/benchmark/contexts/standalone/nodes_ovs_dpdk_sample.yaml deleted file mode 100644 index 0f51dbe63..000000000 --- a/tests/unit/benchmark/contexts/standalone/nodes_ovs_dpdk_sample.yaml +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################## -# 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 -############################################################################## -nodes: -- - name: node1 - role: Controller - ip: 10.229.47.137 - user: root - key_filename: /root/.yardstick_key -- - name: node2 - role: Controller - ip: 10.229.47.138 - user: root - key_filename: /root/.yardstick_key -- - name: node3 - role: Compute - ip: 10.229.47.139 - user: root - key_filename: /root/.yardstick_key -- - name: node4 - role: Baremetal - ip: 10.229.47.140 - user: root - key_filename: /root/.yardstick_key -- - name: node5 - role: OvsDpdk - ip: 10.229.47.140 - user: root - password: password - key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/standalone/nodes_sample.yaml b/tests/unit/benchmark/contexts/standalone/nodes_sample.yaml deleted file mode 100644 index 8d50c3aea..000000000 --- a/tests/unit/benchmark/contexts/standalone/nodes_sample.yaml +++ /dev/null @@ -1,33 +0,0 @@ -############################################################################## -# 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 -############################################################################## -nodes: -- - name: node1 - role: Controller - ip: 10.229.47.137 - user: root - key_filename: /root/.yardstick_key -- - name: node2 - role: Controller - ip: 10.229.47.138 - user: root - key_filename: /root/.yardstick_key -- - name: node3 - role: Compute - ip: 10.229.47.139 - user: root - key_filename: /root/.yardstick_key -- - name: node4 - role: Baremetal - ip: 10.229.47.140 - user: root - key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/standalone/nodes_sriov_sample.yaml b/tests/unit/benchmark/contexts/standalone/nodes_sriov_sample.yaml deleted file mode 100644 index 1c43b8725..000000000 --- a/tests/unit/benchmark/contexts/standalone/nodes_sriov_sample.yaml +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################## -# 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 -############################################################################## -nodes: -- - name: node1 - role: Controller - ip: 10.229.47.137 - user: root - key_filename: /root/.yardstick_key -- - name: node2 - role: Controller - ip: 10.229.47.138 - user: root - key_filename: /root/.yardstick_key -- - name: node3 - role: Compute - ip: 10.229.47.139 - user: root - key_filename: /root/.yardstick_key -- - name: node4 - role: Baremetal - ip: 10.229.47.140 - user: root - key_filename: /root/.yardstick_key -- - name: node5 - role: Sriov - ip: 10.229.47.140 - user: root - password: password - key_filename: /root/.yardstick_key diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py deleted file mode 100644 index 6090356b6..000000000 --- a/tests/unit/benchmark/contexts/standalone/test_model.py +++ /dev/null @@ -1,435 +0,0 @@ -# Copyright (c) 2016-2017 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import copy -import os -import unittest -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 - - -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.return_value = ssh_mock - # 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.return_value = ssh_mock - # 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.return_value = ssh_mock - # 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" - 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 - image = model.Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") - self.assertEqual(image, result) - - @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) - ssh_mock.execute = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - mock_create_snapshot_qemu.return_value = "0.img" - - 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): - 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 - # 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): - - NODE_SAMPLE = "nodes_sample.yaml" - NODE_SRIOV_SAMPLE = "nodes_sriov_sample.yaml" - - NETWORKS = { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'private_0': { - 'phy_port': "0000:05:00.0", - 'vpci': "0000:00:07.0", - 'cidr': '152.16.100.10/24', - 'gateway_ip': '152.16.100.20'}, - 'public_0': { - 'phy_port': "0000:05:00.1", - 'vpci': "0000:00:08.0", - 'cidr': '152.16.40.10/24', - 'gateway_ip': '152.16.100.20'} - } - - def setUp(self): - self.helper = model.StandaloneContextHelper() - - def test___init__(self): - self.assertIsNone(self.helper.file_path) - - def test_install_req_libs(self): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "a", "")) - ssh.return_value = ssh_mock - # 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: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "i40e", "")) - ssh.return_value = ssh_mock - # 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.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.return_value = ssh_mock - mock_get_kernel_module.return_value = "i40e" - # 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" - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, pattern, "")) - ssh.return_value = ssh_mock - # 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__)) - file_path = os.path.join(curr_path, filename) - return file_path - - def test_read_config_file(self): - self.helper.file_path = self._get_file_abspath(self.NODE_SAMPLE) - status = self.helper.read_config_file() - self.assertIsNotNone(status) - - 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.helper.file_path = self._get_file_abspath(self.NODE_SAMPLE) - 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 = model.StandaloneContextHelper.get_mac_address() - self.assertIsNotNone(status) - - @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( - return_value=(1, "1.2.3.4 00:00:00:00:00:01", "")) - ssh.return_value = ssh_mock - # 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, *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 = model.StandaloneContextHelper.get_mgmt_ip( - ssh_mock, "99", "1.1.1.1/24", {}) - self.assertIsNone(status) - - -class ServerTestCase(unittest.TestCase): - - NETWORKS = { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'private_0': { - 'phy_port': "0000:05:00.0", - 'vpci': "0000:00:07.0", - 'driver': 'i40e', - 'mac': '', - 'cidr': '152.16.100.10/24', - 'gateway_ip': '152.16.100.20'}, - 'public_0': { - 'phy_port': "0000:05:00.1", - 'vpci': "0000:00:08.0", - 'driver': 'i40e', - 'mac': '', - 'cidr': '152.16.40.10/24', - 'gateway_ip': '152.16.100.20'} - } - - def setUp(self): - self.server = model.Server() - - def test___init__(self): - self.assertIsNotNone(self.server) - - def test_build_vnf_interfaces(self): - vnf = { - "network_ports": { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'xe0': ['private_0'], - 'xe1': ['public_0'], - } - } - status = model.Server.build_vnf_interfaces(vnf, self.NETWORKS) - self.assertIsNotNone(status) - - def test_generate_vnf_instance(self): - vnf = { - "network_ports": { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'xe0': ['private_0'], - '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') - self.assertIsNotNone(status) - -class OvsDeployTestCase(unittest.TestCase): - - NETWORKS = { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'private_0': { - 'phy_port': "0000:05:00.0", - 'vpci': "0000:00:07.0", - 'driver': 'i40e', - 'mac': '', - 'cidr': '152.16.100.10/24', - 'gateway_ip': '152.16.100.20'}, - 'public_0': { - 'phy_port': "0000:05:00.1", - 'vpci': "0000:00:08.0", - 'driver': 'i40e', - 'mac': '', - 'cidr': '152.16.40.10/24', - 'gateway_ip': '152.16.100.20'} - } - @mock.patch('yardstick.ssh.SSH') - def setUp(self, mock_ssh): - self.ovs_deploy = model.OvsDeploy(mock_ssh, '/tmp/dpdk-devbind.py', {}) - - def test___init__(self): - self.assertIsNotNone(self.ovs_deploy.connection) - - @mock.patch('yardstick.benchmark.contexts.standalone.model.os') - 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_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.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 deleted file mode 100644 index e39ecf4f2..000000000 --- a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py +++ /dev/null @@ -1,370 +0,0 @@ -# Copyright (c) 2016-2017 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Unittest for yardstick.benchmark.contexts.standalone.standaloneovs - -from __future__ import absolute_import -import os -import unittest -import mock - -from yardstick.benchmark.contexts.standalone import ovs_dpdk - - -class OvsDpdkContextTestCase(unittest.TestCase): - - NODES_SAMPLE = "nodes_sample.yaml" - NODES_ovs_dpdk_SAMPLE = "nodes_ovs_dpdk_sample.yaml" - NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml" - - ATTRS = { - 'name': 'StandaloneOvsDpdk', - 'file': 'pod', - 'flavor': {}, - 'servers': {}, - 'networks': {}, - } - - NETWORKS = { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'private_0': { - 'phy_port': "0000:05:00.0", - 'vpci': "0000:00:07.0", - 'cidr': '152.16.100.10/24', - 'interface': 'if0', - 'mac': "00:00:00:00:00:01", - 'vf_pci': {'vf_pci': 0}, - 'gateway_ip': '152.16.100.20'}, - 'public_0': { - 'phy_port': "0000:05:00.1", - 'vpci': "0000:00:08.0", - 'cidr': '152.16.40.10/24', - 'interface': 'if0', - 'vf_pci': {'vf_pci': 0}, - 'mac': "00:00:00:00:00:01", - 'gateway_ip': '152.16.100.20'}, - } - - def setUp(self): - self.ovs_dpdk = ovs_dpdk.OvsDpdkContext() - - @mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper') - @mock.patch('yardstick.benchmark.contexts.standalone.model.Server') - def test___init__(self, mock_helper, mock_server): - self.ovs_dpdk.helper = mock_helper - self.ovs_dpdk.vnf_node = mock_server - self.assertIsNone(self.ovs_dpdk.file_path) - self.assertTrue(self.ovs_dpdk.first_run) - - def test_init(self): - self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}]) - self.assertIsNone(self.ovs_dpdk.init(self.ATTRS)) - - def test_setup_ovs(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.return_value = ssh_mock - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.ovs_properties = {} - self.assertIsNone(self.ovs_dpdk.setup_ovs()) - - def test_start_ovs_serverswitch(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.return_value = ssh_mock - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.ovs_properties = {} - self.ovs_dpdk.wait_for_vswitchd = 0 - self.assertIsNone(self.ovs_dpdk.start_ovs_serverswitch()) - - def test_setup_ovs_bridge_add_flows(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.return_value = ssh_mock - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.ovs_properties = { - 'version': {'ovs': '2.7.0'} - } - self.ovs_dpdk.wait_for_vswitchd = 0 - self.assertIsNone(self.ovs_dpdk.setup_ovs_bridge_add_flows()) - - def test_cleanup_ovs_dpdk_env(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.return_value = ssh_mock - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.ovs_properties = { - 'version': {'ovs': '2.7.0'} - } - self.ovs_dpdk.wait_for_vswitchd = 0 - self.assertIsNone(self.ovs_dpdk.cleanup_ovs_dpdk_env()) - - @mock.patch('yardstick.benchmark.contexts.standalone.model.OvsDeploy') - def test_check_ovs_dpdk_env(self, mock_ovs): - with mock.patch("yardstick.ssh.SSH") as ssh: - ssh_mock = mock.Mock(autospec=ssh.SSH) - ssh_mock.execute = \ - mock.Mock(return_value=(1, "a", "")) - ssh.return_value = ssh_mock - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.ovs_properties = { - 'version': {'ovs': '2.7.0', 'dpdk': '16.11.1'} - } - self.ovs_dpdk.wait_for_vswitchd = 0 - self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock() - self.assertIsNone(self.ovs_dpdk.check_ovs_dpdk_env()) - self.ovs_dpdk.ovs_properties = { - 'version': {'ovs': '2.0.0'} - } - self.ovs_dpdk.wait_for_vswitchd = 0 - self.cleanup_ovs_dpdk_env = mock.Mock() - mock_ovs.deploy = mock.Mock() - self.assertRaises(Exception, self.ovs_dpdk.check_ovs_dpdk_env) - - @mock.patch('yardstick.ssh.SSH') - 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()) - - self.ovs_dpdk.vm_deploy = True - self.ovs_dpdk.host_mgmt = {} - self.ovs_dpdk.install_req_libs = mock.Mock() - self.ovs_dpdk.helper.get_nic_details = mock.Mock(return_value={}) - self.ovs_dpdk.check_ovs_dpdk_env = mock.Mock(return_value={}) - self.ovs_dpdk.setup_ovs = mock.Mock(return_value={}) - self.ovs_dpdk.start_ovs_serverswitch = mock.Mock(return_value={}) - 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.model.Libvirt') - @mock.patch('yardstick.ssh.SSH') - 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.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 - self.assertIsNone(self.ovs_dpdk.undeploy()) - - def _get_file_abspath(self, filename): - curr_path = os.path.dirname(os.path.abspath(__file__)) - file_path = os.path.join(curr_path, filename) - return file_path - - def test__get_server_with_dic_attr_name(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE) - } - - self.ovs_dpdk.init(attrs) - - attr_name = {'name': 'foo.bar'} - result = self.ovs_dpdk._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_not_found(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE) - } - - self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}]) - self.ovs_dpdk.init(attrs) - - attr_name = 'bar.foo' - result = self.ovs_dpdk._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_mismatch(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE) - } - - self.ovs_dpdk.init(attrs) - - attr_name = 'bar.foo1' - result = self.ovs_dpdk._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_duplicate(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE) - } - - self.ovs_dpdk.init(attrs) - - attr_name = 'node1.foo' - with self.assertRaises(ValueError): - self.ovs_dpdk._get_server(attr_name) - - def test__get_server_found(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE) - } - - self.ovs_dpdk.init(attrs) - - attr_name = 'node1.foo' - result = self.ovs_dpdk._get_server(attr_name) - - self.assertEqual(result['ip'], '10.229.47.137') - self.assertEqual(result['name'], 'node1.foo') - self.assertEqual(result['user'], 'root') - self.assertEqual(result['key_filename'], '/root/.yardstick_key') - - def test__get_network(self): - network1 = { - 'name': 'net_1', - 'vld_id': 'vld111', - 'segmentation_id': 'seg54', - 'network_type': 'type_a', - 'physical_network': 'phys', - } - network2 = { - 'name': 'net_2', - 'vld_id': 'vld999', - } - self.ovs_dpdk.networks = { - 'a': network1, - 'b': network2, - } - - attr_name = {} - self.assertIsNone(self.ovs_dpdk._get_network(attr_name)) - - attr_name = {'vld_id': 'vld777'} - self.assertIsNone(self.ovs_dpdk._get_network(attr_name)) - - self.assertIsNone(self.ovs_dpdk._get_network(None)) - - attr_name = 'vld777' - self.assertIsNone(self.ovs_dpdk._get_network(attr_name)) - - attr_name = {'vld_id': 'vld999'} - expected = { - "name": 'net_2', - "vld_id": 'vld999', - "segmentation_id": None, - "network_type": None, - "physical_network": None, - } - result = self.ovs_dpdk._get_network(attr_name) - self.assertDictEqual(result, expected) - - attr_name = 'a' - expected = network1 - result = self.ovs_dpdk._get_network(attr_name) - self.assertDictEqual(result, expected) - - def test_configure_nics_for_ovs_dpdk(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.return_value = ssh_mock - self.ovs_dpdk.vm_deploy = True - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.vm_names = ['vm_0', 'vm_1'] - self.ovs_dpdk.drivers = [] - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.helper.get_mac_address = mock.Mock(return_value="") - 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.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 = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - self.ovs_dpdk.vm_deploy = True - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.vm_names = ['vm_0', 'vm_1'] - self.ovs_dpdk.drivers = [] - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.get_vf_datas = mock.Mock(return_value="") - self.assertIsNone(self.ovs_dpdk._enable_interfaces(0, ["private_0"], 'test')) - - @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_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_mock.put = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - self.ovs_dpdk.vm_deploy = True - self.ovs_dpdk.connection = ssh_mock - self.ovs_dpdk.vm_names = ['vm_0', 'vm_1'] - self.ovs_dpdk.drivers = [] - self.ovs_dpdk.servers = { - 'vnf_0': { - 'network_ports': { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'xe0': ['private_0'], - 'xe1': ['public_0'] - } - } - } - self.ovs_dpdk.networks = self.NETWORKS - self.ovs_dpdk.host_mgmt = {} - self.ovs_dpdk.flavor = {} - self.ovs_dpdk.configure_nics_for_ovs_dpdk = mock.Mock(return_value="") - mock_libvirt.check_if_vm_exists_and_delete = mock.Mock(return_value="") - 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="") - 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 deleted file mode 100644 index 7f11a7d59..000000000 --- a/tests/unit/benchmark/contexts/standalone/test_sriov.py +++ /dev/null @@ -1,318 +0,0 @@ -# Copyright (c) 2016-2017 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Unittest for yardstick.benchmark.contexts.standalone.standalonesriov - -from __future__ import absolute_import -import os -import unittest -import mock - -from yardstick import ssh -from yardstick.benchmark.contexts.standalone import sriov - - -class SriovContextTestCase(unittest.TestCase): - - NODES_SAMPLE = "nodes_sample.yaml" - NODES_SRIOV_SAMPLE = "nodes_sriov_sample.yaml" - NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml" - - ATTRS = { - 'name': 'StandaloneSriov', - 'file': 'pod', - 'flavor': {}, - 'servers': {}, - 'networks': {}, - } - - NETWORKS = { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'private_0': { - 'phy_port': "0000:05:00.0", - 'vpci': "0000:00:07.0", - 'cidr': '152.16.100.10/24', - 'interface': 'if0', - 'mac': "00:00:00:00:00:01", - 'vf_pci': {'vf_pci': 0}, - 'gateway_ip': '152.16.100.20'}, - 'public_0': { - 'phy_port': "0000:05:00.1", - 'vpci': "0000:00:08.0", - 'cidr': '152.16.40.10/24', - 'interface': 'if0', - 'vf_pci': {'vf_pci': 0}, - 'mac': "00:00:00:00:00:01", - 'gateway_ip': '152.16.100.20'}, - } - - def setUp(self): - self.sriov = sriov.SriovContext() - - @mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper') - @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.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.object(ssh, 'SSH', return_value=(0, "a", "")) - def test_deploy(self, mock_ssh): - # 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()) - - self.sriov.vm_deploy = True - self.sriov.host_mgmt = {} - self.sriov.install_req_libs = mock.Mock() - self.sriov.get_nic_details = mock.Mock(return_value={}) - self.sriov.setup_sriov_context = mock.Mock(return_value={}) - self.sriov.wait_for_vnfs_to_start = mock.Mock(return_value={}) - self.assertIsNone(self.sriov.deploy()) - - @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): - # 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 = mock_ssh - self.sriov.vm_names = ['vm_0', 'vm_1'] - self.sriov.drivers = ['vm_0', 'vm_1'] - self.assertIsNone(self.sriov.undeploy()) - - def _get_file_abspath(self, filename): - curr_path = os.path.dirname(os.path.abspath(__file__)) - file_path = os.path.join(curr_path, filename) - return file_path - - def test__get_server_with_dic_attr_name(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE) - } - - self.sriov.init(attrs) - - attr_name = {'name': 'foo.bar'} - result = self.sriov._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_not_found(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE) - } - - self.sriov.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}]) - self.sriov.init(attrs) - - attr_name = 'bar.foo' - result = self.sriov._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_mismatch(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE) - } - - self.sriov.init(attrs) - - attr_name = 'bar.foo1' - result = self.sriov._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_duplicate(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE) - } - - self.sriov.init(attrs) - - attr_name = 'node1.foo' - with self.assertRaises(ValueError): - self.sriov._get_server(attr_name) - - def test__get_server_found(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE) - } - - self.sriov.init(attrs) - - attr_name = 'node1.foo' - result = self.sriov._get_server(attr_name) - - self.assertEqual(result['ip'], '10.229.47.137') - self.assertEqual(result['name'], 'node1.foo') - self.assertEqual(result['user'], 'root') - self.assertEqual(result['key_filename'], '/root/.yardstick_key') - - def test__get_network(self): - network1 = { - 'name': 'net_1', - 'vld_id': 'vld111', - 'segmentation_id': 'seg54', - 'network_type': 'type_a', - 'physical_network': 'phys', - } - network2 = { - 'name': 'net_2', - 'vld_id': 'vld999', - } - self.sriov.networks = { - 'a': network1, - 'b': network2, - } - - attr_name = {} - self.assertIsNone(self.sriov._get_network(attr_name)) - - attr_name = {'vld_id': 'vld777'} - self.assertIsNone(self.sriov._get_network(attr_name)) - - self.assertIsNone(self.sriov._get_network(None)) - - attr_name = 'vld777' - self.assertIsNone(self.sriov._get_network(attr_name)) - - attr_name = {'vld_id': 'vld999'} - expected = { - "name": 'net_2', - "vld_id": 'vld999', - "segmentation_id": None, - "network_type": None, - "physical_network": None, - } - result = self.sriov._get_network(attr_name) - self.assertDictEqual(result, expected) - - attr_name = 'a' - expected = network1 - result = self.sriov._get_network(attr_name) - self.assertDictEqual(result, expected) - - def test_configure_nics_for_sriov(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.return_value = ssh_mock - self.sriov.vm_deploy = True - self.sriov.connection = ssh_mock - self.sriov.vm_names = ['vm_0', 'vm_1'] - 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.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, mock_ssh): - # pylint: disable=unused-argument - # NOTE(ralonsoh): the pylint exception should be removed. - self.sriov.vm_deploy = True - 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.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 = \ - mock.Mock(return_value=(0, "a", "")) - ssh_mock.put = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - self.sriov.vm_deploy = True - self.sriov.connection = ssh_mock - self.sriov.vm_names = ['vm_0', 'vm_1'] - self.sriov.drivers = [] - self.sriov.servers = { - 'vnf_0': { - 'network_ports': { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'xe0': ['private_0'], - 'xe1': ['public_0'] - } - } - } - self.sriov.networks = self.NETWORKS - self.sriov.host_mgmt = {} - self.sriov.flavor = {} - self.sriov.configure_nics_for_sriov = mock.Mock(return_value="") - mock_libvirt.build_vm_xml = mock.Mock(return_value=[6, "00:00:00:00:00:01"]) - self.sriov._enable_interfaces = mock.Mock(return_value="") - self.sriov.vnf_node.generate_vnf_instance = mock.Mock(return_value={}) - self.assertIsNotNone(self.sriov.setup_sriov_context()) - - def test__get_vf_data(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.put = \ - mock.Mock(return_value=(0, "a", "")) - ssh.return_value = ssh_mock - self.sriov.vm_deploy = True - self.sriov.connection = ssh_mock - self.sriov.vm_names = ['vm_0', 'vm_1'] - self.sriov.drivers = [] - self.sriov.servers = { - 'vnf_0': { - 'network_ports': { - 'mgmt': {'cidr': '152.16.100.10/24'}, - 'xe0': ['private_0'], - 'xe1': ['public_0'] - } - } - } - 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')) |