diff options
Diffstat (limited to 'yardstick/tests/unit')
-rw-r--r-- | yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py | 2 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_ansible_common.py | 16 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_packages.py | 88 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_utils.py | 38 | ||||
-rw-r--r-- | yardstick/tests/unit/service/__init__.py | 0 | ||||
-rw-r--r-- | yardstick/tests/unit/service/test_environment.py | 49 |
6 files changed, 85 insertions, 108 deletions
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_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() |