aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/benchmark')
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py8
-rw-r--r--tests/unit/benchmark/contexts/test_model.py172
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_qemumigrate.py19
-rw-r--r--tests/unit/benchmark/scenarios/test_base.py53
4 files changed, 240 insertions, 12 deletions
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index 223d64060..f2e725df2 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -119,8 +119,12 @@ class HeatContextTestCase(unittest.TestCase):
"2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
mock_template.add_security_group.assert_called_with("foo-secgroup")
# mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None)
- mock_template.add_router.assert_called_with("bar-fool-network-router", netattrs["external_network"], "bar-fool-network-subnet")
- mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0", "bar-fool-network-router", "bar-fool-network-subnet")
+ mock_template.add_router.assert_called_with("bar-fool-network-router",
+ netattrs["external_network"],
+ "bar-fool-network-subnet")
+ mock_template.add_router_interface.assert_called_with("bar-fool-network-router-if0",
+ "bar-fool-network-router",
+ "bar-fool-network-subnet")
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test_attrs_get(self, mock_template):
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index 48ee01cf0..53b035b82 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -282,6 +282,178 @@ class ServerTestCase(unittest.TestCase):
scheduler_hints='hints',
availability_zone='zone')
+ def test_override_ip(self):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': [
+ {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}},
+ ],
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.interfaces = {
+ "xe0": {
+ "local_ip": "1.2.3.4",
+ "netmask": "255.255.255.0",
+ },
+ "xe1": {
+ "local_ip": "1.2.3.5",
+ "netmask": "255.255.255.0"
+ }
+ }
+ test_server.network_ports = network_ports
+
+ test_server.override_ip("uplink_0", {"port": "xe0"})
+ self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"])
+
+ def test_override_ip_multiple(self):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': [
+ {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}},
+ {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}},
+ ],
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.interfaces = {
+ "xe0": {
+ "local_ip": "1.2.3.4",
+ "netmask": "255.255.255.0",
+ },
+ "xe1": {
+ "local_ip": "1.2.3.5",
+ "netmask": "255.255.255.0"
+ }
+ }
+ test_server.network_ports = network_ports
+ test_server.override_ip("uplink_0", {"port": "xe0"})
+ self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][0]["xe0"])
+
+ def test_override_ip_mixed(self):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': [
+ 'xe0',
+ {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}},
+ ],
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.interfaces = {
+ "xe0": {
+ "local_ip": "1.2.3.4",
+ "netmask": "255.255.255.0",
+ },
+ "xe1": {
+ "local_ip": "1.2.3.5",
+ "netmask": "255.255.255.0"
+ }
+ }
+ test_server.network_ports = network_ports
+ test_server.override_ip("uplink_0", {"port": "xe0"})
+ self.assertEqual(test_server.interfaces["xe0"], network_ports["uplink_0"][1]["xe0"])
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_with_ip_override_invalid_syntax(self, mock_template):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': 'xe0',
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.network_ports = network_ports
+ context = type("Context", (object,), {})
+ # can't use Mock because Mock.name is reserved
+ context.name = "context"
+ networks = [model.Network(n, context, {}) for n in network_ports]
+
+ with self.assertRaises(SyntaxError):
+ test_server._add_instance(mock_template, 'some-server',
+ networks, 'hints')
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_with_ip_override(self, mock_template):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': [
+ {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}},
+ ],
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.network_ports = network_ports
+ context = type("Context", (object,), {})
+ # can't use Mock because Mock.name is reserved
+ context.name = "context"
+ networks = [model.Network(n, context, {}) for n in network_ports]
+
+ test_server._add_instance(mock_template, 'some-server',
+ networks, 'hints')
+ self.assertEqual(test_server.ports, {
+ 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}],
+ 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}],
+ 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'}]
+ })
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test__add_instance_with_multiple_ip_override(self, mock_template):
+ network_ports = {
+ 'mgmt': ['mgmt'],
+ 'uplink_0': [
+ {'xe0': {'local_ip': '10.44.0.20', 'netmask': '255.255.255.0'}},
+ {'xe0': {'local_ip': '10.44.0.21', 'netmask': '255.255.255.0'}},
+ ],
+ 'downlink_0': [
+ {'xe1': {'local_ip': '10.44.0.30', 'netmask': '255.255.255.0'}},
+ ],
+ }
+ attrs = {
+ 'image': 'some-image', 'flavor': 'some-flavor',
+ }
+ test_server = model.Server('foo', self.mock_context, attrs)
+ test_server.network_ports = network_ports
+ context = type("Context", (object,), {})
+ # can't use Mock because Mock.name is reserved
+ context.name = "context"
+ networks = [model.Network(n, context, {}) for n in network_ports]
+
+ test_server._add_instance(mock_template, 'some-server',
+ networks, 'hints')
+ self.assertEqual(test_server.ports, {
+ 'downlink_0': [{'port': 'xe1', 'stack_name': 'some-server-xe1-port'}],
+ 'mgmt': [{'port': 'mgmt', 'stack_name': 'some-server-mgmt-port'}],
+ 'uplink_0': [{'port': 'xe0', 'stack_name': 'some-server-xe0-port'},
+ # this is not an error, we can produce this, it is left to Heat
+ # to detect duplicate ports and error
+ {'port': 'xe0', 'stack_name': 'some-server-xe0-port'}]
+ })
+
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_instance_with_user_data(self, mock_template):
user_data = "USER_DATA"
diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
index f163f1914..1f0ff3c29 100644
--- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
+++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
@@ -16,6 +16,7 @@ from __future__ import absolute_import
import unittest
import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import qemu_migrate
@@ -83,7 +84,7 @@ class QemuMigrateTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
q.run(result)
- expected_result = {}
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_qemu_migrate_successful_sla(self, mock_ssh):
@@ -103,7 +104,7 @@ class QemuMigrateTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
q.run(result)
- expected_result = {}
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_qemu_migrate_unsuccessful_sla_totaltime(self, mock_ssh):
@@ -117,8 +118,7 @@ class QemuMigrateTestCase(unittest.TestCase):
sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}'
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
- with self.assertRaises(AssertionError):
- q.run(result)
+ self.assertRaises(AssertionError, q.run, result)
def test_qemu_migrate_unsuccessful_sla_downtime(self, mock_ssh):
@@ -131,8 +131,7 @@ class QemuMigrateTestCase(unittest.TestCase):
sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}'
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
- with self.assertRaises(AssertionError):
- q.run(result)
+ self.assertRaises(AssertionError, q.run, result)
def test_qemu_migrate_unsuccessful_sla_setuptime(self, mock_ssh):
@@ -145,8 +144,7 @@ class QemuMigrateTestCase(unittest.TestCase):
sample_output = '{"totaltime": 15, "downtime": 2, "setuptime": 1}'
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
- with self.assertRaises(AssertionError):
- q.run(result)
+ self.assertRaises(AssertionError, q.run, result)
def test_qemu_migrate_unsuccessful_script_error(self, mock_ssh):
@@ -156,9 +154,10 @@ 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')
- with self.assertRaises(RuntimeError):
- q.run(result)
+ self.assertRaises(RuntimeError, q.run, result)
+
def main():
unittest.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())