diff options
Diffstat (limited to 'tests/unit/benchmark')
5 files changed, 192 insertions, 34 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py index ddbc1a4bb..6899a0af6 100644 --- a/tests/unit/benchmark/contexts/standalone/test_model.py +++ b/tests/unit/benchmark/contexts/standalone/test_model.py @@ -91,10 +91,12 @@ class ModelLibvirtTestCase(unittest.TestCase): image = Libvirt.create_snapshot_qemu(ssh_mock, "0", "ubuntu.img") self.assertEqual(image, result) + @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.pin_vcpu_for_perf") @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.create_snapshot_qemu") @mock.patch('yardstick.benchmark.contexts.standalone.model.open') @mock.patch('yardstick.benchmark.contexts.standalone.model.write_file') - def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu): + def test_build_vm_xml(self, mock_open, mock_write_file, mock_create_snapshot_qemu, + mock_pin_vcpu_for_perf): result = [4] with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -102,17 +104,10 @@ class ModelLibvirtTestCase(unittest.TestCase): mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock mock_create_snapshot_qemu.return_value = "0.img" + status = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0) self.assertEqual(status[0], result[0]) - def test_split_cpu_list(self): - result = Libvirt.split_cpu_list("1,2,3") - self.assertEqual(result, [1, 2, 3]) - - def test_get_numa_nodes(self): - result = Libvirt.get_numa_nodes() - self.assertIsNotNone(result) - def test_update_interrupts_hugepages_perf(self): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) @@ -122,17 +117,16 @@ class ModelLibvirtTestCase(unittest.TestCase): status = Libvirt.update_interrupts_hugepages_perf(ssh_mock) self.assertIsNone(status) - @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.get_numa_nodes") + @mock.patch("yardstick.benchmark.contexts.standalone.model.CpuSysCores") @mock.patch("yardstick.benchmark.contexts.standalone.model.Libvirt.update_interrupts_hugepages_perf") - def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_get_numa_nodes): + def test_pin_vcpu_for_perf(self, mock_update_interrupts_hugepages_perf, mock_CpuSysCores): with mock.patch("yardstick.ssh.SSH") as ssh: ssh_mock = mock.Mock(autospec=ssh.SSH) ssh_mock.execute = \ mock.Mock(return_value=(0, "a", "")) ssh.return_value = ssh_mock - mock_get_numa_nodes.return_value = {'1': [18, 19, 20, 21], '0': [0, 1, 2, 3]} status = Libvirt.pin_vcpu_for_perf(ssh_mock, "vm_0", 4) - self.assertIsNone(status) + self.assertIsNotNone(status) class StandaloneContextHelperTestCase(unittest.TestCase): diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py index 5444c2bc8..48ee01cf0 100644 --- a/tests/unit/benchmark/contexts/test_model.py +++ b/tests/unit/benchmark/contexts/test_model.py @@ -179,6 +179,7 @@ class NetworkTestCase(unittest.TestCase): test_network = model.Network('foo', self.mock_context, attrs) self.assertIsNone(test_network.gateway_ip) + class ServerTestCase(unittest.TestCase): def setUp(self): @@ -190,7 +191,6 @@ class ServerTestCase(unittest.TestCase): netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'} self.mock_context.networks = [model.Network("some-network", self.mock_context, netattrs)] - def test_construct_defaults(self): attrs = None @@ -227,8 +227,9 @@ class ServerTestCase(unittest.TestCase): @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance(self, mock_template): - - attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', 'floating_ip_assoc': 'some-vm'} + attrs = {'image': 'some-image', 'flavor': 'some-flavor', 'floating_ip': '192.168.1.10', + 'floating_ip_assoc': 'some-vm', + 'availability_zone': 'zone'} test_server = model.Server('foo', self.mock_context, attrs) self.mock_context.flavors = ['flavor1', 'flavor2', 'some-flavor'] @@ -241,7 +242,8 @@ class ServerTestCase(unittest.TestCase): mock_network.subnet_stack_name = 'some-network-stack-subnet' mock_network.provider = 'sriov' mock_network.external_network = 'ext_net' - mock_network.router = model.Router('some-router', 'some-network', self.mock_context, 'ext_net') + mock_network.router = model.Router('some-router', 'some-network', self.mock_context, + 'ext_net') test_server._add_instance(mock_template, 'some-server', [mock_network], 'hints') @@ -277,7 +279,8 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data='', - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone='zone') @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_with_user_data(self, mock_template): @@ -299,7 +302,30 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone=None) + + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') + def test__add_instance_with_availablity_zone(self, mock_template): + attrs = { + 'image': 'some-image', 'flavor': 'some-flavor', + 'availability_zone': 'zone', + } + test_server = model.Server('foo', self.mock_context, attrs) + + test_server._add_instance(mock_template, 'some-server', + [], 'hints') + + mock_template.add_server.assert_called_with( + 'some-server', 'some-image', + flavor='some-flavor', + flavors=self.mock_context.flavors, + ports=[], + user=self.mock_context.user, + key_name=self.mock_context.keypair_name, + user_data='', + scheduler_hints='hints', + availability_zone='zone') @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_plus_flavor(self, mock_template): @@ -339,7 +365,8 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') + scheduler_hints='hints', + availability_zone=None) @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_instance_misc(self, mock_template): @@ -351,7 +378,7 @@ class ServerTestCase(unittest.TestCase): } test_server = model.Server('ServerFlavor-3', self.mock_context, attrs) - self.mock_context.flavors = ['flavor2'] + self.mock_context.flavors = ['flavor2'] self.mock_context.flavor = {'vcpus': 4} mock_network = mock.Mock() mock_network.name = 'some-network' @@ -361,7 +388,6 @@ class ServerTestCase(unittest.TestCase): test_server._add_instance(mock_template, 'ServerFlavor-3', [mock_network], 'hints') - mock_template.add_port( 'ServerFlavor-3-some-network-port', mock_network.stack_name, @@ -387,5 +413,5 @@ class ServerTestCase(unittest.TestCase): user=self.mock_context.user, key_name=self.mock_context.keypair_name, user_data=user_data, - scheduler_hints='hints') - + scheduler_hints='hints', + availability_zone=None) diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py index 9514729ba..f163f1914 100644 --- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py +++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py @@ -16,7 +16,6 @@ from __future__ import absolute_import import unittest import mock -from oslo_serialization import jsonutils from yardstick.benchmark.scenarios.compute import qemu_migrate @@ -84,7 +83,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = jsonutils.loads(sample_output) + expected_result = {} self.assertEqual(result, expected_result) def test_qemu_migrate_successful_sla(self, mock_ssh): @@ -104,7 +103,7 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') q.run(result) - expected_result = jsonutils.loads(sample_output) + expected_result = {} self.assertEqual(result, expected_result) def test_qemu_migrate_unsuccessful_sla_totaltime(self, mock_ssh): @@ -118,7 +117,8 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_sla_downtime(self, mock_ssh): @@ -131,7 +131,8 @@ class QemuMigrateTestCase(unittest.TestCase): sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_sla_setuptime(self, mock_ssh): @@ -142,9 +143,10 @@ class QemuMigrateTestCase(unittest.TestCase): q.setup() sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}' - + mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '') - self.assertRaises(AssertionError, q.run, result) + with self.assertRaises(AssertionError): + q.run(result) def test_qemu_migrate_unsuccessful_script_error(self, mock_ssh): @@ -154,10 +156,9 @@ class QemuMigrateTestCase(unittest.TestCase): mock_ssh.SSH.from_node().execute.return_value = (0, '', '') q.setup() - mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR') - self.assertRaises(RuntimeError, q.run, result) - + with self.assertRaises(RuntimeError): + q.run(result) def main(): unittest.main() diff --git a/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py new file mode 100644 index 000000000..1fb2f89ca --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_check_connectivity.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 +############################################################################## + +# 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'} + } + + result = {} + + 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'} + } + + result = {} + + 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/tests/unit/benchmark/scenarios/test_base.py b/tests/unit/benchmark/scenarios/test_base.py new file mode 100644 index 000000000..78e342978 --- /dev/null +++ b/tests/unit/benchmark/scenarios/test_base.py @@ -0,0 +1,53 @@ +# Copyright 2017: Intel Ltd. +# All Rights Reserved. +# +# 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 unittest + +from yardstick.benchmark.scenarios import base + + +class ScenarioTestCase(unittest.TestCase): + + def test_get_scenario_type(self): + scenario_type = 'dummy scenario' + + class DummyScenario(base.Scenario): + __scenario_type__ = scenario_type + + self.assertEqual(scenario_type, DummyScenario.get_scenario_type()) + + def test_get_scenario_type_not_defined(self): + class DummyScenario(base.Scenario): + pass + + self.assertEqual(str(None), DummyScenario.get_scenario_type()) + + def test_get_description(self): + docstring = """First line + Second line + Third line + """ + + class DummyScenario(base.Scenario): + __doc__ = docstring + + self.assertEqual(docstring.splitlines()[0], + DummyScenario.get_description()) + + def test_get_description_empty(self): + class DummyScenario(base.Scenario): + pass + + self.assertEqual(str(None), DummyScenario.get_description()) |