diff options
author | Emma Foley <emma.l.foley@intel.com> | 2017-11-29 22:56:21 +0000 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-02-12 16:57:56 +0000 |
commit | ba4e9e6e47bd10ecc803bab920178ea973c2fa86 (patch) | |
tree | 54576c199cabe8ccc29d04eedfe0e4f88b2bd598 /yardstick/tests/unit/benchmark/scenarios/lib | |
parent | babe3cc2882e19c6dafdbf41d502d7ba5560635a (diff) |
Move tests: unit/benchmark
* Fix pylint errors
* Add TODOs
Some errors are ignored locally, as they were a symptom of other problems.
These issues have been flagged with a TODO, and should be fixed later.
Change-Id: I30eb4b0aafe0575d0cddbc946108291f21a98ed8
Jira: YARDSTICK-837
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'yardstick/tests/unit/benchmark/scenarios/lib')
34 files changed, 1529 insertions, 0 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/__init__.py b/yardstick/tests/unit/benchmark/scenarios/lib/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/__init__.py 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 new file mode 100644 index 000000000..bda07f723 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py @@ -0,0 +1,65 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.add_memory_load import AddMemoryLoad + + +class AddMemoryLoadTestCase(unittest.TestCase): + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_with_load(self, mock_from_node): + scenario_cfg = { + 'options': { + 'memory_load': 0.5 + } + } + context_cfg = { + 'host': {} + } + mock_from_node().execute.return_value = (0, '0 2048 512', '') + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_without_load(self, mock_from_node): + scenario_cfg = { + 'options': { + 'memory_load': 0 + } + } + context_cfg = { + 'host': {} + } + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + def test_add_memory_load_without_args(self, mock_from_node): + scenario_cfg = { + 'options': { + } + } + context_cfg = { + 'host': {} + } + obj = AddMemoryLoad(scenario_cfg, context_cfg) + obj.run({}) + self.assertTrue(mock_from_node.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py new file mode 100644 index 000000000..25b911d5e --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.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.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/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py new file mode 100644 index 000000000..7188c29d5 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py @@ -0,0 +1,86 @@ +############################################################################## +# 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 +############################################################################## + +# Unittest for yardstick.benchmark.scenarios.lib.check_connectivity.CheckConnectivity + +from __future__ import absolute_import + +import mock +import unittest + +from yardstick.benchmark.scenarios.lib import check_connectivity + + +class CheckConnectivityTestCase(unittest.TestCase): + + def setUp(self): + self.ctx = { + 'host': { + 'ip': '172.16.0.137', + 'user': 'root', + 'key_filename': 'mykey.key', + 'ssh_port': '22' + }, + 'target': { + 'ipaddr': '172.16.0.138' + } + } + + @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh') + def test_check_connectivity(self, mock_ssh): + + args = { + 'options': {'src_ip_addr': '192.168.23.2', + 'dest_ip_addr': '192.168.23.10', + 'ssh_user': 'root', + 'ssh_passwd': 'root', + 'ssh_port': '22', + 'ssh_timeout': 600, + 'ping_parameter': "-s 2048" + }, + 'sla': {'status': 'True', + 'action': 'assert'} + } + + # TODO(elfoley): Properly check the outputs + result = {} # pylint: disable=unused-variable + + obj = check_connectivity.CheckConnectivity(args, {}) + obj.setup() + mock_ssh.SSH.execute.return_value = (0, '100', '') + + @mock.patch('yardstick.benchmark.scenarios.lib.check_connectivity.ssh') + def test_check_connectivity_key(self, mock_ssh): + + args = { + 'options': {'ssh_user': 'root', + 'ssh_key': '/root/.ssh/id_rsa', + 'ssh_port': '22', + 'ssh_timeout': 600, + 'ping_parameter': "-s 2048" + }, + 'sla': {'status': 'True', + 'action': 'assert'} + } + + # TODO(elfoley): Properly check the outputs + result = {} # pylint: disable=unused-variable + + obj = check_connectivity.CheckConnectivity(args, self.ctx) + obj.setup() + + mock_ssh.SSH.execute.return_value = (0, '100', '') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..f983f9c5b --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py @@ -0,0 +1,84 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import mock +import unittest + +from yardstick.benchmark.scenarios.lib.check_numa_info import CheckNumaInfo + + +class CheckNumaInfoTestCase(unittest.TestCase): + + @mock.patch.object(CheckNumaInfo, '_check_vm2_status') + def test_run(self, mock_check_vm2): + scenario_cfg = {'info1': {}, 'info2': {}} + obj = CheckNumaInfo(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_check_vm2.called) + + def test_check_vm2_status_length_eq_1(self): + info1 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + info2 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertTrue(status) + + def test_check_vm2_status_length_gt_1(self): + info1 = { + 'pinning': [0, 1], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + info2 = { + 'pinning': [0, 1], + 'vcpupin': [{ + 'cpuset': '1,2' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertFalse(status) + + def test_check_vm2_status_length_not_in_set(self): + info1 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,7' + }] + } + info2 = { + 'pinning': [0], + 'vcpupin': [{ + 'cpuset': '1,7' + }] + } + scenario_cfg = {'info1': info1, 'info2': info2} + obj = CheckNumaInfo(scenario_cfg, {}) + status = obj._check_vm2_status(info1, info2) + self.assertFalse(status) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py new file mode 100644 index 000000000..5a40e7d8f --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py @@ -0,0 +1,42 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest + +from yardstick.benchmark.scenarios.lib.check_value import CheckValue + +class CheckValueTestCase(unittest.TestCase): + + def setUp(self): + self.result = {} + + def test_check_value_eq(self): + scenario_cfg = {'options': {'operator': 'eq', 'value1': 1, 'value2': 2}} + obj = CheckValue(scenario_cfg, {}) + self.assertRaises(AssertionError, obj.run, self.result) + self.assertEqual({}, self.result) + + def test_check_value_eq_pass(self): + scenario_cfg = {'options': {'operator': 'eq', 'value1': 1, 'value2': 1}} + obj = CheckValue(scenario_cfg, {}) + + obj.run(self.result) + self.assertEqual({}, self.result) + + def test_check_value_ne(self): + scenario_cfg = {'options': {'operator': 'ne', 'value1': 1, 'value2': 1}} + obj = CheckValue(scenario_cfg, {}) + self.assertRaises(AssertionError, obj.run, self.result) + self.assertEqual({}, self.result) + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py new file mode 100644 index 000000000..036ae952d --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py @@ -0,0 +1,37 @@ +############################################################################## +# 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_flavor import CreateFlavor + + +class CreateFlavorTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.create_flavor') + def test_create_flavor(self, mock_create_flavor): + options = { + 'flavor_name': 'yardstick_test_flavor', + 'vcpus': '2', + 'ram': '1024', + 'disk': '100', + 'is_public': 'True' + } + args = {"options": options} + obj = CreateFlavor(args, {}) + obj.run({}) + self.assertTrue(mock_create_flavor.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py new file mode 100644 index 000000000..a7286f5da --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_floating_ip.py @@ -0,0 +1,58 @@ +############################################################################## +# 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 import create_floating_ip +import yardstick.common.openstack_utils as op_utils + + +class CreateFloatingIpTestCase(unittest.TestCase): + + def setUp(self): + self._mock_get_network_id = mock.patch.object( + op_utils, 'get_network_id') + self.mock_get_network_id = self._mock_get_network_id.start() + self._mock_create_floating_ip = mock.patch.object( + op_utils, 'create_floating_ip') + self.mock_create_floating_ip = self._mock_create_floating_ip.start() + self._mock_get_neutron_client = mock.patch.object( + op_utils, 'get_neutron_client') + self.mock_get_neutron_client = self._mock_get_neutron_client.start() + self._mock_get_shade_client = mock.patch.object( + op_utils, 'get_shade_client') + self.mock_get_shade_client = self._mock_get_shade_client.start() + self._mock_log = mock.patch.object(create_floating_ip, 'LOG') + self.mock_log = self._mock_log.start() + + self._fip_obj = create_floating_ip.CreateFloatingIp(mock.ANY, mock.ANY) + self._fip_obj.scenario_cfg = {'output': 'key1\nkey2'} + + self.addCleanup(self._stop_mock) + + def _stop_mock(self): + self._mock_get_network_id.stop() + self._mock_create_floating_ip.stop() + self._mock_get_neutron_client.stop() + self._mock_get_shade_client.stop() + self._mock_log.stop() + + def test_run(self): + self.mock_create_floating_ip.return_value = {'fip_id': 'value1', + 'fip_addr': 'value2'} + output = self._fip_obj.run(mock.ANY) + self.assertDictEqual({'key1': 'value1', 'key2': 'value2'}, output) + + def test_run_no_fip(self): + self.mock_create_floating_ip.return_value = None + output = self._fip_obj.run(mock.ANY) + self.assertIsNone(output) + self.mock_log.error.assert_called_once_with( + 'Creating floating ip failed!') diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py new file mode 100644 index 000000000..b26957979 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py @@ -0,0 +1,43 @@ +############################################################################## +# 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 import create_image +from yardstick.common import openstack_utils + +# NOTE(elfoley): There should be more tests here. +class CreateImageTestCase(unittest.TestCase): + + @mock.patch.object(openstack_utils, 'create_image') + @mock.patch.object(openstack_utils, 'get_glance_client') + def test_create_image(self, mock_get_glance_client, mock_create_image): + options = { + 'image_name': 'yardstick_test_image_01', + 'disk_format': 'qcow2', + 'container_format': 'bare', + 'min_disk': '1', + 'min_ram': '512', + 'protected': 'False', + 'tags': '["yardstick automatic test image"]', + 'file_path': '/home/opnfv/images/cirros-0.3.5-x86_64-disk.img' + } + args = {"options": options} + obj = create_image.CreateImage(args, {}) + obj.run({}) + mock_create_image.assert_called_once() + mock_get_glance_client.assert_called_once() + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py new file mode 100644 index 000000000..10e351b5e --- /dev/null +++ b/yardstick/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 mock +import unittest + +from yardstick.benchmark.scenarios.lib import create_keypair + + +class CreateKeypairTestCase(unittest.TestCase): + @mock.patch.object(create_keypair, 'paramiko') + @mock.patch.object(create_keypair, 'op_utils') + def test_create_keypair(self, mock_op_utils, *args): + options = { + 'key_name': 'yardstick_key', + 'key_path': '/tmp/yardstick_key' + } + args = {"options": options} + obj = create_keypair.CreateKeypair(args, {}) + obj.run({}) + mock_op_utils.create_keypair.assert_called_once() + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py new file mode 100644 index 000000000..e0382851f --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py @@ -0,0 +1,38 @@ +############################################################################## +# 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_network import CreateNetwork + + +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 main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py new file mode 100644 index 000000000..0f15058da --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.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 + +from yardstick.benchmark.scenarios.lib.create_port import CreatePort + + +class CreatePortTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + def test_create_port(self, mock_get_neutron_client): + options = { + 'openstack_paras': { + 'name': 'yardstick_port' + } + } + args = {"options": options} + obj = CreatePort(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py new file mode 100644 index 000000000..8f3914b83 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py @@ -0,0 +1,38 @@ +############################################################################## +# 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_router import CreateRouter + + +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 main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..c1c137cda --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py @@ -0,0 +1,38 @@ +############################################################################## +# 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_sec_group import CreateSecgroup + + +class CreateSecGroupTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.create_security_group_full') + def test_create_sec_group(self, mock_get_neutron_client, mock_create_security_group_full): + options = { + 'openstack_paras': { + 'sg_name': 'yardstick_sec_group', + 'description': 'security group for yardstick manual VM' + } + } + args = {"options": options} + obj = CreateSecgroup(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_create_security_group_full.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py new file mode 100644 index 000000000..74003b995 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py @@ -0,0 +1,42 @@ +############################################################################## +# 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_server import CreateServer + + +class CreateServerTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.create_instance_and_wait_for_active') + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + @mock.patch('yardstick.common.openstack_utils.get_glance_client') + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + def test_create_server(self, mock_get_nova_client, mock_get_neutron_client, + mock_get_glance_client, mock_create_instance_and_wait_for_active): + scenario_cfg = { + 'options': { + 'openstack_paras': 'example' + }, + 'output': 'server' + } + 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) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py new file mode 100644 index 000000000..b7f29dfe4 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py @@ -0,0 +1,40 @@ +############################################################################## +# 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_subnet import CreateSubnet + + +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 main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py new file mode 100644 index 000000000..ca055db2f --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py @@ -0,0 +1,108 @@ +############################################################################## +# 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 mock +import unittest + +from yardstick.benchmark.scenarios.lib import create_volume + + +class CreateVolumeTestCase(unittest.TestCase): + + def setUp(self): + self._mock_cinder_client = mock.patch( + 'yardstick.common.openstack_utils.get_cinder_client') + self.mock_cinder_client = self._mock_cinder_client.start() + self._mock_glance_client = mock.patch( + 'yardstick.common.openstack_utils.get_glance_client') + self.mock_glance_client = self._mock_glance_client.start() + self.addCleanup(self._stop_mock) + + self.scenario_cfg = { + "options" : + { + 'volume_name': 'yardstick_test_volume_01', + 'size': '256', + 'image': 'cirros-0.3.5' + } + } + + self.scenario = create_volume.CreateVolume( + scenario_cfg=self.scenario_cfg, + context_cfg={}) + + def _stop_mock(self): + self._mock_cinder_client.stop() + self._mock_glance_client.stop() + + def test_init(self): + self.mock_cinder_client.return_value = "All volumes are equal" + self.mock_glance_client.return_value = "Images are more equal" + + expected_vol_name = self.scenario_cfg["options"]["volume_name"] + expected_vol_size = self.scenario_cfg["options"]["size"] + expected_im_name = self.scenario_cfg["options"]["image"] + expected_im_id = None + + scenario = create_volume.CreateVolume( + scenario_cfg=self.scenario_cfg, + context_cfg={}) + + self.assertEqual(expected_vol_name, scenario.volume_name) + self.assertEqual(expected_vol_size, scenario.volume_size) + self.assertEqual(expected_im_name, scenario.image_name) + self.assertEqual(expected_im_id, scenario.image_id) + self.assertEqual("All volumes are equal", scenario.cinder_client) + self.assertEqual("Images are more equal", scenario.glance_client) + + def test_setup(self): + self.assertFalse(self.scenario.setup_done) + self.scenario.setup() + self.assertTrue(self.scenario.setup_done) + + @mock.patch('yardstick.common.openstack_utils.create_volume') + @mock.patch('yardstick.common.openstack_utils.get_image_id') + def test_run(self, mock_image_id, mock_create_volume): + self.scenario.run() + + mock_image_id.assert_called_once() + mock_create_volume.assert_called_once() + + @mock.patch.object(create_volume.CreateVolume, 'setup') + def test_run_no_setup(self, scenario_setup): + self.scenario.setup_done = False + self.scenario.run() + scenario_setup.assert_called_once() + + @mock.patch('yardstick.common.openstack_utils.create_volume') + @mock.patch('yardstick.common.openstack_utils.get_image_id') + @mock.patch('yardstick.common.openstack_utils.get_cinder_client') + @mock.patch('yardstick.common.openstack_utils.get_glance_client') + def test_create_volume(self, mock_get_glance_client, + mock_get_cinder_client, mock_image_id, + mock_create_volume): + options = { + 'volume_name': 'yardstick_test_volume_01', + 'size': '256', + 'image': 'cirros-0.3.5' + } + 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) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py new file mode 100644 index 000000000..4a91b8939 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.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 + +from yardstick.benchmark.scenarios.lib.delete_flavor import DeleteFlavor + + +class DeleteFlavorTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.delete_flavor') + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_delete_flavor(self, mock_get_nova_client, mock_delete_flavor): + options = { + 'flavor_name': 'yardstick_test_flavor' + } + args = {"options": options} + obj = DeleteFlavor(args, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_delete_flavor.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..df2321292 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.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 + +from yardstick.benchmark.scenarios.lib.delete_floating_ip import DeleteFloatingIp + + +class DeleteFloatingIpTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + @mock.patch('yardstick.common.openstack_utils.delete_floating_ip') + def test_delete_floating_ip(self, mock_get_nova_client, mock_delete_floating_ip): + options = { + 'floating_ip_id': '123-123-123' + } + args = {"options": options} + obj = DeleteFloatingIp(args, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_delete_floating_ip.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py new file mode 100644 index 000000000..9edc2ff1d --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py @@ -0,0 +1,37 @@ +############################################################################## +# 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.delete_image import DeleteImage + + +class DeleteImageTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.delete_image') + @mock.patch('yardstick.common.openstack_utils.get_image_id') + @mock.patch('yardstick.common.openstack_utils.get_glance_client') + def test_delete_image(self, mock_get_glance_client, mock_image_id, mock_delete_image): + options = { + 'image_name': 'yardstick_test_image_01' + } + 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) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py new file mode 100644 index 000000000..73894a903 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_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 + +from yardstick.benchmark.scenarios.lib.delete_keypair import DeleteKeypair + + +class DeleteKeypairTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + @mock.patch('yardstick.common.openstack_utils.delete_keypair') + def test_detach_volume(self, mock_get_nova_client, mock_delete_keypair): + options = { + 'key_name': 'yardstick_key' + } + args = {"options": options} + obj = DeleteKeypair(args, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_delete_keypair.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_network.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_network.py new file mode 100644 index 000000000..5f11713fa --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_network.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 + +from yardstick.benchmark.scenarios.lib.delete_network import DeleteNetwork + + +class DeleteNetworkTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.delete_neutron_net') + def test_delete_network(self, mock_get_neutron_client, mock_delete_neutron_net): + options = { + 'network_id': '123-123-123' + } + args = {"options": options} + obj = DeleteNetwork(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_delete_neutron_net.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py new file mode 100644 index 000000000..de3179b2d --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.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.delete_port import DeletePort + + +class DeletePortTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + def test_delete_port(self, mock_get_neutron_client): + options = { + 'port_id': '123-123-123' + } + args = {"options": options} + obj = DeletePort(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py new file mode 100644 index 000000000..73cb81278 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.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 + +from yardstick.benchmark.scenarios.lib.delete_router import DeleteRouter + + +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 main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..3cfc4ed21 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.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 + +from yardstick.benchmark.scenarios.lib.delete_router_gateway import DeleteRouterGateway + + +class DeleteRouterGatewayTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.remove_gateway_router') + def test_delete_router_gateway(self, mock_get_neutron_client, mock_remove_gateway_router): + options = { + 'router_id': '123-123-123' + } + args = {"options": options} + obj = DeleteRouterGateway(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_remove_gateway_router.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..67aff1091 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py @@ -0,0 +1,36 @@ +############################################################################## +# 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.delete_router_interface import DeleteRouterInterface + + +class DeleteRouterInterfaceTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.remove_interface_router') + def test_delete_router_interface(self, mock_get_neutron_client, mock_remove_interface_router): + options = { + 'router_id': '123-123-123', + 'subnet_id': '321-321-321' + } + args = {"options": options} + obj = DeleteRouterInterface(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_remove_interface_router.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py new file mode 100644 index 000000000..622ead5ac --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.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 + +from yardstick.benchmark.scenarios.lib.delete_server import DeleteServer + + +class DeleteServerTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.delete_instance') + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_delete_server(self, mock_get_nova_client, mock_delete_instance): + options = { + 'server_id': '1234-4567-0000' + } + args = {"options": options} + obj = DeleteServer(args, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_delete_instance.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py new file mode 100644 index 000000000..9438b077a --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.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 + +from yardstick.benchmark.scenarios.lib.delete_volume import DeleteVolume + + +class DeleteVolumeTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_cinder_client') + @mock.patch('yardstick.common.openstack_utils.delete_volume') + def test_delete_volume(self, mock_get_cinder_client, mock_delete_volume): + options = { + 'volume_id': '123-123-123' + } + args = {"options": options} + obj = DeleteVolume(args, {}) + obj.run({}) + self.assertTrue(mock_get_cinder_client.called) + self.assertTrue(mock_delete_volume.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py new file mode 100644 index 000000000..87af63a55 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.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.detach_volume import DetachVolume + + +class DetachVolumeTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.detach_volume') + def test_detach_volume(self, mock_detach_volume): + options = { + 'server_id': '321-321-321', + 'volume_id': '123-123-123' + } + args = {"options": options} + obj = DetachVolume(args, {}) + obj.run({}) + self.assertTrue(mock_detach_volume.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py new file mode 100644 index 000000000..bf12e0a32 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.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.get_flavor import GetFlavor + + +class GetFlavorTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_flavor_by_name') + def test_get_flavor(self, mock_get_flavor_by_name): + options = { + 'flavor_name': 'yardstick_test_flavor' + } + args = {"options": options} + obj = GetFlavor(args, {}) + obj.run({}) + self.assertTrue(mock_get_flavor_by_name.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() 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 new file mode 100644 index 000000000..f046c92ea --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py @@ -0,0 +1,51 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_migrate_target_host import GetMigrateTargetHost + +BASE = 'yardstick.benchmark.scenarios.lib.get_migrate_target_host' + + +class GetMigrateTargetHostTestCase(unittest.TestCase): + + @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE)) + @mock.patch('{}.GetMigrateTargetHost._get_migrate_host'.format(BASE)) + @mock.patch('{}.GetMigrateTargetHost._get_current_host_name'.format(BASE)) + def test_get_migrate_target_host(self, + mock_get_current_host_name, + mock_get_migrate_host, + mock_get_nova_client): + obj = GetMigrateTargetHost({}, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_get_current_host_name.called) + self.assertTrue(mock_get_migrate_host.called) + + @mock.patch('{}.openstack_utils.get_nova_client'.format(BASE)) + def test_get_migrate_host(self, mock_get_nova_client): + class A(object): + def __init__(self, service): + self.service = service + self.host = 'host4' + + mock_get_nova_client().hosts.list_all.return_value = [A('compute')] + obj = GetMigrateTargetHost({}, {}) + host = obj._get_migrate_host('host5') + self.assertTrue(mock_get_nova_client.called) + self.assertEqual(host, 'host4') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py new file mode 100644 index 000000000..50d5238d7 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py @@ -0,0 +1,111 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_numa_info import GetNumaInfo + + +# pylint: disable=unused-argument +# disable this for now because I keep forgetting mock patch arg ordering + + +BASE = 'yardstick.benchmark.scenarios.lib.get_numa_info' + + +class GetNumaInfoTestCase(unittest.TestCase): + + @mock.patch('{}.GetNumaInfo._check_numa_node'.format(BASE)) + @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE)) + @mock.patch('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, + mock_safe_load, + mock_get_current_host_name, + mock_check_numa_node): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_safe_load.return_value = { + 'nodes': [] + } + obj = GetNumaInfo(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_current_host_name.called) + self.assertTrue(mock_check_numa_node.called) + + @mock.patch('yardstick.ssh.SSH.from_node') + @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE)) + @mock.patch('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, + mock_safe_load, + mock_get_current_host_name, + mock_from_node): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_safe_load.return_value = { + 'nodes': [] + } + data = """ + <data> + </data> + """ + mock_from_node().execute.return_value = (0, data, '') + obj = GetNumaInfo(scenario_cfg, {}) + result = obj._check_numa_node('1', 'host4') + self.assertEqual(result, {'pinning': [], 'vcpupin': []}) + + @mock.patch('{}.change_obj_to_dict'.format(BASE)) + @mock.patch('{}.get_nova_client'.format(BASE)) + @mock.patch('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, + mock_safe_load, + mock_get_nova_client, + mock_change_obj_to_dict): + scenario_cfg = { + 'options': { + 'server': { + 'id': '1' + }, + 'file': 'yardstick/ssh.py' + }, + 'output': 'numa_info' + } + mock_get_nova_client().servers.get.return_value = '' + mock_change_obj_to_dict.return_value = {'OS-EXT-SRV-ATTR:host': 'host5'} + + obj = GetNumaInfo(scenario_cfg, {}) + result = obj._get_current_host_name('1') + self.assertEqual(result, 'host5') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py new file mode 100644 index 000000000..aebbf5416 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py @@ -0,0 +1,50 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock + +from yardstick.benchmark.scenarios.lib.get_server import GetServer + + +class GetServerTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_server_by_name') + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_get_server_with_name(self, mock_get_nova_client, mock_get_server_by_name): + scenario_cfg = { + 'options': { + 'server_name': 'yardstick_server' + }, + 'output': 'status server' + } + obj = GetServer(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + self.assertTrue(mock_get_server_by_name.called) + + @mock.patch('yardstick.common.openstack_utils.get_nova_client') + def test_get_server_with_id(self, mock_get_nova_client): + scenario_cfg = { + 'options': { + 'server_id': '1' + }, + 'output': 'status server' + } + mock_get_nova_client().servers.get.return_value = None + obj = GetServer(scenario_cfg, {}) + obj.run({}) + self.assertTrue(mock_get_nova_client.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py new file mode 100644 index 000000000..3d20d5439 --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py @@ -0,0 +1,41 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest + +from yardstick.benchmark.scenarios.lib.get_server_ip import GetServerIp + + +class GetServerIpTestCase(unittest.TestCase): + def test_get_server_ip(self): + scenario_cfg = { + 'options': { + 'server': { + 'addresses': { + 'net1': [ + { + 'OS-EXT-IPS:type': 'floating', + 'addr': '127.0.0.1' + } + ] + } + } + }, + 'output': 'ip' + } + obj = GetServerIp(scenario_cfg, {}) + result = obj.run({}) + self.assertEqual(result, {'ip': '127.0.0.1'}) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() |