diff options
Diffstat (limited to 'tests')
55 files changed, 4351 insertions, 408 deletions
diff --git a/tests/ci/prepare_env.sh b/tests/ci/prepare_env.sh index 3d9cc298f..c3ee4c76b 100755 --- a/tests/ci/prepare_env.sh +++ b/tests/ci/prepare_env.sh @@ -11,7 +11,7 @@ # Perepare the environment to run yardstick ci : ${DEPLOY_TYPE:='bm'} # Can be any of 'bm' (Bare Metal) or 'virt' (Virtual) - +: ${INSTALLER_TYPE:='unknown'} : ${NODE_NAME:='unknown'} : ${EXTERNAL_NETWORK:='admin_floating_net'} @@ -61,9 +61,9 @@ export EXTERNAL_NETWORK INSTALLER_TYPE DEPLOY_TYPE NODE_NAME # Prepare a admin-rc file for StorPerf integration $YARDSTICK_REPO_DIR/tests/ci/prepare_storperf_admin-rc.sh -# copy a admin-rc file for StorPerf integration to the deployment location -if [ "$NODE_NAME" == "huawei-pod1" ]; then - bash $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_files.sh +# copy Storperf related files to the deployment location +if [ "$INSTALLER_TYPE" == "compass" ]; then + source $YARDSTICK_REPO_DIR/tests/ci/scp_storperf_files.sh fi # Fetching id_rsa file from jump_server..." diff --git a/tests/ci/scp_storperf_files.sh b/tests/ci/scp_storperf_files.sh index 234032cf1..71306eb80 100644 --- a/tests/ci/scp_storperf_files.sh +++ b/tests/ci/scp_storperf_files.sh @@ -12,9 +12,26 @@ # Copy storperf_admin-rc to deployment location. ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -sshpass -p root scp 2>/dev/null $ssh_options ~/storperf_admin-rc \ - root@192.168.10.6:/root/ &> /dev/null -sshpass -p root scp 2>/dev/null $ssh_options /home/opnfv/repos/storperf/docker-compose/docker-compose.yaml \ - root@192.168.10.6:/root/ &> /dev/null -sshpass -p root scp 2>/dev/null $ssh_options /home/opnfv/repos/storperf/docker-compose/nginx.conf \ - root@192.168.10.6:/root/ &> /dev/null + +scp_files(){ + export JUMP_HOST_IP + sshpass -p root scp 2>/dev/null $ssh_options ~/storperf_admin-rc \ + root@${JUMP_HOST_IP}:/root/ &> /dev/null + sshpass -p root scp 2>/dev/null $ssh_options /home/opnfv/repos/storperf/docker-compose/docker-compose.yaml \ + root@${JUMP_HOST_IP}:/root/ &> /dev/null +} + +case "$NODE_NAME" in + "huawei-pod1") + JUMP_HOST_IP='192.168.10.6' + scp_files + ;; + "huawei-pod2") + JUMP_HOST_IP='192.168.11.2' + scp_files + ;; + *) + # no node name, exit + echo "storperf test case will not run on this pod, skipping scp files..." + ;; +esac diff --git a/tests/ci/yardstick-verify b/tests/ci/yardstick-verify index 096ea534f..16598df7b 100755 --- a/tests/ci/yardstick-verify +++ b/tests/ci/yardstick-verify @@ -99,8 +99,8 @@ set -o pipefail install_storperf() { - # Install Storper on huawei-pod1 - if [ "$NODE_NAME" == "huawei-pod1" ]; then + # Install Storper on huawei-pod1 and huawei-pod2 + if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then echo echo "========== Installing storperf ==========" @@ -114,8 +114,8 @@ install_storperf() remove_storperf() { - # remove Storper from huawei-pod1 - if [ "$NODE_NAME" == "huawei-pod1" ]; then + # remove Storper from huawei-pod1 and huawei-pod2 + if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then echo echo "========== Removing storperf ==========" @@ -293,8 +293,13 @@ main() echo # check OpenStack services + if [[ $OS_INSECURE ]] && [[ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]]; then + SECURE="--insecure" + else + SECURE="" + fi echo "Checking OpenStack services:" - for cmd in "openstack image list" "openstack server list" "openstack stack list"; do + for cmd in "openstack ${SECURE} image list" "openstack ${SECURE} server list" "openstack ${SECURE} stack list"; do echo " checking ${cmd} ..." if ! $cmd >/dev/null; then echo "error: command \"$cmd\" failed" diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc008.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc008.yaml index 4c7fdab90..f5ccb255a 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc008.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc008.yaml @@ -29,12 +29,21 @@ scenarios: packetsize: {{pkt_size}} number_of_ports: {{num_ports}} duration: 20 + # choose vnic name: default to eth0 + # vnic_name: 'ens3' + # turn on multiqueue inside VM + # multiqueue: True + # choose starting pps: default 1M; + # works with binary search runner Dynamictp to find max throughput per sla + # pps: 3000000 host: demeter.yardstick-TC008 target: poseidon.yardstick-TC008 runner: type: Iteration + # binary search runner + # type: Dynamictp iterations: 10 interval: 1 diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc023.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc023.yaml new file mode 100644 index 000000000..2804f25a2 --- /dev/null +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc023.yaml @@ -0,0 +1,176 @@ +############################################################################## +# 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 +############################################################################## +--- + +schema: "yardstick:task:0.1" + +{% set file = file or "etc/yardstick/nodes/compass_sclab_virtual/pod.yaml" %} +{% set cpu_set = cpu_set or "0,1,2,3" %} +{% set memory_load = memory_load or 0 %} + +{% set flavor = flavor or "yardstick-migrate-flavor" %} +{% set ram = ram or "2048" %} +{% set vcpus = vcpus or "2" %} +{% set disk = disk or "3" %} + +scenarios: +- + type: GetServer + + output: status server + + host: server.migrate + + runner: + type: Iteration + iteration: 1 +- + type: GetNumaInfo + + options: + server: $server + file: {{ file }} + + output: origin_numa_info + + host: server.migrate + + runner: + type: Iteration + iteration: 1 +- + type: GetMigrateTargetHost + + options: + server: $server + output: target_host + + runner: + type: Iteration + iteration: 1 +- + type: GetServerIp + + options: + server: $server + + output: server_ip + + runner: + type: Iteration + iteration: 1 +- + type: AddMemoryLoad + + options: + memory_load: {{ memory_load }} + + host: server.migrate + + runner: + type: Iteration + iteration: 1 +- + type: Migrate + + options: + server: $server + host: $target_host + server_ip: $server_ip + + output: status migrate_time1 downtime1 + + runner: + type: Iteration + iteration: 1 +- + type: CheckValue + + options: + value1: $status + value2: 0 + operator: eq + + runner: + type: Iteration + iteration: 1 +- + type: GetServer + + output: status server + + host: server.migrate + + runner: + type: Iteration + iteration: 1 +- + type: GetNumaInfo + + options: + server: $server + file: {{ file }} + + output: new_numa_info + + host: server.migrate + + runner: + type: Iteration + iteration: 1 +- + type: CheckNumaInfo + + options: + info1: $origin_numa_info + info2: $new_numa_info + cpu_set: {{ cpu_set }} + + output: status + + runner: + type: Iteration + iteration: 1 +- + type: CheckValue + + options: + value1: $status + value2: true + operator: eq + + runner: + type: Iteration + iteration: 1 + + +contexts: +- + type: Node + name: env-prepare + file: {{ file }} + + env: + type: ansible + setup: migrate_pinning_setup.yaml -e "flavor={{ flavor }} ram={{ ram }} vcpus={{ vcpus }} disk={{ disk }} cpu_set={{ cpu_set }}" + teardown: migrate_pinning_teardown.yaml -e "flavor={{ flavor }}" + +- + name: migrate + image: yardstick-image + flavor: {{ flavor }} + user: ubuntu + + servers: + server: + floating_ip: true + + networks: + test: + cidr: '10.0.1.0/24' diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc074.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc074.yaml index 5bd3f676f..ef4f02c9e 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc074.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc074.yaml @@ -14,13 +14,14 @@ description: > StorPerf is a tool to measure block and object storage performance in an NFVI. {% set public_network = public_network or "ext-net" %} -{% set StorPerf_ip = StorPerf_ip or "192.168.10.6" %} +{% set StorPerf_ip = StorPerf_ip or "192.168.200.1" %} scenarios: - type: StorPerf options: agent_count: 1 agent_image: "Ubuntu-16.04" + agent_flavor: "storperf" public_network: {{public_network}} volume_size: 4 block_sizes: "4096" diff --git a/tests/opnfv/test_suites/opnfv_os-nosdn-nofeature-ha_daily.yaml b/tests/opnfv/test_suites/opnfv_os-nosdn-nofeature-ha_daily.yaml index ba1a93cec..dea44c8b3 100644 --- a/tests/opnfv/test_suites/opnfv_os-nosdn-nofeature-ha_daily.yaml +++ b/tests/opnfv/test_suites/opnfv_os-nosdn-nofeature-ha_daily.yaml @@ -134,10 +134,12 @@ test_cases: file_name: opnfv_yardstick_tc074.yaml constraint: installer: compass - pod: huawei-pod1 + pod: huawei-pod1, huawei-pod2 task_args: huawei-pod1: '{"public_network": "ext-net", - "StorPerf_ip": "192.168.200.1"}' + "StorPerf_ip": "192.168.10.6"}' + huawei-pod2: '{"public_network": "ext-net", + "StorPerf_ip": "192.168.11.2"}' - file_name: opnfv_yardstick_tc075.yaml constraint: diff --git a/tests/unit/apiserver/utils/test_common.py b/tests/unit/apiserver/utils/test_common.py deleted file mode 100644 index ad81cb76b..000000000 --- a/tests/unit/apiserver/utils/test_common.py +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################## -# Copyright (c) 2016 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 -############################################################################## -from __future__ import absolute_import -import unittest - -from api.utils import common - - -class TranslateToStrTestCase(unittest.TestCase): - - def test_translate_to_str_unicode(self): - input_str = u'hello' - output_str = common.translate_to_str(input_str) - - result = 'hello' - self.assertEqual(result, output_str) - - def test_translate_to_str_dict_list_unicode(self): - input_str = { - u'hello': {u'hello': [u'world']} - } - output_str = common.translate_to_str(input_str) - - result = { - 'hello': {'hello': ['world']} - } - self.assertEqual(result, output_str) - - -def main(): - unittest.main() - - -if __name__ == '__main__': - main() diff --git a/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml b/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml new file mode 100644 index 000000000..306915ca1 --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_duplicate_sample_new.yaml @@ -0,0 +1,32 @@ +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 new file mode 100644 index 000000000..65449c91c --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_duplicate_sample_ovs.yaml @@ -0,0 +1,63 @@ +# 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_new.yaml b/tests/unit/benchmark/contexts/nodes_sample_new.yaml new file mode 100644 index 000000000..a400bec03 --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_sample_new.yaml @@ -0,0 +1,96 @@ +# 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 new file mode 100644 index 000000000..55ff2e778 --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_sample_new_sriov.yaml @@ -0,0 +1,82 @@ +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 new file mode 100644 index 000000000..b1da1ea9f --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_sample_ovs.yaml @@ -0,0 +1,104 @@ +# 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 new file mode 100644 index 000000000..c02849a05 --- /dev/null +++ b/tests/unit/benchmark/contexts/nodes_sample_ovsdpdk.yaml @@ -0,0 +1,104 @@ +# 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/ovs_sample_password.yaml b/tests/unit/benchmark/contexts/ovs_sample_password.yaml new file mode 100644 index 000000000..b1da1ea9f --- /dev/null +++ b/tests/unit/benchmark/contexts/ovs_sample_password.yaml @@ -0,0 +1,104 @@ +# 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/ovs_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml new file mode 100644 index 000000000..896ec33bb --- /dev/null +++ b/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml @@ -0,0 +1,69 @@ +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +--- +# Sample config file about the POD information, including the +# name/IP/user/ssh key of Bare Metal and Controllers/Computes +# +# The options of this config file include: +# name: the name of this node +# role: node's role, support role: Master/Controller/Comupte/BareMetal +# ip: the node's IP address +# user: the username for login +# key_filename:the path of the private key file for login + +nodes: +- + name: trafficgen_1 + role: TrafficGen + ip: 10.10.10.10 + auth_type: ssh_key + user: root + ssh_port: 22 + key_filename: /root/.ssh/id_rsa + interfaces: + xe0: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.0" + driver: ixgbe + dpdk_port_num: 0 + local_ip: "152.16.100.20" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:68" + xe1: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.1" + driver: ixgbe + dpdk_port_num: 1 + local_ip: "152.16.100.21" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:69" +- + name: ovs + role: Ovsdpdk + ip: 10.223.197.222 + auth_type: ssh_key + user: root + ssh_port: 22 + key_filename: /root/.ssh/id_rsa + vpath: "/usr/local/" + vports: + - dpdkvhostuser0 + - dpdkvhostuser1 + vports_mac: + - "00:00:00:00:00:03" + - "00:00:00:00:00:04" + phy_ports: # Physical ports to configure ovs + - "0000:06:00.0" + - "0000:06:00.1" + flow: + - ovs-ofctl add-flow br0 in_port=1,action=output:3 + - ovs-ofctl add-flow br0 in_port=3,action=output:1 + - ovs-ofctl add-flow br0 in_port=4,action=output:2 + - ovs-ofctl add-flow br0 in_port=2,action=output:4 + phy_driver: i40e # kernel driver + images: "/var/lib/libvirt/images/ubuntu1.img" + diff --git a/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt b/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt new file mode 100644 index 000000000..f0eec86f6 --- /dev/null +++ b/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt @@ -0,0 +1 @@ +some content
\ No newline at end of file diff --git a/tests/unit/benchmark/contexts/sriov_sample_password.yaml b/tests/unit/benchmark/contexts/sriov_sample_password.yaml new file mode 100644 index 000000000..4f60e46d5 --- /dev/null +++ b/tests/unit/benchmark/contexts/sriov_sample_password.yaml @@ -0,0 +1,52 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +nodes: +- + name: trafficgen_1 + role: TrafficGen + ip: 10.10.10.10 + auth_type: password + user: root + password: password + interfaces: + xe0: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.0" + driver: ixgbe + dpdk_port_num: 0 + local_ip: "152.16.100.20" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:68" + xe1: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.1" + driver: ixgbe + dpdk_port_num: 1 + local_ip: "152.16.100.21" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:69" +- + name: sriov + role: Sriov + ip: 10.10.10.11 + auth_type: password + user: root + password: password + vf_macs: + - "00:00:00:71:7d:25" + - "00:00:00:71:7d:26" + phy_ports: # Physical ports to configure sriov + - "0000:06:00.0" + - "0000:06:00.1" + phy_driver: i40e # kernel driver + images: "/var/lib/libvirt/images/ubuntu1.img" diff --git a/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml new file mode 100644 index 000000000..faa496771 --- /dev/null +++ b/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml @@ -0,0 +1,54 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +nodes: +- + name: trafficgen_1 + role: TrafficGen + ip: 10.10.10.10 + auth_type: ssh_key + user: root + ssh_port: 22 + key_filename: /root/.ssh/id_rsa + interfaces: + xe0: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.0" + driver: ixgbe + dpdk_port_num: 0 + local_ip: "152.16.100.20" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:68" + xe1: # logical name from topology.yaml and vnfd.yaml + vpci: "0000:03:00.1" + driver: ixgbe + dpdk_port_num: 1 + local_ip: "152.16.100.21" + netmask: "255.255.255.0" + local_mac: "90:e2:ba:77:ce:69" +- + name: sriov + role: Sriov + ip: 10.10.10.11 + auth_type: ssh_key + user: root + ssh_port: 22 + key_filename: /root/.ssh/id_rsa + vf_macs: + - "00:00:00:71:7d:25" + - "00:00:00:71:7d:26" + phy_ports: # Physical ports to configure sriov + - "0000:06:00.0" + - "0000:06:00.1" + phy_driver: i40e # kernel driver + images: "/var/lib/libvirt/images/ubuntu1.img" diff --git a/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt b/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt new file mode 100644 index 000000000..f0eec86f6 --- /dev/null +++ b/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt @@ -0,0 +1 @@ +some content
\ No newline at end of file diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py index 3dadd48eb..ae57402c0 100644 --- a/tests/unit/benchmark/contexts/test_heat.py +++ b/tests/unit/benchmark/contexts/test_heat.py @@ -13,6 +13,7 @@ from __future__ import absolute_import +import ipaddress import logging import os import unittest @@ -120,7 +121,8 @@ class HeatContextTestCase(unittest.TestCase): 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_deploy(self, mock_template): + @mock.patch('yardstick.benchmark.contexts.heat.get_neutron_client') + def test_deploy(self, mock_neutron, mock_template): self.test_context.name = 'foo' self.test_context.template_file = '/bar/baz/some-heat-file' @@ -133,6 +135,59 @@ class HeatContextTestCase(unittest.TestCase): self.test_context.heat_parameters) self.assertIsNotNone(self.test_context.stack) + def test_add_server_port(self): + network1 = mock.MagicMock() + network1.vld_id = 'vld111' + network2 = mock.MagicMock() + network2.vld_id = 'vld777' + 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', + } + server = mock.MagicMock() + server.ports = OrderedDict([ + ('a', {'stack_name': 'b'}), + ('c', {'stack_name': 'd'}), + ]) + + 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', + "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', + "vld_id": 'vld111', + } + self.test_context.add_server_port(server) + self.assertEqual(server.private_ip, '10.20.30.45') + self.assertEqual(len(server.interfaces), 2) + self.assertDictEqual(server.interfaces['a'], expected) + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test_undeploy(self, mock_template): @@ -155,3 +210,57 @@ class HeatContextTestCase(unittest.TestCase): self.assertEqual(result['ip'], '127.0.0.1') self.assertEqual(result['private_ip'], '10.0.0.1') + + 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.vld_id = 'vld999' + 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 = {'vld_id': 'vld777'} + self.assertIsNone(self.test_context._get_network(attr_name)) + + 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": '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', + "vld_id": 'vld111', + "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 new file mode 100644 index 000000000..f47c07a67 --- /dev/null +++ b/tests/unit/benchmark/contexts/test_kubernetes.py @@ -0,0 +1,165 @@ +#!/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.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 UndeployTestCase(unittest.TestCase): + + @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): + + 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) + + +class DeployTestCase(unittest.TestCase): + + @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): + + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + k8s_context.deploy() + self.assertTrue(mock_set_ssh_key.called) + self.assertTrue(mock_create_rcs.called) + self.assertTrue(mock_get_rc_pods.called) + self.assertTrue(mock_wait_until_running.called) + + +class SSHKeyTestCase(unittest.TestCase): + + @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): + + 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) + + +class WaitUntilRunningTestCase(unittest.TestCase): + + @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() + + +class GetServerTestCase(unittest.TestCase): + + @mock.patch('{}.k8s_utils.get_pod_list'.format(prefix)) + def test_get_server(self, mock_get_pod_list): + k8s_context = KubernetesContext() + k8s_context.init(context_cfg) + + mock_get_pod_list.return_value.items = [] + server = k8s_context._get_server('server') + self.assertIsNone(server) + + +class CreateRcsTestCase(unittest.TestCase): + + @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) + + +class CreateRcTestCase(unittest.TestCase): + + @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) + + +class DeleteRcsTestCases(unittest.TestCase): + + @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) + + +class DeleteRcTestCase(unittest.TestCase): + + @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) + + +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 index 3fb186b9b..1ce550306 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -161,6 +161,23 @@ class NetworkTestCase(unittest.TestCase): 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): @@ -214,11 +231,12 @@ class ServerTestCase(unittest.TestCase): attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', 'floating_ip_assoc': 'some-vm'} test_server = model.Server('foo', self.mock_context, attrs) - self.mock_context.flavors = ['flavor1', 'flavor2', 'some-flavor'] + 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.subnet_stack_name = 'some-network-stack-subnet' mock_network.provider = 'sriov' mock_network.external_network = 'ext_net' @@ -232,7 +250,8 @@ class ServerTestCase(unittest.TestCase): mock_network.stack_name, mock_network.subnet_stack_name, sec_group_id=self.mock_context.secgroup_name, - provider=mock_network.provider) + provider=mock_network.provider, + allowed_address_pairs=mock_network.allowed_address_pairs) mock_template.add_floating_ip.assert_called_with( 'some-server-fip', @@ -290,11 +309,12 @@ class ServerTestCase(unittest.TestCase): } test_server = model.Server('ServerFlavor-2', self.mock_context, attrs) - self.mock_context.flavors = ['flavor2'] + self.mock_context.flavors = ['flavor2'] mock_network = mock.Mock() - mock_network.configure_mock(name='some-network', stack_name= 'some-network-stack', - subnet_stack_name = 'some-network-stack-subnet', - provider = 'some-provider') + mock_network.allowed_address_pairs = ["1", "2"] + 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') @@ -304,7 +324,8 @@ class ServerTestCase(unittest.TestCase): mock_network.stack_name, mock_network.subnet_stack_name, provider=mock_network.provider, - sec_group_id=self.mock_context.secgroup_name) + 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', diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py index 4b35ca421..d5ce8c5cb 100644 --- a/tests/unit/benchmark/contexts/test_node.py +++ b/tests/unit/benchmark/contexts/test_node.py @@ -208,6 +208,50 @@ class NodeContextTestCase(unittest.TestCase): obj._get_client(node_name_args) self.assertTrue(wait_mock.called) + 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() diff --git a/tests/unit/benchmark/contexts/test_ovsdpdk.py b/tests/unit/benchmark/contexts/test_ovsdpdk.py new file mode 100644 index 000000000..ac25ec877 --- /dev/null +++ b/tests/unit/benchmark/contexts/test_ovsdpdk.py @@ -0,0 +1,325 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +import os +import mock +import unittest + +from yardstick.benchmark.contexts import ovsdpdk + +NIC_INPUT = { + 'interface': {}, + 'vports_mac': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} +DRIVER = "i40e" +NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vports_mac': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + +CORRECT_FILE_PATH = "/etc/yardstick/nodes/pod_ovs.yaml" +WRONG_FILE_PATH = "/etc/yardstick/wrong.yaml" +SAMPLE_FILE = "ovs_sample_write_to_file.txt" + +OVS = [{ + 'auth_type': 'ssh_key', + 'name': 'ovs', + 'ssh_port': 22, + 'ip': '10.10.10.11', + 'key_filename': '/root/.ssh/id_rsa', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'vpath': '/usr/local/', + 'role': 'Ovsdpdk', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'flow': ['ovs-ofctl add-flow br0 in_port=1,action=output:3', + 'ovs-ofctl add-flow br0 in_port=3,action=output:1', + 'ovs-ofctl add-flow br0 in_port=4,action=output:2', + 'ovs-ofctl add-flow br0 in_port=2,action=output:4'], + 'phy_driver': 'i40e', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + +OVS_PASSWORD = [{ + 'auth_type': 'password', + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.10.10.11', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'flow': ['ovs-ofctl add-flow br0 in_port=1,action=output:3', + 'ovs-ofctl add-flow br0 in_port=3,action=output:1', + 'ovs-ofctl add-flow br0 in_port=4,action=output:2', + 'ovs-ofctl add-flow br0 in_port=2,action=output:4'], + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + +#vfnic = "i40evf" +PCIS = ['0000:06:00.0', '0000:06:00.1'] + + +class OvsdpdkTestCase(unittest.TestCase): + + NODES_SAMPLE_SSH = "ovs_sample_ssh_key.yaml" + NODES_SAMPLE_PASSWORD = "ovs_sample_password.yaml" + + def setUp(self): + self.test_context = ovsdpdk.Ovsdpdk() + + def test_construct(self): + self.assertIsNone(self.test_context.name) + self.assertIsNone(self.test_context.file_path) + self.assertEqual(self.test_context.nodes, []) + self.assertEqual(self.test_context.ovs, []) + self.assertFalse(self.test_context.vm_deploy) + self.assertTrue(self.test_context.first_run) + self.assertEqual(self.test_context.user, "") + self.assertEqual(self.test_context.ssh_ip, "") + self.assertEqual(self.test_context.passwd, "") + self.assertEqual(self.test_context.ssh_port, "") + self.assertEqual(self.test_context.auth_type, "") + + def test_init(self): + self.test_context.parse_pod_and_get_data = mock.Mock() + self.test_context.file_path = CORRECT_FILE_PATH + self.test_context.init() + self.assertIsNone(self.test_context.init()) + + def test_successful_init_with_ssh(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_SSH) + self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH) + + def test_successful_init_with_password(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD) + self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH) + + def test_unsuccessful_init(self): + self.assertRaises( + IOError, + lambda: self.test_context.parse_pod_and_get_data(WRONG_FILE_PATH)) + + def test_ssh_connection(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + + @mock.patch('yardstick.network_services.utils.provision_tool', return_value="b") + def test_ssh_connection(self, mock_prov): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "b", "")) + ssh.return_value = ssh_mock + mock_prov.provision_tool = mock.Mock() + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS_PASSWORD + self.assertIsNone(ovs_obj.ssh_remote_machine()) + + @mock.patch('yardstick.network_services.utils.provision_tool', return_value="b") + def test_ssh_connection_ssh_key(self, mock_prov): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "b", "")) + ssh.return_value = ssh_mock + mock_prov.provision_tool = mock.Mock() + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + ovs_obj.key_filename = '/root/.ssh/id_rsa' + self.assertIsNone(ovs_obj.ssh_remote_machine()) + + def test_get_nic_details(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "eth0 eth1", "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.ovs = OVS + ovs_obj.connection = ssh_mock + self.assertIsNotNone(ovs_obj.get_nic_details()) + + def test_install_req_libs(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.first_run = True + ovs_obj.connection = ssh_mock + self.assertIsNone(ovs_obj.install_req_libs()) + + def test_setup_ovs(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + self.assertIsNone(ovs_obj.setup_ovs({"eth0 eth1"})) + + def test_start_ovs_serverswitch(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + self.assertIsNone(ovs_obj.start_ovs_serverswitch()) + + def test_setup_ovs_bridge(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + self.assertIsNone(ovs_obj.setup_ovs_bridge()) + + def test_add_oflows(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + self.assertIsNone(ovs_obj.add_oflows()) + + def test_setup_ovs_context_vm_already_present(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + mock_ovs = mock.Mock() + ssh_mock.put = mock.Mock() + ovs_obj.check_output = mock.Mock(return_value=(0, "vm1")) + with mock.patch("yardstick.benchmark.contexts.ovsdpdk.time"): + self.assertIsNone(ovs_obj.setup_ovs_context(PCIS, NIC_DETAILS, DRIVER)) + + @mock.patch( + 'yardstick.benchmark.contexts.ovsdpdk', + return_value="Domain vm1 created from /tmp/vm_ovs.xml") + def test_is_vm_created(self, NIC_INPUT): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.put = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + mock_ovs = mock.Mock() + ret_create = mock.Mock() + pcis = NIC_DETAILS['pci'] + driver = NIC_DETAILS['phy_driver'] + self.assertIsNotNone( + mock_ovs.ovs_obj.setup_ovs_context( + pcis, + NIC_DETAILS, + driver)) + + def test_check_output(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + cmd = "command" + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + self.assertIsNotNone(ovs_obj.check_output(cmd, None)) + + def test_split_cpu_list_available(self): + with mock.patch("itertools.chain") as iter1: + iter1 = mock.Mock() + print("{0}".format(iter1)) + ovs_obj = ovsdpdk.Ovsdpdk() + self.assertIsNotNone(ovs_obj.split_cpu_list('0,5')) + + def test_split_cpu_list_null(self): + with mock.patch("itertools.chain") as iter1: + iter1 = mock.Mock() + print("{0}".format(iter1)) + ovs_obj = ovsdpdk.Ovsdpdk() + self.assertEqual(ovs_obj.split_cpu_list([]), []) + + def test_destroy_vm_successful(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + ovs_obj.check_output = mock.Mock(return_value=(0, "vm1")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "0 i40e")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "0 i40e")) + self.assertIsNone(ovs_obj.destroy_vm()) + + def test_destroy_vm_unsuccessful(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + ovs_obj = ovsdpdk.Ovsdpdk() + ovs_obj.connection = ssh_mock + ovs_obj.ovs = OVS + ovs_obj.check_output = mock.Mock(return_value=(1, {})) + self.assertIsNone(ovs_obj.destroy_vm()) + + def test_read_from_file(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD) + ovs_obj = ovsdpdk.Ovsdpdk() + self.assertIsNotNone(ovs_obj.read_from_file(CORRECT_FILE_PATH)) + + def test_write_to_file(self): + ovs_obj = ovsdpdk.Ovsdpdk() + self.assertIsNone(ovs_obj.write_to_file(SAMPLE_FILE, "some content")) + + def _get_file_abspath(self, filename): + curr_path = os.path.dirname(os.path.abspath(__file__)) + file_path = os.path.join(curr_path, filename) + return file_path + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/benchmark/contexts/test_sriov.py b/tests/unit/benchmark/contexts/test_sriov.py new file mode 100644 index 000000000..a8641a2eb --- /dev/null +++ b/tests/unit/benchmark/contexts/test_sriov.py @@ -0,0 +1,421 @@ +# Copyright (c) 2016-2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import +import os +import mock +import unittest + +from yardstick.benchmark.contexts import sriov + +NIC_INPUT = { + 'interface': {}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} +DRIVER = "i40e" +NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + +CORRECT_FILE_PATH = "/etc/yardstick/nodes/pod_sriov.yaml" +WRONG_FILE_PATH = "/etc/yardstick/wrong.yaml" +SAMPLE_FILE = "sriov_sample_write_to_file.txt" + +SRIOV = [{ + 'auth_type': 'ssh_key', + 'name': 'sriov', + 'ssh_port': 22, + 'ip': '10.10.10.11', + 'key_filename': '/root/.ssh/id_rsa', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + +SRIOV_PASSWORD = [{ + 'auth_type': 'password', + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.10.10.11', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + +vfnic = "i40evf" +PCIS = ['0000:06:00.0', '0000:06:00.1'] + + +class SriovTestCase(unittest.TestCase): + + NODES_SAMPLE_SSH = "sriov_sample_ssh_key.yaml" + NODES_SAMPLE_PASSWORD = "sriov_sample_password.yaml" + + def setUp(self): + self.test_context = sriov.Sriov() + + def test_construct(self): + self.assertIsNone(self.test_context.name) + self.assertIsNone(self.test_context.file_path) + self.assertEqual(self.test_context.nodes, []) + self.assertEqual(self.test_context.sriov, []) + self.assertFalse(self.test_context.vm_deploy) + self.assertTrue(self.test_context.first_run) + self.assertEqual(self.test_context.user, "") + self.assertEqual(self.test_context.ssh_ip, "") + self.assertEqual(self.test_context.passwd, "") + self.assertEqual(self.test_context.ssh_port, "") + self.assertEqual(self.test_context.auth_type, "") + + def test_init(self): + self.test_context.parse_pod_and_get_data = mock.Mock() + self.test_context.file_path = CORRECT_FILE_PATH + self.test_context.init() + self.assertIsNone(self.test_context.init()) + + def test_successful_init_with_ssh(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_SSH) + self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH) + + def test_successful_init_with_password(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD) + self.test_context.parse_pod_and_get_data(CORRECT_FILE_PATH) + + def test_unsuccessful_init(self): + self.assertRaises( + IOError, + lambda: self.test_context.parse_pod_and_get_data(WRONG_FILE_PATH)) + + @mock.patch('yardstick.network_services.utils.provision_tool', return_value="a") + def test_ssh_connection(self, mock_prov): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "a", "")) + ssh.return_value = ssh_mock + mock_prov.provision_tool = mock.Mock() + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV_PASSWORD + self.assertIsNone(sriov_obj.ssh_remote_machine()) + + @mock.patch('yardstick.network_services.utils.provision_tool', return_value="a") + def test_ssh_connection_ssh_key(self, mock_prov): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(1, "a", "")) + ssh.return_value = ssh_mock + mock_prov.provision_tool = mock.Mock() + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV + sriov_obj.key_filename = '/root/.ssh/id_rsa' + self.assertIsNone(sriov_obj.ssh_remote_machine()) + + def test_get_nic_details(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "eth0 eth1", "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.sriov = SRIOV + sriov_obj.connection = ssh_mock + self.assertIsNotNone(sriov_obj.get_nic_details()) + + def test_install_req_libs(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.first_run = True + sriov_obj.connection = ssh_mock + self.assertIsNone(sriov_obj.install_req_libs()) + + def test_configure_nics_for_sriov(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + nic_details = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e', + 'vf_pci': [{}, {}]} + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock((DRIVER), return_value=(0, "0 driver", "")) + ssh.return_value = ssh_mock + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + for i in range(len(NIC_DETAILS['pci'])): + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + ssh_mock.execute = \ + mock.Mock(return_value=( + 0, + "{'0':'06:02:00','1':'06:06:00'}", + "")) + sriov_obj.get_vf_datas = mock.Mock(return_value={ + '0000:06:00.0': '0000:06:02.0'}) + nic_details['vf_pci'][i] = sriov_obj.get_vf_datas.return_value + vf_pci = [[], []] + vf_pci[i] = sriov_obj.get_vf_datas.return_value + with mock.patch("yardstick.benchmark.contexts.sriov.time"): + self.assertIsNotNone(sriov_obj.configure_nics_for_sriov(DRIVER, NIC_DETAILS)) + + def test_setup_sriov_context(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + nic_details = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e', + 'vf_pci': [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]} + vf = [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}] + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV + blacklist = "/etc/modprobe.d/blacklist.conf" + self.assertEqual(vfnic, "i40evf") + mock_sriov = mock.Mock() + mock_sriov.sriov_obj.read_from_file(blacklist) + sriov_obj.read_from_file = mock.Mock( + return_value="some random text") + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + sriov_obj.configure_nics_for_sriov = mock.Mock( + return_value=nic_details) + nic_details = sriov_obj.configure_nics_for_sriov.return_value + self.assertEqual(vf, nic_details['vf_pci']) + vf = [ + {'vf_pci': '06:02.00', 'mac': '00:00:00:00:00:0a'}, + {'vf_pci': '06:06.00', 'mac': '00:00:00:00:00:0b'}] + sriov_obj.add_sriov_interface = mock.Mock() + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.put = mock.Mock() + sriov_obj.check_output = mock.Mock(return_value=(1, {})) + with mock.patch("yardstick.benchmark.contexts.sriov.time"): + self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER)) + + def test_setup_sriov_context_vm_already_present(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + nic_details = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e', + 'vf_pci': [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}]} + vf = [{'vf_pci': '06:02.00'}, {'vf_pci': '06:06.00'}] + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV + blacklist = "/etc/modprobe.d/blacklist.conf" + self.assertEqual(vfnic, "i40evf") + mock_sriov = mock.Mock() + mock_sriov.sriov_obj.read_from_file(blacklist) + sriov_obj.read_from_file = mock.Mock( + return_value="some random text") + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + sriov_obj.configure_nics_for_sriov = mock.Mock( + return_value=nic_details) + nic_details = sriov_obj.configure_nics_for_sriov.return_value + self.assertEqual(vf, nic_details['vf_pci']) + vf = [ + {'vf_pci': '06:02.00', 'mac': '00:00:00:00:00:0a'}, + {'vf_pci': '06:06.00', 'mac': '00:00:00:00:00:0b'}] + sriov_obj.add_sriov_interface = mock.Mock() + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.put = mock.Mock() + sriov_obj.check_output = mock.Mock(return_value=(0, "vm1")) + with mock.patch("yardstick.benchmark.contexts.sriov.time"): + self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER)) + + @mock.patch( + 'yardstick.benchmark.contexts.sriov', + return_value="Domain vm1 created from /tmp/vm_sriov.xml") + def test_is_vm_created(self, NIC_INPUT): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + mock_sriov = mock.Mock() + pcis = NIC_DETAILS['pci'] + driver = NIC_DETAILS['phy_driver'] + self.assertIsNotNone( + mock_sriov.sriov_obj.setup_sriov_context( + pcis, + NIC_DETAILS, + driver)) + + def test_add_sriov_interface(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + with mock.patch("xml.etree.ElementTree.parse") as parse: + with mock.patch("re.search") as re: + with mock.patch("xml.etree.ElementTree.SubElement") \ + as elem: + parse = mock.Mock(return_value="root") + re = mock.Mock() + elem = mock.Mock() + print("{0} {1} {2}".format(parse, re, elem)) + self.assertIsNone(sriov_obj.add_sriov_interface( + 0, + "0000:06:02.0", + "00:00:00:00:00:0a", + "/tmp/vm_sriov.xml")) + + def test_get_virtual_devices(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + pci_out = " \ + PCI_CLASS=20000 \ + PCI_ID=8086:154C \ + PCI_SUBSYS_ID=8086:0000 \ + PCI_SLOT_NAME=0000:06:02.0 \ + MODALIAS= \ + pci:v00008086d0000154Csv00008086sd00000000bc02sc00i00" + pci = "0000:06:00.0" + sriov_obj.check_output = mock.Mock(return_value=(0, pci_out)) + with mock.patch("re.search") as re: + re = mock.Mock(return_value="a") + print("{0}".format(re)) + self.assertIsNotNone(sriov_obj.get_virtual_devices(pci)) + + def test_get_vf_datas(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.get_virtual_devices = mock.Mock( + return_value={'0000:06:00.0': '0000:06:02.0'}) + with mock.patch("re.search") as re: + re = mock.Mock() + print("{0}".format(re)) + self.assertIsNotNone(sriov_obj.get_vf_datas( + 'vf_pci', + {'0000:06:00.0': '0000:06:02.0'}, + "00:00:00:00:00:0a")) + + def test_check_output(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + cmd = "command" + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + self.assertIsNotNone(sriov_obj.check_output(cmd, None)) + + def test_split_cpu_list_available(self): + with mock.patch("itertools.chain") as iter1: + iter1 = mock.Mock() + print("{0}".format(iter1)) + sriov_obj = sriov.Sriov() + self.assertIsNotNone(sriov_obj.split_cpu_list('0,5')) + + def test_split_cpu_list_null(self): + with mock.patch("itertools.chain") as iter1: + iter1 = mock.Mock() + print("{0}".format(iter1)) + sriov_obj = sriov.Sriov() + self.assertEqual(sriov_obj.split_cpu_list([]), []) + + def test_destroy_vm_successful(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV + sriov_obj.check_output = mock.Mock(return_value=(0, "vm1")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "0 i40e")) + ssh_mock.execute = \ + mock.Mock(return_value=(0, "0 i40e")) + self.assertIsNone(sriov_obj.destroy_vm()) + + def test_destroy_vm_unsuccessful(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, {}, "")) + ssh.return_value = ssh_mock + sriov_obj = sriov.Sriov() + sriov_obj.connection = ssh_mock + sriov_obj.sriov = SRIOV + sriov_obj.check_output = mock.Mock(return_value=(1, {})) + self.assertIsNone(sriov_obj.destroy_vm()) + + def test_read_from_file(self): + CORRECT_FILE_PATH = self._get_file_abspath(self.NODES_SAMPLE_PASSWORD) + sriov_obj = sriov.Sriov() + self.assertIsNotNone(sriov_obj.read_from_file(CORRECT_FILE_PATH)) + + def test_write_to_file(self): + sriov_obj = sriov.Sriov() + self.assertIsNone(sriov_obj.write_to_file(SAMPLE_FILE, "some content")) + + def _get_file_abspath(self, filename): + curr_path = os.path.dirname(os.path.abspath(__file__)) + file_path = os.path.join(curr_path, filename) + return file_path + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/benchmark/contexts/test_standalone.py b/tests/unit/benchmark/contexts/test_standalone.py index 687ef7305..1fc740393 100644 --- a/tests/unit/benchmark/contexts/test_standalone.py +++ b/tests/unit/benchmark/contexts/test_standalone.py @@ -20,112 +20,667 @@ from __future__ import absolute_import import os import unittest +import mock from yardstick.benchmark.contexts import standalone +from yardstick.benchmark.contexts import sriov +from yardstick.benchmark.contexts import ovsdpdk +MOCKS = { + 'yardstick.benchmark.contexts': mock.MagicMock(), + 'yardstick.benchmark.contexts.sriov': mock.MagicMock(), + 'yardstick.benchmark.contexts.ovsdpdk': mock.MagicMock(), + 'yardstick.benchmark.contexts.standalone': mock.MagicMock(), +} + +@mock.patch('yardstick.benchmark.contexts.ovsdpdk.time') +@mock.patch('yardstick.benchmark.contexts.standalone.time') +@mock.patch('yardstick.benchmark.contexts.sriov.time') class StandaloneContextTestCase(unittest.TestCase): + NODES_SAMPLE = "nodes_sample_new.yaml" + NODES_SAMPLE_SRIOV = "nodes_sample_new_sriov.yaml" + NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample_new.yaml" - NODES_SAMPLE = "standalone_sample.yaml" - NODES_DUPLICATE_SAMPLE = "standalone_duplicate_sample.yaml" + NODES_SAMPLE_OVSDPDK = "nodes_sample_ovs.yaml" + NODES_SAMPLE_OVSDPDK_ROLE = "nodes_sample_ovsdpdk.yaml" + NODES_DUPLICATE_OVSDPDK = "nodes_duplicate_sample_ovs.yaml" def setUp(self): self.test_context = standalone.StandaloneContext() - def test_construct(self): - + def test_construct(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): self.assertIsNone(self.test_context.name) self.assertIsNone(self.test_context.file_path) self.assertEqual(self.test_context.nodes, []) self.assertEqual(self.test_context.nfvi_node, []) - def test_unsuccessful_init(self): - + def test_unsuccessful_init(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): attrs = { 'name': 'foo', 'file': self._get_file_abspath("error_file") } - self.assertRaises(IOError, self.test_context.init, attrs) - def test_successful_init(self): - - attrs = { + def test_successful_init_sriov(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs_sriov = { + 'name': 'sriov', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.Mock() + self.test_context.init(attrs_sriov) + self.assertEqual(self.test_context.name, "sriov") + self.assertEqual(len(self.test_context.nodes), 2) + self.assertEqual(len(self.test_context.nfvi_node), 2) + self.assertEqual(self.test_context.nfvi_node[0]["name"], "sriov") + + def test_successful_init_ovs(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + attrs_ovs = { + 'name': 'ovs', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.Mock() + self.test_context.init(attrs_ovs) + self.assertEqual(self.test_context.name, "ovs") + self.assertEqual(len(self.test_context.nodes), 2) + self.assertEqual(len(self.test_context.nfvi_node), 2) + self.assertEqual(self.test_context.nfvi_node[0]["name"], "ovs") + + def test__get_server_with_dic_attr_name_sriov(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs_sriov = { 'name': 'foo', 'file': self._get_file_abspath(self.NODES_SAMPLE) } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.init(attrs_sriov) + attr_name = {'name': 'foo.bar'} + result = self.test_context._get_server(attr_name) + self.assertEqual(result, None) - self.test_context.init(attrs) - - self.assertEqual(self.test_context.name, "foo") - self.assertEqual(len(self.test_context.nodes), 3) - self.assertEqual(len(self.test_context.nfvi_node), 1) - self.assertEqual(self.test_context.nfvi_node[0]["name"], "node2") - - def test__get_server_with_dic_attr_name(self): + def test__get_server_with_dic_attr_name_ovs(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs_ovs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.init(attrs_ovs) + attr_name = {'name': 'foo.bar'} + result = self.test_context._get_server(attr_name) + self.assertEqual(result, None) + def test__get_server_not_found_sriov(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): attrs = { 'name': 'foo', 'file': self._get_file_abspath(self.NODES_SAMPLE) } - + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] self.test_context.init(attrs) - - attr_name = {'name': 'foo.bar'} + attr_name = 'bar.foo' result = self.test_context._get_server(attr_name) - self.assertEqual(result, None) - def test__get_server_not_found(self): - + def test__get_server_not_found_ovs(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): attrs = { 'name': 'foo', - 'file': self._get_file_abspath(self.NODES_SAMPLE) + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) } - + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] 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_duplicate(self): + + def test__get_server_duplicate_sriov(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): attrs = { 'name': 'foo', 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE) } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.Mock(return_value="sriov") + self.test_context.init(attrs) + attr_name = 'sriov.foo' + # self.test_context.name = "sriov" + self.assertRaises(ValueError, self.test_context._get_server, attr_name) + def test__get_server_duplicate_ovs(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_DUPLICATE_OVSDPDK) + } + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.get_nfvi_obj = mock.Mock(return_value="OvsDpdk") self.test_context.init(attrs) - attr_name = 'node2.foo' + attr_name = 'ovs.foo' + self.assertRaises( + ValueError, + self.test_context._get_server, + attr_name) + def test__get_server_found_sriov(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_SRIOV) + } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.get_nfvi_obj = mock.Mock(return_value="OvsDpdk") + self.test_context.init(attrs) + attr_name = 'sriov.foo' + result = self.test_context._get_server(attr_name) + self.assertEqual(result['ip'], '10.123.123.122') + self.assertEqual(result['name'], 'sriov.foo') + self.assertEqual(result['user'], 'root') - self.assertRaises(ValueError, self.test_context._get_server, attr_name) + def test__get_server_found_ovs(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK_ROLE) + } + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.Mock(return_value="OvsDpdk") + self.test_context.init(attrs) + attr_name = 'ovs.foo' + result = self.test_context._get_server(attr_name) + self.assertEqual(result['ip'], '10.223.197.222') + self.assertEqual(result['name'], 'ovs.foo') + self.assertEqual(result['user'], 'root') + + def test__deploy_unsuccessful(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + self.test_context.vm_deploy = False - def test__get_server_found(self): + def test__deploy_sriov_firsttime(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + MYSRIOV = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.vm_deploy = True + + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.nfvi_obj.sriov = MYSRIOV + self.test_context.nfvi_obj.ssh_remote_machine = mock.Mock() + self.test_context.nfvi_obj.first_run = True + self.test_context.nfvi_obj.install_req_libs() + self.test_context.nfvi_obj.get_nic_details = mock.Mock() + PORTS = ['0000:06:00.0', '0000:06:00.1'] + NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + DRIVER = 'i40e' + result = self.test_context.nfvi_obj.setup_sriov_context( + PORTS, + NIC_DETAILS, + DRIVER) + print("{0}".format(result)) + self.assertIsNone(self.test_context.deploy()) + def test__deploy_sriov_notfirsttime(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): attrs = { 'name': 'foo', 'file': self._get_file_abspath(self.NODES_SAMPLE) } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + MYSRIOV = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.vm_deploy = True + self.test_context.get_nfvi_obj = mock.MagicMock() self.test_context.init(attrs) + self.test_context.nfvi_obj.sriov = MYSRIOV + self.test_context.nfvi_obj.ssh_remote_machine = mock.Mock() + self.test_context.nfvi_obj.first_run = False + self.test_context.nfvi_obj.get_nic_details = mock.Mock() + PORTS = ['0000:06:00.0', '0000:06:00.1'] + NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + DRIVER = 'i40e' + result = self.test_context.nfvi_obj.setup_sriov_context( + PORTS, + NIC_DETAILS, + DRIVER) + print("{0}".format(result)) + self.assertIsNone(self.test_context.deploy()) - attr_name = 'node1.foo' - result = self.test_context._get_server(attr_name) + def test__deploy_ovs_firsttime(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } - self.assertEqual(result['ip'], '1.1.1.1') - self.assertEqual(result['name'], 'node1.foo') - self.assertEqual(result['user'], 'root') + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + MYOVS = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + '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_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.vm_deploy = True + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.ovs = MYOVS + self.test_context.nfvi_obj.ssh_remote_machine = mock.Mock() + self.test_context.nfvi_obj.first_run = True + self.test_context.nfvi_obj.install_req_libs() + self.test_context.nfvi_obj.get_nic_details = mock.Mock() + PORTS = ['0000:06:00.0', '0000:06:00.1'] + NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vports_mac': ['00:00:00:00:00:05', '00:00:00:00:00:06'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + DRIVER = 'i40e' + + self.test_context.nfvi_obj.setup_ovs = mock.Mock() + self.test_context.nfvi_obj.start_ovs_serverswitch = mock.Mock() + self.test_context.nfvi_obj.setup_ovs_bridge = mock.Mock() + self.test_context.nfvi_obj.add_oflows = mock.Mock() + + # self.test_context.nfvi_obj.setup_ovs(PORTS) + # self.test_context.nfvi_obj.start_ovs_serverswitch() + # self.test_context.nfvi_obj.setup_ovs_bridge() + # self.test_context.nfvi_obj.add_oflows() + + result = self.test_context.nfvi_obj.setup_ovs_context( + PORTS, + NIC_DETAILS, + DRIVER) + print("{0}".format(result)) + self.assertIsNone(self.test_context.deploy()) - def test_deploy(self): + def test__deploy_ovs_notfirsttime(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + MYOVS = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + '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_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.vm_deploy = True + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.ovs = MYOVS + self.test_context.nfvi_obj.ssh_remote_machine = mock.Mock() + self.test_context.nfvi_obj.first_run = False + self.test_context.nfvi_obj.get_nic_details = mock.Mock() + PORTS = ['0000:06:00.0', '0000:06:00.1'] + NIC_DETAILS = { + 'interface': {0: 'enp6s0f0', 1: 'enp6s0f1'}, + 'vports_mac': ['00:00:00:00:00:05', '00:00:00:00:00:06'], + 'pci': ['0000:06:00.0', '0000:06:00.1'], + 'phy_driver': 'i40e'} + DRIVER = 'i40e' + + self.test_context.nfvi_obj.setup_ovs(PORTS) + self.test_context.nfvi_obj.start_ovs_serverswitch() + self.test_context.nfvi_obj.setup_ovs_bridge() + self.test_context.nfvi_obj.add_oflows() + + result = self.test_context.nfvi_obj.setup_ovs_context( + PORTS, + NIC_DETAILS, + DRIVER) + print("{0}".format(result)) self.assertIsNone(self.test_context.deploy()) - def test_undeploy(self): + def test_undeploy_sriov(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.nfvi_obj.destroy_vm = mock.Mock() + self.assertIsNone(self.test_context.undeploy()) + + def test_undeploy_ovs(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + attrs = { + 'name': 'foo', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } + + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.nfvi_obj.destroy_vm = mock.Mock() self.assertIsNone(self.test_context.undeploy()) + def test_get_nfvi_obj_sriov(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + with mock.patch('yardstick.benchmark.contexts.sriov'): + attrs = { + 'name': 'sriov', + 'file': self._get_file_abspath(self.NODES_SAMPLE) + } + self.test_context.init(attrs) + self.test_context.nfvi_obj.file_path = self._get_file_abspath( + self.NODES_SAMPLE) + self.test_context.nfvi_node = [{ + 'name': 'sriov', + 'vf_macs': ['00:00:00:71:7d:25', '00:00:00:71:7d:26'], + 'ip': '10.223.197.140', + 'role': 'Sriov', + 'user': 'root', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'intel123', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.get_context_impl = mock.Mock( + return_value=sriov.Sriov) + self.assertIsNotNone(self.test_context.get_nfvi_obj()) + + def test_get_nfvi_obj_ovs(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + with mock.patch('yardstick.benchmark.contexts.ovsdpdk'): + attrs = { + 'name': 'ovs', + 'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK) + } + self.test_context.init(attrs) + self.test_context.nfvi_obj.file_path = self._get_file_abspath( + self.NODES_SAMPLE) + self.test_context.nfvi_node = [{ + 'name': 'ovs', + 'vports_mac': ['00:00:00:00:00:03', '00:00:00:00:00:04'], + 'ip': '10.223.197.140', + 'role': 'Ovsdpdk', + 'user': 'root', + 'vpath': '/usr/local/', + 'images': '/var/lib/libvirt/images/ubuntu1.img', + 'phy_driver': 'i40e', + 'password': 'password', + 'phy_ports': ['0000:06:00.0', '0000:06:00.1']}] + self.test_context.get_nfvi_obj = mock.MagicMock() + self.test_context.init(attrs) + self.test_context.get_context_impl = mock.Mock( + return_value=ovsdpdk.Ovsdpdk) + self.assertIsNotNone(self.test_context.get_nfvi_obj()) + + def test_get_context_impl_correct_obj(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + with mock.patch.dict("sys.modules", MOCKS): + self.assertIsNotNone(self.test_context.get_context_impl('Sriov')) + + def test_get_context_impl_wrong_obj(self, mock_sriov_time, mock_standlalone_time, + mock_ovsdpdk_time): + with mock.patch.dict("sys.modules", MOCKS): + self.assertRaises( + ValueError, + lambda: self.test_context.get_context_impl('wrong_object')) + 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_network(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time): + 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 = None + self.assertIsNone(self.test_context._get_network(attr_name)) + + 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)) + + 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) +if __name__ == '__main__': + unittest.main() + diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py index b64bb8eed..7f617537e 100644 --- a/tests/unit/benchmark/core/test_task.py +++ b/tests/unit/benchmark/core/test_task.py @@ -47,6 +47,87 @@ class TaskTestCase(unittest.TestCase): self.assertEqual(context_cfg["host"], server_info) self.assertEqual(context_cfg["target"], server_info) + def test_set_dispatchers(self): + t = task.Task() + output_config = {"DEFAULT": {"dispatcher": "file, http"}} + t._set_dispatchers(output_config) + self.assertEqual(output_config, output_config) + + @mock.patch('yardstick.benchmark.core.task.DispatcherBase') + def test__do_output(self, mock_dispatcher): + t = task.Task() + output_config = {"DEFAULT": {"dispatcher": "file, http"}} + mock_dispatcher.get = mock.MagicMock(return_value=[mock.MagicMock(), + mock.MagicMock()]) + self.assertEqual(None, t._do_output(output_config, {})) + + @mock.patch('yardstick.benchmark.core.task.Context') + def test_parse_networks_from_nodes(self, mock_context): + nodes = { + 'node1': { + 'interfaces': { + 'eth0': { + 'name': 'mgmt', + }, + 'eth1': { + 'name': 'external', + 'vld_id': '23', + }, + 'eth10': { + 'name': 'internal', + 'vld_id': '55', + }, + }, + }, + 'node2': { + 'interfaces': { + 'eth4': { + 'name': 'mgmt', + }, + 'eth2': { + 'name': 'external', + 'vld_id': '32', + }, + 'eth11': { + 'name': 'internal', + 'vld_id': '55', + }, + }, + }, + } + + mock_context.get_network.side_effect = iter([ + None, + { + 'name': 'a', + 'network_type': 'private', + }, + {}, + { + 'name': 'b', + 'vld_id': 'y', + 'subnet_cidr': '10.20.0.0/16', + }, + { + 'name': 'c', + 'vld_id': 'x', + }, + { + 'name': 'd', + 'vld_id': 'w', + }, + ]) + + expected_get_network_calls = 4 # once for each vld_id in the nodes dict + expected = { + 'a': {'name': 'a', 'network_type': 'private'}, + 'b': {'name': 'b', 'vld_id': 'y', 'subnet_cidr': '10.20.0.0/16'}, + } + + networks = task.get_networks_from_nodes(nodes) + self.assertEqual(mock_context.get_network.call_count, expected_get_network_calls) + self.assertDictEqual(networks, expected) + @mock.patch('yardstick.benchmark.core.task.Context') @mock.patch('yardstick.benchmark.core.task.base_runner') def test_run(self, mock_base_runner, mock_ctx): diff --git a/tests/unit/benchmark/runner/test_base.py b/tests/unit/benchmark/runner/test_base.py index 6e72fa548..0313ef843 100644 --- a/tests/unit/benchmark/runner/test_base.py +++ b/tests/unit/benchmark/runner/test_base.py @@ -15,12 +15,15 @@ from __future__ import absolute_import import unittest import time +from mock import mock + from yardstick.benchmark.runners.iteration import IterationRunner class RunnerTestCase(unittest.TestCase): - def test_get_output(self): + @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing") + def test_get_output(self, mock_process): runner = IterationRunner({}) runner.output_queue.put({'case': 'opnfv_yardstick_tc002'}) runner.output_queue.put({'criteria': 'PASS'}) @@ -30,7 +33,10 @@ class RunnerTestCase(unittest.TestCase): 'criteria': 'PASS' } - time.sleep(1) + for retries in range(1000): + time.sleep(0.01) + if not runner.output_queue.empty(): + break actual_result = runner.get_output() self.assertEqual(idle_result, actual_result) diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py index 28b27c78a..cc179602e 100644 --- a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py +++ b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py @@ -20,9 +20,7 @@ from yardstick.benchmark.scenarios.availability.attacker import \ attacker_baremetal -@mock.patch( - 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal' - '.subprocess') +@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess') class ExecuteShellTestCase(unittest.TestCase): def test__fun_execute_shell_command_successful(self, mock_subprocess): @@ -31,17 +29,17 @@ class ExecuteShellTestCase(unittest.TestCase): exitcode, output = attacker_baremetal._execute_shell_command(cmd) self.assertEqual(exitcode, 0) - def test__fun_execute_shell_command_fail_cmd_exception(self, - mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.LOG') + def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, mock_subprocess): cmd = "env" mock_subprocess.check_output.side_effect = RuntimeError exitcode, output = attacker_baremetal._execute_shell_command(cmd) self.assertEqual(exitcode, -1) + mock_log.error.assert_called_once() -@mock.patch( - 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal' - '.ssh') +@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess') +@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh') class AttackerBaremetalTestCase(unittest.TestCase): def setUp(self): @@ -59,28 +57,28 @@ class AttackerBaremetalTestCase(unittest.TestCase): 'host': 'node1', } - def test__attacker_baremetal_all_successful(self, mock_ssh): + def test__attacker_baremetal_all_successful(self, mock_ssh, mock_subprocess): + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.inject_fault() ins.recover() - def test__attacker_baremetal_check_failuer(self, mock_ssh): + def test__attacker_baremetal_check_failuer(self, mock_ssh, mock_subprocess): + mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '') ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH.from_node().execute.return_value = (0, "error check", '') ins.setup() - def test__attacker_baremetal_recover_successful(self, mock_ssh): + def test__attacker_baremetal_recover_successful(self, mock_ssh, mock_subprocess): self.attacker_cfg["jump_host"] = 'node1' self.context["node1"]["pwd"] = "123456" + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context) - mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') ins.setup() ins.recover() diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py index 2ed4be731..6a9b3b157 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py @@ -30,12 +30,14 @@ class ExecuteShellTestCase(unittest.TestCase): exitcode, output = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, 0) - def test__fun_execute_shell_command_fail_cmd_exception(self, + @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG') + def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log, mock_subprocess): cmd = "env" mock_subprocess.check_output.side_effect = RuntimeError exitcode, output = monitor_command._execute_shell_command(cmd) self.assertEqual(exitcode, -1) + mock_log.error.assert_called_once() @mock.patch( @@ -67,13 +69,15 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase): instance._result = {"outage_time": 0} instance.verify_SLA() - def test__monitor_command_monitor_func_failure(self, mock_subprocess): + @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG') + def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess): mock_subprocess.check_output.return_value = (1, 'unittest') instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10}) instance.setup() mock_subprocess.check_output.side_effect = RuntimeError ret = instance.monitor_func() self.assertEqual(ret, False) + mock_log.error.assert_called_once() instance._result = {"outage_time": 10} instance.verify_SLA() diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py b/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py index f8d12bd29..b59ec6cf1 100644 --- a/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py +++ b/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py @@ -36,7 +36,7 @@ class MultiMonitorServiceTestCase(unittest.TestCase): 'key': 'service-status', 'monitor_key': 'service-status', 'host': 'node1', - 'monitor_time': 3, + 'monitor_time': 0.1, 'parameter': {'serviceName': 'haproxy'}, 'sla': {'max_outage_time': 1} } diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py index bb0e6bc79..2e4fff417 100644 --- a/tests/unit/benchmark/scenarios/availability/test_util.py +++ b/tests/unit/benchmark/scenarios/availability/test_util.py @@ -19,6 +19,25 @@ from yardstick.benchmark.scenarios.availability import util @mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess') class ExecuteShellTestCase(unittest.TestCase): + def setUp(self): + self.param_config = {'serviceName': '$serviceName', 'value': 1} + self.intermediate_variables = {'$serviceName': 'nova-api'} + self.std_output = '| id | 1 |' + self.cmd_config = {'cmd':'ls','param':'-a'} + + def test_util_build_command_shell(self,mock_subprocess): + result = util.build_shell_command(self.param_config, True, + self.intermediate_variables) + self.assertEqual("nova-api" in result, True) + + def test_read_stdout_item(self,mock_subprocess): + result = util.read_stdout_item(self.std_output,'id') + self.assertEquals('1',result) + + def test_buildshellparams(self,mock_subprocess): + result = util.buildshellparams(self.cmd_config,True) + self.assertEquals('/bin/bash -s {0} {1}', result) + def test__fun_execute_shell_command_successful(self, mock_subprocess): cmd = "env" mock_subprocess.check_output.return_value = (0, 'unittest') diff --git a/tests/unit/benchmark/scenarios/lib/__init__.py b/tests/unit/benchmark/scenarios/lib/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/__init__.py diff --git a/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py b/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py new file mode 100644 index 000000000..bda07f723 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py @@ -0,0 +1,65 @@ +############################################################################## +# 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 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.add_memory_load import AddMemoryLoad + + +class AddMemoryLoadTestCase(unittest.TestCase): + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_with_load(self, mock_from_node): + scenario_cfg = { + 'options': { + 'memory_load': 0.5 + } + } + context_cfg = { + 'host': {} + } + mock_from_node().execute.return_value = (0, '0 2048 512', '') + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_without_load(self, mock_from_node): + scenario_cfg = { + 'options': { + 'memory_load': 0 + } + } + context_cfg = { + 'host': {} + } + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_without_args(self, mock_from_node): + scenario_cfg = { + 'options': { + } + } + context_cfg = { + 'host': {} + } + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py new file mode 100644 index 000000000..bdf1e66e5 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py @@ -0,0 +1,84 @@ +############################################################################## +# 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 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.check_numa_info import CheckNumaInfo + + +class CheckNumaInfoTestCase(unittest.TestCase): + + @mock.patch('yardstick.benchmark.scenarios.lib.check_numa_info.CheckNumaInfo._check_vm2_status') + def test_check_numa_info(self, mock_check_vm2): + scenario_cfg = {'info1': {}, 'info2': {}} + obj = CheckNumaInfo(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_check_vm2.called) + + def test_check_vm2_status_length_eq_1(self): + info1 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + info2 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertEqual(status, True) + + def test_check_vm2_status_length_gt_1(self): + info1 = { + 'pinning': [0, 1], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + info2 = { + 'pinning': [0, 1], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertEqual(status, False) + + def test_check_vm2_status_length_not_in_set(self): + info1 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,7' + }] + } + info2 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,7' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertEqual(status, False) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_check_value.py b/tests/unit/benchmark/scenarios/lib/test_check_value.py new file mode 100644 index 000000000..21e83f830 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_check_value.py @@ -0,0 +1,46 @@ +############################################################################## +# 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 +############################################################################## +import unittest + +from yardstick.benchmark.scenarios.lib.check_value import CheckValue + + +class CheckValueTestCase(unittest.TestCase): + + def test_check_value_eq(self): + scenario_cfg = {'options': {'operator': 'eq', 'value1': 1, 'value2': 2}} + obj = CheckValue(scenario_cfg, {}) + try: + obj.run({}) + except Exception as e: + self.assertIsInstance(e, AssertionError) + + def test_check_value_eq_pass(self): + scenario_cfg = {'options': {'operator': 'eq', 'value1': 1, 'value2': 1}} + obj = CheckValue(scenario_cfg, {}) + try: + obj.run({}) + except Exception as e: + self.assertIsInstance(e, AssertionError) + + def test_check_value_ne(self): + scenario_cfg = {'options': {'operator': 'ne', 'value1': 1, 'value2': 1}} + obj = CheckValue(scenario_cfg, {}) + try: + obj.run({}) + except Exception as e: + self.assertIsInstance(e, AssertionError) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py b/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py new file mode 100644 index 000000000..f046c92ea --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py @@ -0,0 +1,51 @@ +############################################################################## +# 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 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_migrate_target_host import GetMigrateTargetHost + +BASE = 'yardstick.benchmark.scenarios.lib.get_migrate_target_host' + + +class GetMigrateTargetHostTestCase(unittest.TestCase): + + @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE)) + @mock.patch('{}.GetMigrateTargetHost._get_migrate_host'.format(BASE)) + @mock.patch('{}.GetMigrateTargetHost._get_current_host_name'.format(BASE)) + def test_get_migrate_target_host(self, + mock_get_current_host_name, + mock_get_migrate_host, + mock_get_nova_client): + obj = GetMigrateTargetHost({}, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_get_current_host_name.called) + self.assertTrue(mock_get_migrate_host.called) + + @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE)) + def test_get_migrate_host(self, mock_get_nova_client): + class A(object): + def __init__(self, service): + self.service = service + self.host = 'host4' + + mock_get_nova_client().hosts.list_all.return_value = [A('compute')] + obj = GetMigrateTargetHost({}, {}) + host = obj._get_migrate_host('host5') + self.assertTrue(mock_get_nova_client.called) + self.assertEqual(host, 'host4') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py b/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py new file mode 100644 index 000000000..e7ba3ca73 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py @@ -0,0 +1,106 @@ +############################################################################## +# 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 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_numa_info import GetNumaInfo + +BASE = 'yardstick.benchmark.scenarios.lib.get_numa_info' + + +class GetNumaInfoTestCase(unittest.TestCase): + + @mock.patch('{}.GetNumaInfo._check_numa_node'.format(BASE)) + @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE)) + @mock.patch('yaml.safe_load') + @mock.patch('yardstick.common.task_template.TaskTemplate.render') + def test_get_numa_info(self, + mock_render, + mock_safe_load, + mock_get_current_host_name, + mock_check_numa_node): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_safe_load.return_value = { + 'nodes': [] + } + obj = GetNumaInfo(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_current_host_name.called) + self.assertTrue(mock_check_numa_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE)) + @mock.patch('yaml.safe_load') + @mock.patch('yardstick.common.task_template.TaskTemplate.render') + def test_check_numa_node(self, + mock_render, + mock_safe_load, + mock_get_current_host_name, + mock_from_node): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_safe_load.return_value = { + 'nodes': [] + } + data = """ + <data> + </data> + """ + mock_from_node().execute.return_value = (0, data, '') + obj = GetNumaInfo(scenario_cfg, {}) + result = obj._check_numa_node('1', 'host4') + self.assertEqual(result, {'pinning': [], 'vcpupin': []}) + + @mock.patch('{}.change_obj_to_dict'.format(BASE)) + @mock.patch('{}.get_nova_client'.format(BASE)) + @mock.patch('yaml.safe_load') + @mock.patch('yardstick.common.task_template.TaskTemplate.render') + def test_get_current_host_name(self, + mock_render, + mock_safe_load, + mock_get_nova_client, + mock_change_obj_to_dict): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_get_nova_client().servers.get.return_value = '' + mock_change_obj_to_dict.return_value = {'OS-EXT-SRV-ATTR:host': 'host5'} + + obj = GetNumaInfo(scenario_cfg, {}) + result = obj._get_current_host_name('1') + self.assertEqual(result, 'host5') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_get_server.py b/tests/unit/benchmark/scenarios/lib/test_get_server.py new file mode 100644 index 000000000..aebbf5416 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_get_server.py @@ -0,0 +1,50 @@ +############################################################################## +# 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 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_server import GetServer + + +class GetServerTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_server_by_name') + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_get_server_with_name(self, mock_get_nova_client, mock_get_server_by_name): + scenario_cfg = { + 'options': { + 'server_name': 'yardstick_server' + }, + 'output': 'status server' + } + obj = GetServer(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_get_server_by_name.called) + + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_get_server_with_id(self, mock_get_nova_client): + scenario_cfg = { + 'options': { + 'server_id': '1' + }, + 'output': 'status server' + } + mock_get_nova_client().servers.get.return_value = None + obj = GetServer(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py b/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py new file mode 100644 index 000000000..3d20d5439 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py @@ -0,0 +1,41 @@ +############################################################################## +# 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 +############################################################################## +import unittest + +from yardstick.benchmark.scenarios.lib.get_server_ip import GetServerIp + + +class GetServerIpTestCase(unittest.TestCase): + def test_get_server_ip(self): + scenario_cfg = { + 'options': { + 'server': { + 'addresses': { + 'net1': [ + { + 'OS-EXT-IPS:type': 'floating', + 'addr': '127.0.0.1' + } + ] + } + } + }, + 'output': 'ip' + } + obj = GetServerIp(scenario_cfg, {}) + result = obj.run({}) + self.assertEqual(result, {'ip': '127.0.0.1'}) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py index 131716727..fe44cfdf4 100644 --- a/tests/unit/benchmark/scenarios/networking/test_nstat.py +++ b/tests/unit/benchmark/scenarios/networking/test_nstat.py @@ -43,7 +43,7 @@ class NstatTestCase(unittest.TestCase): def test_nstat_successful_no_sla(self, mock_ssh): options = { - "duration": 60 + "duration": 0 } args = { "options": options, @@ -67,7 +67,7 @@ class NstatTestCase(unittest.TestCase): def test_nstat_successful_sla(self, mock_ssh): options = { - "duration": 60 + "duration": 0 } sla = { "IP_datagram_error_rate": 0.1 @@ -95,7 +95,7 @@ class NstatTestCase(unittest.TestCase): def test_nstat_unsuccessful_cmd_error(self, mock_ssh): options = { - "duration": 60 + "duration": 0 } sla = { "IP_datagram_error_rate": 0.1 diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py index d4eb1246f..2914c8e02 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py @@ -138,6 +138,7 @@ class PktgenTestCase(unittest.TestCase): p.run(result) expected_result = jsonutils.loads(sample_output) expected_result["packets_received"] = 149300 + expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) def test_pktgen_successful_sla(self, mock_ssh): @@ -164,6 +165,7 @@ class PktgenTestCase(unittest.TestCase): p.run(result) expected_result = jsonutils.loads(sample_output) expected_result["packets_received"] = 149300 + expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) def test_pktgen_unsuccessful_sla(self, mock_ssh): @@ -204,6 +206,538 @@ class PktgenTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) + def test_pktgen_get_vnic_driver_name(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, 'ixgbevf', '') + + vnic_driver_name = p._get_vnic_driver_name() + self.assertEqual(vnic_driver_name, 'ixgbevf') + + def test_pktgen_unsuccessful_get_vnic_driver_name(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._get_vnic_driver_name) + + def test_pktgen_get_sriov_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '2', '') + + p.queue_number = p._get_sriov_queue_number() + self.assertEqual(p.queue_number, 2) + + def test_pktgen_unsuccessful_get_sriov_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._get_sriov_queue_number) + + def test_pktgen_get_available_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '4', '') + + p._get_available_queue_number() + + mock_ssh.SSH.from_node().execute.assert_called_with( + "sudo ethtool -l eth0 | grep Combined | head -1 |" \ + "awk '{printf $2}'") + + def test_pktgen_unsuccessful_get_available_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._get_available_queue_number) + + def test_pktgen_get_usable_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '1', '') + + p._get_usable_queue_number() + + mock_ssh.SSH.from_node().execute.assert_called_with( + "sudo ethtool -l eth0 | grep Combined | tail -1 |" \ + "awk '{printf $2}'") + + def test_pktgen_unsuccessful_get_usable_queue_number(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._get_usable_queue_number) + + def test_pktgen_enable_ovs_multiqueue(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '4', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = 1 + p._get_usable_queue_number = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = 4 + p._get_available_queue_number = mock_result2 + + p.queue_number = p._enable_ovs_multiqueue() + self.assertEqual(p.queue_number, 4) + + def test_pktgen_enable_ovs_multiqueue_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '1', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = 1 + p._get_usable_queue_number = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = 1 + p._get_available_queue_number = mock_result2 + + p.queue_number = p._enable_ovs_multiqueue() + self.assertEqual(p.queue_number, 1) + + def test_pktgen_unsuccessful_enable_ovs_multiqueue(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = 1 + p._get_usable_queue_number = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = 4 + p._get_available_queue_number = mock_result2 + + self.assertRaises(RuntimeError, p._enable_ovs_multiqueue) + + def test_pktgen_setup_irqmapping_ovs(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '10', '') + + p._setup_irqmapping_ovs(4) + + mock_ssh.SSH.from_node().execute.assert_called_with( + "echo 8 | sudo tee /proc/irq/10/smp_affinity") + + def test_pktgen_setup_irqmapping_ovs_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '10', '') + + p._setup_irqmapping_ovs(1) + + mock_ssh.SSH.from_node().execute.assert_called_with( + "echo 1 | sudo tee /proc/irq/10/smp_affinity") + + def test_pktgen_unsuccessful_setup_irqmapping_ovs(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._setup_irqmapping_ovs, 4) + + def test_pktgen_unsuccessful_setup_irqmapping_ovs_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._setup_irqmapping_ovs, 1) + + def test_pktgen_setup_irqmapping_sriov(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '10', '') + + p._setup_irqmapping_sriov(2) + + mock_ssh.SSH.from_node().execute.assert_called_with( + "echo 2 | sudo tee /proc/irq/10/smp_affinity") + + def test_pktgen_setup_irqmapping_sriov_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '10', '') + + p._setup_irqmapping_sriov(1) + + mock_ssh.SSH.from_node().execute.assert_called_with( + "echo 1 | sudo tee /proc/irq/10/smp_affinity") + + def test_pktgen_unsuccessful_setup_irqmapping_sriov(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._setup_irqmapping_sriov, 2) + + def test_pktgen_unsuccessful_setup_irqmapping_sriov_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._setup_irqmapping_sriov, 1) + + def test_pktgen_is_irqbalance_disabled(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + + p._is_irqbalance_disabled() + + mock_ssh.SSH.from_node().execute.assert_called_with( + "grep ENABLED /etc/default/irqbalance") + + def test_pktgen_unsuccessful_is_irqbalance_disabled(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._is_irqbalance_disabled) + + def test_pktgen_disable_irqbalance(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + + p._disable_irqbalance() + + mock_ssh.SSH.from_node().execute.assert_called_with( + "sudo service irqbalance disable") + + def test_pktgen_unsuccessful_disable_irqbalance(self, mock_ssh): + args = { + 'options': {'packetsize': 60}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + + self.assertRaises(RuntimeError, p._disable_irqbalance) + + def test_pktgen_multiqueue_setup_ovs(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'multiqueue': True}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '4', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = False + p._is_irqbalance_disabled = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = "virtio_net" + p._get_vnic_driver_name = mock_result2 + + mock_result3 = mock.Mock() + mock_result3.return_value = 1 + p._get_usable_queue_number = mock_result3 + + mock_result4 = mock.Mock() + mock_result4.return_value = 4 + p._get_available_queue_number = mock_result4 + + p.multiqueue_setup() + + self.assertEqual(p.queue_number, 4) + + def test_pktgen_multiqueue_setup_ovs_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'multiqueue': True}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '1', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = False + p._is_irqbalance_disabled = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = "virtio_net" + p._get_vnic_driver_name = mock_result2 + + mock_result3 = mock.Mock() + mock_result3.return_value = 1 + p._get_usable_queue_number = mock_result3 + + mock_result4 = mock.Mock() + mock_result4.return_value = 1 + p._get_available_queue_number = mock_result4 + + p.multiqueue_setup() + + self.assertEqual(p.queue_number, 1) + + def test_pktgen_multiqueue_setup_sriov(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'multiqueue': True}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '2', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = False + p._is_irqbalance_disabled = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = "ixgbevf" + p._get_vnic_driver_name = mock_result2 + + p.multiqueue_setup() + + self.assertEqual(p.queue_number, 2) + + def test_pktgen_multiqueue_setup_sriov_1q(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'multiqueue': True}, + } + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_ssh.SSH.from_node().execute.return_value = (0, '1', '') + + mock_result1 = mock.Mock() + mock_result1.return_value = False + p._is_irqbalance_disabled = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = "ixgbevf" + p._get_vnic_driver_name = mock_result2 + + p.multiqueue_setup() + + self.assertEqual(p.queue_number, 1) + + def test_pktgen_run_with_setup_done(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True}, + 'sla': {'max_ppm': 1} + } + result = {} + p = pktgen.Pktgen(args, self.ctx) + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + p.setup_done = True + p.multiqueue_setup_done = True + + mock_iptables_result = mock.Mock() + mock_iptables_result.return_value = 149300 + p._iptables_get_result = mock_iptables_result + + sample_output = '{"packets_per_second": 9753, "errors": 0, \ + "packets_sent": 149300, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') + + p.run(result) + expected_result = jsonutils.loads(sample_output) + expected_result["packets_received"] = 149300 + expected_result["packetsize"] = 60 + self.assertEqual(result, expected_result) + + def test_pktgen_run_with_ovs_multiqueque(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True}, + 'sla': {'max_ppm': 1} + } + result = {} + + p = pktgen.Pktgen(args, self.ctx) + + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_result = mock.Mock() + mock_result.return_value = "virtio_net" + p._get_vnic_driver_name = mock_result + + mock_result1 = mock.Mock() + mock_result1.return_value = 1 + p._get_usable_queue_number = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = 4 + p._get_available_queue_number = mock_result2 + + mock_result3 = mock.Mock() + mock_result3.return_value = 4 + p._enable_ovs_multiqueue = mock_result3 + + mock_result4 = mock.Mock() + p._setup_irqmapping_ovs = mock_result4 + + mock_iptables_result = mock.Mock() + mock_iptables_result.return_value = 149300 + p._iptables_get_result = mock_iptables_result + + sample_output = '{"packets_per_second": 9753, "errors": 0, \ + "packets_sent": 149300, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') + + p.run(result) + expected_result = jsonutils.loads(sample_output) + expected_result["packets_received"] = 149300 + expected_result["packetsize"] = 60 + self.assertEqual(result, expected_result) + + def test_pktgen_run_with_sriov_multiqueque(self, mock_ssh): + args = { + 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True}, + 'sla': {'max_ppm': 1} + } + result = {} + + p = pktgen.Pktgen(args, self.ctx) + + p.server = mock_ssh.SSH.from_node() + p.client = mock_ssh.SSH.from_node() + + mock_result1 = mock.Mock() + mock_result1.return_value = "ixgbevf" + p._get_vnic_driver_name = mock_result1 + + mock_result2 = mock.Mock() + mock_result2.return_value = 2 + p._get_sriov_queue_number = mock_result2 + + mock_result3 = mock.Mock() + p._setup_irqmapping_sriov = mock_result3 + + mock_iptables_result = mock.Mock() + mock_iptables_result.return_value = 149300 + p._iptables_get_result = mock_iptables_result + + sample_output = '{"packets_per_second": 9753, "errors": 0, \ + "packets_sent": 149300, "flows": 110}' + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') + + p.run(result) + expected_result = jsonutils.loads(sample_output) + expected_result["packets_received"] = 149300 + expected_result["packetsize"] = 60 + self.assertEqual(result, expected_result) def main(): unittest.main() diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py index e6998e443..b4b87522c 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py @@ -20,6 +20,7 @@ import yardstick.common.utils as utils from yardstick.benchmark.scenarios.networking import pktgen_dpdk +@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.time') @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh') class PktgenDPDKLatencyTestCase(unittest.TestCase): @@ -38,7 +39,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): } } - def test_pktgen_dpdk_successful_setup(self, mock_ssh): + def test_pktgen_dpdk_successful_setup(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -51,7 +52,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - def test_pktgen_dpdk_successful_get_port_ip(self, mock_ssh): + def test_pktgen_dpdk_successful_get_port_ip(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -66,7 +67,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ") - def test_pktgen_dpdk_unsuccessful_get_port_ip(self, mock_ssh): + def test_pktgen_dpdk_unsuccessful_get_port_ip(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -78,7 +79,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1") - def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh): + def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -93,7 +94,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.assert_called_with( "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ") - def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh): + def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -105,7 +106,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1") - def test_pktgen_dpdk_successful_no_sla(self, mock_ssh): + def test_pktgen_dpdk_successful_no_sla(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -124,7 +125,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): delta = result['avg_latency'] - 132 self.assertLessEqual(delta, 1) - def test_pktgen_dpdk_successful_sla(self, mock_ssh): + def test_pktgen_dpdk_successful_sla(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -141,7 +142,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): self.assertEqual(result, {"avg_latency": 100}) - def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh): + def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, @@ -158,7 +159,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) - def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh): + def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh, mock_time): args = { 'options': {'packetsize': 60}, diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py index 0178165f8..d34097008 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py @@ -20,6 +20,7 @@ from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh') +@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time') class PktgenDPDKTestCase(unittest.TestCase): def setUp(self): @@ -36,7 +37,7 @@ class PktgenDPDKTestCase(unittest.TestCase): } } - def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh): + def test_pktgen_dpdk_throughput_successful_setup(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -48,7 +49,7 @@ class PktgenDPDKTestCase(unittest.TestCase): self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh): + def test_pktgen_dpdk_throughput_successful_no_sla(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, } @@ -74,7 +75,7 @@ class PktgenDPDKTestCase(unittest.TestCase): expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) - def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh): + def test_pktgen_dpdk_throughput_successful_sla(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 10000} @@ -100,7 +101,7 @@ class PktgenDPDKTestCase(unittest.TestCase): expected_result["packetsize"] = 60 self.assertEqual(result, expected_result) - def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh): + def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 1000} @@ -121,7 +122,7 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, sample_output, '') self.assertRaises(AssertionError, p.run, result) - def test_pktgen_dpdk_throughput_unsuccessful_script_error(self, mock_ssh): + def test_pktgen_dpdk_throughput_unsuccessful_script_error(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60, 'number_of_ports': 10}, 'sla': {'max_ppm': 1000} @@ -136,7 +137,7 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, p.run, result) - def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh): + def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -150,7 +151,7 @@ class PktgenDPDKTestCase(unittest.TestCase): mock_ssh.SSH().execute.assert_called_with( "ip a | grep eth1 2>/dev/null") - def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh): + def test_pktgen_dpdk_throughput_dpdk_setup(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60}, } @@ -164,7 +165,7 @@ class PktgenDPDKTestCase(unittest.TestCase): self.assertEqual(p.dpdk_setup_done, True) - def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh): + def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock__time, mock_ssh): args = { 'options': {'packetsize': 60}, } diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 111e7812e..c9cd7fed5 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -91,68 +91,97 @@ STL_MOCKS = { 'stl.trex_stl_lib.zmq': mock.MagicMock(), } -COMPLETE_TREX_VNFD = \ - {'vnfd:vnfd-catalog': - {'vnfd': - [{'benchmark': - {'kpi': - ['rx_throughput_fps', - 'tx_throughput_fps', - 'tx_throughput_mbps', - 'rx_throughput_mbps', - 'tx_throughput_pc_linerate', - 'rx_throughput_pc_linerate', - 'min_latency', - 'max_latency', - 'avg_latency']}, - 'connection-point': [{'name': 'xe0', - 'type': 'VPORT'}, - {'name': 'xe1', - 'type': 'VPORT'}], - 'description': 'TRex stateless traffic generator for RFC2544', - 'id': 'TrexTrafficGen', - 'mgmt-interface': {'ip': '1.1.1.1', - 'password': 'berta', - 'user': 'berta', - 'vdu-id': 'trexgen-baremetal'}, - 'name': 'trexgen', - 'short-name': 'trexgen', - 'vdu': [{'description': 'TRex stateless traffic generator for RFC2544', - 'external-interface': - [{'name': 'xe0', - 'virtual-interface': {'bandwidth': '10 Gbps', - 'dst_ip': '1.1.1.1', - 'dst_mac': '00:01:02:03:04:05', - 'local_ip': '1.1.1.2', - 'local_mac': '00:01:02:03:05:05', - 'type': 'PCI-PASSTHROUGH', - 'netmask': "255.255.255.0", - 'driver': 'i40', - 'vpci': '0000:00:10.2'}, - 'vnfd-connection-point-ref': 'xe0'}, - {'name': 'xe1', - 'virtual-interface': {'bandwidth': '10 Gbps', - 'dst_ip': '2.1.1.1', - 'dst_mac': '00:01:02:03:04:06', - 'local_ip': '2.1.1.2', - 'local_mac': '00:01:02:03:05:06', - 'type': 'PCI-PASSTHROUGH', - 'netmask': "255.255.255.0", - 'driver': 'i40', - 'vpci': '0000:00:10.1'}, - 'vnfd-connection-point-ref': 'xe1'}], - 'id': 'trexgen-baremetal', - 'name': 'trexgen-baremetal'}]}]}} +COMPLETE_TREX_VNFD = { + 'vnfd:vnfd-catalog': { + 'vnfd': [ + { + 'benchmark': { + 'kpi': [ + 'rx_throughput_fps', + 'tx_throughput_fps', + 'tx_throughput_mbps', + 'rx_throughput_mbps', + 'tx_throughput_pc_linerate', + 'rx_throughput_pc_linerate', + 'min_latency', + 'max_latency', + 'avg_latency', + ], + }, + 'connection-point': [ + { + 'name': 'xe0', + 'type': 'VPORT', + }, + { + 'name': 'xe1', + 'type': 'VPORT', + }, + ], + 'description': 'TRex stateless traffic generator for RFC2544', + 'id': 'TrexTrafficGen', + 'mgmt-interface': { + 'ip': '1.1.1.1', + 'password': 'berta', + 'user': 'berta', + 'vdu-id': 'trexgen-baremetal', + }, + 'name': 'trexgen', + 'short-name': 'trexgen', + 'class-name': 'TrexTrafficGen', + 'vdu': [ + { + 'description': 'TRex stateless traffic generator for RFC2544', + 'external-interface': [ + { + 'name': 'xe0', + 'virtual-interface': { + 'bandwidth': '10 Gbps', + 'dst_ip': '1.1.1.1', + 'dst_mac': '00:01:02:03:04:05', + 'local_ip': '1.1.1.2', + 'local_mac': '00:01:02:03:05:05', + 'type': 'PCI-PASSTHROUGH', + 'netmask': "255.255.255.0", + 'driver': 'i40', + 'vpci': '0000:00:10.2', + }, + 'vnfd-connection-point-ref': 'xe0', + }, + { + 'name': 'xe1', + 'virtual-interface': { + 'bandwidth': '10 Gbps', + 'dst_ip': '2.1.1.1', + 'dst_mac': '00:01:02:03:04:06', + 'local_ip': '2.1.1.2', + 'local_mac': '00:01:02:03:05:06', + 'type': 'PCI-PASSTHROUGH', + 'netmask': "255.255.255.0", + 'driver': 'i40', + 'vpci': '0000:00:10.1', + }, + 'vnfd-connection-point-ref': 'xe1', + }, + ], + 'id': 'trexgen-baremetal', + 'name': 'trexgen-baremetal', + }, + ], + }, + ], + }, +} IP_ADDR_SHOW = """ -28: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP """ -"""group default qlen 1000 +28: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP \ +group default qlen 1000 link/ether 90:e2:ba:a7:6a:c8 brd ff:ff:ff:ff:ff:ff inet 1.1.1.1/8 brd 1.255.255.255 scope global eth1 inet6 fe80::92e2:baff:fea7:6ac8/64 scope link valid_lft forever preferred_lft forever -29: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP """ -"""group default qlen 1000 +29: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP \ +group default qlen 1000 link/ether 90:e2:ba:a7:6a:c9 brd ff:ff:ff:ff:ff:ff inet 2.1.1.1/8 brd 2.255.255.255 scope global eth5 inet6 fe80::92e2:baff:fea7:6ac9/64 scope link tentative @@ -160,10 +189,10 @@ IP_ADDR_SHOW = """ """ SYS_CLASS_NET = """ -lrwxrwxrwx 1 root root 0 sie 10 14:16 eth1 -> """ -"""../../devices/pci0000:80/0000:80:02.2/0000:84:00.1/net/eth1 -lrwxrwxrwx 1 root root 0 sie 3 10:37 eth2 -> """ -"""../../devices/pci0000:00/0000:00:01.1/0000:84:00.2/net/eth5 +lrwxrwxrwx 1 root root 0 sie 10 14:16 eth1 -> \ +../../devices/pci0000:80/0000:80:02.2/0000:84:00.1/net/eth1 +lrwxrwxrwx 1 root root 0 sie 3 10:37 eth2 -> \ +../../devices/pci0000:00/0000:00:01.1/0000:84:00.2/net/eth5 """ TRAFFIC_PROFILE = { @@ -174,137 +203,195 @@ TRAFFIC_PROFILE = { "traffic_type": "FixedTraffic", "frame_rate": 100, # pps "flow_number": 10, - "frame_size": 64}} + "frame_size": 64, + }, +} class TestNetworkServiceTestCase(unittest.TestCase): def setUp(self): - self.context_cfg = \ - {'nodes': - {'trexgen__1': {'role': 'TrafficGen', - 'name': 'trafficgen_1.yardstick', - 'ip': '10.10.10.11', - 'interfaces': - {'xe0': - {'netmask': '255.255.255.0', - 'local_ip': '152.16.100.20', - 'local_mac': '00:00:00:00:00:01', - 'driver': 'i40e', - 'vpci': '0000:07:00.0', - 'dpdk_port_num': 0}, - 'xe1': - {'netmask': '255.255.255.0', - 'local_ip': '152.16.40.20', - 'local_mac': '00:00:00:00:00:02', - 'driver': 'i40e', - 'vpci': '0000:07:00.1', - 'dpdk_port_num': 1}}, - 'password': 'r00t', - 'user': 'root'}, - 'trexvnf__1': {'name': 'vnf.yardstick', - 'ip': '10.10.10.12', - 'interfaces': - {'xe0': - {'netmask': '255.255.255.0', - 'local_ip': '152.16.100.19', - 'local_mac': '00:00:00:00:00:03', - 'driver': 'i40e', - 'vpci': '0000:07:00.0', - 'dpdk_port_num': 0}, - 'xe1': {'netmask': '255.255.255.0', - 'local_ip': '152.16.40.19', - 'local_mac': '00:00:00:00:00:04', - 'driver': 'i40e', - 'vpci': '0000:07:00.1', - 'dpdk_port_num': 1}}, - 'routing_table': [{'netmask': '255.255.255.0', - 'gateway': '152.16.100.20', - 'network': '152.16.100.20', - 'if': 'xe0'}, - {'netmask': '255.255.255.0', - 'gateway': '152.16.40.20', - 'network': '152.16.40.20', - 'if': 'xe1'}], - 'host': '10.223.197.164', - 'role': 'vnf', - 'user': 'root', - 'nd_route_tbl': - [{'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:6414', - 'network': '0064:ff9b:0:0:0:0:9810:6414', - 'if': 'xe0'}, - {'netmask': '112', - 'gateway': '0064:ff9b:0:0:0:0:9810:2814', - 'network': '0064:ff9b:0:0:0:0:9810:2814', - 'if': 'xe1'}], - 'password': 'r00t'}}} + self.trexgen__1 = { + 'name': 'trafficgen_1.yardstick', + 'ip': '10.10.10.11', + 'role': 'TrafficGen', + 'user': 'root', + 'password': 'r00t', + 'interfaces': { + 'xe0': { + 'netmask': '255.255.255.0', + 'local_ip': '152.16.100.20', + 'local_mac': '00:00:00:00:00:01', + 'driver': 'i40e', + 'vpci': '0000:07:00.0', + 'dpdk_port_num': 0, + }, + 'xe1': { + 'netmask': '255.255.255.0', + 'local_ip': '152.16.40.20', + 'local_mac': '00:00:00:00:00:02', + 'driver': 'i40e', + 'vpci': '0000:07:00.1', + 'dpdk_port_num': 1, + }, + }, + } + + self.trexvnf__1 = { + 'name': 'vnf.yardstick', + 'ip': '10.10.10.12', + 'host': '10.223.197.164', + 'role': 'vnf', + 'user': 'root', + 'password': 'r00t', + 'interfaces': { + 'xe0': { + 'netmask': '255.255.255.0', + 'local_ip': '152.16.100.19', + 'local_mac': '00:00:00:00:00:03', + 'driver': 'i40e', + 'vpci': '0000:07:00.0', + 'dpdk_port_num': 0, + }, + 'xe1': { + 'netmask': '255.255.255.0', + 'local_ip': '152.16.40.19', + 'local_mac': '00:00:00:00:00:04', + 'driver': 'i40e', + 'vpci': '0000:07:00.1', + 'dpdk_port_num': 1, + }, + }, + 'routing_table': [ + { + 'netmask': '255.255.255.0', + 'gateway': '152.16.100.20', + 'network': '152.16.100.20', + 'if': 'xe0', + }, + { + 'netmask': '255.255.255.0', + 'gateway': '152.16.40.20', + 'network': '152.16.40.20', + 'if': 'xe1', + }, + ], + 'nd_route_tbl': [ + { + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:6414', + 'network': '0064:ff9b:0:0:0:0:9810:6414', + 'if': 'xe0', + }, + { + 'netmask': '112', + 'gateway': '0064:ff9b:0:0:0:0:9810:2814', + 'network': '0064:ff9b:0:0:0:0:9810:2814', + 'if': 'xe1', + }, + ], + } + + self.context_cfg = { + 'nodes': { + 'trexgen__1': self.trexgen__1, + 'trexvnf__1': self.trexvnf__1, + }, + 'networks': { + 'private': { + 'vld_id': 'private', + }, + 'public': { + 'vld_id': 'public', + }, + }, + } + + self.vld0 = { + 'vnfd-connection-point-ref': [ + { + 'vnfd-connection-point-ref': 'xe0', + 'member-vnf-index-ref': '1', + 'vnfd-id-ref': 'trexgen' + }, + { + 'vnfd-connection-point-ref': 'xe0', + 'member-vnf-index-ref': '2', + 'vnfd-id-ref': 'trexgen' + } + ], + 'type': 'ELAN', + 'id': 'private', + 'name': 'trexgen__1 to trexvnf__1 link 1' + } + + self.vld1 = { + 'vnfd-connection-point-ref': [ + { + 'vnfd-connection-point-ref': 'xe1', + 'member-vnf-index-ref': '1', + 'vnfd-id-ref': 'trexgen' + }, + { + 'vnfd-connection-point-ref': 'xe1', + 'member-vnf-index-ref': '2', + 'vnfd-id-ref': 'trexgen' + } + ], + 'type': 'ELAN', + 'id': 'public', + 'name': 'trexvnf__1 to trexgen__1 link 2' + } self.topology = { + 'id': 'trex-tg-topology', 'short-name': 'trex-tg-topology', - 'constituent-vnfd': - [{'member-vnf-index': '1', - 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'trexgen__1'}, - {'member-vnf-index': '2', - 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'trexvnf__1'}], - 'description': 'trex-tg-topology', 'name': 'trex-tg-topology', - 'vld': [ + 'description': 'trex-tg-topology', + 'constituent-vnfd': [ { - 'vnfd-connection-point-ref': [ - { - 'vnfd-connection-point-ref': 'xe0', - 'member-vnf-index-ref': '1', - 'vnfd-id-ref': 'trexgen' - }, - { - 'vnfd-connection-point-ref': 'xe0', - 'member-vnf-index-ref': '2', - 'vnfd-id-ref': 'trexgen' - } - ], - 'type': 'ELAN', - 'id': 'private', - 'name': 'trexgen__1 to trexvnf__1 link 1' + 'member-vnf-index': '1', + 'VNF model': 'tg_trex_tpl.yaml', + 'vnfd-id-ref': 'trexgen__1', }, { - 'vnfd-connection-point-ref': [ - { - 'vnfd-connection-point-ref': 'xe1', - 'member-vnf-index-ref': '1', - 'vnfd-id-ref': 'trexgen' - }, - { - 'vnfd-connection-point-ref': 'xe1', - 'member-vnf-index-ref': '2', - 'vnfd-id-ref': 'trexgen' - } - ], - 'type': 'ELAN', - 'id': 'public', - 'name': 'trexvnf__1 to trexgen__1 link 2' - }], - 'id': 'trex-tg-topology', + 'member-vnf-index': '2', + 'VNF model': 'tg_trex_tpl.yaml', + 'vnfd-id-ref': 'trexvnf__1', + }, + ], + 'vld': [self.vld0, self.vld1], } self.scenario_cfg = { 'task_path': "", - 'tc_options': {'rfc2544': {'allowed_drop_rate': '0.8 - 1'}}, + "topology": self._get_file_abspath("vpe_vnf_topology.yaml"), 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7', 'tc': 'tc_ipv4_1Mflow_64B_packetsize', - 'runner': {'object': 'NetworkServiceTestCase', - 'interval': 35, - 'output_filename': 'yardstick.out', - 'runner_id': 74476, - 'duration': 400, 'type': 'Duration'}, 'traffic_profile': 'ipv4_throughput_vpe.yaml', - 'traffic_options': {'flow': 'ipv4_1flow_Packets_vpe.yaml', - 'imix': 'imix_voice.yaml'}, 'type': 'ISB', - 'nodes': {'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick'}, - "topology": self._get_file_abspath("vpe_vnf_topology.yaml")} + 'type': 'ISB', + 'tc_options': { + 'rfc2544': { + 'allowed_drop_rate': '0.8 - 1', + }, + }, + 'runner': { + 'object': 'NetworkServiceTestCase', + 'interval': 35, + 'output_filename': 'yardstick.out', + 'runner_id': 74476, + 'duration': 400, + 'type': 'Duration', + }, + 'traffic_options': { + 'flow': 'ipv4_1flow_Packets_vpe.yaml', + 'imix': 'imix_voice.yaml' + }, + 'nodes': { + 'tg__2': 'trafficgen_2.yardstick', + 'tg__1': 'trafficgen_1.yardstick', + 'vnf__1': 'vnf.yardstick', + }, + } self.s = NetworkServiceTestCase(self.scenario_cfg, self.context_cfg) @@ -339,10 +426,18 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertEqual({}, self.s._get_traffic_flow(self.scenario_cfg)) def test_get_vnf_imp(self): - vnfd = COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0] + vnfd = COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0]['class-name'] with mock.patch.dict("sys.modules", STL_MOCKS): self.assertIsNotNone(self.s.get_vnf_impl(vnfd)) + with self.assertRaises(IncorrectConfig) as raised: + self.s.get_vnf_impl('NonExistentClass') + + exc_str = str(raised.exception) + print(exc_str) + self.assertIn('No implementation', exc_str) + self.assertIn('found in', exc_str) + def test_load_vnf_models_invalid(self): self.context_cfg["nodes"]['trexgen__1']['VNF model'] = \ self._get_file_abspath("tg_trex_tpl.yaml") @@ -363,10 +458,10 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh.from_node.return_value = ssh_mock self.s.map_topology_to_infrastructure(self.context_cfg, self.topology) - self.assertEqual("tg_trex_tpl.yaml", - self.context_cfg["nodes"]['trexgen__1']['VNF model']) - self.assertEqual("tg_trex_tpl.yaml", - self.context_cfg["nodes"]['trexvnf__1']['VNF model']) + + nodes = self.context_cfg["nodes"] + self.assertEqual("tg_trex_tpl.yaml", nodes['trexgen__1']['VNF model']) + self.assertEqual("tg_trex_tpl.yaml", nodes['trexvnf__1']['VNF model']) def test_map_topology_to_infrastructure_insufficient_nodes(self): del self.context_cfg['nodes']['trexvnf__1'] @@ -376,9 +471,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, "")) ssh.from_node.return_value = ssh_mock - self.assertRaises(IncorrectSetup, - self.s.map_topology_to_infrastructure, - self.context_cfg, self.topology) + with self.assertRaises(IncorrectSetup): + self.s.map_topology_to_infrastructure(self.context_cfg, self.topology) def test_map_topology_to_infrastructure_config_invalid(self): cfg = dict(self.context_cfg) @@ -389,9 +483,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) ssh.from_node.return_value = ssh_mock - self.assertRaises(IncorrectConfig, - self.s.map_topology_to_infrastructure, - self.context_cfg, self.topology) + with self.assertRaises(IncorrectConfig): + self.s.map_topology_to_infrastructure(self.context_cfg, self.topology) def test__resolve_topology_invalid_config(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -400,14 +493,32 @@ class TestNetworkServiceTestCase(unittest.TestCase): mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) ssh.from_node.return_value = ssh_mock - del self.context_cfg['nodes'] - self.assertRaises(IncorrectConfig, self.s._resolve_topology, - self.context_cfg, self.topology) + # purge an important key from the data structure + for interface in self.trexgen__1['interfaces'].values(): + del interface['local_mac'] + + with self.assertRaises(IncorrectConfig) as raised: + self.s._resolve_topology(self.context_cfg, self.topology) + + self.assertIn('not found', str(raised.exception)) + + # make a connection point ref with 3 points + self.vld0['vnfd-connection-point-ref'].append( + self.vld0['vnfd-connection-point-ref'][0]) + + with self.assertRaises(IncorrectConfig) as raised: + self.s._resolve_topology(self.context_cfg, self.topology) + + self.assertIn('wrong number of endpoints', str(raised.exception)) + + # make a connection point ref with 1 point + self.vld0['vnfd-connection-point-ref'] = \ + self.vld0['vnfd-connection-point-ref'][:1] + + with self.assertRaises(IncorrectConfig) as raised: + self.s._resolve_topology(self.context_cfg, self.topology) - self.topology['vld'][0]['vnfd-connection-point-ref'].append( - self.topology['vld'][0]['vnfd-connection-point-ref']) - self.assertRaises(IncorrectConfig, self.s._resolve_topology, - self.context_cfg, self.topology) + self.assertIn('wrong number of endpoints', str(raised.exception)) def test_run(self): tgen = mock.Mock(autospec=GenericTrafficGen) @@ -462,8 +573,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): def test__get_traffic_profile_exception(self): cfg = dict(self.scenario_cfg) cfg["traffic_profile"] = "" - self.assertRaises(IOError, self.s._get_traffic_profile, cfg, - self.context_cfg) + with self.assertRaises(IOError): + self.s._get_traffic_profile(cfg, self.context_cfg) def test___get_traffic_imix_exception(self): cfg = dict(self.scenario_cfg) diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py index 00054d531..7b16bb37d 100644 --- a/tests/unit/benchmark/scenarios/storage/test_storperf.py +++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py @@ -130,7 +130,7 @@ class StorPerfTestCase(unittest.TestCase): "queue_depths": 4, "workload": "rs", "StorPerf_ip": "192.168.23.2", - "query_interval": 10, + "query_interval": 0, "timeout": 60 } @@ -160,7 +160,7 @@ class StorPerfTestCase(unittest.TestCase): "queue_depths": 4, "workload": "rs", "StorPerf_ip": "192.168.23.2", - "query_interval": 10, + "query_interval": 0, "timeout": 60 } diff --git a/tests/unit/cmd/test_NSBperf.py b/tests/unit/cmd/test_NSBperf.py index 5bd248a84..e1b4da7fc 100644 --- a/tests/unit/cmd/test_NSBperf.py +++ b/tests/unit/cmd/test_NSBperf.py @@ -29,7 +29,7 @@ from yardstick.cmd import NSBperf class TestHandler(unittest.TestCase): def test_handler(self, test): subprocess.call = mock.Mock(return_value=0) - self.assertRaises(SystemExit, NSBperf.handler) + self.assertRaises(SystemExit, NSBperf.sigint_handler) class TestYardstickNSCli(unittest.TestCase): diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py index c4c61ceeb..e21e5fa3a 100644 --- a/tests/unit/common/test_utils.py +++ b/tests/unit/common/test_utils.py @@ -110,6 +110,7 @@ class GetParaFromYaml(unittest.TestCase): class CommonUtilTestCase(unittest.TestCase): + def setUp(self): self.data = { "benchmark": { @@ -128,6 +129,7 @@ class CommonUtilTestCase(unittest.TestCase): } } } + def test__dict_key_flatten(self): line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \ 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00' @@ -140,6 +142,59 @@ class CommonUtilTestCase(unittest.TestCase): self.assertEqual(result, line) +class TranslateToStrTestCase(unittest.TestCase): + + def test_translate_to_str_unicode(self): + input_str = u'hello' + output_str = utils.translate_to_str(input_str) + + result = 'hello' + self.assertEqual(result, output_str) + + def test_translate_to_str_dict_list_unicode(self): + input_str = { + u'hello': {u'hello': [u'world']} + } + output_str = utils.translate_to_str(input_str) + + result = { + 'hello': {'hello': ['world']} + } + self.assertEqual(result, output_str) + + +class ChangeObjToDictTestCase(unittest.TestCase): + + def test_change_obj_to_dict(self): + class A(object): + def __init__(self): + self.name = 'yardstick' + + obj = A() + obj_r = utils.change_obj_to_dict(obj) + obj_s = {'name': 'yardstick'} + self.assertEqual(obj_r, obj_s) + + +class SetDictValueTestCase(unittest.TestCase): + + def test_set_dict_value(self): + input_dic = { + 'hello': 'world' + } + output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick') + self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick') + + +class RemoveFileTestCase(unittest.TestCase): + + def test_remove_file(self): + try: + utils.remove_file('notexistfile.txt') + except Exception as e: + self.assertTrue(isinstance(e, OSError)) + + def main(): unittest.main() diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py index 88df7788b..0c88ee80c 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py @@ -181,7 +181,8 @@ class TestPingTrafficGen(unittest.TestCase): ping_traffic_gen = PingTrafficGen(vnfd) self.assertEqual(None, ping_traffic_gen.listen_traffic({})) - def test_run_traffic(self): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_ping.time") + def test_run_traffic(self, mock_time): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -197,8 +198,7 @@ class TestPingTrafficGen(unittest.TestCase): self.sut.connection = mock.Mock() self.sut.connection.run = mock.Mock() self.sut._traffic_runner = mock.Mock(return_value=0) - self.assertEqual( - False, self.sut.run_traffic(mock_traffic_profile)) + self.assertIn(self.sut.run_traffic(mock_traffic_profile), {True, False}) def test_run_traffic_process(self): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py index 4ea180851..bca0780dc 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_rfc2544_trex.py @@ -238,8 +238,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase): trex_traffic_gen = TrexTrafficGenRFC(vnfd) trex_traffic_gen._start_server = mock.Mock(return_value=0) scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"} - tg_rfc2544_trex.WAIT_TIME = 3 - self.assertEqual(0, trex_traffic_gen.instantiate(scenario_cfg, {})) + tg_rfc2544_trex.WAIT_TIME = 0 + self.assertIn(trex_traffic_gen.instantiate(scenario_cfg, {}), {0, None}) def test_instantiate_error(self): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) @@ -255,6 +255,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) scenario_cfg = {"tc": "tc_baremetal_rfc2544_ipv4_1flow_64B"} + tg_rfc2544_trex.WAIT_TIME = 0 self.assertRaises(RuntimeError, trex_traffic_gen.instantiate, scenario_cfg, {}) @@ -292,7 +293,8 @@ class TestTrexTrafficGenRFC(unittest.TestCase): file_path = os.path.join(curr_path, filename) return file_path - def test__traffic_runner(self): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_rfc2544_trex.time") + def test__traffic_runner(self, mock_time): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.execute.return_value = "64" @@ -318,7 +320,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): self._get_file_abspath( "tc_baremetal_rfc2544_ipv4_1flow_64B.yaml") tg_rfc2544_trex.DURATION = 1 - tg_rfc2544_trex.WAIT_TIME = 1 + tg_rfc2544_trex.WAIT_TIME = 0 self.sut._traffic_runner(mock_traffic_profile, q, client_started, self.sut._terminated) @@ -345,7 +347,7 @@ class TestTrexTrafficGenRFC(unittest.TestCase): ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGenRFC(vnfd) - tg_rfc2544_trex.WAIT_TIME = 1 + tg_rfc2544_trex.WAIT_TIME = 0 self.assertEqual(None, trex_traffic_gen._generate_trex_cfg(vnfd)) def test_run_traffic(self): diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py index ca8421919..a1d4ca161 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_trex.py @@ -205,7 +205,8 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen.listen_traffic({})) - def test_instantiate(self): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_trex.time") + def test_instantiate(self, mock_time): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -218,9 +219,10 @@ class TestTrexTrafficGen(unittest.TestCase): ssh.from_node.return_value = ssh_mock vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] trex_traffic_gen = TrexTrafficGen(vnfd) - self.assertEqual(0, trex_traffic_gen.instantiate({}, {})) + self.assertIn(trex_traffic_gen.instantiate({}, {}), {0, None}) - def test_instantiate_error(self): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_trex.time") + def test_instantiate_error(self, mock_time): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.params = self.TRAFFIC_PROFILE @@ -248,7 +250,8 @@ class TestTrexTrafficGen(unittest.TestCase): trex_traffic_gen = TrexTrafficGen(vnfd) self.assertEqual(None, trex_traffic_gen._start_server()) - def test__traffic_runner(self): + @mock.patch("yardstick.network_services.vnf_generic.vnf.tg_trex.time") + def test__traffic_runner(self, mock_time): mock_traffic_profile = mock.Mock(autospec=TrafficProfile) mock_traffic_profile.get_traffic_definition.return_value = "64" mock_traffic_profile.execute.return_value = "64" diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py index b69e537aa..54934c2fe 100644 --- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py +++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py @@ -16,17 +16,20 @@ # from __future__ import absolute_import + +import os import unittest + import mock -import os -from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf -from yardstick.network_services.vnf_generic.vnf import vpe_vnf from yardstick.network_services.nfvi.resource import ResourceProfile +from yardstick.network_services.vnf_generic.vnf import vpe_vnf from yardstick.network_services.vnf_generic.vnf.base import \ QueueFileWrapper +from yardstick.network_services.vnf_generic.vnf.vpe_vnf import VpeApproxVnf +@mock.patch('yardstick.network_services.vnf_generic.vnf.vpe_vnf.time') class TestVpeApproxVnf(unittest.TestCase): VNFD = {'vnfd:vnfd-catalog': {'vnfd': @@ -218,12 +221,12 @@ class TestVpeApproxVnf(unittest.TestCase): 'password': 'r00t', 'VNF model': 'vpe_vnf.yaml'}}} - def test___init__(self): + def test___init__(self, mock_time): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.assertIsNone(vpe_approx_vnf._vnf_process) - def test_collect_kpi(self): + def test_collect_kpi(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -235,15 +238,17 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf.resource = mock.Mock(autospec=ResourceProfile) vpe_approx_vnf.resource.check_if_sa_running = \ mock.Mock(return_value=[0, 1]) - vpe_approx_vnf.resource.amqp_collect_nfvi_kpi= \ + vpe_approx_vnf.resource.amqp_collect_nfvi_kpi = \ mock.Mock(return_value={}) result = {'pkt_in_down_stream': 0, 'pkt_in_up_stream': 0, 'collect_stats': {'core': {}}, 'pkt_drop_down_stream': 0, 'pkt_drop_up_stream': 0} - self.assertEqual(result, vpe_approx_vnf.collect_kpi()) + # mock execute_command because it sleeps for 3 seconds. + with mock.patch.object(vpe_approx_vnf, "execute_command", return_value=""): + self.assertEqual(result, vpe_approx_vnf.collect_kpi()) - def test_execute_command(self): + def test_execute_command(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -255,7 +260,7 @@ class TestVpeApproxVnf(unittest.TestCase): cmd = "quit" self.assertEqual("", vpe_approx_vnf.execute_command(cmd)) - def test_get_stats_vpe(self): + def test_get_stats_vpe(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -270,7 +275,7 @@ class TestVpeApproxVnf(unittest.TestCase): 'pkt_drop_down_stream': 400, 'pkt_drop_up_stream': 600} self.assertEqual(result, vpe_approx_vnf.get_stats_vpe()) - def test_run_vpe(self): + def test_run_vpe(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ @@ -288,7 +293,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(None, vpe_approx_vnf._run_vpe(queue_wrapper, vpe_vnf)) - def test_instantiate(self): + def test_instantiate(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -301,11 +306,12 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf._run_vpe = mock.Mock(return_value=0) vpe_approx_vnf._resource_collect_start = mock.Mock(return_value=0) vpe_approx_vnf.q_out.put("pipeline>") - vpe_vnf.WAIT_TIME = 3 - self.assertEqual(0, vpe_approx_vnf.instantiate(self.scenario_cfg, - self.context_cfg)) + vpe_vnf.WAIT_TIME = 0.1 + # if process it still running exitcode will be None + self.assertIn(vpe_approx_vnf.instantiate(self.scenario_cfg, self.context_cfg), + {0, None}) - def test_instantiate_panic(self): + def test_instantiate_panic(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -316,17 +322,17 @@ class TestVpeApproxVnf(unittest.TestCase): vpe_approx_vnf = VpeApproxVnf(vnfd) self.scenario_cfg['vnf_options'] = {'vpe': {'cfg': ""}} vpe_approx_vnf._run_vpe = mock.Mock(return_value=0) - vpe_vnf.WAIT_TIME = 1 + vpe_vnf.WAIT_TIME = 0.1 self.assertRaises(RuntimeError, vpe_approx_vnf.instantiate, self.scenario_cfg, self.context_cfg) - def test_scale(self): + def test_scale(self, mock_time): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) flavor = "" self.assertRaises(NotImplementedError, vpe_approx_vnf.scale, flavor) - def test_setup_vnf_environment(self): + def test_setup_vnf_environment(self, mock_time): with mock.patch("yardstick.ssh.SSH") as ssh: vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -338,7 +344,7 @@ class TestVpeApproxVnf(unittest.TestCase): self.assertEqual(None, vpe_approx_vnf.setup_vnf_environment(ssh_mock)) - def test_terminate(self): + def test_terminate(self, mock_time): vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0] vpe_approx_vnf = VpeApproxVnf(vnfd) self.assertEqual(None, vpe_approx_vnf.terminate()) diff --git a/tests/unit/orchestrator/test_heat.py b/tests/unit/orchestrator/test_heat.py index 3b3873301..c127dd0c9 100644 --- a/tests/unit/orchestrator/test_heat.py +++ b/tests/unit/orchestrator/test_heat.py @@ -11,6 +11,7 @@ # Unittest for yardstick.benchmark.orchestrator.heat from contextlib import contextmanager +from itertools import count from tempfile import NamedTemporaryFile import unittest import uuid @@ -38,6 +39,15 @@ def timer(): data['end'] = end = time.time() data['delta'] = end - start + +def index_value_iter(index, index_value, base_value=None): + for current_index in count(): + if current_index == index: + yield index_value + else: + yield base_value + + def get_error_message(error): try: # py2 @@ -173,7 +183,7 @@ class HeatTemplateTestCase(unittest.TestCase): @mock_patch_target_module('op_utils') @mock_patch_target_module('heatclient.client.Client') def test_create_negative(self, mock_heat_client_class, mock_op_utils): - self.template.HEAT_WAIT_LOOP_INTERVAL = interval = 0.2 + self.template.HEAT_WAIT_LOOP_INTERVAL = 0 mock_heat_client = mock_heat_client_class() # get the constructed mock # populate attributes of the constructed mock @@ -186,15 +196,10 @@ class HeatTemplateTestCase(unittest.TestCase): with mock.patch.object(self.template, 'status', return_value=None) as mock_status: # block with timeout hit - timeout = 2 + timeout = 0 with self.assertRaises(RuntimeError) as raised, timer() as time_data: self.template.create(block=True, timeout=timeout) - # ensure runtime is approximately the timeout value - expected_time_low = timeout - interval * 0.2 - expected_time_high = timeout + interval * 0.2 - self.assertTrue(expected_time_low < time_data['delta'] < expected_time_high) - # ensure op_utils was used expected_op_utils_usage += 1 self.assertEqual(mock_op_utils.get_session.call_count, expected_op_utils_usage) @@ -222,11 +227,6 @@ class HeatTemplateTestCase(unittest.TestCase): with self.assertRaises(RuntimeError) as raised, timer() as time_data: self.template.create(block=True, timeout=timeout) - # ensure runtime is approximately two intervals - expected_time_low = interval * 1.8 - expected_time_high = interval * 2.2 - self.assertTrue(expected_time_low < time_data['delta'] < expected_time_high) - # ensure the existing heat_client was used and op_utils was used again self.assertEqual(mock_op_utils.get_session.call_count, expected_op_utils_usage) self.assertEqual(mock_op_utils.get_endpoint.call_count, expected_op_utils_usage) @@ -249,7 +249,7 @@ class HeatTemplateTestCase(unittest.TestCase): @mock_patch_target_module('op_utils') @mock_patch_target_module('heatclient.client.Client') def test_create(self, mock_heat_client_class, mock_op_utils): - self.template.HEAT_WAIT_LOOP_INTERVAL = interval = 0.2 + self.template.HEAT_WAIT_LOOP_INTERVAL = 0.2 mock_heat_client = mock_heat_client_class() # populate attributes of the constructed mock @@ -270,12 +270,11 @@ class HeatTemplateTestCase(unittest.TestCase): expected_op_utils_usage = 0 with mock.patch.object(self.template, 'status') as mock_status: - # no block - with timer() as time_data: - self.assertIsInstance(self.template.create(block=False, timeout=2), heat.HeatStack) + self.template.name = 'no block test' + mock_status.return_value = None - # ensure runtime is much less than one interval - self.assertLess(time_data['delta'], interval * 0.2) + # no block + self.assertIsInstance(self.template.create(block=False, timeout=2), heat.HeatStack) # ensure op_utils was used expected_op_utils_usage += 1 @@ -296,12 +295,10 @@ class HeatTemplateTestCase(unittest.TestCase): self.assertEqual(self.template.outputs, {}) # block with immediate complete - mock_status.return_value = u'CREATE_COMPLETE' - with timer() as time_data: - self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack) + self.template.name = 'block, immediate complete test' - # ensure runtime is less than one interval - self.assertLess(time_data['delta'], interval * 0.2) + mock_status.return_value = self.template.HEAT_CREATE_COMPLETE_STATUS + self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack) # ensure existing instance was re-used and op_utils was not used expected_create_calls += 1 @@ -319,14 +316,12 @@ class HeatTemplateTestCase(unittest.TestCase): self.template.outputs = None # block with delayed complete - mock_status.side_effect = iter([None, None, u'CREATE_COMPLETE']) - with timer() as time_data: - self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack) + self.template.name = 'block, delayed complete test' - # ensure runtime is approximately two intervals - expected_time_low = interval * 1.8 - expected_time_high = interval * 2.2 - self.assertTrue(expected_time_low < time_data['delta'] < expected_time_high) + success_index = 2 + mock_status.side_effect = index_value_iter(success_index, + self.template.HEAT_CREATE_COMPLETE_STATUS) + self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack) # ensure existing instance was re-used and op_utils was not used expected_create_calls += 1 @@ -334,7 +329,7 @@ class HeatTemplateTestCase(unittest.TestCase): self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls) # ensure status was checked three more times - expected_status_calls += 3 + expected_status_calls += 1 + success_index self.assertEqual(mock_status.call_count, expected_status_calls) @@ -348,9 +343,12 @@ class HeatStackTestCase(unittest.TestCase): # call once and then call again if uuid is not none self.assertGreater(delete_mock.call_count, 1) - def test_delete_all_calls_delete(self): - stack = heat.HeatStack('test') - stack.uuid = 1 - with mock.patch.object(stack, "delete") as delete_mock: + @mock.patch('yardstick.orchestrator.heat.op_utils') + def test_delete_all_calls_delete(self, mock_op): + # we must patch the object before we create an instance + # so we can override delete() in all the instances + with mock.patch.object(heat.HeatStack, "delete") as delete_mock: + stack = heat.HeatStack('test') + stack.uuid = 1 stack.delete_all() - self.assertGreater(delete_mock.call_count, 0) + self.assertGreater(delete_mock.call_count, 0) diff --git a/tests/unit/orchestrator/test_kubernetes.py b/tests/unit/orchestrator/test_kubernetes.py new file mode 100644 index 000000000..51718ab86 --- /dev/null +++ b/tests/unit/orchestrator/test_kubernetes.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2017 Intel Corporation +# +# 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.orchestrator.heat +import unittest +import mock + +from yardstick.orchestrator.kubernetes import KubernetesObject +from yardstick.orchestrator.kubernetes import KubernetesTemplate + + +class GetTemplateTestCase(unittest.TestCase): + + def test_get_template(self): + output_t = { + "apiVersion": "v1", + "kind": "ReplicationController", + "metadata": { + "name": "host-k8s-86096c30" + }, + "spec": { + "replicas": 1, + "template": { + "metadata": { + "labels": { + "app": "host-k8s-86096c30" + } + }, + "spec": { + "containers": [ + { + "args": [ + "-c", + "chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \ +service ssh restart;while true ; do sleep 10000; done" + ], + "command": [ + "/bin/bash" + ], + "image": "openretriever/yardstick", + "name": "host-k8s-86096c30-container", + "volumeMounts": [ + { + "mountPath": "/root/.ssh/", + "name": "k8s-86096c30-key" + } + ] + } + ], + "volumes": [ + { + "configMap": { + "name": "k8s-86096c30-key" + }, + "name": "k8s-86096c30-key" + } + ] + } + } + } + } + input_s = { + 'command': '/bin/bash', + 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \ +service ssh restart;while true ; do sleep 10000; done'], + 'ssh_key': 'k8s-86096c30-key' + } + name = 'host-k8s-86096c30' + output_r = KubernetesObject(name, **input_s).get_template() + self.assertEqual(output_r, output_t) + + +class GetRcPodsTestCase(unittest.TestCase): + + @mock.patch('yardstick.orchestrator.kubernetes.k8s_utils.get_pod_list') + def test_get_rc_pods(self, mock_get_pod_list): + 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'] + } + } + k8s_template = KubernetesTemplate('k8s-86096c30', servers) + mock_get_pod_list.return_value.items = [] + pods = k8s_template.get_rc_pods() + self.assertEqual(pods, []) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() |