diff options
Diffstat (limited to 'yardstick/tests/unit')
6 files changed, 177 insertions, 19 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py index 153c6a527..b19883479 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_base.py +++ b/yardstick/tests/unit/benchmark/contexts/test_base.py @@ -25,6 +25,7 @@ class FlagsTestCase(unittest.TestCase): def test___init__(self): self.assertFalse(self.flags.no_setup) self.assertFalse(self.flags.no_teardown) + self.assertEqual({'verify': False}, self.flags.os_cloud_config) def test___init__with_flags(self): flags = base.Flags(no_setup=True) @@ -32,10 +33,12 @@ class FlagsTestCase(unittest.TestCase): self.assertFalse(flags.no_teardown) def test_parse(self): - self.flags.parse(no_setup=True, no_teardown="False") + self.flags.parse(no_setup=True, no_teardown='False', + os_cloud_config={'verify': True}) self.assertTrue(self.flags.no_setup) - self.assertEqual(self.flags.no_teardown, "False") + self.assertEqual('False', self.flags.no_teardown) + self.assertEqual({'verify': True}, self.flags.os_cloud_config) def test_parse_forbidden_flags(self): self.flags.parse(foo=42) diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py index 1d491fe60..ebb1d69ba 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_heat.py +++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py @@ -234,7 +234,7 @@ class HeatContextTestCase(unittest.TestCase): @mock.patch.object(os.path, 'exists', return_value=False) @mock.patch.object(ssh.SSH, 'gen_keys') - @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + @mock.patch.object(heat, 'HeatTemplate') def test_deploy(self, mock_template, mock_genkeys, mock_path_exists): self.test_context._name = 'foo' self.test_context._task_id = '1234567890' @@ -245,9 +245,10 @@ class HeatContextTestCase(unittest.TestCase): self.test_context.get_neutron_info = mock.MagicMock() self.test_context.deploy() - mock_template.assert_called_with('foo-12345678', - '/bar/baz/some-heat-file', - {'image': 'cirros'}) + mock_template.assert_called_with( + 'foo-12345678', template_file='/bar/baz/some-heat-file', + heat_parameters={'image': 'cirros'}, + os_cloud_config=self.test_context._flags.os_cloud_config) self.assertIsNotNone(self.test_context.stack) key_filename = ''.join( [consts.YARDSTICK_ROOT_PATH, diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py index 81bcd8c33..cc19d98b4 100644 --- a/yardstick/tests/unit/common/test_openstack_utils.py +++ b/yardstick/tests/unit/common/test_openstack_utils.py @@ -10,8 +10,10 @@ from oslo_utils import uuidutils import unittest import mock - +import shade from shade import exc + +from yardstick.common import constants from yardstick.common import openstack_utils @@ -35,6 +37,29 @@ class GetHeatApiVersionTestCase(unittest.TestCase): self.assertEqual(api_version, expected_result) +class GetShadeClientTestCase(unittest.TestCase): + + @mock.patch.object(shade, 'openstack_cloud', return_value='os_client') + def test_get_shade_client(self, mock_openstack_cloud): + os_cloud_config = {'param1': True, 'param2': 'value2'} + self.assertEqual('os_client', + openstack_utils.get_shade_client(**os_cloud_config)) + os_cloud_config.update(constants.OS_CLOUD_DEFAULT_CONFIG) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + + mock_openstack_cloud.reset_mock() + os_cloud_config = {'verify': True, 'param2': 'value2'} + self.assertEqual('os_client', + openstack_utils.get_shade_client(**os_cloud_config)) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + + @mock.patch.object(shade, 'openstack_cloud', return_value='os_client') + def test_get_shade_client_no_parameters(self, mock_openstack_cloud): + self.assertEqual('os_client', openstack_utils.get_shade_client()) + mock_openstack_cloud.assert_called_once_with( + **constants.OS_CLOUD_DEFAULT_CONFIG) + + class DeleteNeutronNetTestCase(unittest.TestCase): def setUp(self): @@ -511,3 +536,25 @@ class GetFlavorTestCase(unittest.TestCase): 'flavor_name_or_id') mock_logger.error.assert_called_once() self.assertIsNone(output) + +# ********************************************* +# CINDER +# ********************************************* + + +class GetVolumeIDTestCase(unittest.TestCase): + + def test_get_volume_id(self): + self.mock_shade_client = mock.Mock() + _uuid = uuidutils.generate_uuid() + self.mock_shade_client.get_volume_id.return_value = _uuid + output = openstack_utils.get_volume_id(self.mock_shade_client, + 'volume_name') + self.assertEqual(_uuid, output) + + def test_get_volume_id_None(self): + self.mock_shade_client = mock.Mock() + self.mock_shade_client.get_volume_id.return_value = None + output = openstack_utils.get_volume_id(self.mock_shade_client, + 'volume_name') + self.assertIsNone(output) diff --git a/yardstick/tests/unit/common/test_packages.py b/yardstick/tests/unit/common/test_packages.py new file mode 100644 index 000000000..ba59a3015 --- /dev/null +++ b/yardstick/tests/unit/common/test_packages.py @@ -0,0 +1,88 @@ +# 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/network_services/libs/ixia_libs/test_IxNet.py b/yardstick/tests/unit/network_services/libs/ixia_libs/test_IxNet.py index fe750e5ba..7ca2f0f19 100644 --- a/yardstick/tests/unit/network_services/libs/ixia_libs/test_IxNet.py +++ b/yardstick/tests/unit/network_services/libs/ixia_libs/test_IxNet.py @@ -13,8 +13,9 @@ # limitations under the License. # -import unittest import mock +import IxNetwork +import unittest from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IxNextgen from yardstick.network_services.libs.ixia_libs.IxNet.IxNet import IP_VERSION_4 @@ -30,15 +31,20 @@ class TestIxNextgen(unittest.TestCase): ixnet_gen = IxNextgen() self.assertIsNone(ixnet_gen._bidir) - @mock.patch("yardstick.network_services.libs.ixia_libs.IxNet.IxNet.sys") - def test_connect(self, *args): - + @mock.patch.object(IxNetwork, 'IxNet') + def test_connect(self, mock_ixnet): + ixnet_instance = mock.Mock() + mock_ixnet.return_value = ixnet_instance ixnet_gen = IxNextgen() - ixnet_gen.get_config = mock.MagicMock() - ixnet_gen.get_ixnet = mock.MagicMock() + with mock.patch.object(ixnet_gen, 'get_config') as mock_config: + mock_config.return_value = {'machine': 'machine_fake', + 'port': 'port_fake', + 'version': 12345} + ixnet_gen._connect(mock.ANY) - self.assertRaises(ImportError, ixnet_gen._connect, - {"py_lib_path": "/tmp"}) + ixnet_instance.connect.assert_called_once_with( + 'machine_fake', '-port', 'port_fake', '-version', '12345') + mock_config.assert_called_once() def test_clear_ixia_config(self): ixnet = mock.MagicMock() @@ -655,13 +661,11 @@ class TestIxNextgen(unittest.TestCase): "version": "test3", "ixchassis": "test4", "tcl_port": "test5", - "py_lib_path": "test6", }, } } expected = { - 'py_lib_path': 'test6', 'machine': 'test1', 'port': 'test5', 'chassis': 'test4', diff --git a/yardstick/tests/unit/orchestrator/test_heat.py b/yardstick/tests/unit/orchestrator/test_heat.py index 9598eeb04..3ec59a3c2 100644 --- a/yardstick/tests/unit/orchestrator/test_heat.py +++ b/yardstick/tests/unit/orchestrator/test_heat.py @@ -17,6 +17,7 @@ import shade import unittest from yardstick.benchmark.contexts import node +from yardstick.common import constants from yardstick.common import exceptions from yardstick.orchestrator import heat @@ -53,6 +54,14 @@ class HeatStackTestCase(unittest.TestCase): self._mock_stack_get.stop() heat._DEPLOYED_STACKS = {} + @mock.patch.object(shade, 'openstack_cloud') + def test__init(self, mock_openstack_cloud): + os_cloud_config = {'key': 'value'} + heatstack = heat.HeatStack('name', os_cloud_config=os_cloud_config) + self.assertEqual('name', heatstack.name) + os_cloud_config.update(constants.OS_CLOUD_DEFAULT_CONFIG) + mock_openstack_cloud.assert_called_once_with(**os_cloud_config) + def test_create(self): template = {'tkey': 'tval'} heat_parameters = {'pkey': 'pval'} @@ -192,7 +201,9 @@ class HeatStackTestCase(unittest.TestCase): class HeatTemplateTestCase(unittest.TestCase): def setUp(self): - self.template = heat.HeatTemplate('test') + self._os_cloud_config = {'key1': 'value1'} + self.template = heat.HeatTemplate( + 'test', os_cloud_config=self._os_cloud_config) def test_add_tenant_network(self): self.template.add_network('some-network') @@ -337,8 +348,12 @@ class HeatTemplateTestCase(unittest.TestCase): def test_create_not_block(self): heat_stack = mock.Mock() - with mock.patch.object(heat, 'HeatStack', return_value=heat_stack): + with mock.patch.object(heat, 'HeatStack', return_value=heat_stack) \ + as mock_heatstack: ret = self.template.create(block=False) + + mock_heatstack.assert_called_once_with( + self.template.name, os_cloud_config=self.template._os_cloud_config) heat_stack.create.assert_called_once_with( self.template._template, self.template.heat_parameters, False, 3600) |