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 | |
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')
24 files changed, 0 insertions, 3782 deletions
diff --git a/tests/unit/benchmark/contexts/__init__.py b/tests/unit/benchmark/contexts/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/tests/unit/benchmark/contexts/__init__.py +++ /dev/null diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml deleted file mode 100644 index dbdd3700d..000000000 --- a/tests/unit/benchmark/contexts/nodes_duplicate_sample.yaml +++ /dev/null @@ -1,21 +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 diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml deleted file mode 100644 index 306915ca1..000000000 --- a/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml +++ /dev/null @@ -1,32 +0,0 @@ -nodes: -- - name: sriov - role: Sriov1 - ip: 10.123.123.122 - user: root - auth_type: password - password: password - vf_macs: - - "00:00:00:00:00:00" - - "00:00:00:00:00:00" - 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" -- - name: sriov - role: Sriov1 - ip: 10.123.123.111 - user: root - auth_type: password - password: password - vf_macs: - - "00:00:00:00:00:00" - - "00:00:00:00:00:00" - 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/nodes_duplicate_sample_ovs.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample_ovs.yaml deleted file mode 100644 index 65449c91c..000000000 --- a/tests/unit/benchmark/contexts/nodes_duplicate_sample_ovs.yaml +++ /dev/null @@ -1,63 +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: ovs - role: test - 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: ovs - role: test - ip: 10.223.197.112 - 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" - diff --git a/tests/unit/benchmark/contexts/nodes_sample.yaml b/tests/unit/benchmark/contexts/nodes_sample.yaml deleted file mode 100644 index 8d50c3aea..000000000 --- a/tests/unit/benchmark/contexts/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/nodes_sample_new.yaml b/tests/unit/benchmark/contexts/nodes_sample_new.yaml deleted file mode 100644 index a400bec03..000000000 --- a/tests/unit/benchmark/contexts/nodes_sample_new.yaml +++ /dev/null @@ -1,96 +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.123.123.123 - user: root - auth_type: password - 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: "00:00:00:00:00:00" - 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: "00:00:00:00:00:00" -- - name: sriov - role: Sriov - ip: 10.123.123.122 - user: root - auth_type: password - password: password - vf_macs: - - "00:00:00:00:00:00" - - "00:00:00:00:00:00" - 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" - -- - name: vnf - role: vnf - ip: 10.123.123.121 - user: root - auth_type: password - password: password - host: 10.123.123.121 #BM host == ip, SRIOV & ovs-dpdk host == compute node. - interfaces: - xe0: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:06:00.0" - driver: i40e - dpdk_port_num: 0 - local_ip: "152.16.100.19" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:00" - - xe1: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:06:00.1" - driver: i40e - dpdk_port_num: 1 - local_ip: "152.16.40.19" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:00" - 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/nodes_sample_new_sriov.yaml b/tests/unit/benchmark/contexts/nodes_sample_new_sriov.yaml deleted file mode 100644 index 55ff2e778..000000000 --- a/tests/unit/benchmark/contexts/nodes_sample_new_sriov.yaml +++ /dev/null @@ -1,82 +0,0 @@ -nodes: -- - name: trafficgen_1 - role: TrafficGen - ip: 10.123.123.123 - user: root - auth_type: password - 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: "00:00:00:00:00:00" - 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: "00:00:00:00:00:00" -- - name: sriov - role: Sriov1 - ip: 10.123.123.122 - user: root - auth_type: password - password: password - vf_macs: - - "00:00:00:00:00:00" - - "00:00:00:00:00:00" - 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" - -- - name: vnf - role: vnf - ip: 10.123.123.121 - user: root - auth_type: password - password: password - host: 10.123.123.121 #BM host == ip, SRIOV & ovs-dpdk host == compute node. - interfaces: - xe0: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:06:00.0" - driver: i40e - dpdk_port_num: 0 - local_ip: "152.16.100.19" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:00" - - xe1: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:06:00.1" - driver: i40e - dpdk_port_num: 1 - local_ip: "152.16.40.19" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:00" - 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/nodes_sample_ovs.yaml b/tests/unit/benchmark/contexts/nodes_sample_ovs.yaml deleted file mode 100644 index b1da1ea9f..000000000 --- a/tests/unit/benchmark/contexts/nodes_sample_ovs.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/nodes_sample_ovsdpdk.yaml b/tests/unit/benchmark/contexts/nodes_sample_ovsdpdk.yaml deleted file mode 100644 index c02849a05..000000000 --- a/tests/unit/benchmark/contexts/nodes_sample_ovsdpdk.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: Ovsdpdk1 - 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/__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')) diff --git a/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml b/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml deleted file mode 100644 index e468d0465..000000000 --- a/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml +++ /dev/null @@ -1,135 +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. -# ---- -# 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: node1 - role: TrafficGen - ip: 1.1.1.1 - user: root - password: r00t - interfaces: - xe0: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:05:00.0" - driver: i40e - dpdk_port_num: 0 - local_ip: "152.16.100.20" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:01" - xe1: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:05:00.1" - driver: i40e - dpdk_port_num: 1 - local_ip: "152.16.100.21" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:02" -- - name: node2 - role: nfvi_node - class: OvsDpdk - ip: 1.1.1.2 - user: root - password: r00t - vports: - - dpdkvhostuser0 - - dpdkvhostuser1 - vports_mac: - - "00:00:00:00:00:03" - - "00:00:00:00:00:04" - phy_ports: # Physical ports to configure sriov - - "0000:05:00.0" - - "0000:05: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/ubuntu.qcow2" -- - name: node2 - role: nfvi_node - class: OvsDpdk - ip: 1.1.1.5 - user: root - password: r00t - vports: - - dpdkvhostuser0 - - dpdkvhostuser1 - vports_mac: - - "00:00:00:00:00:03" - - "00:00:00:00:00:04" - phy_ports: # Physical ports to configure sriov - - "0000:05:00.0" - - "0000:05: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/ubuntu.qcow2" - -- - name: node3 - role: vnf - ip: 1.1.1.3 - user: root - password: r00t - host: 1.1.1.1 - 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:05" - - 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:06" - 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_sample.yaml b/tests/unit/benchmark/contexts/standalone_sample.yaml deleted file mode 100644 index 95e12d62f..000000000 --- a/tests/unit/benchmark/contexts/standalone_sample.yaml +++ /dev/null @@ -1,112 +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. -# ---- -# 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: node1 - role: TrafficGen - ip: 1.1.1.1 - user: root - password: r00t - interfaces: - xe0: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:05:00.0" - driver: i40e - dpdk_port_num: 0 - local_ip: "152.16.100.20" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:01" - xe1: # logical name from topology.yaml and vnfd.yaml - vpci: "0000:05:00.1" - driver: i40e - dpdk_port_num: 1 - local_ip: "152.16.100.21" - netmask: "255.255.255.0" - local_mac: "00:00:00:00:00:02" -- - name: node2 - role: nfvi_node - class: OvsDpdk - ip: 1.1.1.2 - user: root - password: r00t - vports: - - dpdkvhostuser0 - - dpdkvhostuser1 - vports_mac: - - "00:00:00:00:00:03" - - "00:00:00:00:00:04" - phy_ports: # Physical ports to configure sriov - - "0000:05:00.0" - - "0000:05: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/ubuntu.qcow2" - -- - name: node3 - role: vnf - ip: 1.1.1.3 - user: root - password: r00t - host: 1.1.1.1 - 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:05" - - 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:06" - 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/test_dummy.py b/tests/unit/benchmark/contexts/test_dummy.py deleted file mode 100644 index 1a54035df..000000000 --- a/tests/unit/benchmark/contexts/test_dummy.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# 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 -############################################################################## - -# Unittest for yardstick.benchmark.contexts.dummy - -from __future__ import absolute_import -import unittest - -from yardstick.benchmark.contexts import dummy - - -class DummyContextTestCase(unittest.TestCase): - - def setUp(self): - self.test_context = dummy.DummyContext() - - def test__get_server(self): - self.test_context.init(None) - self.test_context.deploy() - - result = self.test_context._get_server(None) - self.assertEqual(result, None) - - self.test_context.undeploy() diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py deleted file mode 100644 index f2e725df2..000000000 --- a/tests/unit/benchmark/contexts/test_heat.py +++ /dev/null @@ -1,503 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# Copyright (c) 2015 Ericsson AB and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# Unittest for yardstick.benchmark.contexts.heat - -from __future__ import absolute_import - -import logging -import os -import unittest -import uuid -from collections import OrderedDict - -import mock - -from itertools import count -from yardstick.benchmark.contexts import heat -from yardstick.benchmark.contexts import model - -LOG = logging.getLogger(__name__) - - -class HeatContextTestCase(unittest.TestCase): - - def __init__(self, *args, **kwargs): - super(HeatContextTestCase, self).__init__(*args, **kwargs) - self.name_iter = ('vnf{:03}'.format(x) for x in count(0, step=3)) - - def setUp(self): - self.test_context = heat.HeatContext() - self.mock_context = mock.Mock(spec=heat.HeatContext()) - - def test___init__(self): - self.assertIsNone(self.test_context.name) - self.assertIsNone(self.test_context.stack) - self.assertEqual(self.test_context.networks, OrderedDict()) - self.assertEqual(self.test_context.servers, []) - self.assertEqual(self.test_context.placement_groups, []) - self.assertEqual(self.test_context.server_groups, []) - self.assertIsNone(self.test_context.keypair_name) - self.assertIsNone(self.test_context.secgroup_name) - self.assertEqual(self.test_context._server_map, {}) - self.assertIsNone(self.test_context._image) - self.assertIsNone(self.test_context._flavor) - self.assertIsNone(self.test_context._user) - self.assertIsNone(self.test_context.template_file) - self.assertIsNone(self.test_context.heat_parameters) - self.assertIsNotNone(self.test_context.key_uuid) - self.assertIsNotNone(self.test_context.key_filename) - - @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup') - @mock.patch('yardstick.benchmark.contexts.heat.ServerGroup') - @mock.patch('yardstick.benchmark.contexts.heat.Network') - @mock.patch('yardstick.benchmark.contexts.heat.Server') - def test_init(self, mock_server, mock_network, mock_sg, mock_pg): - - pgs = {'pgrp1': {'policy': 'availability'}} - sgs = {'servergroup1': {'policy': 'affinity'}} - networks = {'bar': {'cidr': '10.0.1.0/24'}} - servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}} - attrs = {'name': 'foo', - 'placement_groups': pgs, - 'server_groups': sgs, - 'networks': networks, - 'servers': servers} - - self.test_context.init(attrs) - - self.assertEqual(self.test_context.name, "foo") - self.assertEqual(self.test_context.keypair_name, "foo-key") - self.assertEqual(self.test_context.secgroup_name, "foo-secgroup") - - mock_pg.assert_called_with('pgrp1', self.test_context, - pgs['pgrp1']['policy']) - mock_sg.assert_called_with('servergroup1', self.test_context, - sgs['servergroup1']['policy']) - self.assertTrue(len(self.test_context.placement_groups) == 1) - self.assertTrue(len(self.test_context.server_groups) == 1) - - mock_network.assert_called_with( - 'bar', self.test_context, networks['bar']) - self.assertTrue(len(self.test_context.networks) == 1) - - mock_server.assert_called_with('baz', self.test_context, - servers['baz']) - self.assertTrue(len(self.test_context.servers) == 1) - - if os.path.exists(self.test_context.key_filename): - try: - os.remove(self.test_context.key_filename) - os.remove(self.test_context.key_filename + ".pub") - except OSError: - LOG.exception("key_filename: %s", - self.test_context.key_filename) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_resources_to_template_no_servers(self, mock_template): - - self.test_context.keypair_name = "foo-key" - self.test_context.secgroup_name = "foo-secgroup" - self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b" - netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} - self.mock_context.name = 'bar' - self.test_context.networks = OrderedDict( - {"fool-network": model.Network("fool-network", self.mock_context, - netattrs)}) - - self.test_context._add_resources_to_template(mock_template) - mock_template.add_keypair.assert_called_with( - "foo-key", - "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b") - mock_template.add_security_group.assert_called_with("foo-secgroup") -# mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None) - mock_template.add_router.assert_called_with("bar-fool-network-router", - netattrs["external_network"], - "bar-fool-network-subnet") - mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", - "bar-fool-network-router", - "bar-fool-network-subnet") - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_attrs_get(self, mock_template): - image, flavor, user = expected_tuple = 'foo1', 'foo2', 'foo3' - self.assertNotEqual(self.test_context.image, image) - self.assertNotEqual(self.test_context.flavor, flavor) - self.assertNotEqual(self.test_context.user, user) - self.test_context._image = image - self.test_context._flavor = flavor - self.test_context._user = user - attr_tuple = self.test_context.image, self.test_context.flavor, self.test_context.user - self.assertEqual(attr_tuple, expected_tuple) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_attrs_set_negative(self, mock_template): - with self.assertRaises(AttributeError): - self.test_context.image = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.flavor = 'foo' - - with self.assertRaises(AttributeError): - self.test_context.user = 'foo' - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_deploy(self, mock_template): - self.test_context.name = 'foo' - self.test_context.template_file = '/bar/baz/some-heat-file' - self.test_context.heat_parameters = {'image': 'cirros'} - self.test_context.get_neutron_info = mock.MagicMock() - self.test_context.deploy() - - mock_template.assert_called_with('foo', - '/bar/baz/some-heat-file', - {'image': 'cirros'}) - self.assertIsNotNone(self.test_context.stack) - - def test_add_server_port(self): - network1 = mock.MagicMock() - network2 = mock.MagicMock() - self.test_context.name = 'foo' - self.test_context.stack = mock.MagicMock() - self.test_context.networks = { - 'a': network1, - 'c': network2, - } - self.test_context.stack.outputs = { - u'b': u'10.20.30.45', - u'b-subnet_id': 1, - u'foo-a-subnet-cidr': u'10.20.0.0/15', - u'foo-a-subnet-gateway_ip': u'10.20.30.1', - u'b-mac_address': u'00:01', - u'b-device_id': u'dev21', - u'b-network_id': u'net789', - u'd': u'40.30.20.15', - u'd-subnet_id': 2, - u'foo-c-subnet-cidr': u'40.30.0.0/18', - u'foo-c-subnet-gateway_ip': u'40.30.20.254', - u'd-mac_address': u'00:10', - u'd-device_id': u'dev43', - u'd-network_id': u'net987', - u'e': u'40.30.20.15', - u'e-subnet_id': 2, - u'e-mac_address': u'00:10', - u'e-device_id': u'dev43', - u'e-network_id': u'net987', - } - server = mock.MagicMock() - server.ports = OrderedDict([ - ('a', [{'stack_name': 'b', 'port': 'port_a'}]), - ('c', [{'stack_name': 'd', 'port': 'port_c'}, - {'stack_name': 'e', 'port': 'port_f'}]), - ]) - - expected = { - "private_ip": '10.20.30.45', - "subnet_id": 1, - "subnet_cidr": '10.20.0.0/15', - "network": '10.20.0.0', - "netmask": '255.254.0.0', - "name": "port_a", - "gateway_ip": '10.20.30.1', - "mac_address": '00:01', - "device_id": 'dev21', - "network_id": 'net789', - "network_name": 'a', - "local_mac": '00:01', - "local_ip": '10.20.30.45', - } - self.test_context.add_server_port(server) - self.assertEqual(server.private_ip, '10.20.30.45') - self.assertEqual(len(server.interfaces), 3) - self.assertDictEqual(server.interfaces['port_a'], expected) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test_undeploy(self, mock_template): - self.test_context.stack = mock_template - self.test_context.undeploy() - self.assertTrue(mock_template.delete.called) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - @mock.patch('yardstick.benchmark.contexts.heat.os') - def test_undeploy_key_filename(self, mock_template, mock_os): - self.test_context.stack = mock_template - mock_os.path.exists.return_value = True - self.assertIsNone(self.test_context.undeploy()) - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_found_dict(self, mock_pkg_resources): - """ - Use HeatContext._get_server to get a server that matches - based on a dictionary input. - """ - foo2_server = mock.Mock() - foo2_server.key_filename = None - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.key_filename = None - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = '127.0.0.3' - baz3_server.context.user = 'zab' - - self.test_context.name = 'bar' - self.test_context._user = 'bot' - self.test_context.stack = mock.Mock() - self.test_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.test_context.key_uuid = uuid.uuid4() - self.test_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - } - - attr_name = { - 'name': 'foo.bar', - 'private_ip_attr': 'private_ip', - 'public_ip_attr': 'public_ip', - } - result = self.test_context._get_server(attr_name) - self.assertEqual(result['user'], 'bot') - self.assertEqual(result['ip'], '127.0.0.1') - self.assertEqual(result['private_ip'], '10.0.0.1') - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_found_dict_no_attrs(self, mock_pkg_resources): - """ - Use HeatContext._get_server to get a server that matches - based on a dictionary input. - """ - foo2_server = mock.Mock() - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = '127.0.0.3' - baz3_server.context.user = 'zab' - - self.test_context.name = 'bar' - self.test_context._user = 'bot' - self.test_context.stack = mock.Mock() - self.test_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.test_context.key_uuid = uuid.uuid4() - self.test_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - } - - attr_name = { - 'name': 'foo.bar', - } - result = self.test_context._get_server(attr_name) - self.assertEqual(result['user'], 'bot') - # no private ip attr mapping in the map results in None value in the result - self.assertIsNone(result['private_ip']) - # no public ip attr mapping in the map results in no value in the result - self.assertNotIn('ip', result) - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_found_not_dict(self, mock_pkg_resources): - """ - Use HeatContext._get_server to get a server that matches - based on a non-dictionary input - """ - foo2_server = mock.Mock() - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = None - baz3_server.context.user = 'zab' - - self.test_context.name = 'bar1' - self.test_context.stack = mock.Mock() - self.test_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.test_context.key_uuid = uuid.uuid4() - self.test_context.generate_routing_table = mock.MagicMock(return_value=[]) - - self.test_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - } - - attr_name = 'baz3' - result = self.test_context._get_server(attr_name) - self.assertEqual(result['user'], 'zab') - self.assertEqual(result['private_ip'], '10.0.0.3') - # no public_ip on the server results in no value in the result - self.assertNotIn('public_ip', result) - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_none_found_not_dict(self, mock_pkg_resources): - """ - Use HeatContext._get_server to not get a server due to - None value associated with the match to a non-dictionary - input - """ - foo2_server = mock.Mock() - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = None - baz3_server.context.user = 'zab' - - self.test_context.name = 'bar1' - self.test_context.stack = mock.Mock() - self.test_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.test_context.key_uuid = uuid.uuid4() - self.test_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - 'wow4': None, - } - - attr_name = 'wow4' - result = self.test_context._get_server(attr_name) - self.assertIsNone(result) - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_not_found_dict(self, mock_pkg_resources): - """ - Use HeatContext._get_server to not get a server for lack - of a match to a dictionary input - """ - foo2_server = mock.Mock() - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = None - baz3_server.context.user = 'zab' - - self.test_context.name = 'bar1' - self.test_context.stack = mock.Mock() - self.test_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.test_context.key_uuid = uuid.uuid4() - self.test_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - } - - attr_name = { - 'name': 'foo.wow4', - 'private_ip_attr': 'private_ip', - 'public_ip_attr': 'public_ip', - } - result = self.test_context._get_server(attr_name) - self.assertIsNone(result) - - @mock.patch("yardstick.benchmark.contexts.heat.pkg_resources") - def test__get_server_not_found_not_dict(self, mock_pkg_resources): - """ - Use HeatContext._get_server to not get a server for lack - of a match to a non-dictionary input - """ - foo2_server = mock.Mock() - foo2_server.private_ip = '10.0.0.2' - foo2_server.public_ip = '127.0.0.2' - foo2_server.context.user = 'oof' - - baz3_server = mock.Mock() - baz3_server.private_ip = '10.0.0.3' - baz3_server.public_ip = None - baz3_server.context.user = 'zab' - - self.mock_context.name = 'bar1' - self.test_context.stack = mock.Mock() - self.mock_context.stack.outputs = { - 'private_ip': '10.0.0.1', - 'public_ip': '127.0.0.1', - } - self.mock_context.key_uuid = uuid.uuid4() - self.mock_context._server_map = { - 'baz3': baz3_server, - 'foo2': foo2_server, - } - - attr_name = 'foo.wow4' - result = self.test_context._get_server(attr_name) - self.assertIsNone(result) - - def test__get_network(self): - network1 = mock.MagicMock() - network1.name = 'net_1' - network1.vld_id = 'vld111' - network1.segmentation_id = 'seg54' - network1.network_type = 'type_a' - network1.physical_network = 'phys' - - network2 = mock.MagicMock() - network2.name = 'net_2' - network2.segmentation_id = 'seg45' - network2.network_type = 'type_b' - network2.physical_network = 'virt' - - self.test_context.networks = { - 'a': network1, - 'b': network2, - } - - attr_name = None - self.assertIsNone(self.test_context._get_network(attr_name)) - - attr_name = {} - self.assertIsNone(self.test_context._get_network(attr_name)) - - attr_name = {'network_type': 'nosuch'} - self.assertIsNone(self.test_context._get_network(attr_name)) - - attr_name = 'vld777' - self.assertIsNone(self.test_context._get_network(attr_name)) - - attr_name = {'segmentation_id': 'seg45'} - expected = { - "name": 'net_2', - "segmentation_id": 'seg45', - "network_type": 'type_b', - "physical_network": 'virt', - } - result = self.test_context._get_network(attr_name) - self.assertDictEqual(result, expected) - - attr_name = 'a' - expected = { - "name": 'net_1', - "segmentation_id": 'seg54', - "network_type": 'type_a', - "physical_network": 'phys', - } - result = self.test_context._get_network(attr_name) - self.assertDictEqual(result, expected) diff --git a/tests/unit/benchmark/contexts/test_kubernetes.py b/tests/unit/benchmark/contexts/test_kubernetes.py deleted file mode 100644 index 3a926f85c..000000000 --- a/tests/unit/benchmark/contexts/test_kubernetes.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# 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 -############################################################################## - -# Unittest for yardstick.benchmark.contexts.kubernetes - -from __future__ import absolute_import -import unittest -import mock - -from yardstick.benchmark.contexts.base import Context -from yardstick.benchmark.contexts.kubernetes import KubernetesContext - - -context_cfg = { - 'type': 'Kubernetes', - 'name': 'k8s', - 'servers': { - 'host': { - 'image': 'openretriever/yardstick', - 'command': '/bin/bash', - 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \ -service ssh restart;while true ; do sleep 10000; done'] - }, - 'target': { - 'image': 'openretriever/yardstick', - 'command': '/bin/bash', - 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \ -service ssh restart;while true ; do sleep 10000; done'] - } - } -} - -prefix = 'yardstick.benchmark.contexts.kubernetes' - - -class KubernetesTestCase(unittest.TestCase): - - def tearDown(self): - # clear kubernetes contexts from global list so we don't break other tests - Context.list = [] - - @mock.patch('{}.KubernetesContext._delete_services'.format(prefix)) - @mock.patch('{}.KubernetesContext._delete_ssh_key'.format(prefix)) - @mock.patch('{}.KubernetesContext._delete_rcs'.format(prefix)) - @mock.patch('{}.KubernetesContext._delete_pods'.format(prefix)) - def test_undeploy(self, - mock_delete_pods, - mock_delete_rcs, - mock_delete_ssh, - mock_delete_services): - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context.undeploy() - self.assertTrue(mock_delete_ssh.called) - self.assertTrue(mock_delete_rcs.called) - self.assertTrue(mock_delete_pods.called) - self.assertTrue(mock_delete_services.called) - - @mock.patch('{}.KubernetesContext._create_services'.format(prefix)) - @mock.patch('{}.KubernetesContext._wait_until_running'.format(prefix)) - @mock.patch('{}.KubernetesTemplate.get_rc_pods'.format(prefix)) - @mock.patch('{}.KubernetesContext._create_rcs'.format(prefix)) - @mock.patch('{}.KubernetesContext._set_ssh_key'.format(prefix)) - def test_deploy(self, - mock_set_ssh_key, - mock_create_rcs, - mock_get_rc_pods, - mock_wait_until_running, - mock_create_services): - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - with mock.patch("yardstick.benchmark.contexts.kubernetes.time"): - k8s_context.deploy() - self.assertTrue(mock_set_ssh_key.called) - self.assertTrue(mock_create_rcs.called) - self.assertTrue(mock_create_services.called) - self.assertTrue(mock_get_rc_pods.called) - self.assertTrue(mock_wait_until_running.called) - - @mock.patch('{}.paramiko'.format(prefix), **{"resource_filename.return_value": ""}) - @mock.patch('{}.pkg_resources'.format(prefix), **{"resource_filename.return_value": ""}) - @mock.patch('{}.utils'.format(prefix)) - @mock.patch('{}.open'.format(prefix), create=True) - @mock.patch('{}.k8s_utils.delete_config_map'.format(prefix)) - @mock.patch('{}.k8s_utils.create_config_map'.format(prefix)) - def test_ssh_key(self, mock_create, mock_delete, mock_open, mock_utils, mock_resources, - mock_paramiko): - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._set_ssh_key() - k8s_context._delete_ssh_key() - self.assertTrue(mock_create.called) - self.assertTrue(mock_delete.called) - - @mock.patch('{}.k8s_utils.read_pod_status'.format(prefix)) - def test_wait_until_running(self, mock_read_pod_status): - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context.template.pods = ['server'] - mock_read_pod_status.return_value = 'Running' - k8s_context._wait_until_running() - - @mock.patch('{}.k8s_utils.get_pod_by_name'.format(prefix)) - @mock.patch('{}.KubernetesContext._get_node_ip'.format(prefix)) - @mock.patch('{}.k8s_utils.get_service_by_name'.format(prefix)) - def test_get_server(self, - mock_get_service_by_name, - mock_get_node_ip, - mock_get_pod_by_name): - class Service(object): - def __init__(self): - self.name = 'yardstick' - self.node_port = 30000 - - class Services(object): - def __init__(self): - self.ports = [Service()] - - class Status(object): - def __init__(self): - self.pod_ip = '172.16.10.131' - - class Pod(object): - def __init__(self): - self.status = Status() - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - - mock_get_service_by_name.return_value = Services() - mock_get_pod_by_name.return_value = Pod() - mock_get_node_ip.return_value = '172.16.10.131' - - server = k8s_context._get_server('server') - self.assertIsNotNone(server) - - @mock.patch('{}.KubernetesContext._create_rc'.format(prefix)) - def test_create_rcs(self, mock_create_rc): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._create_rcs() - self.assertTrue(mock_create_rc.called) - - @mock.patch('{}.k8s_utils.create_replication_controller'.format(prefix)) - def test_create_rc(self, mock_create_replication_controller): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._create_rc({}) - self.assertTrue(mock_create_replication_controller.called) - - @mock.patch('{}.KubernetesContext._delete_rc'.format(prefix)) - def test_delete_rcs(self, mock_delete_rc): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._delete_rcs() - self.assertTrue(mock_delete_rc.called) - - @mock.patch('{}.k8s_utils.delete_replication_controller'.format(prefix)) - def test_delete_rc(self, mock_delete_replication_controller): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._delete_rc({}) - self.assertTrue(mock_delete_replication_controller.called) - - @mock.patch('{}.k8s_utils.get_node_list'.format(prefix)) - def test_get_node_ip(self, mock_get_node_list): - - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._get_node_ip() - self.assertTrue(mock_get_node_list.called) - - @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create') - def test_create_services(self, mock_create): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._create_services() - self.assertTrue(mock_create.called) - - @mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete') - def test_delete_services(self, mock_delete): - k8s_context = KubernetesContext() - k8s_context.init(context_cfg) - k8s_context._delete_services() - self.assertTrue(mock_delete.called) - - -def main(): - unittest.main() - - -if __name__ == '__main__': - main() diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py deleted file mode 100644 index 53b035b82..000000000 --- a/tests/unit/benchmark/contexts/test_model.py +++ /dev/null @@ -1,589 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# Copyright (c) 2015 Ericsson AB and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# Unittest for yardstick.benchmark.contexts.model - -from __future__ import absolute_import -import unittest -import mock - -from yardstick.benchmark.contexts import model - - -class ObjectTestCase(unittest.TestCase): - - def setUp(self): - self.mock_context = mock.Mock() - - def test_construct(self): - - test_object = model.Object('foo', self.mock_context) - - self.assertEqual(test_object.name, 'foo') - self.assertEqual(test_object._context, self.mock_context) - self.assertIsNone(test_object.stack_name) - self.assertIsNone(test_object.stack_id) - - def test_dn(self): - - self.mock_context.name = 'bar' - test_object = model.Object('foo', self.mock_context) - - self.assertEqual('foo.bar', test_object.dn) - - -class PlacementGroupTestCase(unittest.TestCase): - - def setUp(self): - self.mock_context = mock.Mock() - self.mock_context.name = 'bar' - - def tearDown(self): - model.PlacementGroup.map = {} - - def test_sucessful_construct(self): - - test_pg = model.PlacementGroup('foo', self.mock_context, 'affinity') - - self.assertEqual(test_pg.name, 'foo') - self.assertEqual(test_pg.members, set()) - self.assertEqual(test_pg.stack_name, 'bar-foo') - self.assertEqual(test_pg.policy, 'affinity') - - test_map = {'foo': test_pg} - self.assertEqual(model.PlacementGroup.map, test_map) - - def test_wrong_policy_in_construct(self): - - self.assertRaises(ValueError, model.PlacementGroup, 'foo', - self.mock_context, 'baz') - - def test_add_member(self): - - test_pg = model.PlacementGroup('foo', self.mock_context, 'affinity') - test_pg.add_member('foo') - - self.assertEqual(test_pg.members, set(['foo'])) - - def test_get_name_successful(self): - - model.PlacementGroup.map = {'foo': True} - self.assertTrue(model.PlacementGroup.get('foo')) - - def test_get_name_unsuccessful(self): - - self.assertIsNone(model.PlacementGroup.get('foo')) - - -class RouterTestCase(unittest.TestCase): - - def test_construct(self): - - mock_context = mock.Mock() - mock_context.name = 'baz' - test_router = model.Router('foo', 'bar', mock_context, 'qux') - - self.assertEqual(test_router.stack_name, 'baz-bar-foo') - self.assertEqual(test_router.stack_if_name, 'baz-bar-foo-if0') - self.assertEqual(test_router.external_gateway_info, 'qux') - - -class NetworkTestCase(unittest.TestCase): - - def setUp(self): - self.mock_context = mock.Mock() - self.mock_context.name = 'bar' - - def tearDown(self): - model.Network.list = [] - - def test_construct_no_external_network(self): - - attrs = {'cidr': '10.0.0.0/24'} - test_network = model.Network('foo', self.mock_context, attrs) - - self.assertEqual(test_network.stack_name, 'bar-foo') - self.assertEqual(test_network.subnet_stack_name, 'bar-foo-subnet') - self.assertEqual(test_network.subnet_cidr, attrs['cidr']) - self.assertIsNone(test_network.router) - self.assertIn(test_network, model.Network.list) - - def test_construct_has_external_network(self): - - attrs = {'external_network': 'ext_net'} - test_network = model.Network('foo', self.mock_context, attrs) - exp_router = model.Router('router', 'foo', self.mock_context, - 'ext_net') - - self.assertEqual(test_network.router.stack_name, exp_router.stack_name) - self.assertEqual(test_network.router.stack_if_name, - exp_router.stack_if_name) - self.assertEqual(test_network.router.external_gateway_info, - exp_router.external_gateway_info) - - def test_has_route_to(self): - - attrs = {'external_network': 'ext_net'} - test_network = model.Network('foo', self.mock_context, attrs) - - self.assertTrue(test_network.has_route_to('ext_net')) - - def test_has_no_route_to(self): - - attrs = {} - test_network = model.Network('foo', self.mock_context, attrs) - - self.assertFalse(test_network.has_route_to('ext_net')) - - @mock.patch('yardstick.benchmark.contexts.model.Network.has_route_to') - def test_find_by_route_to(self, mock_has_route_to): - - mock_network = mock.Mock() - model.Network.list = [mock_network] - mock_has_route_to.return_value = True - - self.assertIs(mock_network, model.Network.find_by_route_to('foo')) - - def test_find_external_network(self): - - mock_network = mock.Mock() - mock_network.router = mock.Mock() - mock_network.router.external_gateway_info = 'ext_net' - model.Network.list = [mock_network] - - self.assertEqual(model.Network.find_external_network(), 'ext_net') - - def test_construct_gateway_ip_is_null(self): - - attrs = {'gateway_ip': 'null'} - test_network = model.Network('foo', self.mock_context, attrs) - self.assertEqual(test_network.gateway_ip, 'null') - - def test_construct_gateway_ip_is_none(self): - - attrs = {'gateway_ip': None} - test_network = model.Network('foo', self.mock_context, attrs) - self.assertEqual(test_network.gateway_ip, 'null') - - def test_construct_gateway_ip_is_absent(self): - - attrs = {} - test_network = model.Network('foo', self.mock_context, attrs) - self.assertIsNone(test_network.gateway_ip) - - -class ServerTestCase(unittest.TestCase): - - def setUp(self): - self.mock_context = mock.Mock() - self.mock_context.name = 'bar' - self.mock_context.keypair_name = 'some-keys' - self.mock_context.secgroup_name = 'some-secgroup' - self.mock_context.user = "some-user" - netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} - self.mock_context.networks = [model.Network("some-network", self.mock_context, netattrs)] - - def test_construct_defaults(self): - - attrs = None - test_server = model.Server('foo', self.mock_context, attrs) - - self.assertEqual(test_server.stack_name, 'foo.bar') - self.assertEqual(test_server.keypair_name, 'some-keys') - self.assertEqual(test_server.secgroup_name, 'some-secgroup') - self.assertEqual(test_server.placement_groups, []) - self.assertIsNone(test_server.server_group) - self.assertEqual(test_server.instances, 1) - self.assertIsNone(test_server.floating_ip) - self.assertIsNone(test_server._image) - self.assertIsNone(test_server._flavor) - self.assertIn(test_server, model.Server.list) - - @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup') - def test_construct_get_wrong_placement_group(self, mock_pg): - - attrs = {'placement': 'baz'} - mock_pg.get.return_value = None - - self.assertRaises(ValueError, model.Server, 'foo', - self.mock_context, attrs) - - @mock.patch('yardstick.benchmark.contexts.model.PlacementGroup') - def test_construct_get_wrong_server_group(self, mock_sg): - - attrs = {'server_group': 'baz'} - mock_sg.get.return_value = None - - self.assertRaises(ValueError, model.Server, 'foo', - self.mock_context, attrs) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance(self, mock_template): - attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', - 'floating_ip_assoc': 'some-vm', - 'availability_zone': 'zone'} - test_server = model.Server('foo', self.mock_context, attrs) - - self.mock_context.flavors = ['flavor1', 'flavor2', 'some-flavor'] - - mock_network = mock.Mock() - mock_network.name = 'some-network' - mock_network.stack_name = 'some-network-stack' - mock_network.allowed_address_pairs = ["1", "2"] - mock_network.vnic_type = 'normal' - mock_network.subnet_stack_name = 'some-network-stack-subnet' - mock_network.provider = 'sriov' - mock_network.external_network = 'ext_net' - mock_network.router = model.Router('some-router', 'some-network', self.mock_context, - 'ext_net') - - test_server._add_instance(mock_template, 'some-server', - [mock_network], 'hints') - - mock_template.add_port.assert_called_with( - 'some-server-some-network-port', - mock_network.stack_name, - mock_network.subnet_stack_name, - mock_network.vnic_type, - sec_group_id=self.mock_context.secgroup_name, - provider=mock_network.provider, - allowed_address_pairs=mock_network.allowed_address_pairs) - - mock_template.add_floating_ip.assert_called_with( - 'some-server-fip', - mock_network.external_network, - 'some-server-some-network-port', - 'bar-some-network-some-router-if0', - 'some-secgroup' - ) - - mock_template.add_floating_ip_association.assert_called_with( - 'some-server-fip-assoc', - 'some-server-fip', - 'some-server-some-network-port' - ) - - mock_template.add_server.assert_called_with( - 'some-server', 'some-image', - flavor='some-flavor', - flavors=['flavor1', 'flavor2', 'some-flavor'], - ports=['some-server-some-network-port'], - user=self.mock_context.user, - key_name=self.mock_context.keypair_name, - user_data='', - scheduler_hints='hints', - availability_zone='zone') - - def test_override_ip(self): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': [ - {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, - ], - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.interfaces = { - "xe0": { - "local_ip": "1.2.3.4", - "netmask": "255.255.255.0", - }, - "xe1": { - "local_ip": "1.2.3.5", - "netmask": "255.255.255.0" - } - } - test_server.network_ports = network_ports - - test_server.override_ip("uplink_0", {"port": "xe0"}) - self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"]) - - def test_override_ip_multiple(self): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': [ - {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, - {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, - ], - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.interfaces = { - "xe0": { - "local_ip": "1.2.3.4", - "netmask": "255.255.255.0", - }, - "xe1": { - "local_ip": "1.2.3.5", - "netmask": "255.255.255.0" - } - } - test_server.network_ports = network_ports - test_server.override_ip("uplink_0", {"port": "xe0"}) - self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"]) - - def test_override_ip_mixed(self): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': [ - 'xe0', - {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, - ], - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.interfaces = { - "xe0": { - "local_ip": "1.2.3.4", - "netmask": "255.255.255.0", - }, - "xe1": { - "local_ip": "1.2.3.5", - "netmask": "255.255.255.0" - } - } - test_server.network_ports = network_ports - test_server.override_ip("uplink_0", {"port": "xe0"}) - self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][1]["xe0"]) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_with_ip_override_invalid_syntax(self, mock_template): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': 'xe0', - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.network_ports = network_ports - context = type("Context", (object,), {}) - # can't use Mock because Mock.name is reserved - context.name = "context" - networks = [model.Network(n, context, {}) for n in network_ports] - - with self.assertRaises(SyntaxError): - test_server._add_instance(mock_template, 'some-server', - networks, 'hints') - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_with_ip_override(self, mock_template): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': [ - {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, - ], - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.network_ports = network_ports - context = type("Context", (object,), {}) - # can't use Mock because Mock.name is reserved - context.name = "context" - networks = [model.Network(n, context, {}) for n in network_ports] - - test_server._add_instance(mock_template, 'some-server', - networks, 'hints') - self.assertEqual(test_server.ports, { - 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}], - 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}], - 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'}] - }) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_with_multiple_ip_override(self, mock_template): - network_ports = { - 'mgmt': ['mgmt'], - 'uplink_0': [ - {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}}, - {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}}, - ], - 'downlink_0': [ - {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}}, - ], - } - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - } - test_server = model.Server('foo', self.mock_context, attrs) - test_server.network_ports = network_ports - context = type("Context", (object,), {}) - # can't use Mock because Mock.name is reserved - context.name = "context" - networks = [model.Network(n, context, {}) for n in network_ports] - - test_server._add_instance(mock_template, 'some-server', - networks, 'hints') - self.assertEqual(test_server.ports, { - 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}], - 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}], - 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'}, - # this is not an error, we can produce this, it is left to Heat - # to detect duplicate ports and error - {'port': 'xe0', 'stack_name': 'some-server-xe0-port'}] - }) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_with_user_data(self, mock_template): - user_data = "USER_DATA" - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - 'user_data': user_data, - } - test_server = model.Server('foo', self.mock_context, attrs) - - test_server._add_instance(mock_template, 'some-server', - [], 'hints') - - mock_template.add_server.assert_called_with( - 'some-server', 'some-image', - flavor='some-flavor', - flavors=self.mock_context.flavors, - ports=[], - user=self.mock_context.user, - key_name=self.mock_context.keypair_name, - user_data=user_data, - scheduler_hints='hints', - availability_zone=None) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_with_availablity_zone(self, mock_template): - attrs = { - 'image': 'some-image', 'flavor': 'some-flavor', - 'availability_zone': 'zone', - } - test_server = model.Server('foo', self.mock_context, attrs) - - test_server._add_instance(mock_template, 'some-server', - [], 'hints') - - mock_template.add_server.assert_called_with( - 'some-server', 'some-image', - flavor='some-flavor', - flavors=self.mock_context.flavors, - ports=[], - user=self.mock_context.user, - key_name=self.mock_context.keypair_name, - user_data='', - scheduler_hints='hints', - availability_zone='zone') - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_plus_flavor(self, mock_template): - - user_data = '' - attrs = { - 'image': 'some-image', 'flavor': 'flavor1', - 'flavors': ['flavor2'], 'user_data': user_data - } - test_server = model.Server('ServerFlavor-2', self.mock_context, attrs) - - self.mock_context.flavors = ['flavor2'] - mock_network = mock.Mock() - mock_network.allowed_address_pairs = ["1", "2"] - mock_network.vnic_type = 'normal' - mock_network.configure_mock(name='some-network', stack_name='some-network-stack', - subnet_stack_name='some-network-stack-subnet', - provider='some-provider') - - test_server._add_instance(mock_template, 'ServerFlavor-2', - [mock_network], 'hints') - - mock_template.add_port.assert_called_with( - 'ServerFlavor-2-some-network-port', - mock_network.stack_name, - mock_network.subnet_stack_name, - mock_network.vnic_type, - provider=mock_network.provider, - sec_group_id=self.mock_context.secgroup_name, - allowed_address_pairs=mock_network.allowed_address_pairs) - - mock_template.add_server.assert_called_with( - 'ServerFlavor-2', 'some-image', - flavor='flavor1', - flavors=['flavor2'], - ports=['ServerFlavor-2-some-network-port'], - user=self.mock_context.user, - key_name=self.mock_context.keypair_name, - user_data=user_data, - scheduler_hints='hints', - availability_zone=None) - - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') - def test__add_instance_misc(self, mock_template): - - user_data = '' - attrs = { - 'image': 'some-image', 'flavor': 'flavor1', - 'flavors': ['flavor2'], 'user_data': user_data - } - test_server = model.Server('ServerFlavor-3', self.mock_context, attrs) - - self.mock_context.flavors = ['flavor2'] - self.mock_context.flavor = {'vcpus': 4} - mock_network = mock.Mock() - mock_network.name = 'some-network' - mock_network.stack_name = 'some-network-stack' - mock_network.subnet_stack_name = 'some-network-stack-subnet' - - test_server._add_instance(mock_template, 'ServerFlavor-3', - [mock_network], 'hints') - - mock_template.add_port( - 'ServerFlavor-3-some-network-port', - mock_network.stack_name, - mock_network.subnet_stack_name, - sec_group_id=self.mock_context.secgroup_name) - - mock_template.add_flavor( - vcpus=4, - ram=2048, - disk=1) - - mock_template.add_flavor( - vcpus=4, - ram=2048, - disk=1, - extra_specs={'cat': 1, 'dog': 2, 'dragon': 1000}) - - mock_template.add_server.assert_called_with( - 'ServerFlavor-3', 'some-image', - flavor='flavor1', - flavors=['flavor2'], - ports=['ServerFlavor-3-some-network-port'], - user=self.mock_context.user, - key_name=self.mock_context.keypair_name, - user_data=user_data, - scheduler_hints='hints', - availability_zone=None) diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py deleted file mode 100644 index a2e2f7b9a..000000000 --- a/tests/unit/benchmark/contexts/test_node.py +++ /dev/null @@ -1,398 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# Copyright (c) 2015-2017 Huawei Technologies Co.,Ltd and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# Unittest for yardstick.benchmark.contexts.node - -from __future__ import absolute_import -import os -import unittest -import errno -import mock - -from yardstick.common import constants as consts -from yardstick.benchmark.contexts import node - - -class NodeContextTestCase(unittest.TestCase): - - PREFIX = 'yardstick.benchmark.contexts.node' - - NODES_SAMPLE = "nodes_sample.yaml" - NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml" - - def setUp(self): - self.test_context = node.NodeContext() - self.os_path_join = os.path.join - - def _get_file_abspath(self, filename): - curr_path = os.path.dirname(os.path.abspath(__file__)) - file_path = self.os_path_join(curr_path, filename) - return file_path - - def test___init__(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.controllers, []) - self.assertEqual(self.test_context.computes, []) - self.assertEqual(self.test_context.baremetals, []) - self.assertEqual(self.test_context.env, {}) - self.assertEqual(self.test_context.attrs, {}) - - @mock.patch('{}.os.path.join'.format(PREFIX)) - def test_init_negative(self, mock_path_join): - special_path = '/foo/bar/error_file' - error_path = self._get_file_abspath("error_file") - - def path_join(*args): - if args == (consts.YARDSTICK_ROOT_PATH, error_path): - return special_path - return self.os_path_join(*args) - - # we can't count mock_path_join calls because - # it can catch join calls for .pyc files. - mock_path_join.side_effect = path_join - self.test_context.read_config_file = read_mock = mock.Mock() - read_calls = 0 - - with self.assertRaises(KeyError): - self.test_context.init({}) - - self.assertEqual(read_mock.call_count, read_calls) - - attrs = { - 'name': 'foo', - 'file': error_path, - } - read_mock.side_effect = IOError(errno.EBUSY, 'busy') - with self.assertRaises(IOError) as raised: - self.test_context.init(attrs) - - read_calls += 1 - self.assertEqual(read_mock.called, read_calls) - self.assertIn(attrs['file'], self.test_context.file_path) - self.assertEqual(raised.exception.errno, errno.EBUSY) - self.assertEqual(str(raised.exception), str(read_mock.side_effect)) - - read_mock.side_effect = IOError(errno.ENOENT, 'not found') - with self.assertRaises(IOError) as raised: - self.test_context.init(attrs) - - read_calls += 2 - self.assertEqual(read_mock.call_count, read_calls) - self.assertEqual(self.test_context.file_path, special_path) - self.assertEqual(raised.exception.errno, errno.ENOENT) - self.assertEqual(str(raised.exception), str(read_mock.side_effect)) - - def test_read_config_file(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - self.assertIsNotNone(self.test_context.read_config_file()) - - def test__dispatch_script(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - self.test_context.env = {'bash': [{'script': 'dummy'}]} - self.test_context._execute_script = mock.Mock() - self.assertEqual(self.test_context._dispatch_script('bash'), None) - - def test__dispatch_ansible(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - self.test_context.env = {'ansible': [{'script': 'dummy'}]} - self.test_context._do_ansible_job = mock.Mock() - self.assertEqual(self.test_context._dispatch_ansible('ansible'), None) - self.test_context.env = {} - self.assertEqual(self.test_context._dispatch_ansible('ansible'), None) - - @mock.patch("{}.AnsibleCommon".format(PREFIX)) - def test__do_ansible_job(self, mock_ansible): - self.assertEqual(None, self.test_context._do_ansible_job('dummy')) - - def test_successful_init(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - self.assertEqual(self.test_context.name, "foo") - self.assertEqual(len(self.test_context.nodes), 4) - self.assertEqual(len(self.test_context.controllers), 2) - self.assertEqual(len(self.test_context.computes), 1) - self.assertEqual(self.test_context.computes[0]["name"], "node3") - self.assertEqual(len(self.test_context.baremetals), 1) - self.assertEqual(self.test_context.baremetals[0]["name"], "node4") - - def test__get_server_with_dic_attr_name(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - attr_name = {'name': 'foo.bar'} - result = self.test_context._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_SAMPLE) - } - - self.test_context.init(attrs) - - attr_name = 'bar.foo' - result = self.test_context._get_server(attr_name) - - self.assertEqual(result, None) - - def test__get_server_mismatch(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - attr_name = 'bar.foo1' - result = self.test_context._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.test_context.init(attrs) - - attr_name = 'node1.foo' - with self.assertRaises(ValueError): - self.test_context._get_server(attr_name) - - def test__get_server_found(self): - - attrs = { - 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) - } - - self.test_context.init(attrs) - - attr_name = 'node1.foo' - result = self.test_context._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') - - @mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX)) - def test_deploy(self, dispatch_script_mock): - obj = node.NodeContext() - obj.env = { - 'type': 'script' - } - obj.deploy() - self.assertTrue(dispatch_script_mock.called) - - @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX)) - def test_deploy_anisible(self, dispatch_ansible_mock): - obj = node.NodeContext() - obj.env = { - 'type': 'ansible' - } - obj.deploy() - self.assertTrue(dispatch_ansible_mock.called) - - @mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX)) - def test_undeploy(self, dispatch_script_mock): - obj = node.NodeContext() - obj.env = { - 'type': 'script' - } - obj.undeploy() - self.assertTrue(dispatch_script_mock.called) - - @mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX)) - def test_undeploy_anisble(self, dispatch_ansible_mock): - obj = node.NodeContext() - obj.env = { - 'type': 'ansible' - } - obj.undeploy() - self.assertTrue(dispatch_ansible_mock.called) - - @mock.patch('{}.ssh.SSH._put_file_shell'.format(PREFIX)) - @mock.patch('{}.ssh.SSH.execute'.format(PREFIX)) - def test_execute_remote_script(self, execute_mock, put_file_mock): - obj = node.NodeContext() - obj.env = {'prefix': 'yardstick.benchmark.scenarios.compute'} - node_name_args = 'node5' - obj.nodes = [{ - 'name': node_name_args, - 'user': 'ubuntu', - 'ip': '10.10.10.10', - 'pwd': 'ubuntu', - }] - - info = {'script': 'computecapacity.bash'} - execute_mock.return_value = (0, '', '') - obj._execute_remote_script('node5', info) - - self.assertTrue(put_file_mock.called) - self.assertTrue(execute_mock.called) - - @mock.patch('{}.NodeContext._execute_local_script'.format(PREFIX)) - def test_execute_script_local(self, local_execute_mock): - node_name = 'local' - info = {} - node.NodeContext()._execute_script(node_name, info) - self.assertTrue(local_execute_mock.called) - - @mock.patch('{}.NodeContext._execute_remote_script'.format(PREFIX)) - def test_execute_script_remote(self, remote_execute_mock): - node_name = 'node5' - info = {} - node.NodeContext()._execute_script(node_name, info) - self.assertTrue(remote_execute_mock.called) - - def test_get_script(self): - script_args = 'hello.bash' - info_args = { - 'script': script_args - } - script, options = node.NodeContext()._get_script(info_args) - self.assertEqual(script_args, script) - self.assertEqual('', options) - - def test_node_info(self): - node_name_args = 'node5' - obj = node.NodeContext() - obj.nodes = [{'name': node_name_args, 'check': node_name_args}] - node_info = obj._get_node_info(node_name_args) - self.assertEqual(node_info.get('check'), node_name_args) - - @mock.patch('{}.ssh.SSH.wait'.format(PREFIX)) - def test_get_client(self, wait_mock): - node_name_args = 'node5' - obj = node.NodeContext() - obj.nodes = [{ - 'name': node_name_args, - 'user': 'ubuntu', - 'ip': '10.10.10.10', - 'pwd': 'ubuntu', - }] - obj._get_client(node_name_args) - self.assertTrue(wait_mock.called) - - def test_get_server(self): - self.test_context.name = 'vnf1' - self.test_context.nodes = [{'name': 'my', 'value': 100}] - - with self.assertRaises(ValueError): - self.test_context.get_server('my.vnf2') - - expected = {'name': 'my.vnf1', 'value': 100, 'interfaces': {}} - result = self.test_context.get_server('my.vnf1') - self.assertDictEqual(result, expected) - - def test_get_context_from_server(self): - self.test_context.name = 'vnf1' - self.test_context.nodes = [{'name': 'my', 'value': 100}] - self.test_context.attrs = {'attr1': 200} - - with self.assertRaises(ValueError): - self.test_context.get_context_from_server('my.vnf2') - - result = self.test_context.get_context_from_server('my.vnf1') - self.assertIs(result, self.test_context) - - 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.test_context.networks = { - 'a': network1, - 'b': network2, - } - - attr_name = {} - self.assertIsNone(self.test_context._get_network(attr_name)) - - attr_name = {'vld_id': 'vld777'} - self.assertIsNone(self.test_context._get_network(attr_name)) - - self.assertIsNone(self.test_context._get_network(None)) - - attr_name = 'vld777' - self.assertIsNone(self.test_context._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.test_context._get_network(attr_name) - self.assertDictEqual(result, expected) - - attr_name = 'a' - expected = network1 - result = self.test_context._get_network(attr_name) - self.assertDictEqual(result, expected) - - -def main(): - unittest.main() - - -if __name__ == '__main__': - main() |