Do not process additional fields in search response
API can return additional fields in the search response data. Search fails in this case with exception from the client. This patch adds code that ignores processing of these fields, additional information redirects to debug log. Closes-Bug: #1621061 Change-Id: I749057d217518447cb24f9727a883e2cb148218a
This commit is contained in:
parent
3cf93f7f64
commit
8ac0b8bc9e
|
@ -114,14 +114,21 @@ class SearchResource(command.Lister):
|
|||
result = []
|
||||
for r in data.hits['hits']:
|
||||
converted = {}
|
||||
extra = {}
|
||||
# hit._id may include extra information appended after _,
|
||||
# so use r['_source']['id'] for safe.
|
||||
r['_id'] = r.get('_source', {}).get('id')
|
||||
for k, v in six.iteritems(r):
|
||||
converted[mapping[k]] = v
|
||||
if k == "_source" and not parsed_args.source:
|
||||
converted["name"] = v.get("name")
|
||||
converted["updated"] = v.get("updated_at")
|
||||
map_key = mapping.get(k)
|
||||
if map_key is not None:
|
||||
converted[map_key] = v
|
||||
if k == "_source" and not parsed_args.source:
|
||||
converted["name"] = v.get("name")
|
||||
converted["updated"] = v.get("updated_at")
|
||||
else:
|
||||
extra[k] = v
|
||||
if extra:
|
||||
self.log.debug("extra info returned: %s", extra)
|
||||
result.append(utils.get_dict_properties(converted, columns))
|
||||
return (columns, result)
|
||||
|
||||
|
|
|
@ -29,11 +29,10 @@ class TestSearchResource(TestSearch):
|
|||
def setUp(self):
|
||||
super(TestSearchResource, self).setUp()
|
||||
self.cmd = search.SearchResource(self.app, None)
|
||||
fake_data = copy.deepcopy(searchlight_fakes.Resource)
|
||||
fake_data['hits']['hits'][0]['is_not_processed'] = 'foo'
|
||||
self.search_client.search.return_value = \
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(searchlight_fakes.Resource),
|
||||
loaded=True)
|
||||
fakes.FakeResource(None, fake_data, loaded=True)
|
||||
|
||||
def _test_search(self, arglist, **assertArgs):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
|
Loading…
Reference in New Issue