From ef4efad6796680b1c948c490ee2d5af254b7c4f6 Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Mon, 12 Sep 2016 13:56:19 +0300 Subject: [PATCH] Added graph_type and dry_run flag for tasks output Also changed behaviour of method get_display_data_single, it uses special value for missing fields instead of raising exception. Change-Id: I2b92b66f47e4e5c866790f486571f69ff5ae14dd Closes-Bug: 1622563 (cherry picked from commit d29dcfcc5009757c60a20f6c29bf6b90a701581f) --- fuelclient/commands/task.py | 4 ++++ fuelclient/common/data_utils.py | 10 +++------- fuelclient/tests/unit/common/test_utils.py | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fuelclient/commands/task.py b/fuelclient/commands/task.py index 3bc4b52..5ba3aa7 100644 --- a/fuelclient/commands/task.py +++ b/fuelclient/commands/task.py @@ -126,8 +126,10 @@ class TaskList(TaskMixIn, base.BaseListCommand): columns = ('id', 'status', 'name', + 'graph_type', 'cluster', 'result', + 'dry_run', 'progress') @@ -137,8 +139,10 @@ class TaskShow(TaskMixIn, base.BaseShowCommand): 'uuid', 'status', 'name', + 'graph_type', 'cluster', 'result', + 'dry_run', 'progress', 'message') diff --git a/fuelclient/common/data_utils.py b/fuelclient/common/data_utils.py index 95202ee..7b52d68 100644 --- a/fuelclient/common/data_utils.py +++ b/fuelclient/common/data_utils.py @@ -16,27 +16,23 @@ import json import os import yaml -from fuelclient.cli import error from fuelclient import utils -def get_display_data_single(fields, data): +def get_display_data_single(fields, data, missing_field_value=None): """Performs slicing of data by set of given fields :param fields: Iterable containing names of fields to be retrieved from data :param data: Collection of JSON objects representing some external entities + :param missing_field_value: the value will be used for all missing fields :return: list containing the collection of values of the supplied attributes. """ - try: - return [data[field] for field in fields] - except KeyError as e: - raise error.BadDataException('{} is not found in the supplied ' - 'data.'.format(e.args[0])) + return [data.get(field, missing_field_value) for field in fields] def get_display_data_multi(fields, data): diff --git a/fuelclient/tests/unit/common/test_utils.py b/fuelclient/tests/unit/common/test_utils.py index 0c807bf..751a9ab 100644 --- a/fuelclient/tests/unit/common/test_utils.py +++ b/fuelclient/tests/unit/common/test_utils.py @@ -203,10 +203,10 @@ class TestUtils(base.UnitTestCase): def test_get_display_data_bad_key(self): test_data = {'a': 1, 'b': 2, 'c': 3} fields = ('b', 'bad_key') - - self.assertRaises(error.BadDataException, - data_utils.get_display_data_single, - fields, test_data) + self.assertEqual( + [2, None], + data_utils.get_display_data_single(fields, test_data) + ) def test_get_display_data_multi(self): test_data = [{'a': 1, 'b': 2, 'c': 3}, {'b': 8, 'c': 9}]