aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick')
-rw-r--r--yardstick/benchmark/core/task.py22
-rw-r--r--yardstick/benchmark/scenarios/availability/ha_tools/nova/add_server_to_existing_secgroup.bash26
-rw-r--r--yardstick/benchmark/scenarios/availability/ha_tools/nova/create_instance_from_image.bash26
-rw-r--r--yardstick/benchmark/scenarios/availability/ha_tools/nova/delete_instance.bash24
-rw-r--r--yardstick/benchmark/scenarios/availability/ha_tools/nova/get_server_privateip.bash24
-rw-r--r--yardstick/benchmark/scenarios/availability/ha_tools/nova/remove_server_from_secgroup.bash25
-rw-r--r--yardstick/benchmark/scenarios/availability/operation_conf.yaml8
-rw-r--r--yardstick/benchmark/scenarios/lib/create_network.py41
-rw-r--r--yardstick/benchmark/scenarios/lib/create_router.py46
-rw-r--r--yardstick/benchmark/scenarios/lib/create_subnet.py60
-rw-r--r--yardstick/benchmark/scenarios/lib/delete_router.py24
-rwxr-xr-xyardstick/benchmark/scenarios/networking/netperf.py4
-rw-r--r--yardstick/common/ansible_common.py53
-rw-r--r--yardstick/common/exceptions.py24
-rw-r--r--yardstick/common/openstack_utils.py121
-rw-r--r--yardstick/network_services/constants.py2
-rw-r--r--yardstick/network_services/traffic_profile/prox_binsearch.py7
-rw-r--r--yardstick/network_services/vnf_generic/vnf/prox_helpers.py52
-rw-r--r--yardstick/network_services/vnf_generic/vnf/prox_vnf.py4
-rw-r--r--yardstick/network_services/vnf_generic/vnf/sample_vnf.py20
-rw-r--r--yardstick/network_services/vnf_generic/vnf/vnf_ssh_helper.py4
-rw-r--r--yardstick/service/__init__.py12
-rw-r--r--yardstick/service/environment.py101
-rw-r--r--yardstick/tests/unit/apiserver/resources/v1/__init__.py0
-rw-r--r--yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py35
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py2
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_kubernetes.py36
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_node.py18
-rw-r--r--yardstick/tests/unit/benchmark/core/test_task.py30
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py6
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py57
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py57
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py60
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py6
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py51
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py6
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py2
-rw-r--r--yardstick/tests/unit/common/test_ansible_common.py16
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py102
-rw-r--r--yardstick/tests/unit/common/test_packages.py88
-rw-r--r--yardstick/tests/unit/common/test_utils.py38
-rw-r--r--yardstick/tests/unit/service/__init__.py0
-rw-r--r--yardstick/tests/unit/service/test_environment.py49
-rw-r--r--yardstick/tests/unit/test_cmd/commands/test_env.py14
-rw-r--r--yardstick/tests/unit/test_cmd/commands/test_testcase.py2
65 files changed, 1091 insertions, 390 deletions
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index e7acde696..955b8cae2 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -344,7 +344,8 @@ class Task(object): # pragma: no cover
# TODO support get multi hosts/vms info
context_cfg = {}
- server_name = scenario_cfg.get('options', {}).get('server_name', {})
+ options = scenario_cfg.get('options') or {}
+ server_name = options.get('server_name') or {}
def config_context_target(cfg):
target = cfg['target']
@@ -613,21 +614,32 @@ class TaskParser(object): # pragma: no cover
vnf__0: vnf_0.yardstick
"""
def qualified_name(name):
- node_name, context_name = name.split('.')
+ try:
+ # for openstack
+ node_name, context_name = name.split('.')
+ sep = '.'
+ except ValueError:
+ # for kubernetes, some kubernetes resources don't support
+ # name format like 'xxx.xxx', so we use '-' instead
+ # need unified later
+ node_name, context_name = name.split('-')
+ sep = '-'
+
try:
ctx = next((context for context in contexts
- if context.assigned_name == context_name))
+ if context.assigned_name == context_name))
except StopIteration:
raise y_exc.ScenarioConfigContextNameNotFound(
context_name=context_name)
- return '{}.{}'.format(node_name, ctx.name)
+ return '{}{}{}'.format(node_name, sep, ctx.name)
if 'host' in scenario:
scenario['host'] = qualified_name(scenario['host'])
if 'target' in scenario:
scenario['target'] = qualified_name(scenario['target'])
- server_name = scenario.get('options', {}).get('server_name', {})
+ options = scenario.get('options') or {}
+ server_name = options.get('server_name') or {}
if 'host' in server_name:
server_name['host'] = qualified_name(server_name['host'])
if 'target' in server_name:
diff --git a/yardstick/benchmark/scenarios/availability/ha_tools/nova/add_server_to_existing_secgroup.bash b/yardstick/benchmark/scenarios/availability/ha_tools/nova/add_server_to_existing_secgroup.bash
new file mode 100644
index 000000000..3a50626f5
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/ha_tools/nova/add_server_to_existing_secgroup.bash
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2018 Intracom Telecom 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
+##############################################################################
+
+# add server to existing security group
+# parameters: $1 - server name, $2 - security group name
+
+set -e
+
+if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
+ SECURE="--insecure"
+else
+ SECURE=""
+fi
+
+SECGROUPNAME="$(openstack ${SECURE} security group list -f value -c Name | grep $2)"
+
+openstack ${SECURE} server add security group $1 ${SECGROUPNAME}
+
diff --git a/yardstick/benchmark/scenarios/availability/ha_tools/nova/create_instance_from_image.bash b/yardstick/benchmark/scenarios/availability/ha_tools/nova/create_instance_from_image.bash
new file mode 100644
index 000000000..5e0b1ccf1
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/ha_tools/nova/create_instance_from_image.bash
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2018 Intracom Telecom 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
+##############################################################################
+
+# create nova server
+# parameters: $1 - server name, $2 - image name, $3 - flavor name, $4 - network name
+
+set -e
+
+if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
+ SECURE="--insecure"
+else
+ SECURE=""
+fi
+
+NETNAME="$(openstack ${SECURE} network list -f value -c Name | grep $4)"
+
+openstack ${SECURE} server create $1 --image $2 --flavor $3 --network ${NETNAME}
+
diff --git a/yardstick/benchmark/scenarios/availability/ha_tools/nova/delete_instance.bash b/yardstick/benchmark/scenarios/availability/ha_tools/nova/delete_instance.bash
new file mode 100644
index 000000000..008e7f5ff
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/ha_tools/nova/delete_instance.bash
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2018 Intracom Telecom 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
+##############################################################################
+
+# delete nova server
+# parameters: $1 - server name
+
+set -e
+
+if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
+ SECURE="--insecure"
+else
+ SECURE=""
+fi
+
+openstack ${SECURE} server delete $1
+
diff --git a/yardstick/benchmark/scenarios/availability/ha_tools/nova/get_server_privateip.bash b/yardstick/benchmark/scenarios/availability/ha_tools/nova/get_server_privateip.bash
new file mode 100644
index 000000000..7f2bad540
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/ha_tools/nova/get_server_privateip.bash
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2018 Intracom Telecom 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
+##############################################################################
+
+# get private ip of a server
+# parameter: $1 - server name
+
+set -e
+
+if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
+ SECURE="--insecure"
+else
+ SECURE=""
+fi
+
+openstack ${SECURE} server list -f value -c Name -c Networks | grep $1 | awk '{print $2}' | sed -r 's/.*=([0-9\.\:]+)[;,]*/\1/'
+
diff --git a/yardstick/benchmark/scenarios/availability/ha_tools/nova/remove_server_from_secgroup.bash b/yardstick/benchmark/scenarios/availability/ha_tools/nova/remove_server_from_secgroup.bash
new file mode 100644
index 000000000..61d0a2b49
--- /dev/null
+++ b/yardstick/benchmark/scenarios/availability/ha_tools/nova/remove_server_from_secgroup.bash
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2018 Intracom Telecom 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
+##############################################################################
+
+# remove server from existing security group
+# parameters: $1 - server name, $2 - security group name
+
+set -e
+
+if [ $OS_INSECURE ] && [ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]; then
+ SECURE="--insecure"
+else
+ SECURE=""
+fi
+
+SECGROUPNAME="$(openstack ${SECURE} security group list -f value -c Name | grep $2)"
+
+openstack ${SECURE} server remove security group $1 ${SECGROUPNAME}
diff --git a/yardstick/benchmark/scenarios/availability/operation_conf.yaml b/yardstick/benchmark/scenarios/availability/operation_conf.yaml
index 0ca88393b..5f3f6c91e 100644
--- a/yardstick/benchmark/scenarios/availability/operation_conf.yaml
+++ b/yardstick/benchmark/scenarios/availability/operation_conf.yaml
@@ -38,3 +38,11 @@ get-vip-host:
start-service:
action_script: ha_tools/start_service.bash
rollback_script: ha_tools/check_process_python.bash
+
+add-server-to-secgroup:
+ action_script: ha_tools/nova/add_server_to_existing_secgroup.bash
+ rollback_script: ha_tools/nova/remove_server_from_secgroup.bash
+
+get-privateip:
+ action_script: ha_tools/nova/get_server_privateip.bash
+ rollback_script: ha_tools/nova/list_servers.bash
diff --git a/yardstick/benchmark/scenarios/lib/create_network.py b/yardstick/benchmark/scenarios/lib/create_network.py
index cffff132a..734820519 100644
--- a/yardstick/benchmark/scenarios/lib/create_network.py
+++ b/yardstick/benchmark/scenarios/lib/create_network.py
@@ -7,13 +7,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+
LOG = logging.getLogger(__name__)
@@ -28,9 +27,14 @@ class CreateNetwork(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.openstack = self.options.get("openstack_paras", None)
+ self.network_name = self.options["network_name"]
+ self.shared = self.options.get("shared", False)
+ self.admin_state_up = self.options.get("admin_state_up", True)
+ self.external = self.options.get("external", False)
+ self.provider = self.options.get("provider")
+ self.project_id = self.options.get("project_id")
- self.neutron_client = op_utils.get_neutron_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -45,20 +49,17 @@ class CreateNetwork(base.Scenario):
if not self.setup_done:
self.setup()
- openstack_paras = {'network': self.openstack}
- network_id = op_utils.create_neutron_net(self.neutron_client,
- openstack_paras)
- if network_id:
- result.update({"network_create": 1})
- LOG.info("Create network successful!")
- else:
+ network_id = openstack_utils.create_neutron_net(
+ self.shade_client, self.network_name, shared=self.shared,
+ admin_state_up=self.admin_state_up, external=self.external,
+ provider=self.provider, project_id=self.project_id)
+ if not network_id:
result.update({"network_create": 0})
LOG.error("Create network failed!")
+ raise exceptions.ScenarioCreateNetworkError
- try:
- keys = self.scenario_cfg.get('output', '').split()
- except KeyError:
- pass
- else:
- values = [network_id]
- return self._push_to_outputs(keys, values)
+ result.update({"network_create": 1})
+ LOG.info("Create network successful!")
+ keys = self.scenario_cfg.get('output', '').split()
+ values = [network_id]
+ return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/create_router.py b/yardstick/benchmark/scenarios/lib/create_router.py
index 9aa57ebb2..34252f603 100644
--- a/yardstick/benchmark/scenarios/lib/create_router.py
+++ b/yardstick/benchmark/scenarios/lib/create_router.py
@@ -7,13 +7,11 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
LOG = logging.getLogger(__name__)
@@ -28,9 +26,14 @@ class CreateRouter(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.openstack = self.options.get("openstack_paras", None)
+ self.name = self.options.get('name')
+ self.admin_state_up = self.options.get('admin_state_up', True)
+ self.ext_gateway_net_id = self.options.get('ext_gateway_net_id')
+ self.enable_snat = self.options.get('enable_snat')
+ self.ext_fixed_ips = self.options.get('ext_fixed_ips')
+ self.project_id = self.options.get('project_id')
- self.neutron_client = op_utils.get_neutron_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -45,22 +48,19 @@ class CreateRouter(base.Scenario):
if not self.setup_done:
self.setup()
- openstack_paras = {'router': self.openstack}
- router_id = op_utils.create_neutron_router(self.neutron_client,
- openstack_paras)
- if router_id:
- result.update({"network_create": 1})
- LOG.info("Create router successful!")
- else:
- result.update({"network_create": 0})
+ router_id = openstack_utils.create_neutron_router(
+ self.shade_client, name=self.name,
+ admin_state_up=self.admin_state_up,
+ ext_gateway_net_id=self.ext_gateway_net_id,
+ enable_snat=self.enable_snat, ext_fixed_ips=self.ext_fixed_ips,
+ project_id=self.project_id)
+ if not router_id:
+ result.update({"router_create": 0})
LOG.error("Create router failed!")
+ raise exceptions.ScenarioCreateRouterError
- check_result = router_id
-
- try:
- keys = self.scenario_cfg.get('output', '').split()
- except KeyError:
- pass
- else:
- values = [check_result]
- return self._push_to_outputs(keys, values)
+ result.update({"router_create": 1})
+ LOG.info("Create router successful!")
+ keys = self.scenario_cfg.get('output', '').split()
+ values = [router_id]
+ return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/create_subnet.py b/yardstick/benchmark/scenarios/lib/create_subnet.py
index c34af8a9e..e383c99de 100644
--- a/yardstick/benchmark/scenarios/lib/create_subnet.py
+++ b/yardstick/benchmark/scenarios/lib/create_subnet.py
@@ -7,13 +7,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+
LOG = logging.getLogger(__name__)
@@ -28,9 +27,23 @@ class CreateSubnet(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.openstack = self.options.get("openstack_paras", None)
-
- self.neutron_client = op_utils.get_neutron_client()
+ self.network_name_or_id = self.options['network_name_or_id']
+ self.cidr = self.options.get('cidr')
+ self.ip_version = self.options.get('ip_version', 4)
+ self.enable_dhcp = self.options.get('enable_dhcp', False)
+ self.subnet_name = self.options.get('subnet_name')
+ self.tenant_id = self.options.get('tenant_id')
+ self.allocation_pools = self.options.get('allocation_pools')
+ self.gateway_ip = self.options.get('gateway_ip')
+ self.disable_gateway_ip = self.options.get('disable_gateway_ip', False)
+ self.dns_nameservers = self.options.get('dns_nameservers')
+ self.host_routes = self.options.get('host_routes')
+ self.ipv6_ra_mode = self.options.get('ipv6_ra_mode')
+ self.ipv6_address_mode = self.options.get('ipv6_address_mode')
+ self.use_default_subnetpool = self.options.get(
+ 'use_default_subnetpool', False)
+
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -45,22 +58,23 @@ class CreateSubnet(base.Scenario):
if not self.setup_done:
self.setup()
- openstack_paras = {'subnets': [self.openstack]}
- subnet_id = op_utils.create_neutron_subnet(self.neutron_client,
- openstack_paras)
- if subnet_id:
- result.update({"subnet_create": 1})
- LOG.info("Create subnet successful!")
- else:
+ subnet_id = openstack_utils.create_neutron_subnet(
+ self.shade_client, self.network_name_or_id, cidr=self.cidr,
+ ip_version=self.ip_version, enable_dhcp=self.enable_dhcp,
+ subnet_name=self.subnet_name, tenant_id=self.tenant_id,
+ allocation_pools=self.allocation_pools, gateway_ip=self.gateway_ip,
+ disable_gateway_ip=self.disable_gateway_ip,
+ dns_nameservers=self.dns_nameservers, host_routes=self.host_routes,
+ ipv6_ra_mode=self.ipv6_ra_mode,
+ ipv6_address_mode=self.ipv6_address_mode,
+ use_default_subnetpool=self.use_default_subnetpool)
+ if not subnet_id:
result.update({"subnet_create": 0})
LOG.error("Create subnet failed!")
+ raise exceptions.ScenarioCreateSubnetError
- check_result = subnet_id
-
- try:
- keys = self.scenario_cfg.get('output', '').split()
- except KeyError:
- pass
- else:
- values = [check_result]
- return self._push_to_outputs(keys, values)
+ result.update({"subnet_create": 1})
+ LOG.info("Create subnet successful!")
+ keys = self.scenario_cfg.get('output', '').split()
+ values = [subnet_id]
+ return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/delete_router.py b/yardstick/benchmark/scenarios/lib/delete_router.py
index 358fd40cf..5e7467b2c 100644
--- a/yardstick/benchmark/scenarios/lib/delete_router.py
+++ b/yardstick/benchmark/scenarios/lib/delete_router.py
@@ -7,13 +7,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+
LOG = logging.getLogger(__name__)
@@ -28,9 +27,9 @@ class DeleteRouter(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.router_id = self.options.get("router_id", None)
+ self.router_id = self.options["router_id"]
- self.neutron_client = op_utils.get_neutron_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -45,11 +44,12 @@ class DeleteRouter(base.Scenario):
if not self.setup_done:
self.setup()
- status = op_utils.delete_neutron_router(self.neutron_client,
- router_id=self.router_id)
- if status:
- result.update({"delete_router": 1})
- LOG.info("Delete router successful!")
- else:
+ status = openstack_utils.delete_neutron_router(self.shade_client,
+ self.router_id)
+ if not status:
result.update({"delete_router": 0})
LOG.error("Delete router failed!")
+ raise exceptions.ScenarioDeleteRouterError
+
+ result.update({"delete_router": 1})
+ LOG.info("Delete router successful!")
diff --git a/yardstick/benchmark/scenarios/networking/netperf.py b/yardstick/benchmark/scenarios/networking/netperf.py
index a8d9010ed..33c02d409 100755
--- a/yardstick/benchmark/scenarios/networking/netperf.py
+++ b/yardstick/benchmark/scenarios/networking/netperf.py
@@ -104,7 +104,9 @@ class Netperf(base.Scenario):
cmd_args = "-H %s -l %s -t %s" % (ipaddr, testlen, testname)
# get test specific options
- default_args = "-O 'THROUGHPUT,THROUGHPUT_UNITS,MEAN_LATENCY'"
+ output_opt = options.get(
+ "output_opt", "THROUGHPUT,THROUGHPUT_UNITS,MEAN_LATENCY")
+ default_args = "-O %s" % output_opt
cmd_args += " -- %s" % default_args
option_pair_list = [("send_msg_size", "-m"),
("recv_msg_size", "-M"),
diff --git a/yardstick/common/ansible_common.py b/yardstick/common/ansible_common.py
index be262c215..38d2dd7c2 100644
--- a/yardstick/common/ansible_common.py
+++ b/yardstick/common/ansible_common.py
@@ -31,6 +31,7 @@ import six.moves.configparser as ConfigParser
import yaml
from six import StringIO
from chainmap import ChainMap
+from oslo_serialization import jsonutils
from yardstick.common.utils import Timer
from yardstick.common import constants as consts
@@ -508,6 +509,58 @@ class AnsibleCommon(object):
timeout = 1200.0
return timeout
+ def _generate_ansible_cfg(self, directory):
+ parser = ConfigParser.ConfigParser()
+ parser.add_section('defaults')
+ parser.set('defaults', 'host_key_checking', 'False')
+
+ cfg_path = os.path.join(directory, 'setup.cfg')
+ with open(cfg_path, 'w') as f:
+ parser.write(f)
+
+ def get_sut_info(self, directory, sut_dir='sut'):
+ if not os.path.isdir(directory):
+ raise OSError('No such directory: %s' % directory)
+
+ self._generate_ansible_cfg(directory)
+
+ prefix = 'tmp'
+ self.gen_inventory_ini_dict()
+ ini_file = self._gen_ansible_inventory_file(directory, prefix=prefix)
+ with ini_file as f:
+ inventory_path = str(f)
+
+ self._exec_get_sut_info_cmd(directory, inventory_path, sut_dir)
+
+ sut_dir = os.path.join(directory, sut_dir)
+ sut_info = self._gen_sut_info_dict(sut_dir)
+
+ return sut_info
+
+ def _exec_get_sut_info_cmd(self, directory, inventory_path, sut_dir):
+ cmd = ['ansible', 'all', '-m', 'setup', '-i',
+ inventory_path, '--tree', sut_dir]
+
+ proc = Popen(cmd, stdout=PIPE, cwd=directory)
+ output, _ = proc.communicate()
+ retcode = proc.wait()
+ LOG.debug("exit status = %s", retcode)
+ if retcode != 0:
+ raise CalledProcessError(retcode, cmd, output)
+
+ def _gen_sut_info_dict(self, sut_dir):
+ sut_info = {}
+
+ if os.path.isdir(sut_dir):
+ root, _, files = next(os.walk(sut_dir))
+ for filename in files:
+ abs_path = os.path.join(root, filename)
+ with open(abs_path) as f:
+ data = jsonutils.load(f)
+ sut_info[filename] = data
+
+ return sut_info
+
def execute_ansible(self, playbooks, directory, timeout=None,
extra_vars=None, ansible_check=False, prefix='tmp',
verbose=False):
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 7f72887e1..8160c5b0c 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -100,3 +100,27 @@ class TaskReadError(YardstickException):
class TaskRenderError(YardstickException):
message = 'Failed to render template:\n%(input_task)s'
+
+
+class ScenarioCreateNetworkError(YardstickException):
+ message = 'Create Neutron Network Scenario failed'
+
+
+class ScenarioCreateSubnetError(YardstickException):
+ message = 'Create Neutron Subnet Scenario failed'
+
+
+class ScenarioDeleteRouterError(YardstickException):
+ message = 'Delete Neutron Router Scenario failed'
+
+
+class MissingPodInfoError(YardstickException):
+ message = 'Missing pod args, please check'
+
+
+class UnsupportedPodFormatError(YardstickException):
+ message = 'Failed to load pod info, unsupported format'
+
+
+class ScenarioCreateRouterError(YardstickException):
+ message = 'Create Neutron Router Scenario failed'
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index e3f67baa5..a4fd4e550 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -435,13 +435,29 @@ def get_network_id(shade_client, network_name):
return networks[0]['id']
-def create_neutron_net(neutron_client, json_body): # pragma: no cover
+def create_neutron_net(shade_client, network_name, shared=False,
+ admin_state_up=True, external=False, provider=None,
+ project_id=None):
+ """Create a neutron network.
+
+ :param network_name:(string) name of the network being created.
+ :param shared:(bool) whether the network is shared.
+ :param admin_state_up:(bool) set the network administrative state.
+ :param external:(bool) whether this network is externally accessible.
+ :param provider:(dict) a dict of network provider options.
+ :param project_id:(string) specify the project ID this network
+ will be created on (admin-only).
+ :returns:(string) the network id.
+ """
try:
- network = neutron_client.create_network(body=json_body)
- return network['network']['id']
- except Exception: # pylint: disable=broad-except
- log.error("Error [create_neutron_net(neutron_client)]")
- raise Exception("operation error")
+ networks = shade_client.create_network(
+ name=network_name, shared=shared, admin_state_up=admin_state_up,
+ external=external, provider=provider, project_id=project_id)
+ return networks['id']
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [create_neutron_net(shade_client)]."
+ "Exception message, '%s'", o_exc.orig_message)
+ return None
def delete_neutron_net(shade_client, network_id):
@@ -452,31 +468,88 @@ def delete_neutron_net(shade_client, network_id):
return False
-def create_neutron_subnet(neutron_client, json_body): # pragma: no cover
+def create_neutron_subnet(shade_client, network_name_or_id, cidr=None,
+ ip_version=4, enable_dhcp=False, subnet_name=None,
+ tenant_id=None, allocation_pools=None,
+ gateway_ip=None, disable_gateway_ip=False,
+ dns_nameservers=None, host_routes=None,
+ ipv6_ra_mode=None, ipv6_address_mode=None,
+ use_default_subnetpool=False):
+ """Create a subnet on a specified network.
+
+ :param network_name_or_id:(string) the unique name or ID of the
+ attached network. If a non-unique name is
+ supplied, an exception is raised.
+ :param cidr:(string) the CIDR.
+ :param ip_version:(int) the IP version.
+ :param enable_dhcp:(bool) whether DHCP is enable.
+ :param subnet_name:(string) the name of the subnet.
+ :param tenant_id:(string) the ID of the tenant who owns the network.
+ :param allocation_pools: A list of dictionaries of the start and end
+ addresses for the allocation pools.
+ :param gateway_ip:(string) the gateway IP address.
+ :param disable_gateway_ip:(bool) whether gateway IP address is enabled.
+ :param dns_nameservers: A list of DNS name servers for the subnet.
+ :param host_routes: A list of host route dictionaries for the subnet.
+ :param ipv6_ra_mode:(string) IPv6 Router Advertisement mode.
+ Valid values are: 'dhcpv6-stateful',
+ 'dhcpv6-stateless', or 'slaac'.
+ :param ipv6_address_mode:(string) IPv6 address mode.
+ Valid values are: 'dhcpv6-stateful',
+ 'dhcpv6-stateless', or 'slaac'.
+ :param use_default_subnetpool:(bool) use the default subnetpool for
+ ``ip_version`` to obtain a CIDR. It is
+ required to pass ``None`` to the ``cidr``
+ argument when enabling this option.
+ :returns:(string) the subnet id.
+ """
try:
- subnet = neutron_client.create_subnet(body=json_body)
- return subnet['subnets'][0]['id']
- except Exception: # pylint: disable=broad-except
- log.error("Error [create_neutron_subnet")
- raise Exception("operation error")
+ subnet = shade_client.create_subnet(
+ network_name_or_id, cidr=cidr, ip_version=ip_version,
+ enable_dhcp=enable_dhcp, subnet_name=subnet_name,
+ tenant_id=tenant_id, allocation_pools=allocation_pools,
+ gateway_ip=gateway_ip, disable_gateway_ip=disable_gateway_ip,
+ dns_nameservers=dns_nameservers, host_routes=host_routes,
+ ipv6_ra_mode=ipv6_ra_mode, ipv6_address_mode=ipv6_address_mode,
+ use_default_subnetpool=use_default_subnetpool)
+ return subnet['id']
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [create_neutron_subnet(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
+ return None
+
+def create_neutron_router(shade_client, name=None, admin_state_up=True,
+ ext_gateway_net_id=None, enable_snat=None,
+ ext_fixed_ips=None, project_id=None):
+ """Create a logical router.
-def create_neutron_router(neutron_client, json_body): # pragma: no cover
+ :param name:(string) the router name.
+ :param admin_state_up:(bool) the administrative state of the router.
+ :param ext_gateway_net_id:(string) network ID for the external gateway.
+ :param enable_snat:(bool) enable Source NAT (SNAT) attribute.
+ :param ext_fixed_ips: List of dictionaries of desired IP and/or subnet
+ on the external network.
+ :param project_id:(string) project ID for the router.
+
+ :returns:(string) the router id.
+ """
try:
- router = neutron_client.create_router(json_body)
- return router['router']['id']
- except Exception: # pylint: disable=broad-except
- log.error("Error [create_neutron_router(neutron_client)]")
- raise Exception("operation error")
+ router = shade_client.create_router(
+ name, admin_state_up, ext_gateway_net_id, enable_snat,
+ ext_fixed_ips, project_id)
+ return router['id']
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [create_neutron_router(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
-def delete_neutron_router(neutron_client, router_id): # pragma: no cover
+def delete_neutron_router(shade_client, router_id):
try:
- neutron_client.delete_router(router=router_id)
- return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [delete_neutron_router(neutron_client, '%s')]",
- router_id)
+ return shade_client.delete_router(router_id)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [delete_neutron_router(shade_client, '%s')]. "
+ "Exception message: %s", router_id, o_exc.orig_message)
return False
diff --git a/yardstick/network_services/constants.py b/yardstick/network_services/constants.py
index 79951e353..0064b4fc5 100644
--- a/yardstick/network_services/constants.py
+++ b/yardstick/network_services/constants.py
@@ -15,3 +15,5 @@
REMOTE_TMP = "/tmp"
DEFAULT_VNF_TIMEOUT = 3600
PROCESS_JOIN_TIMEOUT = 3
+ONE_GIGABIT_IN_BITS = 1000000000
+NIC_GBPS_DEFAULT = 10
diff --git a/yardstick/network_services/traffic_profile/prox_binsearch.py b/yardstick/network_services/traffic_profile/prox_binsearch.py
index 5700f98e5..c3277fb12 100644
--- a/yardstick/network_services/traffic_profile/prox_binsearch.py
+++ b/yardstick/network_services/traffic_profile/prox_binsearch.py
@@ -20,6 +20,7 @@ import datetime
import time
from yardstick.network_services.traffic_profile.prox_profile import ProxProfile
+from yardstick.network_services import constants
LOG = logging.getLogger(__name__)
@@ -99,9 +100,13 @@ class ProxBinSearchProfile(ProxProfile):
# throughput and packet loss from the most recent successful test
successful_pkt_loss = 0.0
+ line_speed = traffic_gen.scenario_helper.all_options.get(
+ "interface_speed_gbps", constants.NIC_GBPS_DEFAULT) * constants.ONE_GIGABIT_IN_BITS
for test_value in self.bounds_iterator(LOG):
result, port_samples = self._profile_helper.run_test(pkt_size, duration,
- test_value, self.tolerated_loss)
+ test_value,
+ self.tolerated_loss,
+ line_speed)
self.curr_time = time.time()
diff_time = self.curr_time - self.prev_time
self.prev_time = self.curr_time
diff --git a/yardstick/network_services/vnf_generic/vnf/prox_helpers.py b/yardstick/network_services/vnf_generic/vnf/prox_helpers.py
index 29f9c7bba..31ed30140 100644
--- a/yardstick/network_services/vnf_generic/vnf/prox_helpers.py
+++ b/yardstick/network_services/vnf_generic/vnf/prox_helpers.py
@@ -35,6 +35,7 @@ from yardstick.common.utils import SocketTopology, join_non_strings, try_int
from yardstick.network_services.helpers.iniparser import ConfigParser
from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
+from yardstick.network_services import constants
PROX_PORT = 8474
@@ -44,7 +45,6 @@ SECTION_CONTENTS = 1
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
-TEN_GIGABIT = 1e10
BITS_PER_BYTE = 8
RETRY_SECONDS = 60
RETRY_INTERVAL = 1
@@ -466,13 +466,14 @@ class ProxSocketHelper(object):
core_data['current'] = core_data[key1] + core_data[key2]
self.set_speed(core_data['cores'], core_data['current'])
- def set_pps(self, cores, pps, pkt_size):
+ def set_pps(self, cores, pps, pkt_size,
+ line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
""" set packets per second for specific cores on the remote instance """
msg = "Set packets per sec for core(s) %s to %g%% of line rate (packet size: %d)"
LOG.debug(msg, cores, pps, pkt_size)
# speed in percent of line-rate
- speed = float(pps) * (pkt_size + 20) / TEN_GIGABIT / BITS_PER_BYTE
+ speed = float(pps) * (pkt_size + 20) / line_speed / BITS_PER_BYTE
self._run_template_over_cores("speed {} 0 {}\n", cores, speed)
def lat_stats(self, cores, task=0):
@@ -698,6 +699,20 @@ class ProxDpdkVnfSetupEnvHelper(DpdkVnfSetupEnvHelper):
mac = intf["virtual-interface"]["dst_mac"]
section_data[1] = mac
+ if item_val.startswith("@@src_mac"):
+ tx_port_iter = re.finditer(r'\d+', item_val)
+ tx_port_no = int(next(tx_port_iter).group(0))
+ intf = self.vnfd_helper.find_interface_by_port(tx_port_no)
+ mac = intf["virtual-interface"]["local_mac"]
+ section_data[1] = mac.replace(":", " ", 6)
+
+ if item_key == "src mac" and item_val.startswith("@@"):
+ tx_port_iter = re.finditer(r'\d+', item_val)
+ tx_port_no = int(next(tx_port_iter).group(0))
+ intf = self.vnfd_helper.find_interface_by_port(tx_port_no)
+ mac = intf["virtual-interface"]["local_mac"]
+ section_data[1] = mac
+
# if addition file specified in prox config
if not self.additional_files:
return sections
@@ -967,12 +982,13 @@ class ProxResourceHelper(ClientResourceHelper):
class ProxDataHelper(object):
- def __init__(self, vnfd_helper, sut, pkt_size, value, tolerated_loss):
+ def __init__(self, vnfd_helper, sut, pkt_size, value, tolerated_loss, line_speed):
super(ProxDataHelper, self).__init__()
self.vnfd_helper = vnfd_helper
self.sut = sut
self.pkt_size = pkt_size
self.value = value
+ self.line_speed = line_speed
self.tolerated_loss = tolerated_loss
self.port_count = len(self.vnfd_helper.port_pairs.all_ports)
self.tsc_hz = None
@@ -1058,9 +1074,7 @@ class ProxDataHelper(object):
self.tsc_hz = float(self.sut.hz())
def line_rate_to_pps(self):
- # NOTE: to fix, don't hardcode 10Gb/s
- return self.port_count * TEN_GIGABIT / BITS_PER_BYTE / (self.pkt_size + 20)
-
+ return self.port_count * self.line_speed / BITS_PER_BYTE / (self.pkt_size + 20)
class ProxProfileHelper(object):
@@ -1139,8 +1153,10 @@ class ProxProfileHelper(object):
return cores
- def run_test(self, pkt_size, duration, value, tolerated_loss=0.0):
- data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size, value, tolerated_loss)
+ def run_test(self, pkt_size, duration, value, tolerated_loss=0.0,
+ line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
+ data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
+ value, tolerated_loss, line_speed)
with data_helper, self.traffic_context(pkt_size, value):
with data_helper.measure_tot_stats():
@@ -1396,8 +1412,10 @@ class ProxBngProfileHelper(ProxProfileHelper):
time.sleep(3)
self.sut.stop(self.all_rx_cores)
- def run_test(self, pkt_size, duration, value, tolerated_loss=0.0):
- data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size, value, tolerated_loss)
+ def run_test(self, pkt_size, duration, value, tolerated_loss=0.0,
+ line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
+ data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
+ value, tolerated_loss, line_speed)
with data_helper, self.traffic_context(pkt_size, value):
with data_helper.measure_tot_stats():
@@ -1583,8 +1601,10 @@ class ProxVpeProfileHelper(ProxProfileHelper):
time.sleep(3)
self.sut.stop(self.all_rx_cores)
- def run_test(self, pkt_size, duration, value, tolerated_loss=0.0):
- data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size, value, tolerated_loss)
+ def run_test(self, pkt_size, duration, value, tolerated_loss=0.0,
+ line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
+ data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
+ value, tolerated_loss, line_speed)
with data_helper, self.traffic_context(pkt_size, value):
with data_helper.measure_tot_stats():
@@ -1772,8 +1792,10 @@ class ProxlwAFTRProfileHelper(ProxProfileHelper):
time.sleep(3)
self.sut.stop(self.all_rx_cores)
- def run_test(self, pkt_size, duration, value, tolerated_loss=0.0):
- data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size, value, tolerated_loss)
+ def run_test(self, pkt_size, duration, value, tolerated_loss=0.0,
+ line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
+ data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
+ value, tolerated_loss, line_speed)
with data_helper, self.traffic_context(pkt_size, value):
with data_helper.measure_tot_stats():
diff --git a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
index 2cdb3f904..285e08659 100644
--- a/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/prox_vnf.py
@@ -22,7 +22,7 @@ from yardstick.common.process import check_if_process_failed
from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
-from yardstick.network_services.constants import PROCESS_JOIN_TIMEOUT
+from yardstick.network_services import constants
LOG = logging.getLogger(__name__)
@@ -136,5 +136,5 @@ class ProxApproxVnf(SampleVNF):
self._tear_down()
if self._vnf_process is not None:
LOG.debug("joining before terminate %s", self._vnf_process.name)
- self._vnf_process.join(PROCESS_JOIN_TIMEOUT)
+ self._vnf_process.join(constants.PROCESS_JOIN_TIMEOUT)
self._vnf_process.terminate()
diff --git a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
index c3c10e5a4..77488c479 100644
--- a/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
+++ b/yardstick/network_services/vnf_generic/vnf/sample_vnf.py
@@ -32,9 +32,7 @@ from yardstick.benchmark.contexts.base import Context
from yardstick.common import exceptions as y_exceptions
from yardstick.common.process import check_if_process_failed
from yardstick.common import utils
-from yardstick.network_services.constants import DEFAULT_VNF_TIMEOUT
-from yardstick.network_services.constants import PROCESS_JOIN_TIMEOUT
-from yardstick.network_services.constants import REMOTE_TMP
+from yardstick.network_services import constants
from yardstick.network_services.helpers.dpdkbindnic_helper import DpdkBindHelper, DpdkNode
from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig
from yardstick.network_services.helpers.samplevnf_helper import PortPairs
@@ -51,8 +49,8 @@ LOG = logging.getLogger(__name__)
class SetupEnvHelper(object):
- CFG_CONFIG = os.path.join(REMOTE_TMP, "sample_config")
- CFG_SCRIPT = os.path.join(REMOTE_TMP, "sample_script")
+ CFG_CONFIG = os.path.join(constants.REMOTE_TMP, "sample_config")
+ CFG_SCRIPT = os.path.join(constants.REMOTE_TMP, "sample_script")
DEFAULT_CONFIG_TPL_CFG = "sample.cfg"
PIPELINE_COMMAND = ''
VNF_TYPE = "SAMPLE"
@@ -371,7 +369,7 @@ class ClientResourceHelper(ResourceHelper):
try:
return self.client.get_stats(*args, **kwargs)
except STLError:
- LOG.exception("TRex client not connected")
+ LOG.error('TRex client not connected')
return {}
def generate_samples(self, ports, key=None, default=None):
@@ -610,8 +608,8 @@ class ScenarioHelper(object):
@property
def timeout(self):
test_duration = self.scenario_cfg.get('runner', {}).get('duration',
- self.options.get('timeout', DEFAULT_VNF_TIMEOUT))
- test_timeout = self.options.get('timeout', DEFAULT_VNF_TIMEOUT)
+ self.options.get('timeout', constants.DEFAULT_VNF_TIMEOUT))
+ test_timeout = self.options.get('timeout', constants.DEFAULT_VNF_TIMEOUT)
return test_duration if test_duration > test_timeout else test_timeout
class SampleVNF(GenericVNF):
@@ -796,7 +794,7 @@ class SampleVNF(GenericVNF):
if self._vnf_process is not None:
# be proper and join first before we kill
LOG.debug("joining before terminate %s", self._vnf_process.name)
- self._vnf_process.join(PROCESS_JOIN_TIMEOUT)
+ self._vnf_process.join(constants.PROCESS_JOIN_TIMEOUT)
self._vnf_process.terminate()
# no terminate children here because we share processes with tg
@@ -940,12 +938,12 @@ class SampleVNFTrafficGen(GenericTrafficGen):
if self._traffic_process is not None:
# be proper and try to join before terminating
LOG.debug("joining before terminate %s", self._traffic_process.name)
- self._traffic_process.join(PROCESS_JOIN_TIMEOUT)
+ self._traffic_process.join(constants.PROCESS_JOIN_TIMEOUT)
self._traffic_process.terminate()
if self._tg_process is not None:
# be proper and try to join before terminating
LOG.debug("joining before terminate %s", self._tg_process.name)
- self._tg_process.join(PROCESS_JOIN_TIMEOUT)
+ self._tg_process.join(constants.PROCESS_JOIN_TIMEOUT)
self._tg_process.terminate()
# no terminate children here because we share processes with vnf
diff --git a/yardstick/network_services/vnf_generic/vnf/vnf_ssh_helper.py b/yardstick/network_services/vnf_generic/vnf/vnf_ssh_helper.py
index 8e02cf3ac..de6fd9329 100644
--- a/yardstick/network_services/vnf_generic/vnf/vnf_ssh_helper.py
+++ b/yardstick/network_services/vnf_generic/vnf/vnf_ssh_helper.py
@@ -17,7 +17,7 @@ import os
from six.moves import StringIO
-from yardstick.network_services.constants import REMOTE_TMP
+from yardstick.network_services import constants
from yardstick.ssh import AutoConnectSSH
LOG = logging.getLogger(__name__)
@@ -46,7 +46,7 @@ class VnfSshHelper(AutoConnectSSH):
return self.get_class()(self.node, self.bin_path)
def upload_config_file(self, prefix, content):
- cfg_file = os.path.join(REMOTE_TMP, prefix)
+ cfg_file = os.path.join(constants.REMOTE_TMP, prefix)
LOG.debug(content)
file_obj = StringIO(content)
self.put_file_obj(file_obj, cfg_file)
diff --git a/yardstick/service/__init__.py b/yardstick/service/__init__.py
new file mode 100644
index 000000000..1c3953de6
--- /dev/null
+++ b/yardstick/service/__init__.py
@@ -0,0 +1,12 @@
+##############################################################################
+# 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
+##############################################################################
+
+
+class Service(object):
+ pass
diff --git a/yardstick/service/environment.py b/yardstick/service/environment.py
new file mode 100644
index 000000000..324589f79
--- /dev/null
+++ b/yardstick/service/environment.py
@@ -0,0 +1,101 @@
+##############################################################################
+# 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
+##############################################################################
+import tempfile
+import logging
+import collections
+
+from oslo_serialization import jsonutils
+
+from yardstick.service import Service
+from yardstick.common.exceptions import MissingPodInfoError
+from yardstick.common.exceptions import UnsupportedPodFormatError
+from yardstick.common.ansible_common import AnsibleCommon
+
+LOG = logging.getLogger(__name__)
+
+
+class Environment(Service):
+ def __init__(self, pod=None):
+ super(Environment, self).__init__()
+ # pod can be a dict or a json format string
+ self.pod = pod
+
+ def get_sut_info(self):
+ temdir = tempfile.mkdtemp(prefix='sut')
+
+ nodes = self._load_pod_info()
+ ansible = AnsibleCommon(nodes=nodes)
+ ansible.gen_inventory_ini_dict()
+ sut_info = ansible.get_sut_info(temdir)
+
+ return self._format_sut_info(sut_info)
+
+ def _load_pod_info(self):
+ if self.pod is None:
+ raise MissingPodInfoError
+
+ if isinstance(self.pod, collections.Mapping):
+ try:
+ return self.pod['nodes']
+ except KeyError:
+ raise UnsupportedPodFormatError
+
+ try:
+ return jsonutils.loads(self.pod)['nodes']
+ except (ValueError, KeyError):
+ raise UnsupportedPodFormatError
+
+ def _format_sut_info(self, sut_info):
+ return {k: self._format_node_info(v) for k, v in sut_info.items()}
+
+ def _format_node_info(self, node_info):
+ info = []
+ facts = node_info.get('ansible_facts', {})
+
+ info.append(['hostname', facts.get('ansible_hostname')])
+
+ info.append(['product_name', facts.get('ansible_product_name')])
+ info.append(['product_version', facts.get('ansible_product_version')])
+
+ processors = facts.get('ansible_processor', [])
+ try:
+ processor_type = '{} {}'.format(processors[0], processors[1])
+ except IndexError:
+ LOG.exception('No Processor in SUT data')
+ processor_type = None
+
+ info.append(['processor_type', processor_type])
+ info.append(['architecture', facts.get('ansible_architecture')])
+ info.append(['processor_cores', facts.get('ansible_processor_cores')])
+ info.append(['processor_vcpus', facts.get('ansible_processor_vcpus')])
+
+ memory = facts.get('ansible_memtotal_mb')
+ memory = round(memory * 1.0 / 1024, 2) if memory else None
+ info.append(['memory', '{} GB'.format(memory)])
+
+ devices = facts.get('ansible_devices', {})
+ info.extend([self._get_device_info(k, v) for k, v in devices.items()])
+
+ lsb_description = facts.get('ansible_lsb', {}).get('description')
+ info.append(['OS', lsb_description])
+
+ interfaces = facts.get('ansible_interfaces')
+ info.append(['interfaces', interfaces])
+ if isinstance(interfaces, collections.Sequence):
+ info.extend([self._get_interface_info(facts, i) for i in interfaces])
+ info = [i for i in info if i]
+
+ return info
+
+ def _get_interface_info(self, facts, name):
+ mac = facts.get('ansible_{}'.format(name), {}).get('macaddress')
+ return [name, mac] if mac else []
+
+ def _get_device_info(self, name, info):
+ return ['disk_{}'.format(name), info.get('size')]
diff --git a/yardstick/tests/unit/apiserver/resources/v1/__init__.py b/yardstick/tests/unit/apiserver/resources/v1/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/apiserver/resources/v1/__init__.py
diff --git a/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py b/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py
new file mode 100644
index 000000000..85c045f44
--- /dev/null
+++ b/yardstick/tests/unit/apiserver/resources/v1/test_testsuites.py
@@ -0,0 +1,35 @@
+##############################################################################
+# Copyright (c) 2018 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 mock
+
+import unittest
+
+from yardstick.tests.unit.apiserver import APITestCase
+from api.utils.thread import TaskThread
+
+
+class TestsuiteTestCase(APITestCase):
+
+ def test_run_test_suite(self):
+ if self.app is None:
+ unittest.skip('host config error')
+ return
+
+ TaskThread.start = mock.MagicMock()
+
+ url = 'yardstick/testsuites/action'
+ data = {
+ 'action': 'run_test_suite',
+ 'args': {
+ 'opts': {},
+ 'testsuite': 'opnfv_smoke'
+ }
+ }
+ resp = self._post(url, data)
+ self.assertEqual(resp.get('status'), 1)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index c54a7ab12..625f97bf4 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -420,7 +420,7 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.key_filename = 'foo/bar/foobar'
self.test_context.undeploy()
mock_delete_key.assert_called()
- self.assertTrue(mock_template.delete.called)
+ mock_template.delete.assert_called_once()
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test_undeploy_no_teardown(self, mock_template):
diff --git a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
index 22153e4e8..4dd9d40d1 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
@@ -58,10 +58,10 @@ class KubernetesTestCase(unittest.TestCase):
mock_delete_services):
self.k8s_context.undeploy()
- self.assertTrue(mock_delete_ssh.called)
- self.assertTrue(mock_delete_rcs.called)
- self.assertTrue(mock_delete_pods.called)
- self.assertTrue(mock_delete_services.called)
+ mock_delete_ssh.assert_called_once()
+ mock_delete_rcs.assert_called_once()
+ mock_delete_pods.assert_called_once()
+ mock_delete_services.assert_called_once()
@mock.patch.object(kubernetes.KubernetesContext, '_create_services')
@mock.patch.object(kubernetes.KubernetesContext, '_wait_until_running')
@@ -77,11 +77,11 @@ class KubernetesTestCase(unittest.TestCase):
with mock.patch("yardstick.benchmark.contexts.kubernetes.time"):
self.k8s_context.deploy()
- self.assertTrue(mock_set_ssh_key.called)
- self.assertTrue(mock_create_rcs.called)
- self.assertTrue(mock_create_services.called)
- self.assertTrue(mock_get_rc_pods.called)
- self.assertTrue(mock_wait_until_running.called)
+ mock_set_ssh_key.assert_called_once()
+ mock_create_rcs.assert_called_once()
+ mock_create_services.assert_called_once()
+ mock_get_rc_pods.assert_called_once()
+ mock_wait_until_running.assert_called_once()
@mock.patch.object(kubernetes, 'paramiko', **{"resource_filename.return_value": ""})
@mock.patch.object(kubernetes, 'pkg_resources', **{"resource_filename.return_value": ""})
@@ -93,8 +93,8 @@ class KubernetesTestCase(unittest.TestCase):
self.k8s_context._set_ssh_key()
self.k8s_context._delete_ssh_key()
- self.assertTrue(mock_create.called)
- self.assertTrue(mock_delete.called)
+ mock_create.assert_called_once()
+ mock_delete.assert_called_once()
@mock.patch.object(kubernetes.k8s_utils, 'read_pod_status')
def test_wait_until_running(self, mock_read_pod_status):
@@ -136,34 +136,34 @@ class KubernetesTestCase(unittest.TestCase):
@mock.patch.object(kubernetes.KubernetesContext, '_create_rc')
def test_create_rcs(self, mock_create_rc):
self.k8s_context._create_rcs()
- self.assertTrue(mock_create_rc.called)
+ mock_create_rc.assert_called()
@mock.patch.object(kubernetes.k8s_utils, 'create_replication_controller')
def test_create_rc(self, mock_create_replication_controller):
self.k8s_context._create_rc({})
- self.assertTrue(mock_create_replication_controller.called)
+ mock_create_replication_controller.assert_called_once()
@mock.patch.object(kubernetes.KubernetesContext, '_delete_rc')
def test_delete_rcs(self, mock_delete_rc):
self.k8s_context._delete_rcs()
- self.assertTrue(mock_delete_rc.called)
+ mock_delete_rc.assert_called()
@mock.patch.object(kubernetes.k8s_utils, 'delete_replication_controller')
def test_delete_rc(self, mock_delete_replication_controller):
self.k8s_context._delete_rc({})
- self.assertTrue(mock_delete_replication_controller.called)
+ mock_delete_replication_controller.assert_called_once()
@mock.patch.object(kubernetes.k8s_utils, 'get_node_list')
def test_get_node_ip(self, mock_get_node_list):
self.k8s_context._get_node_ip()
- self.assertTrue(mock_get_node_list.called)
+ mock_get_node_list.assert_called_once()
@mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.create')
def test_create_services(self, mock_create):
self.k8s_context._create_services()
- self.assertTrue(mock_create.called)
+ mock_create.assert_called()
@mock.patch('yardstick.orchestrator.kubernetes.ServiceObject.delete')
def test_delete_services(self, mock_delete):
self.k8s_context._delete_services()
- self.assertTrue(mock_delete.called)
+ mock_delete.assert_called()
diff --git a/yardstick/tests/unit/benchmark/contexts/test_node.py b/yardstick/tests/unit/benchmark/contexts/test_node.py
index 9761f6d53..8b232481b 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_node.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_node.py
@@ -176,7 +176,7 @@ class NodeContextTestCase(unittest.TestCase):
'type': 'script'
}
obj.deploy()
- self.assertTrue(dispatch_script_mock.called)
+ dispatch_script_mock.assert_called_once()
@mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX))
def test_deploy_anisible(self, dispatch_ansible_mock):
@@ -186,7 +186,7 @@ class NodeContextTestCase(unittest.TestCase):
'type': 'ansible'
}
obj.deploy()
- self.assertTrue(dispatch_ansible_mock.called)
+ dispatch_ansible_mock.assert_called_once()
@mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX))
def test_undeploy(self, dispatch_script_mock):
@@ -195,7 +195,7 @@ class NodeContextTestCase(unittest.TestCase):
'type': 'script'
}
obj.undeploy()
- self.assertTrue(dispatch_script_mock.called)
+ dispatch_script_mock.assert_called_once()
@mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX))
def test_undeploy_anisble(self, dispatch_ansible_mock):
@@ -204,7 +204,7 @@ class NodeContextTestCase(unittest.TestCase):
'type': 'ansible'
}
obj.undeploy()
- self.assertTrue(dispatch_ansible_mock.called)
+ dispatch_ansible_mock.assert_called_once()
@mock.patch('{}.ssh.SSH._put_file_shell'.format(PREFIX))
@mock.patch('{}.ssh.SSH.execute'.format(PREFIX))
@@ -224,8 +224,8 @@ class NodeContextTestCase(unittest.TestCase):
execute_mock.return_value = (0, '', '')
obj._execute_remote_script('node5', info)
- self.assertTrue(put_file_mock.called)
- self.assertTrue(execute_mock.called)
+ put_file_mock.assert_called_once()
+ execute_mock.assert_called()
@mock.patch('{}.NodeContext._execute_local_script'.format(PREFIX))
def test_execute_script_local(self, local_execute_mock):
@@ -234,7 +234,7 @@ class NodeContextTestCase(unittest.TestCase):
obj = node.NodeContext()
self.addCleanup(obj._delete_context)
obj._execute_script(node_name, info)
- self.assertTrue(local_execute_mock.called)
+ local_execute_mock.assert_called_once()
@mock.patch('{}.NodeContext._execute_remote_script'.format(PREFIX))
def test_execute_script_remote(self, remote_execute_mock):
@@ -243,7 +243,7 @@ class NodeContextTestCase(unittest.TestCase):
obj = node.NodeContext()
self.addCleanup(obj._delete_context)
obj._execute_script(node_name, info)
- self.assertTrue(remote_execute_mock.called)
+ remote_execute_mock.assert_called_once()
def test_get_script(self):
script_args = 'hello.bash'
@@ -276,7 +276,7 @@ class NodeContextTestCase(unittest.TestCase):
'pwd': 'ubuntu',
}]
obj._get_client(node_name_args)
- self.assertTrue(wait_mock.called)
+ wait_mock.assert_called_once()
def test_get_server(self):
self.test_context.init(self.attrs)
diff --git a/yardstick/tests/unit/benchmark/core/test_task.py b/yardstick/tests/unit/benchmark/core/test_task.py
index 82a90b172..9e8e4e9f7 100644
--- a/yardstick/tests/unit/benchmark/core/test_task.py
+++ b/yardstick/tests/unit/benchmark/core/test_task.py
@@ -153,7 +153,7 @@ class TaskTestCase(unittest.TestCase):
runner.get_result.return_value = []
mock_base_runner.Runner.get.return_value = runner
t._run([scenario], False, "yardstick.out")
- self.assertTrue(runner.run.called)
+ runner.run.assert_called_once()
@mock.patch.object(os, 'environ')
def test_check_precondition(self, mock_os_environ):
@@ -421,6 +421,34 @@ key2:
self.parser._change_node_names(scenario, [my_context])
self.assertEqual(scenario, expected_scenario)
+ def test__change_node_names_options_empty(self):
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890'
+ }
+
+ my_context = dummy.DummyContext()
+ my_context.init(ctx_attrs)
+ scenario = copy.deepcopy(self.scenario)
+ scenario['options'] = None
+
+ self.parser._change_node_names(scenario, [my_context])
+ self.assertIsNone(scenario['options'])
+
+ def test__change_node_names_options_server_name_empty(self):
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890'
+ }
+
+ my_context = dummy.DummyContext()
+ my_context.init(ctx_attrs)
+ scenario = copy.deepcopy(self.scenario)
+ scenario['options']['server_name'] = None
+
+ self.parser._change_node_names(scenario, [my_context])
+ self.assertIsNone(scenario['options']['server_name'])
+
def test__parse_tasks(self):
task_obj = task.Task()
_uuid = uuid.uuid4()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
index 98d967f2b..af4f0c8ab 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
@@ -27,7 +27,7 @@ class AddMemoryLoadTestCase(unittest.TestCase):
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_from_node.assert_called()
@mock.patch('yardstick.ssh.SSH.from_node')
def test_add_memory_load_without_load(self, mock_from_node):
@@ -41,7 +41,7 @@ class AddMemoryLoadTestCase(unittest.TestCase):
}
obj = AddMemoryLoad(scenario_cfg, context_cfg)
obj.run({})
- self.assertTrue(mock_from_node.called)
+ mock_from_node.assert_called_once()
@mock.patch('yardstick.ssh.SSH.from_node')
def test_add_memory_load_without_args(self, mock_from_node):
@@ -54,4 +54,4 @@ class AddMemoryLoadTestCase(unittest.TestCase):
}
obj = AddMemoryLoad(scenario_cfg, context_cfg)
obj.run({})
- self.assertTrue(mock_from_node.called)
+ mock_from_node.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
index a61195f66..2964ecc14 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
@@ -23,4 +23,4 @@ class AttachVolumeTestCase(unittest.TestCase):
args = {"options": options}
obj = AttachVolume(args, {})
obj.run({})
- self.assertTrue(mock_attach_server_volume.called)
+ mock_attach_server_volume.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
index a50e752fa..270c9d3c9 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
@@ -19,7 +19,7 @@ class CheckNumaInfoTestCase(unittest.TestCase):
scenario_cfg = {'info1': {}, 'info2': {}}
obj = CheckNumaInfo(scenario_cfg, {})
obj.run({})
- self.assertTrue(mock_check_vm2.called)
+ mock_check_vm2.assert_called_once()
def test_check_vm2_status_length_eq_1(self):
info1 = {
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
index 663ca5d5b..0b175fae8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
@@ -26,4 +26,4 @@ class CreateFlavorTestCase(unittest.TestCase):
args = {"options": options}
obj = CreateFlavor(args, {})
obj.run({})
- self.assertTrue(mock_create_flavor.called)
+ mock_create_flavor.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
index ad4adeeb2..17a4ef2e1 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
@@ -6,25 +6,52 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.create_network import CreateNetwork
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import create_network
class CreateNetworkTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.create_neutron_net')
- def test_create_network(self, mock_get_neutron_client, mock_create_neutron_net):
- options = {
- 'openstack_paras': {
- 'name': 'yardstick_net',
- 'admin_state_up': 'True'
- }
- }
- args = {"options": options}
- obj = CreateNetwork(args, {})
- obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_create_neutron_net.called)
+ def setUp(self):
+
+ self._mock_create_neutron_net = mock.patch.object(
+ openstack_utils, 'create_neutron_net')
+ self.mock_create_neutron_net = self._mock_create_neutron_net.start()
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(create_network, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'network_name': 'yardstick_net'}}
+ self.result = {}
+
+ self._cnet_obj = create_network.CreateNetwork(self.args, mock.ANY)
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_create_neutron_net.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ _uuid = uuidutils.generate_uuid()
+ self._cnet_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_neutron_net.return_value = _uuid
+ output = self._cnet_obj.run(self.result)
+ self.assertEqual({"network_create": 1}, self.result)
+ self.assertEqual({'id': _uuid}, output)
+ self.mock_log.info.asset_called_once_with('Create network successful!')
+
+ def test_run_fail_exception(self):
+ self.mock_create_neutron_net.return_value = None
+ with self.assertRaises(exceptions.ScenarioCreateNetworkError):
+ self._cnet_obj.run(self.result)
+ self.assertEqual({"network_create": 0}, self.result)
+ self.mock_log.error.assert_called_once_with(
+ 'Create network failed!')
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
index 9a1611c3d..bea02a630 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
@@ -24,4 +24,4 @@ class CreatePortTestCase(unittest.TestCase):
args = {"options": options}
obj = CreatePort(args, {})
obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
+ mock_get_neutron_client.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
index 107921403..8d6f119ab 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
@@ -6,25 +6,52 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.create_router import CreateRouter
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import create_router
class CreateRouterTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.create_neutron_router')
- def test_create_router(self, mock_get_neutron_client, mock_create_neutron_router):
- options = {
- 'openstack_paras': {
- 'admin_state_up': 'True',
- 'name': 'yardstick_router'
- }
- }
- args = {"options": options}
- obj = CreateRouter(args, {})
- obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_create_neutron_router.called)
+ def setUp(self):
+
+ self._mock_create_neutron_router = mock.patch.object(
+ openstack_utils, 'create_neutron_router')
+ self.mock_create_neutron_router = (
+ self._mock_create_neutron_router.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(create_router, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'name': 'yardstick_net'}}
+ self.result = {}
+
+ self.crouter_obj = create_router.CreateRouter(self.args, mock.ANY)
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_create_neutron_router.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ _uuid = uuidutils.generate_uuid()
+ self.crouter_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_neutron_router.return_value = _uuid
+ output = self.crouter_obj.run(self.result)
+ self.assertEqual({"router_create": 1}, self.result)
+ self.assertEqual({'id': _uuid}, output)
+ self.mock_log.info.asset_called_once_with('Create router successful!')
+
+ def test_run_fail(self):
+ self.mock_create_neutron_router.return_value = None
+ with self.assertRaises(exceptions.ScenarioCreateRouterError):
+ self.crouter_obj.run(self.result)
+ self.assertEqual({"router_create": 0}, self.result)
+ self.mock_log.error.assert_called_once_with('Create router failed!')
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
index b55767360..21158ab17 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
@@ -26,5 +26,5 @@ class CreateSecGroupTestCase(unittest.TestCase):
args = {"options": options}
obj = CreateSecgroup(args, {})
obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_create_security_group_full.called)
+ mock_get_neutron_client.assert_called_once()
+ mock_create_security_group_full.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
index faee98fd1..9d6d8cb1b 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
@@ -28,7 +28,7 @@ class CreateServerTestCase(unittest.TestCase):
}
obj = CreateServer(scenario_cfg, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_get_glance_client.called)
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_create_instance_and_wait_for_active.called)
+ mock_get_nova_client.assert_called_once()
+ mock_get_glance_client.assert_called_once()
+ mock_get_neutron_client.assert_called_once()
+ mock_create_instance_and_wait_for_active.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
index 1536e83e0..856e985c4 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
@@ -6,27 +6,53 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.create_subnet import CreateSubnet
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import create_subnet
class CreateSubnetTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.create_neutron_subnet')
- def test_create_subnet(self, mock_get_neutron_client, mock_create_neutron_subnet):
- options = {
- 'openstack_paras': {
- 'network_id': '123-123-123',
- 'name': 'yardstick_subnet',
- 'cidr': '10.10.10.0/24',
- 'ip_version': '4'
- }
- }
- args = {"options": options}
- obj = CreateSubnet(args, {})
- obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_create_neutron_subnet.called)
+ def setUp(self):
+
+ self._mock_create_neutron_subnet = mock.patch.object(
+ openstack_utils, 'create_neutron_subnet')
+ self.mock_create_neutron_subnet = (
+ self._mock_create_neutron_subnet.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(create_subnet, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'network_name_or_id': 'yardstick_net'}}
+ self.result = {"subnet_create": 0}
+
+ self._csubnet_obj = create_subnet.CreateSubnet(self.args, mock.ANY)
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_create_neutron_subnet.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ _uuid = uuidutils.generate_uuid()
+ self._csubnet_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_neutron_subnet.return_value = _uuid
+ output = self._csubnet_obj.run(self.result)
+ self.assertDictEqual({"subnet_create": 1}, self.result)
+ self.assertDictEqual({'id': _uuid}, output)
+ self.mock_log.info.asset_called_once_with('Create subnet successful!')
+
+ def test_run_fail(self):
+ self._csubnet_obj.scenario_cfg = {'output': 'id'}
+ self.mock_create_neutron_subnet.return_value = None
+ with self.assertRaises(exceptions.ScenarioCreateSubnetError):
+ self._csubnet_obj.run(self.result)
+ self.assertDictEqual({"subnet_create": 0}, self.result)
+ self.mock_log.error.assert_called_once_with('Create subnet failed!')
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
index 4bfec3252..30333dda8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
@@ -94,7 +94,7 @@ class CreateVolumeTestCase(unittest.TestCase):
args = {"options": options}
scenario = create_volume.CreateVolume(args, {})
scenario.run()
- self.assertTrue(mock_create_volume.called)
- self.assertTrue(mock_image_id.called)
- self.assertTrue(mock_get_glance_client.called)
- self.assertTrue(mock_get_cinder_client.called)
+ mock_create_volume.assert_called_once()
+ mock_image_id.assert_called_once()
+ mock_get_glance_client.assert_called_once()
+ mock_get_cinder_client.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
index e345afe3c..24dbf8a16 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
@@ -23,5 +23,5 @@ class DeleteFlavorTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteFlavor(args, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_delete_flavor.called)
+ mock_get_nova_client.assert_called_once()
+ mock_delete_flavor.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
index be997199c..3185ec59f 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
@@ -23,5 +23,5 @@ class DeleteFloatingIpTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteFloatingIp(args, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_delete_floating_ip.called)
+ mock_get_nova_client.assert_called_once()
+ mock_delete_floating_ip.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
index eb3f9fc85..e382d46fa 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
@@ -24,6 +24,6 @@ class DeleteImageTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteImage(args, {})
obj.run({})
- self.assertTrue(mock_delete_image.called)
- self.assertTrue(mock_image_id.called)
- self.assertTrue(mock_get_glance_client.called)
+ mock_delete_image.assert_called_once()
+ mock_image_id.assert_called_once()
+ mock_get_glance_client.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
index 38cc929c0..6e790ba90 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
@@ -23,5 +23,5 @@ class DeleteKeypairTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteKeypair(args, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_delete_keypair.called)
+ mock_get_nova_client.assert_called_once()
+ mock_delete_keypair.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
index 008ed9168..9fd318580 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
@@ -22,4 +22,4 @@ class DeletePortTestCase(unittest.TestCase):
args = {"options": options}
obj = DeletePort(args, {})
obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
+ mock_get_neutron_client.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
index 9b31566ac..b76100f19 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
@@ -6,22 +6,49 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.delete_router import DeleteRouter
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
+from yardstick.benchmark.scenarios.lib import delete_router
class DeleteRouterTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.delete_neutron_router')
- def test_delete_router(self, mock_get_neutron_client, mock_delete_neutron_router):
- options = {
- 'router_id': '123-123-123'
- }
- args = {"options": options}
- obj = DeleteRouter(args, {})
- obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_delete_neutron_router.called)
+ def setUp(self):
+ self._mock_delete_neutron_router = mock.patch.object(
+ openstack_utils, 'delete_neutron_router')
+ self.mock_delete_neutron_router = (
+ self._mock_delete_neutron_router.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(delete_router, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'router_id': uuidutils.generate_uuid()}}
+ self.result = {"delete_router": 0}
+
+ self._del_obj = delete_router.DeleteRouter(self.args, mock.ANY)
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_delete_neutron_router.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ self.mock_delete_neutron_router.return_value = True
+ self.assertIsNone(self._del_obj.run(self.result))
+ self.assertEqual({"delete_router": 1}, self.result)
+ self.mock_log.info.assert_called_once_with("Delete router successful!")
+
+ def test_run_fail(self):
+ self.mock_delete_neutron_router.return_value = False
+ with self.assertRaises(exceptions.ScenarioDeleteRouterError):
+ self._del_obj.run(self.result)
+ self.assertEqual({"delete_router": 0}, self.result)
+ self.mock_log.error.assert_called_once_with("Delete router failed!")
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
index e19c38d47..0c9cf7c17 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
@@ -23,5 +23,5 @@ class DeleteRouterGatewayTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteRouterGateway(args, {})
obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_remove_gateway_router.called)
+ mock_get_neutron_client.assert_called_once()
+ mock_remove_gateway_router.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
index 6c4fdd5e3..9e9c5a5b6 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
@@ -24,5 +24,5 @@ class DeleteRouterInterfaceTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteRouterInterface(args, {})
obj.run({})
- self.assertTrue(mock_get_neutron_client.called)
- self.assertTrue(mock_remove_interface_router.called)
+ mock_get_neutron_client.assert_called_once()
+ mock_remove_interface_router.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
index dedce2d4a..eee565de7 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
@@ -23,5 +23,5 @@ class DeleteServerTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteServer(args, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_delete_instance.called)
+ mock_get_nova_client.assert_called_once()
+ mock_delete_instance.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
index 2ea82e2a4..93f76e819 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
@@ -23,5 +23,5 @@ class DeleteVolumeTestCase(unittest.TestCase):
args = {"options": options}
obj = DeleteVolume(args, {})
obj.run({})
- self.assertTrue(mock_get_cinder_client.called)
- self.assertTrue(mock_delete_volume.called)
+ mock_get_cinder_client.assert_called_once()
+ mock_delete_volume.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
index 34fbac68c..9794d2129 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
@@ -23,4 +23,4 @@ class DetachVolumeTestCase(unittest.TestCase):
args = {"options": options}
obj = DetachVolume(args, {})
obj.run({})
- self.assertTrue(mock_detach_volume.called)
+ mock_detach_volume.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
index e9025f33f..15a6f7c8f 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
@@ -22,4 +22,4 @@ class GetFlavorTestCase(unittest.TestCase):
args = {"options": options}
obj = GetFlavor(args, {})
obj.run({})
- self.assertTrue(mock_get_flavor_by_name.called)
+ mock_get_flavor_by_name.assert_called_once()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
index aa9f63e26..879b2b988 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
@@ -25,9 +25,9 @@ class GetMigrateTargetHostTestCase(unittest.TestCase):
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_get_nova_client.assert_called_once()
+ mock_get_current_host_name.assert_called_once()
+ mock_get_migrate_host.assert_called_once()
@mock.patch('{}.openstack_utils.get_nova_client'.format(BASE))
def test_get_migrate_host(self, mock_get_nova_client):
@@ -39,5 +39,5 @@ class GetMigrateTargetHostTestCase(unittest.TestCase):
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)
+ mock_get_nova_client.assert_called()
self.assertEqual(host, 'host4')
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
index 4b2132c2c..bea978b8a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
@@ -44,8 +44,8 @@ class GetNumaInfoTestCase(unittest.TestCase):
}
obj = GetNumaInfo(scenario_cfg, {})
obj.run({})
- self.assertTrue(mock_get_current_host_name.called)
- self.assertTrue(mock_check_numa_node.called)
+ mock_get_current_host_name.assert_called_once()
+ mock_check_numa_node.assert_called_once()
@mock.patch('yardstick.ssh.SSH.from_node')
@mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
index 97b81ed60..83ec903bc 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
@@ -25,8 +25,8 @@ class GetServerTestCase(unittest.TestCase):
}
obj = GetServer(scenario_cfg, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
- self.assertTrue(mock_get_server_by_name.called)
+ mock_get_nova_client.assert_called_once()
+ mock_get_server_by_name.assert_called_once()
@mock.patch('yardstick.common.openstack_utils.get_nova_client')
def test_get_server_with_id(self, mock_get_nova_client):
@@ -39,4 +39,4 @@ class GetServerTestCase(unittest.TestCase):
mock_get_nova_client().servers.get.return_value = None
obj = GetServer(scenario_cfg, {})
obj.run({})
- self.assertTrue(mock_get_nova_client.called)
+ mock_get_nova_client.assert_called()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
index d6636383a..74144afd5 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
@@ -65,7 +65,7 @@ class IperfTestCase(unittest.TestCase):
p.target = mock_ssh.SSH.from_node()
p.teardown()
- self.assertTrue(mock_ssh.SSH.from_node().close.called)
+ mock_ssh.SSH.from_node().close.assert_called()
mock_ssh.SSH.from_node().execute.assert_called_with("pkill iperf3")
def test_iperf_successful_no_sla(self, mock_ssh):
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
index ec22d6147..9bfbf0752 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
@@ -355,7 +355,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
return file_path
def test___init__(self):
- assert self.topology
+ self.assertIsNotNone(self.topology)
def test__get_ip_flow_range_string(self):
self.scenario_cfg["traffic_options"]["flow"] = \
diff --git a/yardstick/tests/unit/common/test_ansible_common.py b/yardstick/tests/unit/common/test_ansible_common.py
index b01195fcc..48d8a60c8 100644
--- a/yardstick/tests/unit/common/test_ansible_common.py
+++ b/yardstick/tests/unit/common/test_ansible_common.py
@@ -17,6 +17,7 @@ from __future__ import absolute_import
import os
import tempfile
+import shutil
from collections import defaultdict
import mock
@@ -246,3 +247,18 @@ class AnsibleCommonTestCase(unittest.TestCase):
a.execute_ansible('', d, ansible_check=True, verbose=True)
finally:
os.rmdir(d)
+
+ def test_get_sut_info(self):
+ d = tempfile.mkdtemp()
+ a = ansible_common.AnsibleCommon({})
+ try:
+ a.get_sut_info(d)
+ finally:
+ shutil.rmtree(d)
+
+ def test_get_sut_info_not_exist(self):
+ a = ansible_common.AnsibleCommon({})
+ try:
+ a.get_sut_info('/hello/world')
+ except OSError:
+ pass
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index 4863f05c0..e39a13f1b 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -83,3 +83,105 @@ class DeleteNeutronNetTestCase(unittest.TestCase):
'network_id')
self.assertFalse(output)
mock_logger.error.assert_called_once()
+
+
+class CreateNeutronNetTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.network_name = 'name'
+ self.mock_shade_client.create_network = mock.Mock()
+
+ def test_create_neutron_net(self):
+ _uuid = uuidutils.generate_uuid()
+ self.mock_shade_client.create_network.return_value = {'id': _uuid}
+ output = openstack_utils.create_neutron_net(self.mock_shade_client,
+ self.network_name)
+ self.assertEqual(_uuid, output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_neutron_net_exception(self, mock_logger):
+ self.mock_shade_client.create_network.side_effect = (
+ exc.OpenStackCloudException('error message'))
+
+ output = openstack_utils.create_neutron_net(self.mock_shade_client,
+ self.network_name)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)
+
+
+class CreateNeutronSubnetTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.network_name_or_id = 'name_or_id'
+ self.mock_shade_client.create_subnet = mock.Mock()
+
+ def test_create_neutron_subnet(self):
+ _uuid = uuidutils.generate_uuid()
+ self.mock_shade_client.create_subnet.return_value = {'id': _uuid}
+ output = openstack_utils.create_neutron_subnet(
+ self.mock_shade_client, self.network_name_or_id)
+ self.assertEqual(_uuid, output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_neutron_subnet_exception(self, mock_logger):
+ self.mock_shade_client.create_subnet.side_effect = (
+ exc.OpenStackCloudException('error message'))
+
+ output = openstack_utils.create_neutron_subnet(
+ self.mock_shade_client, self.network_name_or_id)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)
+
+
+class DeleteNeutronRouterTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.mock_shade_client.delete_router = mock.Mock()
+
+ def test_delete_neutron_router(self):
+ self.mock_shade_client.delete_router.return_value = True
+ output = openstack_utils.delete_neutron_router(self.mock_shade_client,
+ 'router_id')
+ self.assertTrue(output)
+
+ def test_delete_neutron_router_fail(self):
+ self.mock_shade_client.delete_router.return_value = False
+ output = openstack_utils.delete_neutron_router(self.mock_shade_client,
+ 'router_id')
+ self.assertFalse(output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_delete_neutron_router_exception(self, mock_logger):
+ self.mock_shade_client.delete_router.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.delete_neutron_router(self.mock_shade_client,
+ 'router_id')
+ mock_logger.error.assert_called_once()
+ self.assertFalse(output)
+
+
+class CreateNeutronRouterTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.mock_shade_client.create_subnet = mock.Mock()
+
+ def test_create_neutron_router(self):
+ _uuid = uuidutils.generate_uuid()
+ self.mock_shade_client.create_router.return_value = {'id': _uuid}
+ output = openstack_utils.create_neutron_router(
+ self.mock_shade_client)
+ self.assertEqual(_uuid, output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_create_neutron_subnet_exception(self, mock_logger):
+ self.mock_shade_client.create_router.side_effect = (
+ exc.OpenStackCloudException('error message'))
+
+ output = openstack_utils.create_neutron_router(
+ self.mock_shade_client)
+ mock_logger.error.assert_called_once()
+ self.assertIsNone(output)
diff --git a/yardstick/tests/unit/common/test_packages.py b/yardstick/tests/unit/common/test_packages.py
deleted file mode 100644
index ba59a3015..000000000
--- a/yardstick/tests/unit/common/test_packages.py
+++ /dev/null
@@ -1,88 +0,0 @@
-# Copyright (c) 2018 Intel Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import mock
-from pip import exceptions as pip_exceptions
-from pip.operations import freeze
-import unittest
-
-from yardstick.common import packages
-
-
-class PipExecuteActionTestCase(unittest.TestCase):
-
- def setUp(self):
- self._mock_pip_main = mock.patch.object(packages, '_pip_main')
- self.mock_pip_main = self._mock_pip_main.start()
- self.mock_pip_main.return_value = 0
- self._mock_freeze = mock.patch.object(freeze, 'freeze')
- self.mock_freeze = self._mock_freeze.start()
- self.addCleanup(self._cleanup)
-
- def _cleanup(self):
- self._mock_pip_main.stop()
- self._mock_freeze.stop()
-
- def test_pip_execute_action(self):
- self.assertEqual(0, packages._pip_execute_action('test_package'))
-
- def test_remove(self):
- self.assertEqual(0, packages._pip_execute_action('test_package',
- action='uninstall'))
-
- def test_install(self):
- self.assertEqual(0, packages._pip_execute_action(
- 'test_package', action='install', target='temp_dir'))
-
- def test_pip_execute_action_error(self):
- self.mock_pip_main.return_value = 1
- self.assertEqual(1, packages._pip_execute_action('test_package'))
-
- def test_pip_execute_action_exception(self):
- self.mock_pip_main.side_effect = pip_exceptions.PipError
- self.assertEqual(1, packages._pip_execute_action('test_package'))
-
- def test_pip_list(self):
- pkg_input = [
- 'XStatic-Rickshaw==1.5.0.0',
- 'xvfbwrapper==0.2.9',
- '-e git+https://git.opnfv.org/yardstick@50773a24afc02c9652b662ecca'
- '2fc5621ea6097a#egg=yardstick',
- 'zope.interface==4.4.3'
- ]
- pkg_dict = {
- 'XStatic-Rickshaw': '1.5.0.0',
- 'xvfbwrapper': '0.2.9',
- 'yardstick': '50773a24afc02c9652b662ecca2fc5621ea6097a',
- 'zope.interface': '4.4.3'
- }
- self.mock_freeze.return_value = pkg_input
-
- pkg_output = packages.pip_list()
- for pkg_name, pkg_version in pkg_output.items():
- self.assertEqual(pkg_dict.get(pkg_name), pkg_version)
-
- def test_pip_list_single_package(self):
- pkg_input = [
- 'XStatic-Rickshaw==1.5.0.0',
- 'xvfbwrapper==0.2.9',
- '-e git+https://git.opnfv.org/yardstick@50773a24afc02c9652b662ecca'
- '2fc5621ea6097a#egg=yardstick',
- 'zope.interface==4.4.3'
- ]
- self.mock_freeze.return_value = pkg_input
-
- pkg_output = packages.pip_list(pkg_name='xvfbwrapper')
- self.assertEqual(1, len(pkg_output))
- self.assertEqual(pkg_output.get('xvfbwrapper'), '0.2.9')
diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py
index e71d0ff0f..9540a39e8 100644
--- a/yardstick/tests/unit/common/test_utils.py
+++ b/yardstick/tests/unit/common/test_utils.py
@@ -305,8 +305,8 @@ power management:
"""
socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
- assert sorted(socket_map.keys()) == [0]
- assert sorted(socket_map[0].keys()) == [2, 3, 4]
+ self.assertEqual(sorted(socket_map.keys()), [0])
+ self.assertEqual(sorted(socket_map[0].keys()), [2, 3, 4])
def test_single_socket_hyperthread(self):
cpuinfo = """\
@@ -393,11 +393,11 @@ power management:
"""
socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
- assert sorted(socket_map.keys()) == [0]
- assert sorted(socket_map[0].keys()) == [1, 2, 3]
- assert sorted(socket_map[0][1]) == [5]
- assert sorted(socket_map[0][2]) == [6]
- assert sorted(socket_map[0][3]) == [7]
+ self.assertEqual(sorted(socket_map.keys()), [0])
+ self.assertEqual(sorted(socket_map[0].keys()), [1, 2, 3])
+ self.assertEqual(sorted(socket_map[0][1]), [5])
+ self.assertEqual(sorted(socket_map[0][2]), [6])
+ self.assertEqual(sorted(socket_map[0][3]), [7])
def test_dual_socket_hyperthread(self):
cpuinfo = """\
@@ -592,15 +592,15 @@ power management:
"""
socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
- assert sorted(socket_map.keys()) == [0, 1]
- assert sorted(socket_map[0].keys()) == [0, 1, 2]
- assert sorted(socket_map[1].keys()) == [26, 27, 28]
- assert sorted(socket_map[0][0]) == [44]
- assert sorted(socket_map[0][1]) == [1]
- assert sorted(socket_map[0][2]) == [2]
- assert sorted(socket_map[1][26]) == [85]
- assert sorted(socket_map[1][27]) == [86]
- assert sorted(socket_map[1][28]) == [43, 87]
+ self.assertEqual(sorted(socket_map.keys()), [0, 1])
+ self.assertEqual(sorted(socket_map[0].keys()), [0, 1, 2])
+ self.assertEqual(sorted(socket_map[1].keys()), [26, 27, 28])
+ self.assertEqual(sorted(socket_map[0][0]), [44])
+ self.assertEqual(sorted(socket_map[0][1]), [1])
+ self.assertEqual(sorted(socket_map[0][2]), [2])
+ self.assertEqual(sorted(socket_map[1][26]), [85])
+ self.assertEqual(sorted(socket_map[1][27]), [86])
+ self.assertEqual(sorted(socket_map[1][28]), [43, 87])
def test_dual_socket_no_hyperthread(self):
cpuinfo = """\
@@ -796,11 +796,11 @@ power management:
"""
socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
processors = socket_map.processors()
- assert processors == [1, 2, 43, 44, 85, 86, 87]
+ self.assertEqual(processors, [1, 2, 43, 44, 85, 86, 87])
cores = socket_map.cores()
- assert cores == [0, 1, 2, 26, 27, 28]
+ self.assertEqual(cores, [0, 1, 2, 26, 27, 28])
sockets = socket_map.sockets()
- assert sockets == [0, 1]
+ self.assertEqual(sockets, [0, 1])
class ChangeObjToDictTestCase(unittest.TestCase):
diff --git a/yardstick/tests/unit/service/__init__.py b/yardstick/tests/unit/service/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/service/__init__.py
diff --git a/yardstick/tests/unit/service/test_environment.py b/yardstick/tests/unit/service/test_environment.py
new file mode 100644
index 000000000..4af9a3958
--- /dev/null
+++ b/yardstick/tests/unit/service/test_environment.py
@@ -0,0 +1,49 @@
+##############################################################################
+# 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
+##############################################################################
+import unittest
+
+import mock
+
+from yardstick.service.environment import Environment
+from yardstick.service.environment import AnsibleCommon
+from yardstick.common.exceptions import UnsupportedPodFormatError
+
+
+class EnvironmentTestCase(unittest.TestCase):
+
+ def test_get_sut_info(self):
+ pod_info = {
+ 'nodes': [
+ {
+ 'name': 'node1',
+ 'host_name': 'host1',
+ 'role': 'Controller',
+ 'ip': '10.1.0.50',
+ 'user': 'root',
+ 'passward': 'root'
+ }
+ ]
+ }
+
+ AnsibleCommon.gen_inventory_ini_dict = mock.MagicMock()
+ AnsibleCommon.get_sut_info = mock.MagicMock(return_value={'node1': {}})
+
+ env = Environment(pod=pod_info)
+ env.get_sut_info()
+
+ def test_get_sut_info_pod_str(self):
+ pod_info = 'nodes'
+
+ env = Environment(pod=pod_info)
+ with self.assertRaises(UnsupportedPodFormatError):
+ env.get_sut_info()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/yardstick/tests/unit/test_cmd/commands/test_env.py b/yardstick/tests/unit/test_cmd/commands/test_env.py
index 1156b6642..57dacbcd3 100644
--- a/yardstick/tests/unit/test_cmd/commands/test_env.py
+++ b/yardstick/tests/unit/test_cmd/commands/test_env.py
@@ -21,30 +21,30 @@ class EnvCommandTestCase(unittest.TestCase):
def test_do_influxdb(self, check_status_mock, start_async_task_mock):
env = EnvCommand()
env.do_influxdb({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
+ start_async_task_mock.assert_called_once()
+ check_status_mock.assert_called_once()
@mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
@mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
def test_do_grafana(self, check_status_mock, start_async_task_mock):
env = EnvCommand()
env.do_grafana({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
+ start_async_task_mock.assert_called_once()
+ check_status_mock.assert_called_once()
@mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
@mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
def test_do_prepare(self, check_status_mock, start_async_task_mock):
env = EnvCommand()
env.do_prepare({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
+ start_async_task_mock.assert_called_once()
+ check_status_mock.assert_called_once()
@mock.patch('yardstick.cmd.commands.env.HttpClient.post')
def test_start_async_task(self, post_mock):
data = {'action': 'create_grafana'}
EnvCommand()._start_async_task(data)
- self.assertTrue(post_mock.called)
+ post_mock.assert_called_once()
@mock.patch('yardstick.cmd.commands.env.HttpClient.get')
@mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
diff --git a/yardstick/tests/unit/test_cmd/commands/test_testcase.py b/yardstick/tests/unit/test_cmd/commands/test_testcase.py
index f6f842e20..922167614 100644
--- a/yardstick/tests/unit/test_cmd/commands/test_testcase.py
+++ b/yardstick/tests/unit/test_cmd/commands/test_testcase.py
@@ -18,4 +18,4 @@ class TestcaseCommandsUT(unittest.TestCase):
def test_do_list(self, mock_client, mock_print):
mock_client.get.return_value = {'result': []}
TestcaseCommands().do_list({})
- self.assertTrue(mock_print.called)
+ mock_print.assert_called_once()