[TrivialFix] Log only if document parentSelector set

This is intended to lessen the number of LOG statements being
dumped out. The log statement regarding missing document
parent will only be issued if the document has a parentSelector
and yet no parent for it could be found. Also, the log level
is changed to DEBUG so that it's only issued if CONF.debug is
True.

Change-Id: I32d3a43604b5fce564f6af5579a0b173625533a1
This commit is contained in:
Felipe Monteiro 2018-02-27 18:46:53 +00:00
parent 4e796ed30a
commit 7aca9a1a98
2 changed files with 16 additions and 11 deletions

View File

@ -178,9 +178,11 @@ class DocumentLayering(object):
# `layerOrder` of the LayeringPolicy, it should be a child document
# of another document.
if doc not in all_children_elements:
LOG.info('Could not find parent for document with name=%s, '
'schema=%s, layer=%s, parentSelector=%s.',
doc.name, doc.schema, doc.layer, doc.parent_selector)
if doc.parent_selector:
LOG.debug(
'Could not find parent for document with name=%s, '
'schema=%s, layer=%s, parentSelector=%s.', doc.name,
doc.schema, doc.layer, doc.parent_selector)
self._parentless_documents.append(doc)
# If the document is a child document of more than 1 parent, then
# the document has too many parents, which is a validation error.

View File

@ -103,9 +103,10 @@ class TestDocumentLayeringNegative(
'parentSelector'] = parent_selector
layering.DocumentLayering(documents)
self.assertRegexpMatches(mock_log.info.mock_calls[0][1][0],
'Could not find parent for document .*')
mock_log.info.reset_mock()
self.assertTrue(any('Could not find parent for document' in
mock_log.debug.mock_calls[x][1][0])
for x in range(len(mock_log.debug.mock_calls)))
mock_log.debug.reset_mock()
@mock.patch.object(layering, 'LOG', autospec=True)
def test_layering_unreferenced_parent_label(self, mock_log):
@ -117,9 +118,10 @@ class TestDocumentLayeringNegative(
documents[1]['metadata']['labels'] = parent_label
layering.DocumentLayering(documents)
self.assertRegexpMatches(mock_log.info.mock_calls[0][1][0],
'Could not find parent for document .*')
mock_log.info.reset_mock()
self.assertTrue(any('Could not find parent for document' in
mock_log.debug.mock_calls[x][1][0])
for x in range(len(mock_log.debug.mock_calls)))
mock_log.debug.reset_mock()
def test_layering_duplicate_parent_selector_2_layer(self):
# Validate that documents belonging to the same layer cannot have the
@ -155,8 +157,9 @@ class TestDocumentLayeringNegative(
'parentSelector'] = self_ref
layering.DocumentLayering(documents)
self.assertRegexpMatches(mock_log.info.mock_calls[0][1][0],
'Could not find parent for document .*')
self.assertTrue(any('Could not find parent for document' in
mock_log.debug.mock_calls[x][1][0])
for x in range(len(mock_log.debug.mock_calls)))
def test_layering_without_layering_policy_raises_exc(self):
doc_factory = factories.DocumentFactory(1, [1])