summaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts/standalone
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark/contexts/standalone')
-rw-r--r--tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml37
-rw-r--r--tests/unit/benchmark/contexts/standalone/nodes_ovs_dpdk_sample.yaml40
-rw-r--r--tests/unit/benchmark/contexts/standalone/nodes_sample.yaml33
-rw-r--r--tests/unit/benchmark/contexts/standalone/nodes_sriov_sample.yaml40
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml104
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml69
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt1
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml52
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml54
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt1
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_model.py331
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py377
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py327
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_sriov.py643
14 files changed, 1129 insertions, 980 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml
new file mode 100644
index 000000000..2e501a6af
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/nodes_duplicate_sample.yaml
@@ -0,0 +1,37 @@
+##############################################################################
+# 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
new file mode 100644
index 000000000..0f51dbe63
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/nodes_ovs_dpdk_sample.yaml
@@ -0,0 +1,40 @@
+##############################################################################
+# 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
new file mode 100644
index 000000000..8d50c3aea
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/nodes_sample.yaml
@@ -0,0 +1,33 @@
+##############################################################################
+# 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
new file mode 100644
index 000000000..1c43b8725
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/nodes_sriov_sample.yaml
@@ -0,0 +1,40 @@
+##############################################################################
+# 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/ovs_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml
deleted file mode 100644
index b1da1ea9f..000000000
--- a/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml
+++ /dev/null
@@ -1,104 +0,0 @@
-# Copyright (c) 2016 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.
-
-nodes:
--
- name: trafficgen_1
- role: TrafficGen
- ip: 10.223.197.182
- user: root
- auth_type: password
- password: intel123
- interfaces:
- xe0: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.0"
- driver: ixgbe
- dpdk_port_num: 0
- local_ip: "152.16.100.20"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:68"
- xe1: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.1"
- driver: ixgbe
- dpdk_port_num: 1
- local_ip: "152.16.100.21"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:69"
--
- name: ovs
- role: Ovsdpdk
- ip: 10.223.197.222
- user: root
- auth_type: password
- password: intel123
- vpath: "/usr/local/"
- vports:
- - dpdkvhostuser0
- - dpdkvhostuser1
- vports_mac:
- - "00:00:00:00:00:03"
- - "00:00:00:00:00:04"
- phy_ports: # Physical ports to configure ovs
- - "0000:06:00.0"
- - "0000:06:00.1"
- flow:
- - ovs-ofctl add-flow br0 in_port=1,action=output:3
- - ovs-ofctl add-flow br0 in_port=3,action=output:1
- - ovs-ofctl add-flow br0 in_port=4,action=output:2
- - ovs-ofctl add-flow br0 in_port=2,action=output:4
- phy_driver: i40e # kernel driver
- images: "/var/lib/libvirt/images/ubuntu1.img"
-
--
- name: vnf
- role: vnf
- ip: 10.223.197.155
- user: root
- auth_type: password
- password: intel123
- host: 10.223.197.140
- interfaces:
- xe0: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:00:04.0"
- driver: virtio-pci
- dpdk_port_num: 0
- local_ip: "152.16.100.19"
- netmask: "255.255.255.0"
- local_mac: "00:00:00:00:00:03"
-
- xe1: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:00:05.0"
- driver: virtio-pci
- dpdk_port_num: 1
- local_ip: "152.16.40.19"
- netmask: "255.255.255.0"
- local_mac: "00:00:00:00:00:04"
- routing_table:
- - network: "152.16.100.20"
- netmask: "255.255.255.0"
- gateway: "152.16.100.20"
- if: "xe0"
- - network: "152.16.40.20"
- netmask: "255.255.255.0"
- gateway: "152.16.40.20"
- if: "xe1"
- nd_route_tbl:
- - network: "0064:ff9b:0:0:0:0:9810:6414"
- netmask: "112"
- gateway: "0064:ff9b:0:0:0:0:9810:6414"
- if: "xe0"
- - network: "0064:ff9b:0:0:0:0:9810:2814"
- netmask: "112"
- gateway: "0064:ff9b:0:0:0:0:9810:2814"
- if: "xe1"
diff --git a/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml
deleted file mode 100644
index 896ec33bb..000000000
--- a/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml
+++ /dev/null
@@ -1,69 +0,0 @@
-##############################################################################
-# Copyright (c) 2015 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
-##############################################################################
----
-# Sample config file about the POD information, including the
-# name/IP/user/ssh key of Bare Metal and Controllers/Computes
-#
-# The options of this config file include:
-# name: the name of this node
-# role: node's role, support role: Master/Controller/Comupte/BareMetal
-# ip: the node's IP address
-# user: the username for login
-# key_filename:the path of the private key file for login
-
-nodes:
--
- name: trafficgen_1
- role: TrafficGen
- ip: 10.10.10.10
- auth_type: ssh_key
- user: root
- ssh_port: 22
- key_filename: /root/.ssh/id_rsa
- interfaces:
- xe0: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.0"
- driver: ixgbe
- dpdk_port_num: 0
- local_ip: "152.16.100.20"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:68"
- xe1: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.1"
- driver: ixgbe
- dpdk_port_num: 1
- local_ip: "152.16.100.21"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:69"
--
- name: ovs
- role: Ovsdpdk
- ip: 10.223.197.222
- auth_type: ssh_key
- user: root
- ssh_port: 22
- key_filename: /root/.ssh/id_rsa
- vpath: "/usr/local/"
- vports:
- - dpdkvhostuser0
- - dpdkvhostuser1
- vports_mac:
- - "00:00:00:00:00:03"
- - "00:00:00:00:00:04"
- phy_ports: # Physical ports to configure ovs
- - "0000:06:00.0"
- - "0000:06:00.1"
- flow:
- - ovs-ofctl add-flow br0 in_port=1,action=output:3
- - ovs-ofctl add-flow br0 in_port=3,action=output:1
- - ovs-ofctl add-flow br0 in_port=4,action=output:2
- - ovs-ofctl add-flow br0 in_port=2,action=output:4
- phy_driver: i40e # kernel driver
- images: "/var/lib/libvirt/images/ubuntu1.img"
-
diff --git a/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt
deleted file mode 100644
index f0eec86f6..000000000
--- a/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt
+++ /dev/null
@@ -1 +0,0 @@
-some content \ No newline at end of file
diff --git a/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml
deleted file mode 100644
index 4f60e46d5..000000000
--- a/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml
+++ /dev/null
@@ -1,52 +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.
-
-nodes:
--
- name: trafficgen_1
- role: TrafficGen
- ip: 10.10.10.10
- auth_type: password
- user: root
- password: password
- interfaces:
- xe0: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.0"
- driver: ixgbe
- dpdk_port_num: 0
- local_ip: "152.16.100.20"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:68"
- xe1: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.1"
- driver: ixgbe
- dpdk_port_num: 1
- local_ip: "152.16.100.21"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:69"
--
- name: sriov
- role: Sriov
- ip: 10.10.10.11
- auth_type: password
- user: root
- password: password
- vf_macs:
- - "00:00:00:71:7d:25"
- - "00:00:00:71:7d:26"
- phy_ports: # Physical ports to configure sriov
- - "0000:06:00.0"
- - "0000:06:00.1"
- phy_driver: i40e # kernel driver
- images: "/var/lib/libvirt/images/ubuntu1.img"
diff --git a/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml
deleted file mode 100644
index faa496771..000000000
--- a/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml
+++ /dev/null
@@ -1,54 +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.
-
-nodes:
--
- name: trafficgen_1
- role: TrafficGen
- ip: 10.10.10.10
- auth_type: ssh_key
- user: root
- ssh_port: 22
- key_filename: /root/.ssh/id_rsa
- interfaces:
- xe0: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.0"
- driver: ixgbe
- dpdk_port_num: 0
- local_ip: "152.16.100.20"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:68"
- xe1: # logical name from topology.yaml and vnfd.yaml
- vpci: "0000:03:00.1"
- driver: ixgbe
- dpdk_port_num: 1
- local_ip: "152.16.100.21"
- netmask: "255.255.255.0"
- local_mac: "90:e2:ba:77:ce:69"
--
- name: sriov
- role: Sriov
- ip: 10.10.10.11
- auth_type: ssh_key
- user: root
- ssh_port: 22
- key_filename: /root/.ssh/id_rsa
- vf_macs:
- - "00:00:00:71:7d:25"
- - "00:00:00:71:7d:26"
- phy_ports: # Physical ports to configure sriov
- - "0000:06:00.0"
- - "0000:06:00.1"
- phy_driver: i40e # kernel driver
- images: "/var/lib/libvirt/images/ubuntu1.img"
diff --git a/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt
deleted file mode 100644
index f0eec86f6..000000000
--- a/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt
+++ /dev/null
@@ -1 +0,0 @@
-some content \ No newline at end of file
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py
new file mode 100644
index 000000000..ddbc1a4bb
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/test_model.py
@@ -0,0 +1,331 @@
+#!/usr/bin/env python
+
+# 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.model
+
+
+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.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
+
+
+class ModelLibvirtTestCase(unittest.TestCase):
+
+ 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
+ result = Libvirt.check_if_vm_exists_and_delete("vm_0", ssh_mock)
+ self.assertIsNone(result)
+
+ 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
+ result = Libvirt.virsh_create_vm(ssh_mock, "vm_0")
+ self.assertIsNone(result)
+
+ 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
+ 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)
+
+ 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 = Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img")
+ self.assertEqual(image, result)
+
+ @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):
+ 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 = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0)
+ self.assertEqual(status[0], result[0])
+
+ def test_split_cpu_list(self):
+ result = Libvirt.split_cpu_list("1,2,3")
+ self.assertEqual(result, [1, 2, 3])
+
+ def test_get_numa_nodes(self):
+ result = Libvirt.get_numa_nodes()
+ self.assertIsNotNone(result)
+
+ 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
+ status = Libvirt.update_interrupts_hugepages_perf(ssh_mock)
+ self.assertIsNone(status)
+
+ @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.get_numa_nodes")
+ @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_get_numa_nodes):
+ 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_get_numa_nodes.return_value = {'1': [18, 19, 20, 21], '0': [0, 1, 2, 3]}
+ status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4)
+ self.assertIsNone(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 = 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
+ status = StandaloneContextHelper.install_req_libs(ssh_mock)
+ self.assertIsNone(status)
+
+ 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
+ status = StandaloneContextHelper.get_kernel_module(ssh_mock, "05:00.0", None)
+ self.assertEqual(status, "i40e")
+
+ @mock.patch('yardstick.benchmark.contexts.standalone.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"
+ status = StandaloneContextHelper.get_nic_details(ssh_mock, self.NETWORKS, "dpdk-devbind.py")
+ self.assertIsNotNone(status)
+
+ 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
+ status = StandaloneContextHelper.get_virtual_devices(ssh_mock, "0000:00:05.0")
+ self.assertIsNotNone(status)
+
+ 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 = StandaloneContextHelper.get_mac_address()
+ self.assertIsNotNone(status)
+
+ @mock.patch('yardstick.ssh.SSH')
+ def test_get_mgmt_ip(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=(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", {})
+ self.assertIsNotNone(status)
+
+ @mock.patch('yardstick.ssh.SSH')
+ def test_get_mgmt_ip_no(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=(1, "", ""))
+ ssh.return_value = ssh_mock
+
+ model.WAIT_FOR_BOOT = 0
+ status = 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, mock_ssh):
+ 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):
+ 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
new file mode 100644
index 000000000..5d1b0421c
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -0,0 +1,377 @@
+# 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 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):
+
+ 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.assertEqual(self.ovs_dpdk.first_run, True)
+
+ 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, 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
+ 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={})
+ self.assertIsNone(self.ovs_dpdk.deploy())
+
+ @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.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
+ 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.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.ovs_dpdk.Libvirt')
+ def test__enable_interfaces(self, mock_add_ovs_interface):
+ 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_server, 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_ovsdpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py
deleted file mode 100644
index 1d68384c9..000000000
--- a/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py
+++ /dev/null
@@ -1,327 +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.
-
-from __future__ import absolute_import
-
-import os
-import unittest
-
-import mock
-
-from yardstick.benchmark.contexts.standalone import ovsdpdk
-
-NIC_INPUT = {
- 'interface': {},
- 'vports_mac': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e'}
-DRIVER = "i40e"
-NIC_DETAILS = {
- 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'},
- 'vports_mac': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e'}
-
-CORRECT_FILE_PATH = "/etc/yardstick/nodes/pod_ovs.yaml"
-WRONG_FILE_PATH = "/etc/yardstick/wrong.yaml"
-SAMPLE_FILE = "ovs_sample_write_to_file.txt"
-
-OVS = [{
- 'auth_type': 'ssh_key',
- 'name': 'ovs',
- 'ssh_port': 22,
- 'ip': '10.10.10.11',
- 'key_filename': '/root/.ssh/id_rsa',
- 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'],
- 'vpath': '/usr/local/',
- 'role': 'Ovsdpdk',
- 'user': 'root',
- 'images': '/var/lib/libvirt/images/ubuntu1.img',
- 'flow': ['ovs-ofctl add-flow br0 in_port=1,action=output:3',
- 'ovs-ofctl add-flow br0 in_port=3,action=output:1',
- 'ovs-ofctl add-flow br0 in_port=4,action=output:2',
- 'ovs-ofctl add-flow br0 in_port=2,action=output:4'],
- 'phy_driver': 'i40e',
- 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}]
-
-OVS_PASSWORD = [{
- 'auth_type': 'password',
- 'name': 'ovs',
- 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'],
- 'ip': '10.10.10.11',
- 'role': 'Ovsdpdk',
- 'user': 'root',
- 'vpath': '/usr/local/',
- 'images': '/var/lib/libvirt/images/ubuntu1.img',
- 'flow': ['ovs-ofctl add-flow br0 in_port=1,action=output:3',
- 'ovs-ofctl add-flow br0 in_port=3,action=output:1',
- 'ovs-ofctl add-flow br0 in_port=4,action=output:2',
- 'ovs-ofctl add-flow br0 in_port=2,action=output:4'],
- 'phy_driver': 'i40e',
- 'password': 'password',
- 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}]
-
-#vfnic = "i40evf"
-PCIS = ['0000:06:00.0', '0000:06:00.1']
-
-
-class OvsdpdkTestCase(unittest.TestCase):
-
- NODES_SAMPLE_SSH = "ovs_sample_ssh_key.yaml"
- NODES_SAMPLE_PASSWORD = "ovs_sample_password.yaml"
-
- def setUp(self):
- self.test_context = ovsdpdk.Ovsdpdk()
-
- def test_construct(self):
- self.assertIsNone(self.test_context.name)
- self.assertIsNone(self.test_context.file_path)
- self.assertEqual(self.test_context.nodes, [])
- self.assertEqual(self.test_context.ovs, [])
- self.assertFalse(self.test_context.vm_deploy)
- self.assertTrue(self.test_context.first_run)
- self.assertEqual(self.test_context.user, "")
- self.assertEqual(self.test_context.ssh_ip, "")
- self.assertEqual(self.test_context.passwd, "")
- self.assertEqual(self.test_context.ssh_port, "")
- self.assertEqual(self.test_context.auth_type, "")
-
- def test_init(self):
- self.test_context.parse_pod_and_get_data = mock.Mock()
- self.test_context.file_path = CORRECT_FILE_PATH
- self.test_context.init()
- self.assertIsNone(self.test_context.init())
-
- def test_successful_init_with_ssh(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_SSH)
- self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH)
-
- def test_successful_init_with_password(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD)
- self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH)
-
- def test_unsuccessful_init(self):
- self.assertRaises(
- IOError,
- lambda: self.test_context.parse_pod_and_get_data(WRONG_FILE_PATH))
-
- def test_ssh_connection(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
-
- @mock.patch('yardstick.network_services.utils.provision_tool', return_value="b")
- def test_ssh_connection(self, mock_prov):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(1, "b", ""))
- ssh.return_value = ssh_mock
- mock_prov.provision_tool = mock.Mock()
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS_PASSWORD
- self.assertIsNone(ovs_obj.ssh_remote_machine())
-
- @mock.patch('yardstick.network_services.utils.provision_tool', return_value="b")
- def test_ssh_connection_ssh_key(self, mock_prov):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(1, "b", ""))
- ssh.return_value = ssh_mock
- mock_prov.provision_tool = mock.Mock()
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- ovs_obj.key_filename = '/root/.ssh/id_rsa'
- self.assertIsNone(ovs_obj.ssh_remote_machine())
-
- def test_get_nic_details(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "eth0 eth1", ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.ovs = OVS
- ovs_obj.connection = ssh_mock
- self.assertIsNotNone(ovs_obj.get_nic_details())
-
- 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=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.first_run = True
- ovs_obj.connection = ssh_mock
- self.assertIsNone(ovs_obj.install_req_libs())
-
- 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, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- self.assertIsNone(ovs_obj.setup_ovs({"eth0 eth1"}))
-
- 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, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- self.assertIsNone(ovs_obj.start_ovs_serverswitch())
-
- def test_setup_ovs_bridge(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- self.assertIsNone(ovs_obj.setup_ovs_bridge())
-
- def test_add_oflows(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- self.assertIsNone(ovs_obj.add_oflows())
-
- def test_setup_ovs_context_vm_already_present(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- mock_ovs = mock.Mock()
- ssh_mock.put = mock.Mock()
- ovs_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- with mock.patch("yardstick.benchmark.contexts.standalone.ovsdpdk.time"):
- self.assertIsNone(ovs_obj.setup_ovs_context(PCIS, NIC_DETAILS, DRIVER))
-
- @mock.patch(
- 'yardstick.benchmark.contexts.standalone.ovsdpdk',
- return_value="Domain vm1 created from /tmp/vm_ovs.xml")
- def test_is_vm_created(self, NIC_INPUT):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.put = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- mock_ovs = mock.Mock()
- ret_create = mock.Mock()
- pcis = NIC_DETAILS['pci']
- driver = NIC_DETAILS['phy_driver']
- self.assertIsNotNone(
- mock_ovs.ovs_obj.setup_ovs_context(
- pcis,
- NIC_DETAILS,
- driver))
-
- def test_check_output(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- cmd = "command"
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- self.assertIsNotNone(ovs_obj.check_output(cmd, None))
-
- def test_split_cpu_list_available(self):
- with mock.patch("itertools.chain") as iter1:
- iter1 = mock.Mock()
- print("{0}".format(iter1))
- ovs_obj = ovsdpdk.Ovsdpdk()
- self.assertIsNotNone(ovs_obj.split_cpu_list('0,5'))
-
- def test_split_cpu_list_null(self):
- with mock.patch("itertools.chain") as iter1:
- iter1 = mock.Mock()
- print("{0}".format(iter1))
- ovs_obj = ovsdpdk.Ovsdpdk()
- self.assertEqual(ovs_obj.split_cpu_list([]), [])
-
- def test_destroy_vm_successful(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- ovs_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "0 i40e"))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "0 i40e"))
- self.assertIsNone(ovs_obj.destroy_vm())
-
- def test_destroy_vm_unsuccessful(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- ovs_obj = ovsdpdk.Ovsdpdk()
- ovs_obj.connection = ssh_mock
- ovs_obj.ovs = OVS
- ovs_obj.check_output = mock.Mock(return_value=(1, {}))
- self.assertIsNone(ovs_obj.destroy_vm())
-
- def test_read_from_file(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD)
- ovs_obj = ovsdpdk.Ovsdpdk()
- self.assertIsNotNone(ovs_obj.read_from_file(CORRECT_FILE_PATH))
-
- def test_write_to_file(self):
- ovs_obj = ovsdpdk.Ovsdpdk()
- self.assertIsNone(ovs_obj.write_to_file(SAMPLE_FILE, "some content"))
-
- 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
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/unit/benchmark/contexts/standalone/test_sriov.py b/tests/unit/benchmark/contexts/standalone/test_sriov.py
index ea72e1bab..50ae5fe13 100644
--- a/tests/unit/benchmark/contexts/standalone/test_sriov.py
+++ b/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -12,412 +12,311 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import absolute_import
+# Unittest for yardstick.benchmark.contexts.standalone.standalonesriov
+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 sriov
-
-NIC_INPUT = {
- 'interface': {},
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e'}
-DRIVER = "i40e"
-NIC_DETAILS = {
- 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'},
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e'}
-
-CORRECT_FILE_PATH = "/etc/yardstick/nodes/pod_sriov.yaml"
-WRONG_FILE_PATH = "/etc/yardstick/wrong.yaml"
-SAMPLE_FILE = "sriov_sample_write_to_file.txt"
-
-SRIOV = [{
- 'auth_type': 'ssh_key',
- 'name': 'sriov',
- 'ssh_port': 22,
- 'ip': '10.10.10.11',
- 'key_filename': '/root/.ssh/id_rsa',
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'role': 'Sriov',
- 'user': 'root',
- 'images': '/var/lib/libvirt/images/ubuntu1.img',
- 'phy_driver': 'i40e',
- 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}]
-
-SRIOV_PASSWORD = [{
- 'auth_type': 'password',
- 'name': 'sriov',
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'ip': '10.10.10.11',
- 'role': 'Sriov',
- 'user': 'root',
- 'images': '/var/lib/libvirt/images/ubuntu1.img',
- 'phy_driver': 'i40e',
- 'password': 'password',
- 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}]
-
-vfnic = "i40evf"
-PCIS = ['0000:06:00.0', '0000:06:00.1']
-
-
-class SriovTestCase(unittest.TestCase):
-
- NODES_SAMPLE_SSH = "sriov_sample_ssh_key.yaml"
- NODES_SAMPLE_PASSWORD = "sriov_sample_password.yaml"
+from yardstick.network_services.utils import PciAddress
+
+
+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.test_context = sriov.Sriov()
-
- def test_construct(self):
- self.assertIsNone(self.test_context.name)
- self.assertIsNone(self.test_context.file_path)
- self.assertEqual(self.test_context.nodes, [])
- self.assertEqual(self.test_context.sriov, [])
- self.assertFalse(self.test_context.vm_deploy)
- self.assertTrue(self.test_context.first_run)
- self.assertEqual(self.test_context.user, "")
- self.assertEqual(self.test_context.ssh_ip, "")
- self.assertEqual(self.test_context.passwd, "")
- self.assertEqual(self.test_context.ssh_port, "")
- self.assertEqual(self.test_context.auth_type, "")
+ 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):
+ self.sriov.helper = mock_helper
+ self.sriov.vnf_node = mock_server
+ self.assertIsNone(self.sriov.file_path)
+ self.assertEqual(self.sriov.first_run, True)
def test_init(self):
- self.test_context.parse_pod_and_get_data = mock.Mock()
- self.test_context.file_path = CORRECT_FILE_PATH
- self.test_context.init()
- self.assertIsNone(self.test_context.init())
-
- def test_successful_init_with_ssh(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_SSH)
- self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH)
-
- def test_successful_init_with_password(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD)
- self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH)
-
- def test_unsuccessful_init(self):
- self.assertRaises(
- IOError,
- lambda: self.test_context.parse_pod_and_get_data(WRONG_FILE_PATH))
-
- @mock.patch('yardstick.network_services.utils.provision_tool', return_value="a")
- def test_ssh_connection(self, mock_prov):
- 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
- mock_prov.provision_tool = mock.Mock()
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV_PASSWORD
- self.assertIsNone(sriov_obj.ssh_remote_machine())
-
- @mock.patch('yardstick.network_services.utils.provision_tool', return_value="a")
- def test_ssh_connection_ssh_key(self, mock_prov):
- 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
- mock_prov.provision_tool = mock.Mock()
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV
- sriov_obj.key_filename = '/root/.ssh/id_rsa'
- self.assertIsNone(sriov_obj.ssh_remote_machine())
-
- def test_get_nic_details(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "eth0 eth1", ""))
- ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.sriov = SRIOV
- sriov_obj.connection = ssh_mock
- self.assertIsNotNone(sriov_obj.get_nic_details())
+ self.sriov.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
+ self.assertIsNone(self.sriov.init(self.ATTRS))
- def test_install_req_libs(self):
+ @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, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.first_run = True
- sriov_obj.connection = ssh_mock
- self.assertIsNone(sriov_obj.install_req_libs())
- def test_configure_nics_for_sriov(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- nic_details = {
- 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'},
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e',
- 'vf_pci': [{}, {}]}
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock((DRIVER), return_value=(0, "0 driver", ""))
- ssh.return_value = ssh_mock
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- for i in range(len(NIC_DETAILS['pci'])):
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- ssh_mock.execute = \
- mock.Mock(return_value=(
- 0,
- "{'0':'06:02:00','1':'06:06:00'}",
- ""))
- sriov_obj.get_vf_datas = mock.Mock(return_value={
- '0000:06:00.0': '0000:06:02.0'})
- nic_details['vf_pci'][i] = sriov_obj.get_vf_datas.return_value
- vf_pci = [[], []]
- vf_pci[i] = sriov_obj.get_vf_datas.return_value
- with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
- self.assertIsNotNone(sriov_obj.configure_nics_for_sriov(DRIVER, NIC_DETAILS))
-
- def test_setup_sriov_context(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- nic_details = {
- 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'},
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e',
- 'vf_pci': [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]}
- vf = [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV
- blacklist = "/etc/modprobe.d/blacklist.conf"
- self.assertEqual(vfnic, "i40evf")
- mock_sriov = mock.Mock()
- mock_sriov.sriov_obj.read_from_file(blacklist)
- sriov_obj.read_from_file = mock.Mock(
- return_value="some random text")
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- sriov_obj.configure_nics_for_sriov = mock.Mock(
- return_value=nic_details)
- nic_details = sriov_obj.configure_nics_for_sriov.return_value
- self.assertEqual(vf, nic_details['vf_pci'])
- vf = [
- {'vf_pci': '06:02.00', 'mac': '00:00:00:00:00:0a'},
- {'vf_pci': '06:06.00', 'mac': '00:00:00:00:00:0b'}]
- sriov_obj.add_sriov_interface = mock.Mock()
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.put = mock.Mock()
- sriov_obj.check_output = mock.Mock(return_value=(1, {}))
- with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
- self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER))
+ self.sriov.vm_deploy = False
+ self.assertIsNone(self.sriov.deploy())
- def test_setup_sriov_context_vm_already_present(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- nic_details = {
- 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'},
- 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'],
- 'pci': ['0000:06:00.0', '0000:06:00.1'],
- 'phy_driver': 'i40e',
- 'vf_pci': [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]}
- vf = [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV
- blacklist = "/etc/modprobe.d/blacklist.conf"
- self.assertEqual(vfnic, "i40evf")
- mock_sriov = mock.Mock()
- mock_sriov.sriov_obj.read_from_file(blacklist)
- sriov_obj.read_from_file = mock.Mock(
- return_value="some random text")
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- sriov_obj.configure_nics_for_sriov = mock.Mock(
- return_value=nic_details)
- nic_details = sriov_obj.configure_nics_for_sriov.return_value
- self.assertEqual(vf, nic_details['vf_pci'])
- vf = [
- {'vf_pci': '06:02.00', 'mac': '00:00:00:00:00:0a'},
- {'vf_pci': '06:06.00', 'mac': '00:00:00:00:00:0b'}]
- sriov_obj.add_sriov_interface = mock.Mock()
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.put = mock.Mock()
- sriov_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
- self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER))
-
- @mock.patch(
- 'yardstick.benchmark.contexts.standalone.sriov',
- return_value="Domain vm1 created from /tmp/vm_sriov.xml")
- def test_is_vm_created(self, NIC_INPUT):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- mock_sriov = mock.Mock()
- pcis = NIC_DETAILS['pci']
- driver = NIC_DETAILS['phy_driver']
- self.assertIsNotNone(
- mock_sriov.sriov_obj.setup_sriov_context(
- pcis,
- NIC_DETAILS,
- driver))
-
- def test_add_sriov_interface(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- with mock.patch("xml.etree.ElementTree.parse") as parse:
- with mock.patch("re.search") as re:
- with mock.patch("xml.etree.ElementTree.SubElement") \
- as elem:
- parse = mock.Mock(return_value="root")
- re = mock.Mock()
- elem = mock.Mock()
- print("{0} {1} {2}".format(parse, re, elem))
- self.assertIsNone(sriov_obj.add_sriov_interface(
- 0,
- "0000:06:02.0",
- "00:00:00:00:00:0a",
- "/tmp/vm_sriov.xml"))
-
- def test_get_virtual_devices(self):
+ 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('yardstick.ssh.SSH')
+ @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, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- pci_out = " \
- PCI_CLASS=20000 \
- PCI_ID=8086:154C \
- PCI_SUBSYS_ID=8086:0000 \
- PCI_SLOT_NAME=0000:06:02.0 \
- MODALIAS= \
- pci:v00008086d0000154Csv00008086sd00000000bc02sc00i00"
- pci = "0000:06:00.0"
- sriov_obj.check_output = mock.Mock(return_value=(0, pci_out))
- with mock.patch("re.search") as re:
- re = mock.Mock(return_value="a")
- print("{0}".format(re))
- self.assertIsNotNone(sriov_obj.get_virtual_devices(pci))
-
- def test_get_vf_datas(self):
+
+ self.sriov.vm_deploy = False
+ self.assertIsNone(self.sriov.undeploy())
+
+ self.sriov.vm_deploy = True
+ self.sriov.connection = ssh_mock
+ 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, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.get_virtual_devices = mock.Mock(
- return_value={'0000:06:00.0': '0000:06:02.0'})
- with mock.patch("re.search") as re:
- re = mock.Mock()
- print("{0}".format(re))
- self.assertIsNotNone(sriov_obj.get_vf_datas(
- 'vf_pci',
- {'0000:06:00.0': '0000:06:02.0'},
- "00:00:00:00:00:0a"))
-
- def test_check_output(self):
+ 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('yardstick.benchmark.contexts.standalone.sriov.Libvirt')
+ def test__enable_interfaces(self, mock_libvirt):
with mock.patch("yardstick.ssh.SSH") as ssh:
- cmd = "command"
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- self.assertIsNotNone(sriov_obj.check_output(cmd, None))
-
- def test_split_cpu_list_available(self):
- with mock.patch("itertools.chain") as iter1:
- iter1 = mock.Mock()
- print("{0}".format(iter1))
- sriov_obj = sriov.Sriov()
- self.assertIsNotNone(sriov_obj.split_cpu_list('0,5'))
-
- def test_split_cpu_list_null(self):
- with mock.patch("itertools.chain") as iter1:
- iter1 = mock.Mock()
- print("{0}".format(iter1))
- sriov_obj = sriov.Sriov()
- self.assertEqual(sriov_obj.split_cpu_list([]), [])
-
- def test_destroy_vm_successful(self):
+ 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.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):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
+ ssh_mock.put = \
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV
- sriov_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, {}, ""))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "0 i40e"))
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "0 i40e"))
- self.assertIsNone(sriov_obj.destroy_vm())
-
- def test_destroy_vm_unsuccessful(self):
+ 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, {}, ""))
+ mock.Mock(return_value=(0, "a", ""))
+ ssh_mock.put = \
+ mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- sriov_obj = sriov.Sriov()
- sriov_obj.connection = ssh_mock
- sriov_obj.sriov = SRIOV
- sriov_obj.check_output = mock.Mock(return_value=(1, {}))
- self.assertIsNone(sriov_obj.destroy_vm())
-
- def test_read_from_file(self):
- CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD)
- sriov_obj = sriov.Sriov()
- self.assertIsNotNone(sriov_obj.read_from_file(CORRECT_FILE_PATH))
-
- def test_write_to_file(self):
- sriov_obj = sriov.Sriov()
- self.assertIsNone(sriov_obj.write_to_file(SAMPLE_FILE, "some content"))
-
- 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
-
-if __name__ == '__main__':
- unittest.main()
+ 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"))