def test_parse_options(self): options = { 'openstack': { 'EXTERNAL_NETWORK': '$network' }, 'ndoes': ['node1', '$node'], 'host': '$host' } t = task.Task() t.outputs = { 'network': 'ext-net', 'node': 'node2', 'host': 'server.yardstick' } idle_result = { 'openstack': { 'EXTERNAL_NETWORK': 'ext-net' }, 'ndoes': ['node1', 'node2'], 'host': 'server.yardstick' } actual_result = t._parse_options(options) self.assertEqual(idle_result, actual_result)
def test_parse_options_no_teardown(self): options = { 'openstack': { 'EXTERNAL_NETWORK': '$network' }, 'nodes': ['node1', '$node'], 'host': '$host', 'contexts' : {'name': "my-context", 'no_teardown': True} } t = task.Task() t.outputs = { 'network': 'ext-net', 'node': 'node2', 'host': 'server.yardstick' } expected_result = { 'openstack': { 'EXTERNAL_NETWORK': 'ext-net' }, 'nodes': ['node1', 'node2'], 'host': 'server.yardstick', 'contexts': {'name': 'my-context', 'no_teardown': True, } } actual_result = t._parse_options(options) self.assertEqual(expected_result, actual_result)
def test__do_output(self, mock_dispatcher): t = task.Task() output_config = {"DEFAULT": {"dispatcher": "file, http"}} dispatcher1 = mock.MagicMock() dispatcher1.__dispatcher_type__ = 'file' dispatcher2 = mock.MagicMock() dispatcher2.__dispatcher_type__ = 'http' mock_dispatcher.get = mock.MagicMock(return_value=[dispatcher1, dispatcher2]) self.assertIsNone(t._do_output(output_config, {}))
def test__parse_tasks_render_only(self, mock_makedirs, mock_write_file, mock_exit): task_obj = task.Task() _uuid = uuid.uuid4() task_obj.task_id = _uuid task_files = ['/directory/task_file_name.yml'] mock_parser = mock.Mock() mock_parser.parse_task.return_value = {'rendered': 'File content'} mock_args = mock.Mock() mock_args.render_only = '/output_directory' task_obj._parse_tasks(mock_parser, task_files, mock_args, ['arg1'], ['file_arg1']) mock_makedirs.assert_called_once_with('/output_directory') mock_write_file.assert_called_once_with( '/output_directory/000-task_file_name.yml', 'File content') mock_exit.assert_called_once_with(0)
def test__parse_tasks(self): task_obj = task.Task() _uuid = uuid.uuid4() task_obj.task_id = _uuid task_files = ['/directory/task_file_name.yml'] mock_parser = mock.Mock() mock_parser.parse_task.return_value = {'rendered': 'File content'} mock_args = mock.Mock() mock_args.render_only = False tasks = task_obj._parse_tasks(mock_parser, task_files, mock_args, ['arg1'], ['file_arg1']) self.assertEqual( [{'rendered': 'File content', 'case_name': 'task_file_name'}], tasks) mock_parser.parse_task.assert_called_once_with( _uuid, 'arg1', 'file_arg1')
def test_run(self, mock_base_runner, mock_ctx): scenario = { 'host': 'athena.demo', 'target': 'ares.demo', 'runner': { 'duration': 60, 'interval': 1, 'type': 'Duration' }, 'type': 'Ping' } t = task.Task() runner = mock.Mock() runner.join.return_value = 0 mock_base_runner.Runner.get.return_value = runner t._run([scenario], False, "yardstick.out") self.assertTrue(runner.run.called)
def test_run(self, mock_base_runner, *args): scenario = { 'host': 'athena.demo', 'target': 'ares.demo', 'runner': { 'duration': 60, 'interval': 1, 'type': 'Duration' }, 'type': 'Ping' } t = task.Task() runner = mock.Mock() runner.join.return_value = 0 runner.get_output.return_value = {} runner.get_result.return_value = [] mock_base_runner.Runner.get.return_value = runner t._run([scenario], False, "yardstick.out") runner.run.assert_called_once()
def test__do_output(self, mock_dispatcher): t = task.Task() output_config = {"DEFAULT": {"dispatcher": "file, http"}} mock_dispatcher.get = mock.MagicMock( return_value=[mock.MagicMock(), mock.MagicMock()]) self.assertEqual(None, t._do_output(output_config, {}))
def test_set_dispatchers(self): t = task.Task() output_config = {"DEFAULT": {"dispatcher": "file, http"}} t._set_dispatchers(output_config) self.assertEqual(output_config, output_config)
def test_set_log(self, mock_logging, mock_utils): task_obj = task.Task() task_obj.task_id = 'task_id' task_obj._set_log() self.assertTrue(mock_logging.root.addHandler.called)
def test_set_log(self, mock_logging_root, *args): task_obj = task.Task() task_obj.task_id = 'task_id' task_obj._set_log() mock_logging_root.addHandler.assert_called()