diff options
Diffstat (limited to 'yardstick/tests/unit/benchmark')
8 files changed, 387 insertions, 267 deletions
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py index 3ccae44c7..fbc6fd26d 100644 --- a/yardstick/tests/unit/benchmark/contexts/test_heat.py +++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py @@ -81,6 +81,7 @@ class HeatContextTestCase(unittest.TestCase): self.assertIsNone(self.test_context.template_file) self.assertIsNone(self.test_context.heat_parameters) self.assertIsNone(self.test_context.key_filename) + self.assertTrue(self.test_context.yardstick_gen_key_file) @mock.patch.object(yaml_loader, 'read_yaml_file') @mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup') @@ -173,6 +174,23 @@ class HeatContextTestCase(unittest.TestCase): self.assertTrue(self.test_context._flags.no_setup) self.assertTrue(self.test_context._flags.no_teardown) + def test_init_key_filename(self): + attrs = {'name': 'foo', + 'file': 'pod.yaml', + 'task_id': '1234567890', + 'server_groups': {}, + 'networks': {}, + 'servers': {}, + 'heat_template': "/root/clearwater.yaml", + 'key_filename': '/etc/yardstick/yardstick.pem'} + + with mock.patch.object(openstack_utils, 'get_shade_client'), \ + mock.patch.object(openstack_utils, 'get_shade_operator_client'): + self.test_context.init(attrs) + + self.assertIsNotNone(self.test_context.key_filename) + self.assertFalse(self.test_context.yardstick_gen_key_file) + @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate') def test__add_resources_to_template_no_servers(self, mock_template): self.test_context._name = 'ctx' @@ -373,6 +391,25 @@ class HeatContextTestCase(unittest.TestCase): self.assertTrue(mock_manager.mock_calls.index(mock_call_gen_keys) < mock_manager.mock_calls.index(mock_call_add_resources)) + @mock.patch.object(heat, 'HeatTemplate') + @mock.patch.object(ssh.SSH, 'gen_keys') + @mock.patch.object(heat.HeatContext, '_create_new_stack') + def test_deploy_with_key_filename_provided(self, mock_create_new_stack, + mock_gen_keys, *args): + self.test_context._name = 'foo' + self.test_context._task_id = '1234567890' + self.test_context._name_task_id = '{}-{}'.format( + self.test_context._name, self.test_context._task_id[:8]) + self.test_context.template_file = '/bar/baz/some-heat-file' + self.test_context.heat_parameters = {'image': 'cirros'} + self.test_context.yardstick_gen_key_file = False + self.test_context.key_filename = '/etc/yardstick/yardstick.pem' + self.test_context.get_neutron_info = mock.MagicMock() + self.test_context.deploy() + + mock_create_new_stack.assert_called() + mock_gen_keys.assert_not_called() + def test_check_for_context(self): pass # check that the context exists diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py index 11d017ff0..b498299a9 100644 --- a/yardstick/tests/unit/benchmark/core/test_report.py +++ b/yardstick/tests/unit/benchmark/core/test_report.py @@ -1,6 +1,6 @@ ############################################################################## # Copyright (c) 2017 Rajesh Kudaka. -# Copyright (c) 2018 Intel Corporation. +# Copyright (c) 2018-2019 Intel Corporation. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -9,6 +9,7 @@ ############################################################################## import mock +import six import unittest import uuid @@ -19,13 +20,82 @@ from yardstick.cmd.commands import change_osloobj_to_paras GOOD_YAML_NAME = 'fake_name' GOOD_TASK_ID = str(uuid.uuid4()) GOOD_DB_FIELDKEYS = [{'fieldKey': 'fake_key'}] -GOOD_DB_TASK = [{ +GOOD_DB_METRICS = [{ 'fake_key': 1.234, 'time': '0000-00-00T12:34:56.789012Z', }] GOOD_TIMESTAMP = ['12:34:56.789012'] BAD_YAML_NAME = 'F@KE_NAME' BAD_TASK_ID = 'aaaaaa-aaaaaaaa-aaaaaaaaaa-aaaaaa' +MORE_DB_FIELDKEYS = [ + {'fieldKey': 'fake_key'}, + {'fieldKey': 'str_str'}, + {'fieldKey': u'str_unicode'}, + {u'fieldKey': 'unicode_str'}, + {u'fieldKey': u'unicode_unicode'}, + ] +MORE_DB_METRICS = [{ + 'fake_key': None, + 'time': '0000-00-00T00:00:00.000000Z', + }, { + 'fake_key': 123, + 'time': '0000-00-00T00:00:01.000000Z', + }, { + 'fake_key': 4.56, + 'time': '0000-00-00T00:00:02.000000Z', + }, { + 'fake_key': 9876543210987654321, + 'time': '0000-00-00T00:00:03.000000Z', + }, { + 'fake_key': 'str_str value', + 'time': '0000-00-00T00:00:04.000000Z', + }, { + 'fake_key': u'str_unicode value', + 'time': '0000-00-00T00:00:05.000000Z', + }, { + u'fake_key': 'unicode_str value', + 'time': '0000-00-00T00:00:06.000000Z', + }, { + u'fake_key': u'unicode_unicode value', + 'time': '0000-00-00T00:00:07.000000Z', + }, { + 'fake_key': '7.89', + 'time': '0000-00-00T00:00:08.000000Z', + }, { + 'fake_key': '1011', + 'time': '0000-00-00T00:00:09.000000Z', + }, { + 'fake_key': '9876543210123456789', + 'time': '0000-00-00T00:00:10.000000Z', + }] +MORE_TIMESTAMP = ['00:00:%02d.000000' % n for n in range(len(MORE_DB_METRICS))] +MORE_EMPTY_DATA = [None] * len(MORE_DB_METRICS) +MORE_EXPECTED_TABLE_VALS = { + 'Timestamp': MORE_TIMESTAMP, + 'fake_key': [ + None, + 123, + 4.56, + 9876543210987654321 if six.PY3 else 9.876543210987655e+18, + 'str_str value', + 'str_unicode value', + 'unicode_str value', + 'unicode_unicode value', + 7.89, + 1011, + 9876543210123456789 if six.PY3 else 9.876543210123457e+18, + ], + 'str_str': MORE_EMPTY_DATA, + 'str_unicode': MORE_EMPTY_DATA, + 'unicode_str': MORE_EMPTY_DATA, + 'unicode_unicode': MORE_EMPTY_DATA, + } +MORE_EXPECTED_DATASETS = [{ + 'label': key, + 'data': MORE_EXPECTED_TABLE_VALS[key], + } + for key in map(str, [field['fieldKey'] for field in MORE_DB_FIELDKEYS]) + ] class JSTreeTestCase(unittest.TestCase): @@ -47,23 +117,15 @@ class JSTreeTestCase(unittest.TestCase): def test_format_for_jstree(self): data = [ - {'data': [0, ], 'label': 'tg__0.DropPackets'}, - {'data': [548, ], 'label': 'tg__0.LatencyAvg.5'}, - {'data': [1172, ], 'label': 'tg__0.LatencyAvg.6'}, - {'data': [1001, ], 'label': 'tg__0.LatencyMax.5'}, - {'data': [1468, ], 'label': 'tg__0.LatencyMax.6'}, - {'data': [18.11, ], 'label': 'tg__0.RxThroughput'}, - {'data': [18.11, ], 'label': 'tg__0.TxThroughput'}, - {'data': [0, ], 'label': 'tg__1.DropPackets'}, - {'data': [548, ], 'label': 'tg__1.LatencyAvg.5'}, - {'data': [1172, ], 'label': 'tg__1.LatencyAvg.6'}, - {'data': [1001, ], 'label': 'tg__1.LatencyMax.5'}, - {'data': [1468, ], 'label': 'tg__1.LatencyMax.6'}, - {'data': [18.1132084505, ], 'label': 'tg__1.RxThroughput'}, - {'data': [18.1157260383, ], 'label': 'tg__1.TxThroughput'}, - {'data': [9057888, ], 'label': 'vnf__0.curr_packets_in'}, - {'data': [0, ], 'label': 'vnf__0.packets_dropped'}, - {'data': [617825443, ], 'label': 'vnf__0.packets_fwd'}, + 'tg__0.DropPackets', + 'tg__0.LatencyAvg.5', 'tg__0.LatencyAvg.6', + 'tg__0.LatencyMax.5', 'tg__0.LatencyMax.6', + 'tg__0.RxThroughput', 'tg__0.TxThroughput', + 'tg__1.DropPackets', + 'tg__1.LatencyAvg.5', 'tg__1.LatencyAvg.6', + 'tg__1.LatencyMax.5', 'tg__1.LatencyMax.6', + 'tg__1.RxThroughput', 'tg__1.TxThroughput', + 'vnf__0.curr_packets_in', 'vnf__0.packets_dropped', 'vnf__0.packets_fwd', ] expected_output = [ @@ -117,11 +179,11 @@ class ReportTestCase(unittest.TestCase): self.assertEqual(GOOD_TASK_ID, str(self.rep.task_id)) def test__validate_invalid_yaml_name(self): - with self.assertRaisesRegexp(ValueError, "yaml*"): + with six.assertRaisesRegex(self, ValueError, "yaml*"): self.rep._validate(BAD_YAML_NAME, GOOD_TASK_ID) def test__validate_invalid_task_id(self): - with self.assertRaisesRegexp(ValueError, "task*"): + with six.assertRaisesRegex(self, ValueError, "task*"): self.rep._validate(GOOD_YAML_NAME, BAD_TASK_ID) @mock.patch.object(influx, 'query') @@ -141,42 +203,59 @@ class ReportTestCase(unittest.TestCase): mock_query.return_value = [] self.rep.yaml_name = GOOD_YAML_NAME self.rep.task_id = GOOD_TASK_ID - self.assertRaisesRegexp(KeyError, "Test case", self.rep._get_fieldkeys) + six.assertRaisesRegex(self, KeyError, "Test case", self.rep._get_fieldkeys) @mock.patch.object(influx, 'query') - def test__get_tasks(self, mock_query): - mock_query.return_value = GOOD_DB_TASK + def test__get_metrics(self, mock_query): + mock_query.return_value = GOOD_DB_METRICS self.rep.yaml_name = GOOD_YAML_NAME self.rep.task_id = GOOD_TASK_ID - self.assertEqual(GOOD_DB_TASK, self.rep._get_tasks()) + self.assertEqual(GOOD_DB_METRICS, self.rep._get_metrics()) @mock.patch.object(influx, 'query') - def test__get_tasks_task_not_found(self, mock_query): + def test__get_metrics_task_not_found(self, mock_query): mock_query.return_value = [] self.rep.yaml_name = GOOD_YAML_NAME self.rep.task_id = GOOD_TASK_ID - self.assertRaisesRegexp(KeyError, "Task ID", self.rep._get_tasks) + six.assertRaisesRegex(self, KeyError, "Task ID", self.rep._get_metrics) + + def test__get_timestamps(self): + + metrics = MORE_DB_METRICS + self.assertEqual( + MORE_TIMESTAMP, + self.rep._get_timestamps(metrics) + ) + + @mock.patch.object(report.Report, '_get_metrics') + @mock.patch.object(report.Report, '_get_fieldkeys') + def test__generate_common(self, mock_keys, mock_metrics): + mock_metrics.return_value = MORE_DB_METRICS + mock_keys.return_value = MORE_DB_FIELDKEYS + datasets, table_vals = self.rep._generate_common(self.param) + self.assertEqual(MORE_EXPECTED_DATASETS, datasets) + self.assertEqual(MORE_EXPECTED_TABLE_VALS, table_vals) - @mock.patch.object(report.Report, '_get_tasks') + @mock.patch.object(report.Report, '_get_metrics') @mock.patch.object(report.Report, '_get_fieldkeys') @mock.patch.object(report.Report, '_validate') - def test_generate(self, mock_valid, mock_keys, mock_tasks): - mock_tasks.return_value = GOOD_DB_TASK + def test_generate(self, mock_valid, mock_keys, mock_metrics): + mock_metrics.return_value = GOOD_DB_METRICS mock_keys.return_value = GOOD_DB_FIELDKEYS self.rep.generate(self.param) mock_valid.assert_called_once_with(GOOD_YAML_NAME, GOOD_TASK_ID) - mock_tasks.assert_called_once_with() + mock_metrics.assert_called_once_with() mock_keys.assert_called_once_with() self.assertEqual(GOOD_TIMESTAMP, self.rep.Timestamp) - @mock.patch.object(report.Report, '_get_tasks') + @mock.patch.object(report.Report, '_get_metrics') @mock.patch.object(report.Report, '_get_fieldkeys') @mock.patch.object(report.Report, '_validate') - def test_generate_nsb(self, mock_valid, mock_keys, mock_tasks): - mock_tasks.return_value = GOOD_DB_TASK + def test_generate_nsb(self, mock_valid, mock_keys, mock_metrics): + mock_metrics.return_value = GOOD_DB_METRICS mock_keys.return_value = GOOD_DB_FIELDKEYS self.rep.generate_nsb(self.param) mock_valid.assert_called_once_with(GOOD_YAML_NAME, GOOD_TASK_ID) - mock_tasks.assert_called_once_with() + mock_metrics.assert_called_once_with() mock_keys.assert_called_once_with() self.assertEqual(GOOD_TIMESTAMP, self.rep.Timestamp) diff --git a/yardstick/tests/unit/benchmark/runner/test_base.py b/yardstick/tests/unit/benchmark/runner/test_base.py index 49ba1efe4..07d6f1843 100644 --- a/yardstick/tests/unit/benchmark/runner/test_base.py +++ b/yardstick/tests/unit/benchmark/runner/test_base.py @@ -8,17 +8,12 @@ ############################################################################## import time -import uuid import mock -from oslo_config import cfg -import oslo_messaging import subprocess from yardstick.benchmark.runners import base as runner_base from yardstick.benchmark.runners import iteration -from yardstick.common import messaging -from yardstick.common.messaging import payloads from yardstick.tests.unit import base as ut_base @@ -48,6 +43,29 @@ class ActionTestCase(ut_base.BaseUnitTestCase): runner_base._periodic_action(0, 'echo', mock.Mock()) +class ScenarioOutputTestCase(ut_base.BaseUnitTestCase): + + def setUp(self): + self.output_queue = mock.Mock() + self.scenario_output = runner_base.ScenarioOutput(self.output_queue, + sequence=1) + + @mock.patch.object(time, 'time') + def test_push(self, mock_time): + mock_time.return_value = 2 + data = {"value1": 1} + self.scenario_output.push(data) + self.output_queue.put.assert_called_once_with({'timestamp': 2, + 'sequence': 1, + 'data': data}, True, 10) + + def test_push_no_timestamp(self): + self.scenario_output["value1"] = 1 + self.scenario_output.push(None, False) + self.output_queue.put.assert_called_once_with({'sequence': 1, + 'value1': 1}, True, 10) + + class RunnerTestCase(ut_base.BaseUnitTestCase): def setUp(self): @@ -99,54 +117,3 @@ class RunnerTestCase(ut_base.BaseUnitTestCase): with self.assertRaises(NotImplementedError): runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()) - - -class RunnerProducerTestCase(ut_base.BaseUnitTestCase): - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(cfg, 'CONF') - def test__init(self, mock_config, mock_transport, mock_rpcclient, - mock_target): - _id = uuid.uuid1().int - runner_producer = runner_base.RunnerProducer(_id) - mock_transport.assert_called_once_with( - mock_config, url='rabbit://yardstick:yardstick@localhost:5672/') - mock_target.assert_called_once_with(topic=messaging.TOPIC_RUNNER, - fanout=True, - server=messaging.SERVER) - mock_rpcclient.assert_called_once_with('rpc_transport', 'rpc_target') - self.assertEqual(_id, runner_producer._id) - self.assertEqual(messaging.TOPIC_RUNNER, runner_producer._topic) - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(payloads, 'RunnerPayload', return_value='runner_pload') - def test_start_iteration(self, mock_runner_payload, *args): - runner_producer = runner_base.RunnerProducer(uuid.uuid1().int) - with mock.patch.object(runner_producer, - 'send_message') as mock_message: - runner_producer.start_iteration(version=10) - - mock_message.assert_called_once_with( - messaging.RUNNER_METHOD_START_ITERATION, 'runner_pload') - mock_runner_payload.assert_called_once_with(version=10, data={}) - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(payloads, 'RunnerPayload', return_value='runner_pload') - def test_stop_iteration(self, mock_runner_payload, *args): - runner_producer = runner_base.RunnerProducer(uuid.uuid1().int) - with mock.patch.object(runner_producer, - 'send_message') as mock_message: - runner_producer.stop_iteration(version=15) - - mock_message.assert_called_once_with( - messaging.RUNNER_METHOD_STOP_ITERATION, 'runner_pload') - mock_runner_payload.assert_called_once_with(version=15, data={}) diff --git a/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py b/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py deleted file mode 100644 index 10d14a8a0..000000000 --- a/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright (c) 2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import multiprocessing -import time -import os -import uuid - -import mock - -from yardstick.benchmark.runners import iteration_ipc -from yardstick.common import messaging -from yardstick.common.messaging import payloads -from yardstick.tests.unit import base as ut_base - - -class RunnerIterationIPCEndpointTestCase(ut_base.BaseUnitTestCase): - - def setUp(self): - self._id = uuid.uuid1().int - self._ctx_ids = [uuid.uuid1().int, uuid.uuid1().int] - self._queue = multiprocessing.Queue() - self.runner = iteration_ipc.RunnerIterationIPCEndpoint( - self._id, self._ctx_ids, self._queue) - self._kwargs = {'version': 1, 'iteration': 10, 'kpi': {}} - self._pload_dict = payloads.TrafficGeneratorPayload.dict_to_obj( - self._kwargs).obj_to_dict() - - def test_tg_method_started(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_started(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_STARTED, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - def test_tg_method_finished(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_finished(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_FINISHED, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - def test_tg_method_iteration(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_iteration(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_ITERATION, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - -class RunnerIterationIPCConsumerTestCase(ut_base.BaseUnitTestCase): - - def setUp(self): - self._id = uuid.uuid1().int - self._ctx_ids = [uuid.uuid1().int, uuid.uuid1().int] - self.consumer = iteration_ipc.RunnerIterationIPCConsumer( - self._id, self._ctx_ids) - self.consumer._queue = mock.Mock() - - def test__init(self): - self.assertEqual({self._ctx_ids[0]: [], self._ctx_ids[1]: []}, - self.consumer._kpi_per_id) - - def test_is_all_kpis_received_in_iteration(self): - payload = payloads.TrafficGeneratorPayload( - version=1, iteration=1, kpi={}) - msg1 = {'action': messaging.TG_METHOD_ITERATION, - 'id': self._ctx_ids[0], 'payload': payload} - msg2 = {'action': messaging.TG_METHOD_ITERATION, - 'id': self._ctx_ids[1], 'payload': payload} - self.consumer.iteration_index = 1 - - self.consumer._queue.empty.side_effect = [False, True] - self.consumer._queue.get.return_value = msg1 - self.assertFalse(self.consumer.is_all_kpis_received_in_iteration()) - - self.consumer._queue.empty.side_effect = [False, True] - self.consumer._queue.get.return_value = msg2 - self.assertTrue(self.consumer.is_all_kpis_received_in_iteration()) - - -class IterationIPCRunnerTestCase(ut_base.BaseUnitTestCase): - - @mock.patch.object(iteration_ipc, '_worker_process') - @mock.patch.object(os, 'getpid', return_value=12345678) - @mock.patch.object(multiprocessing, 'Process', return_value=mock.Mock()) - def test__run_benchmark(self, mock_process, mock_getpid, mock_worker): - method = 'method' - scenario_cfg = {'type': 'scenario_type'} - context_cfg = 'context_cfg' - name = '%s-%s-%s' % ('IterationIPC', 'scenario_type', 12345678) - runner = iteration_ipc.IterationIPCRunner(mock.ANY) - mock_getpid.reset_mock() - - runner._run_benchmark('class', method, scenario_cfg, context_cfg) - mock_process.assert_called_once_with( - name=name, - target=mock_worker, - args=(runner.result_queue, 'class', method, scenario_cfg, - context_cfg, runner.aborted, runner.output_queue)) - mock_getpid.assert_called_once() diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py index e9c680257..dc3a4b99a 100644 --- a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py +++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py @@ -63,3 +63,20 @@ class MultiMonitorServiceTestCase(unittest.TestCase): ins.start_monitor() ins.wait_monitor() ins.verify_SLA() + + def test__monitor_multi_no_sla(self, mock_open, mock_ssh): + monitor_cfg = { + 'monitor_type': 'general-monitor', + 'monitor_number': 3, + 'key': 'service-status', + 'monitor_key': 'service-status', + 'host': 'node1', + 'monitor_time': 0.1, + 'parameter': {'serviceName': 'haproxy'} + } + ins = monitor_multi.MultiMonitor( + monitor_cfg, self.context, {"nova-api": 10}) + mock_ssh.SSH.from_node().execute.return_value = (0, "running", '') + ins.start_monitor() + ins.wait_monitor() + self.assertTrue(ins.verify_SLA()) diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py index a6d2ca398..8c73bf221 100644 --- a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py +++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py @@ -55,3 +55,19 @@ class MonitorProcessTestCase(unittest.TestCase): ins.monitor_func() ins._result = {"outage_time": 10} ins.verify_SLA() + + def test__monitor_process_no_sla(self, mock_ssh): + + monitor_cfg = { + 'monitor_type': 'process', + 'process_name': 'nova-api', + 'host': "node1", + 'monitor_time': 1, + } + ins = monitor_process.MonitorProcess(monitor_cfg, self.context, {"nova-api": 10}) + + mock_ssh.SSH.from_node().execute.return_value = (0, "0", '') + ins.setup() + ins.monitor_func() + ins._result = {"outage_time": 10} + self.assertTrue(ins.verify_SLA()) diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py index 8214782b2..cf9a26a76 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -159,7 +159,7 @@ TRAFFIC_PROFILE = { class TestNetworkServiceTestCase(unittest.TestCase): def setUp(self): - self.tg__1 = { + self.tg__0 = { 'name': 'trafficgen_1.yardstick', 'ip': '10.10.10.11', 'role': 'TrafficGen', @@ -185,7 +185,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): }, } - self.vnf__1 = { + self.vnf__0 = { 'name': 'vnf.yardstick', 'ip': '10.10.10.12', 'host': '10.223.197.164', @@ -242,8 +242,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.context_cfg = { 'nodes': { - 'tg__1': self.tg__1, - 'vnf__1': self.vnf__1, + 'tg__0': self.tg__0, + 'vnf__0': self.vnf__0, }, 'networks': { GenericVNF.UPLINK: { @@ -270,7 +270,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ], 'type': 'ELAN', 'id': GenericVNF.UPLINK, - 'name': 'tg__1 to vnf__1 link 1' + 'name': 'tg__0 to vnf__0 link 1' } self.vld1 = { @@ -288,7 +288,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ], 'type': 'ELAN', 'id': GenericVNF.DOWNLINK, - 'name': 'vnf__1 to tg__1 link 2' + 'name': 'vnf__0 to tg__0 link 2' } self.topology = { @@ -300,12 +300,12 @@ class TestNetworkServiceTestCase(unittest.TestCase): { 'member-vnf-index': '1', 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'tg__1', + 'vnfd-id-ref': 'tg__0', }, { 'member-vnf-index': '2', 'VNF model': 'tg_trex_tpl.yaml', - 'vnfd-id-ref': 'vnf__1', + 'vnfd-id-ref': 'vnf__0', }, ], 'vld': [self.vld0, self.vld1], @@ -343,8 +343,8 @@ class TestNetworkServiceTestCase(unittest.TestCase): }, 'nodes': { 'tg__2': 'trafficgen_2.yardstick', - 'tg__1': 'trafficgen_1.yardstick', - 'vnf__1': 'vnf.yardstick', + 'tg__0': 'trafficgen_1.yardstick', + 'vnf__0': 'vnf.yardstick', }, } @@ -411,12 +411,12 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'flow': { 'src_ip': [ { - 'tg__1': 'xe0', + 'tg__0': 'xe0', }, ], 'dst_ip': [ { - 'tg__1': 'xe1', + 'tg__0': 'xe1', }, ], 'public_ip': ['1.1.1.1'], @@ -446,11 +446,10 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertIn('found in', exc_str) def test_load_vnf_models_invalid(self): - self.context_cfg["nodes"]['tg__1']['VNF model'] = \ + self.context_cfg["nodes"]['tg__0']['VNF model'] = \ self._get_file_abspath("tg_trex_tpl.yaml") - self.context_cfg["nodes"]['vnf__1']['VNF model'] = \ + self.context_cfg["nodes"]['vnf__0']['VNF model'] = \ self._get_file_abspath("tg_trex_tpl.yaml") - self.context_cfg['task_id'] = 'fake_task_id' vnf = mock.Mock(autospec=GenericVNF) self.s.get_vnf_impl = mock.Mock(return_value=vnf) @@ -470,13 +469,13 @@ class TestNetworkServiceTestCase(unittest.TestCase): nodes = self.context_cfg["nodes"] self.assertEqual('../../vnf_descriptors/tg_rfc2544_tpl.yaml', - nodes['tg__1']['VNF model']) + nodes['tg__0']['VNF model']) self.assertEqual('../../vnf_descriptors/vpe_vnf.yaml', - nodes['vnf__1']['VNF model']) + nodes['vnf__0']['VNF model']) def test_map_topology_to_infrastructure_insufficient_nodes(self): cfg = deepcopy(self.context_cfg) - del cfg['nodes']['vnf__1'] + del cfg['nodes']['vnf__0'] cfg_patch = mock.patch.object(self.s, 'context_cfg', cfg) with cfg_patch: @@ -490,10 +489,10 @@ class TestNetworkServiceTestCase(unittest.TestCase): cfg = deepcopy(self.s.context_cfg) # delete all, we don't know which will come first - del cfg['nodes']['vnf__1']['interfaces']['xe0']['local_mac'] - del cfg['nodes']['vnf__1']['interfaces']['xe1']['local_mac'] - del cfg['nodes']['tg__1']['interfaces']['xe0']['local_mac'] - del cfg['nodes']['tg__1']['interfaces']['xe1']['local_mac'] + del cfg['nodes']['vnf__0']['interfaces']['xe0']['local_mac'] + del cfg['nodes']['vnf__0']['interfaces']['xe1']['local_mac'] + del cfg['nodes']['tg__0']['interfaces']['xe0']['local_mac'] + del cfg['nodes']['tg__0']['interfaces']['xe1']['local_mac'] config_patch = mock.patch.object(self.s, 'context_cfg', cfg) with config_patch: @@ -508,7 +507,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): ssh.from_node.return_value = ssh_mock # purge an important key from the data structure - for interface in self.tg__1['interfaces'].values(): + for interface in self.tg__0['interfaces'].values(): del interface['local_mac'] with self.assertRaises(exceptions.IncorrectConfig) as raised: @@ -517,7 +516,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertIn('not found', str(raised.exception)) # restore local_mac - for index, interface in enumerate(self.tg__1['interfaces'].values()): + for index, interface in enumerate(self.tg__0['interfaces'].values()): interface['local_mac'] = '00:00:00:00:00:{:2x}'.format(index) # make a connection point ref with 3 points @@ -568,7 +567,6 @@ class TestNetworkServiceTestCase(unittest.TestCase): tgen.verify_traffic = lambda x: verified_dict tgen.terminate = mock.Mock(return_value=True) tgen.name = "tgen__1" - tgen.run_traffic.return_value = 'tg_id' vnf = mock.Mock(autospec=GenericVNF) vnf.runs_traffic = False vnf.terminate = mock.Mock(return_value=True) @@ -581,6 +579,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) self.s._fill_traffic_profile = \ mock.Mock(return_value=TRAFFIC_PROFILE) + self.assertIsNone(self.s.setup()) def test_setup_exception(self): with mock.patch("yardstick.ssh.SSH") as ssh: @@ -641,6 +640,14 @@ class TestNetworkServiceTestCase(unittest.TestCase): self.assertEqual({'imix': {'64B': 100}}, self.s._get_traffic_imix()) + def test__get_ip_priority(self): + with mock.patch.dict(self.scenario_cfg["options"], + {'priority': {'raw': '0x01'}}): + self.assertEqual({'raw': '0x01'}, self.s._get_ip_priority()) + + def test__get_ip_priority_exception(self): + self.assertEqual({}, self.s._get_ip_priority()) + @mock.patch.object(base.TrafficProfile, 'get') @mock.patch.object(vnfdgen, 'generate_vnfd') def test__fill_traffic_profile(self, mock_generate, mock_tprofile_get): @@ -657,6 +664,7 @@ class TestNetworkServiceTestCase(unittest.TestCase): 'extra_args': {'arg1': 'value1', 'arg2': 'value2'}, 'flow': {'flow': {}}, 'imix': {'imix': {'64B': 100}}, + 'priority': {}, 'uplink': {}, 'duration': 30, 'simulated_users': { @@ -705,9 +713,6 @@ class TestNetworkServiceTestCase(unittest.TestCase): ) self.assertEqual(self.s.topology, 'fake_nsd') - def test_get_mq_ids(self): - self.assertEqual(self.s._mq_ids, self.s.get_mq_ids()) - def test_teardown(self): vnf = mock.Mock(autospec=GenericVNF) vnf.terminate = mock.Mock(return_value=True) @@ -731,3 +736,138 @@ class TestNetworkServiceTestCase(unittest.TestCase): mock.Mock(return_value=True) with self.assertRaises(RuntimeError): self.s.teardown() + + +class TestNetworkServiceRFC2544TestCase(TestNetworkServiceTestCase): + + def setUp(self): + super(TestNetworkServiceRFC2544TestCase, self).setUp() + self.s = vnf_generic.NetworkServiceRFC2544(self.scenario_cfg, + self.context_cfg) + + def test_run(self): + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.name = "tgen__1" + tgen.wait_on_trafic.return_value = 'COMPLETE' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s._fill_traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = mock.Mock( + return_value={tgen.name: verified_dict}) + result = mock.Mock() + self.s.run(result) + self.s._fill_traffic_profile.assert_called_once() + result.push.assert_called_once() + + def test_setup(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + tgen.run_traffic.return_value = 'tg_id' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s.setup() + + def test_setup_exception(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.instantiate.side_effect = RuntimeError( + "error during instantiate") + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s._fill_traffic_profile = \ + mock.Mock(return_value=TRAFFIC_PROFILE) + with self.assertRaises(RuntimeError): + self.s.setup() + +class TestNetworkServiceRFC3511TestCase(TestNetworkServiceTestCase): + + def setUp(self): + super(TestNetworkServiceRFC3511TestCase, self).setUp() + self.s = vnf_generic.NetworkServiceRFC3511(self.scenario_cfg, + self.context_cfg) + + def test_run(self): + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.name = "tgen__1" + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s._fill_traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = mock.Mock() + result = mock.Mock() + self.s.run(result) + self.s._fill_traffic_profile.assert_called_once() + result.push.assert_called_once() + + def test_setup(self): + with mock.patch("yardstick.ssh.SSH") as ssh: + ssh_mock = mock.Mock(autospec=ssh.SSH) + ssh_mock.execute = \ + mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, "")) + ssh.from_node.return_value = ssh_mock + + tgen = mock.Mock(autospec=GenericTrafficGen) + tgen.traffic_finished = True + verified_dict = {"verified": True} + tgen.verify_traffic = lambda x: verified_dict + tgen.terminate = mock.Mock(return_value=True) + tgen.name = "tgen__1" + tgen.run_traffic.return_value = 'tg_id' + vnf = mock.Mock(autospec=GenericVNF) + vnf.runs_traffic = False + vnf.terminate = mock.Mock(return_value=True) + self.s.vnfs = [tgen, vnf] + self.s.traffic_profile = mock.Mock() + self.s.collector = mock.Mock(autospec=Collector) + self.s.collector.get_kpi = \ + mock.Mock(return_value={tgen.name: verified_dict}) + self.s.map_topology_to_infrastructure = mock.Mock(return_value=0) + self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs) + self.s.setup() diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml b/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml index 1ac6c1f89..aaf84bb5e 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml +++ b/yardstick/tests/unit/benchmark/scenarios/networking/vpe_vnf_topology.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Intel Corporation +# Copyright (c) 2016-2019 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,31 +20,31 @@ nsd:nsd-catalog: description: scenario with VPE,L3fwd and VNF constituent-vnfd: - member-vnf-index: '1' - vnfd-id-ref: tg__1 - VNF model: ../../vnf_descriptors/tg_rfc2544_tpl.yaml #tg_vpe_upstream.yaml #VPE VNF + vnfd-id-ref: tg__0 + VNF model: ../../vnf_descriptors/tg_rfc2544_tpl.yaml #tg_trex_tpl.yaml #TREX - member-vnf-index: '2' - vnfd-id-ref: vnf__1 - VNF model: ../../vnf_descriptors/vpe_vnf.yaml #tg_l3fwd.yaml #tg_trex_tpl.yaml #TREX + vnfd-id-ref: vnf__0 + VNF model: ../../vnf_descriptors/vpe_vnf.yaml #VPE VNF vld: - id: uplink - name: tg__1 to vnf__1 link 1 + name: tg__0 to vnf__0 link 1 type: ELAN vnfd-connection-point-ref: - member-vnf-index-ref: '1' vnfd-connection-point-ref: xe0 - vnfd-id-ref: tg__1 #TREX + vnfd-id-ref: tg__0 - member-vnf-index-ref: '2' vnfd-connection-point-ref: xe0 - vnfd-id-ref: vnf__1 #VNF + vnfd-id-ref: vnf__0 - id: downlink - name: vnf__1 to tg__1 link 2 + name: vnf__0 to tg__0 link 2 type: ELAN vnfd-connection-point-ref: - member-vnf-index-ref: '2' vnfd-connection-point-ref: xe1 - vnfd-id-ref: vnf__1 #L3fwd + vnfd-id-ref: vnf__0 - member-vnf-index-ref: '1' vnfd-connection-point-ref: xe1 - vnfd-id-ref: tg__1 #VPE VNF + vnfd-id-ref: tg__0 |