summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/ci/apexlake-verify29
-rw-r--r--tests/unit/benchmark/contexts/standalone/__init__.py0
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml (renamed from tests/unit/benchmark/contexts/ovs_sample_password.yaml)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml (renamed from tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt (renamed from tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml (renamed from tests/unit/benchmark/contexts/sriov_sample_password.yaml)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml (renamed from tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt (renamed from tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt)0
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py (renamed from tests/unit/benchmark/contexts/test_ovsdpdk.py)10
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_sriov.py (renamed from tests/unit/benchmark/contexts/test_sriov.py)14
-rw-r--r--tests/unit/benchmark/contexts/test_standalone.py17
-rw-r--r--tests/unit/benchmark/core/test_task.py3
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_attach_volume.py33
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py34
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_create_keypair.py35
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_get_numa_info.py6
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vnf_generic.py8
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py2
-rw-r--r--tests/unit/common/test_utils.py35
-rw-r--r--tests/unit/common/test_yaml_loader.py32
-rw-r--r--tests/unit/network_services/libs/ixia_libs/test_IxNet.py15
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py4
-rw-r--r--tests/unit/network_services/test_yang_model.py2
-rw-r--r--tests/unit/network_services/traffic_profile/test_http_ixload.py24
-rw-r--r--tests/unit/network_services/vnf_generic/test_vnfdgen.py65
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py2
26 files changed, 269 insertions, 101 deletions
diff --git a/tests/ci/apexlake-verify b/tests/ci/apexlake-verify
deleted file mode 100755
index 6a691063f..000000000
--- a/tests/ci/apexlake-verify
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-##############################################################################
-# Copyright (c) 2015 Ericsson AB and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-DPDK_HOST=10.118.36.130
-
-YARDSTICK=/home/user/yardstick
-TESTSUITE=$YARDSTICK/tests/opnfv/test_suites/opnfv_vTC_daily.yaml
-
-: ${INSTALLER_TYPE:='unknown'}
-: ${NODE_NAME:='unknown'}
-: ${DEPLOY_SCENARIO:='unknown'}
-
-commands="
-cd $YARDSTICK
-source /home/user/openrc.dasm
-export INSTALLER_TYPE=$INSTALLER_TYPE
-export NODE_NAME=$NODE_NAME
-export DEPLOY_SCENARIO=$DEPLOY_SCENARIO
-sudo -E yardstick task start --suite $TESTSUITE"
-
-echo "$commands" | ssh -l user $DPDK_HOST 'bash -s'
-exit $?
diff --git a/tests/unit/benchmark/contexts/standalone/__init__.py b/tests/unit/benchmark/contexts/standalone/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone/__init__.py
diff --git a/tests/unit/benchmark/contexts/ovs_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml
index b1da1ea9f..b1da1ea9f 100644
--- a/tests/unit/benchmark/contexts/ovs_sample_password.yaml
+++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_password.yaml
diff --git a/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml
index 896ec33bb..896ec33bb 100644
--- a/tests/unit/benchmark/contexts/ovs_sample_ssh_key.yaml
+++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_ssh_key.yaml
diff --git a/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt
index f0eec86f6..f0eec86f6 100644
--- a/tests/unit/benchmark/contexts/ovs_sample_write_to_file.txt
+++ b/tests/unit/benchmark/contexts/standalone/ovs_sample_write_to_file.txt
diff --git a/tests/unit/benchmark/contexts/sriov_sample_password.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml
index 4f60e46d5..4f60e46d5 100644
--- a/tests/unit/benchmark/contexts/sriov_sample_password.yaml
+++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_password.yaml
diff --git a/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml b/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml
index faa496771..faa496771 100644
--- a/tests/unit/benchmark/contexts/sriov_sample_ssh_key.yaml
+++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_ssh_key.yaml
diff --git a/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt b/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt
index f0eec86f6..f0eec86f6 100644
--- a/tests/unit/benchmark/contexts/sriov_sample_write_to_file.txt
+++ b/tests/unit/benchmark/contexts/standalone/sriov_sample_write_to_file.txt
diff --git a/tests/unit/benchmark/contexts/test_ovsdpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py
index ac25ec877..1d68384c9 100644
--- a/tests/unit/benchmark/contexts/test_ovsdpdk.py
+++ b/tests/unit/benchmark/contexts/standalone/test_ovsdpdk.py
@@ -13,11 +13,13 @@
# limitations under the License.
from __future__ import absolute_import
+
import os
-import mock
import unittest
-from yardstick.benchmark.contexts import ovsdpdk
+import mock
+
+from yardstick.benchmark.contexts.standalone import ovsdpdk
NIC_INPUT = {
'interface': {},
@@ -226,11 +228,11 @@ class OvsdpdkTestCase(unittest.TestCase):
mock_ovs = mock.Mock()
ssh_mock.put = mock.Mock()
ovs_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- with mock.patch("yardstick.benchmark.contexts.ovsdpdk.time"):
+ with mock.patch("yardstick.benchmark.contexts.standalone.ovsdpdk.time"):
self.assertIsNone(ovs_obj.setup_ovs_context(PCIS, NIC_DETAILS, DRIVER))
@mock.patch(
- 'yardstick.benchmark.contexts.ovsdpdk',
+ 'yardstick.benchmark.contexts.standalone.ovsdpdk',
return_value="Domain vm1 created from /tmp/vm_ovs.xml")
def test_is_vm_created(self, NIC_INPUT):
with mock.patch("yardstick.ssh.SSH") as ssh:
diff --git a/tests/unit/benchmark/contexts/test_sriov.py b/tests/unit/benchmark/contexts/standalone/test_sriov.py
index a8641a2eb..ea72e1bab 100644
--- a/tests/unit/benchmark/contexts/test_sriov.py
+++ b/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -13,11 +13,13 @@
# limitations under the License.
from __future__ import absolute_import
+
import os
-import mock
import unittest
-from yardstick.benchmark.contexts import sriov
+import mock
+
+from yardstick.benchmark.contexts.standalone import sriov
NIC_INPUT = {
'interface': {},
@@ -185,7 +187,7 @@ class SriovTestCase(unittest.TestCase):
nic_details['vf_pci'][i] = sriov_obj.get_vf_datas.return_value
vf_pci = [[], []]
vf_pci[i] = sriov_obj.get_vf_datas.return_value
- with mock.patch("yardstick.benchmark.contexts.sriov.time"):
+ with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
self.assertIsNotNone(sriov_obj.configure_nics_for_sriov(DRIVER, NIC_DETAILS))
def test_setup_sriov_context(self):
@@ -224,7 +226,7 @@ class SriovTestCase(unittest.TestCase):
mock.Mock(return_value=(0, {}, ""))
ssh_mock.put = mock.Mock()
sriov_obj.check_output = mock.Mock(return_value=(1, {}))
- with mock.patch("yardstick.benchmark.contexts.sriov.time"):
+ with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER))
def test_setup_sriov_context_vm_already_present(self):
@@ -263,11 +265,11 @@ class SriovTestCase(unittest.TestCase):
mock.Mock(return_value=(0, {}, ""))
ssh_mock.put = mock.Mock()
sriov_obj.check_output = mock.Mock(return_value=(0, "vm1"))
- with mock.patch("yardstick.benchmark.contexts.sriov.time"):
+ with mock.patch("yardstick.benchmark.contexts.standalone.sriov.time"):
self.assertIsNone(sriov_obj.setup_sriov_context(PCIS, nic_details, DRIVER))
@mock.patch(
- 'yardstick.benchmark.contexts.sriov',
+ 'yardstick.benchmark.contexts.standalone.sriov',
return_value="Domain vm1 created from /tmp/vm_sriov.xml")
def test_is_vm_created(self, NIC_INPUT):
with mock.patch("yardstick.ssh.SSH") as ssh:
diff --git a/tests/unit/benchmark/contexts/test_standalone.py b/tests/unit/benchmark/contexts/test_standalone.py
index d13e28470..b1402a1c9 100644
--- a/tests/unit/benchmark/contexts/test_standalone.py
+++ b/tests/unit/benchmark/contexts/test_standalone.py
@@ -18,25 +18,26 @@
# Unittest for yardstick.benchmark.contexts.standalone
from __future__ import absolute_import
+
import os
import unittest
+
import mock
from yardstick.benchmark.contexts import standalone
-from yardstick.benchmark.contexts import sriov
-from yardstick.benchmark.contexts import ovsdpdk
+from yardstick.benchmark.contexts.standalone import ovsdpdk, sriov
MOCKS = {
'yardstick.benchmark.contexts': mock.MagicMock(),
- 'yardstick.benchmark.contexts.sriov': mock.MagicMock(),
- 'yardstick.benchmark.contexts.ovsdpdk': mock.MagicMock(),
+ 'yardstick.benchmark.contexts.standalone.sriov': mock.MagicMock(),
+ 'yardstick.benchmark.contexts.standalone.ovsdpdk': mock.MagicMock(),
'yardstick.benchmark.contexts.standalone': mock.MagicMock(),
}
-@mock.patch('yardstick.benchmark.contexts.ovsdpdk.time')
+@mock.patch('yardstick.benchmark.contexts.standalone.ovsdpdk.time')
@mock.patch('yardstick.benchmark.contexts.standalone.time')
-@mock.patch('yardstick.benchmark.contexts.sriov.time')
+@mock.patch('yardstick.benchmark.contexts.standalone.sriov.time')
class StandaloneContextTestCase(unittest.TestCase):
NODES_SAMPLE = "nodes_sample_new.yaml"
NODES_SAMPLE_SRIOV = "nodes_sample_new_sriov.yaml"
@@ -564,7 +565,7 @@ class StandaloneContextTestCase(unittest.TestCase):
self.assertIsNone(self.test_context.undeploy())
def test_get_nfvi_obj_sriov(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time):
- with mock.patch('yardstick.benchmark.contexts.sriov'):
+ with mock.patch('yardstick.benchmark.contexts.standalone.sriov'):
attrs = {
'name': 'sriov',
'file': self._get_file_abspath(self.NODES_SAMPLE)
@@ -589,7 +590,7 @@ class StandaloneContextTestCase(unittest.TestCase):
self.assertIsNotNone(self.test_context.get_nfvi_obj())
def test_get_nfvi_obj_ovs(self, mock_sriov_time, mock_standlalone_time, mock_ovsdpdk_time):
- with mock.patch('yardstick.benchmark.contexts.ovsdpdk'):
+ with mock.patch('yardstick.benchmark.contexts.standalone.ovsdpdk'):
attrs = {
'name': 'ovs',
'file': self._get_file_abspath(self.NODES_SAMPLE_OVSDPDK)
diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py
index 25688bf48..14027e43c 100644
--- a/tests/unit/benchmark/core/test_task.py
+++ b/tests/unit/benchmark/core/test_task.py
@@ -290,8 +290,9 @@ class TaskTestCase(unittest.TestCase):
task.change_server_name(scenario, suffix)
self.assertTrue(scenario['target']['name'], 'demo-8')
+ @mock.patch('yardstick.benchmark.core.task.utils')
@mock.patch('yardstick.benchmark.core.task.logging')
- def test_set_log(self, mock_logging):
+ def test_set_log(self, mock_logging, mock_utils):
task_obj = task.Task()
task_obj.task_id = 'task_id'
task_obj._set_log()
diff --git a/tests/unit/benchmark/scenarios/lib/test_attach_volume.py b/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
new file mode 100644
index 000000000..e69924072
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
@@ -0,0 +1,33 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import unittest
+import mock
+
+from yardstick.benchmark.scenarios.lib.attach_volume import AttachVolume
+
+
+class AttachVolumeTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.common.openstack_utils.attach_server_volume')
+ def test_attach_volume(self, mock_attach_server_volume):
+ options = {
+ 'volume_id': '123-456-000',
+ 'server_id': '000-123-456'
+ }
+ args = {"options": options}
+ obj = AttachVolume(args, {})
+ obj.run({})
+ self.assertTrue(mock_attach_server_volume.called)
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py b/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py
new file mode 100644
index 000000000..72dbcd7cd
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py
@@ -0,0 +1,34 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import unittest
+import mock
+
+from yardstick.benchmark.scenarios.lib.create_floating_ip import CreateFloatingIp
+
+
+class CreateFloatingIpTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.common.openstack_utils.create_floating_ip')
+ @mock.patch('yardstick.common.openstack_utils.get_network_id')
+ @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
+ def test_create_floating_ip(self, mock_create_floating_ip, mock_get_network_id, mock_get_neutron_client):
+ options = {}
+ args = {"options": options}
+ obj = CreateFloatingIp(args, {})
+ obj.run({})
+ self.assertTrue(mock_create_floating_ip.called)
+ self.assertTrue(mock_get_network_id.called)
+ self.assertTrue(mock_get_neutron_client.called)
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/scenarios/lib/test_create_keypair.py b/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
new file mode 100644
index 000000000..99e6b9afa
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
@@ -0,0 +1,35 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import unittest
+import mock
+import paramiko
+
+from yardstick.benchmark.scenarios.lib.create_keypair import CreateKeypair
+
+
+class CreateKeypairTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.common.openstack_utils.create_keypair')
+ def test_create_keypair(self, mock_create_keypair):
+ options = {
+ 'key_name': 'yardstick_key',
+ 'key_path': '/tmp/yardstick_key'
+ }
+ args = {"options": options}
+ obj = CreateKeypair(args, {})
+ obj.run({})
+ self.assertTrue(mock_create_keypair.called)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py b/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
index e7ba3ca73..680692fdc 100644
--- a/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
+++ b/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
@@ -18,7 +18,7 @@ class GetNumaInfoTestCase(unittest.TestCase):
@mock.patch('{}.GetNumaInfo._check_numa_node'.format(BASE))
@mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
- @mock.patch('yaml.safe_load')
+ @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
@mock.patch('yardstick.common.task_template.TaskTemplate.render')
def test_get_numa_info(self,
mock_render,
@@ -44,7 +44,7 @@ class GetNumaInfoTestCase(unittest.TestCase):
@mock.patch('yardstick.ssh.SSH.from_node')
@mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
- @mock.patch('yaml.safe_load')
+ @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
@mock.patch('yardstick.common.task_template.TaskTemplate.render')
def test_check_numa_node(self,
mock_render,
@@ -74,7 +74,7 @@ class GetNumaInfoTestCase(unittest.TestCase):
@mock.patch('{}.change_obj_to_dict'.format(BASE))
@mock.patch('{}.get_nova_client'.format(BASE))
- @mock.patch('yaml.safe_load')
+ @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
@mock.patch('yardstick.common.task_template.TaskTemplate.render')
def test_get_current_host_name(self,
mock_render,
diff --git a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
index 84b42c832..651614d3e 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
@@ -26,7 +26,7 @@ import mock
from yardstick.benchmark.scenarios.networking.vnf_generic import \
SshManager, NetworkServiceTestCase, IncorrectConfig, \
- IncorrectSetup, open_relative_file
+ open_relative_file
from yardstick.network_services.collector.subscriber import Collector
from yardstick.network_services.vnf_generic.vnf.base import \
GenericTrafficGen, GenericVNF
@@ -471,7 +471,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
ssh.from_node.return_value = ssh_mock
- with self.assertRaises(IncorrectSetup):
+ with self.assertRaises(IncorrectConfig):
self.s.map_topology_to_infrastructure()
def test_map_topology_to_infrastructure_config_invalid(self):
@@ -694,11 +694,11 @@ class TestNetworkServiceTestCase(unittest.TestCase):
def test_probe_missing_values(self):
netdevs = self.SAMPLE_NETDEVS.copy()
network = {'local_mac': '0a:de:ad:be:ef:f5'}
- NetworkServiceTestCase._probe_missing_values(netdevs, network, set())
+ NetworkServiceTestCase._probe_missing_values(netdevs, network)
assert network['vpci'] == '0000:0b:00.0'
network = {'local_mac': '0a:de:ad:be:ef:f4'}
- NetworkServiceTestCase._probe_missing_values(netdevs, network, set())
+ NetworkServiceTestCase._probe_missing_values(netdevs, network)
assert network['vpci'] == '0000:00:19.0'
def test_open_relative_path(self):
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
index 3b9f99b08..de5bae2f3 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
@@ -28,8 +28,6 @@ from yardstick.benchmark.scenarios.networking import vsperf_dpdk
@mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.subprocess')
@mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh')
-@mock.patch("yardstick.benchmark.scenarios.networking.vsperf_dpdk.open",
- mock.mock_open())
class VsperfDPDKTestCase(unittest.TestCase):
def setUp(self):
diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py
index 663226242..923ec4aaa 100644
--- a/tests/unit/common/test_utils.py
+++ b/tests/unit/common/test_utils.py
@@ -20,6 +20,7 @@ from itertools import product, chain
import mock
from six.moves import configparser
+import yardstick
from yardstick.common import utils
from yardstick.common import constants
@@ -45,47 +46,25 @@ class IterSubclassesTestCase(unittest.TestCase):
self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
-class TryAppendModuleTestCase(unittest.TestCase):
-
- @mock.patch('yardstick.common.utils.importutils')
- def test_try_append_module_not_in_modules(self, mock_importutils):
-
- modules = {}
- name = 'foo'
- utils.try_append_module(name, modules)
- mock_importutils.import_module.assert_called_with(name)
-
- @mock.patch('yardstick.common.utils.importutils')
- def test_try_append_module_already_in_modules(self, mock_importutils):
-
- modules = {'foo'}
- name = 'foo'
- utils.try_append_module(name, modules)
- self.assertFalse(mock_importutils.import_module.called)
-
-
class ImportModulesFromPackageTestCase(unittest.TestCase):
@mock.patch('yardstick.common.utils.os.walk')
- @mock.patch('yardstick.common.utils.try_append_module')
- def test_import_modules_from_package_no_mod(self, mock_append, mock_walk):
-
- sep = os.sep
+ def test_import_modules_from_package_no_mod(self, mock_walk):
+ yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
mock_walk.return_value = ([
- ('..' + sep + 'foo', ['bar'], ['__init__.py']),
- ('..' + sep + 'foo' + sep + 'bar', [], ['baz.txt', 'qux.rst'])
+ (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']),
+ (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst'])
])
utils.import_modules_from_package('foo.bar')
- self.assertFalse(mock_append.called)
@mock.patch('yardstick.common.utils.os.walk')
@mock.patch('yardstick.common.utils.importutils')
def test_import_modules_from_package(self, mock_importutils, mock_walk):
- sep = os.sep
+ yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
mock_walk.return_value = ([
- ('foo' + sep + '..' + sep + 'bar', [], ['baz.py'])
+ (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])
])
utils.import_modules_from_package('foo.bar')
diff --git a/tests/unit/common/test_yaml_loader.py b/tests/unit/common/test_yaml_loader.py
new file mode 100644
index 000000000..90cbb8157
--- /dev/null
+++ b/tests/unit/common/test_yaml_loader.py
@@ -0,0 +1,32 @@
+# 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.
+
+# yardstick: this file is copied from python-heatclient and slightly modified
+
+from __future__ import absolute_import
+import unittest
+
+from yardstick.common import yaml_loader
+
+
+class TemplateFormatTestCase(unittest.TestCase):
+
+ def test_parse_to_value_exception(self):
+
+ self.assertEquals(yaml_loader.yaml_load("string"), u"string")
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py
index 9114b5163..ae4c58de1 100644
--- a/tests/unit/network_services/libs/ixia_libs/test_IxNet.py
+++ b/tests/unit/network_services/libs/ixia_libs/test_IxNet.py
@@ -32,19 +32,14 @@ class TestIxNextgen(unittest.TestCase):
ixnet_gen = IxNextgen()
self.assertIsNone(ixnet_gen._bidir)
- @mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.IxNetwork")
@mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.sys")
- def test_connect(self, mock_sys, mock_ix_network):
- mock_ix_network.IxNet.return_value = mock_ixnet = mock.Mock()
+ def test_connect(self, mock_sys):
ixnet_gen = IxNextgen()
ixnet_gen.get_config = mock.MagicMock()
ixnet_gen.get_ixnet = mock.MagicMock()
- result = ixnet_gen._connect({"py_lib_path": "/tmp"})
- self.assertIsNotNone(result)
- self.assertEqual(mock_ix_network.IxNet.call_count, 1)
- self.assertEqual(mock_ixnet.connect.call_count, 1)
+ self.assertRaises(ImportError, ixnet_gen._connect, {"py_lib_path": "/tmp"})
def test_clear_ixia_config(self):
ixnet = mock.MagicMock()
@@ -263,7 +258,7 @@ class TestIxNextgen(unittest.TestCase):
result = ixnet_gen.ix_get_statistics()
self.assertIsNotNone(result)
- self.assertEqual(ixnet.getList.call_count, 2)
+ self.assertEqual(ixnet.getList.call_count, 1)
self.assertEqual(ixnet.execute.call_count, 20)
def test_find_view_obj_no_where(self):
@@ -455,7 +450,7 @@ class TestIxNextgen(unittest.TestCase):
}
ixnet = mock.MagicMock()
- ixnet.remapIds.return_value=["0"]
+ ixnet.remapIds.return_value = ["0"]
ixnet.setMultiAttribute.return_value = [1]
ixnet.commit.return_value = [1]
ixnet.getList.side_effect = [[1], [0, 1], [0], ["srcIp", "dstIp"]]
@@ -865,7 +860,7 @@ class TestIxNextgen(unittest.TestCase):
ixnet = mock.MagicMock()
ixnet.setMultiAttribute.return_value = [1]
ixnet.commit.return_value = [1]
- ixnet.getList.side_effect=[
+ ixnet.getList.side_effect = [
[1],
[1],
[1],
diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py
index cb26fd085..072f06edf 100644
--- a/tests/unit/network_services/nfvi/test_resource.py
+++ b/tests/unit/network_services/nfvi/test_resource.py
@@ -108,13 +108,13 @@ class TestResourceProfile(unittest.TestCase):
def test_get_cpu_data(self):
reskey = ["", "cpufreq", "cpufreq-0"]
value = "metric:10"
- val = self.resource_profile.get_cpu_data(reskey, value)
+ val = self.resource_profile.get_cpu_data(reskey[1], reskey[2], value)
self.assertIsNotNone(val)
def test_get_cpu_data_error(self):
reskey = ["", "", ""]
value = "metric:10"
- val = self.resource_profile.get_cpu_data(reskey, value)
+ val = self.resource_profile.get_cpu_data(reskey[0], reskey[1], value)
self.assertEqual(val, ('error', 'Invalid', '', ''))
def test__start_collectd(self):
diff --git a/tests/unit/network_services/test_yang_model.py b/tests/unit/network_services/test_yang_model.py
index 28367f316..0b29da701 100644
--- a/tests/unit/network_services/test_yang_model.py
+++ b/tests/unit/network_services/test_yang_model.py
@@ -95,7 +95,7 @@ class YangModelTestCase(unittest.TestCase):
y._get_entries()
self.assertEqual(y._rules, '')
- @mock.patch('yaml.safe_load')
+ @mock.patch('yardstick.network_services.yang_model.yaml_load')
@mock.patch('yardstick.network_services.yang_model.open')
def test__read_config(self, mock_open, mock_safe_load):
cfg = "yang.yaml"
diff --git a/tests/unit/network_services/traffic_profile/test_http_ixload.py b/tests/unit/network_services/traffic_profile/test_http_ixload.py
index 2e1b6f4ff..5110439fd 100644
--- a/tests/unit/network_services/traffic_profile/test_http_ixload.py
+++ b/tests/unit/network_services/traffic_profile/test_http_ixload.py
@@ -16,11 +16,33 @@
from __future__ import absolute_import
import unittest
import mock
-import runpy
from oslo_serialization import jsonutils
from yardstick.network_services.traffic_profile import http_ixload
+from yardstick.network_services.traffic_profile.http_ixload import \
+ join_non_strings, validate_non_string_sequence
+
+
+class TestJoinNonStrings(unittest.TestCase):
+
+ def test_validate_non_string_sequence(self):
+ self.assertEqual(validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
+ self.assertIsNone(validate_non_string_sequence('123'))
+ self.assertIsNone(validate_non_string_sequence(1))
+
+ self.assertEqual(validate_non_string_sequence(1, 2), 2)
+ self.assertEqual(validate_non_string_sequence(1, default=2), 2)
+
+ with self.assertRaises(RuntimeError):
+ validate_non_string_sequence(1, raise_exc=RuntimeError)
+
+ def test_join_non_strings(self):
+ self.assertEqual(join_non_strings(':'), '')
+ self.assertEqual(join_non_strings(':', 'a'), 'a')
+ self.assertEqual(join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
+ self.assertEqual(join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
+ self.assertEqual(join_non_strings(':', 'abc'), 'abc')
class TestIxLoadTrafficGen(unittest.TestCase):
diff --git a/tests/unit/network_services/vnf_generic/test_vnfdgen.py b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
index be51e4a43..c2b923568 100644
--- a/tests/unit/network_services/vnf_generic/test_vnfdgen.py
+++ b/tests/unit/network_services/vnf_generic/test_vnfdgen.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import
import unittest
from six.moves import range
+from yardstick.common.yaml_loader import yaml_load
from yardstick.network_services.vnf_generic import vnfdgen
TREX_VNFD_TEMPLATE = """
@@ -65,6 +66,8 @@ vnfd:vnfd-catalog:
dst_mac: '{{ interfaces.xe1.dst_mac }}'
bandwidth: 10 Gbps
vnfd-connection-point-ref: xe1
+ routing_table: {{ routing_table }}
+ nd_route_tbl: {{ nd_route_tbl }}
benchmark:
kpi:
@@ -126,6 +129,22 @@ COMPLETE_TREX_VNFD = \
'vpci': '0000:00:10.1'},
'vnfd-connection-point-ref': 'xe1'}],
'id': 'trexgen-baremetal',
+ 'nd_route_tbl': [{'gateway': '0064:ff9b:0:0:0:0:9810:6414',
+ 'if': 'xe0',
+ 'netmask': '112',
+ 'network': '0064:ff9b:0:0:0:0:9810:6414'},
+ {'gateway': '0064:ff9b:0:0:0:0:9810:2814',
+ 'if': 'xe1',
+ 'netmask': '112',
+ 'network': '0064:ff9b:0:0:0:0:9810:2814'}],
+ 'routing_table': [{'gateway': '152.16.100.20',
+ 'if': 'xe0',
+ 'netmask': '255.255.255.0',
+ 'network': '152.16.100.20'},
+ {'gateway': '152.16.40.20',
+ 'if': 'xe1',
+ 'netmask': '255.255.255.0',
+ 'network': '152.16.40.20'}],
'name': 'trexgen-baremetal'}]}]}}
NODE_CFG = {'ip': '1.1.1.1',
@@ -144,7 +163,24 @@ NODE_CFG = {'ip': '1.1.1.1',
'dst_mac': '00:01:02:03:04:06',
'local_ip': '2.1.1.2',
'local_mac': '00:01:02:03:05:06',
- 'vpci': '0000:00:10.1'}}}
+ 'vpci': '0000:00:10.1'}},
+ 'nd_route_tbl': [{u'gateway': u'0064:ff9b:0:0:0:0:9810:6414',
+ u'if': u'xe0',
+ u'netmask': u'112',
+ u'network': u'0064:ff9b:0:0:0:0:9810:6414'},
+ {u'gateway': u'0064:ff9b:0:0:0:0:9810:2814',
+ u'if': u'xe1',
+ u'netmask': u'112',
+ u'network': u'0064:ff9b:0:0:0:0:9810:2814'}],
+ 'routing_table': [{u'gateway': u'152.16.100.20',
+ u'if': u'xe0',
+ u'netmask': u'255.255.255.0',
+ u'network': u'152.16.100.20'},
+ {u'gateway': u'152.16.40.20',
+ u'if': u'xe1',
+ u'netmask': u'255.255.255.0',
+ u'network': u'152.16.40.20'}],
+ }
TRAFFIC_PROFILE_TPL = """
@@ -169,6 +205,20 @@ TRAFFIC_PROFILE = {
"1518B": '40'}}}}]}
+class TestRender(unittest.TestCase):
+
+ def test_render_none(self):
+
+ tmpl = "{{ routing_table }}"
+ self.assertEqual(vnfdgen.render(tmpl, routing_table=None), u'~')
+ self.assertEqual(yaml_load(vnfdgen.render(tmpl, routing_table=None)), None)
+
+ def test_render_unicode_dict(self):
+
+ tmpl = "{{ routing_table }}"
+ self.assertEqual(yaml_load(vnfdgen.render(tmpl, **NODE_CFG)), NODE_CFG["routing_table"])
+
+
class TestVnfdGen(unittest.TestCase):
""" Class to verify VNFS testcases """
@@ -193,6 +243,14 @@ class TestVnfdGen(unittest.TestCase):
d = {'a': 1, 'b': 2}
self.assertEqual(vnfdgen.deepgetitem(d, "a"), 1)
+ def test_dict_flatten_str_int_key_first(self):
+ d = {'0': 1, 0: 24, 'b': 2}
+ self.assertEqual(vnfdgen.deepgetitem(d, "0"), 1)
+
+ def test_dict_flatten_int_key_fallback(self):
+ d = {0: 1, 'b': 2}
+ self.assertEqual(vnfdgen.deepgetitem(d, "0"), 1)
+
def test_dict_flatten_list(self):
d = {'a': 1, 'b': list(range(2))}
self.assertEqual(vnfdgen.deepgetitem(d, "b.0"), 0)
@@ -201,6 +259,11 @@ class TestVnfdGen(unittest.TestCase):
d = {'a': 1, 'b': {x: x for x in list(range(2))}}
self.assertEqual(vnfdgen.deepgetitem(d, "b.0"), 0)
+ def test_dict_flatten_only_str_key(self):
+ d = {'0': 1, 0: 24, 'b': 2}
+ self.assertRaises(AttributeError, vnfdgen.deepgetitem, d, 0)
+
+
def test_generate_tp_single_var(self):
""" Function to verify traffic profile generation with imix """
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
index af0d2ddde..07a862a8e 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
@@ -1142,7 +1142,7 @@ class TestClientResourceHelper(unittest.TestCase):
}
@mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.LOG')
- @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLStateError',
+ @mock.patch('yardstick.network_services.vnf_generic.vnf.sample_vnf.STLError',
new_callable=lambda: MockError)
def test_get_stats_not_connected(self, mock_state_error, mock_logger):
vnfd_helper = VnfdHelper({})