From 7aca9a1a98b68628c6d14c97c1b9608310a158da Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Tue, 27 Feb 2018 18:46:53 +0000 Subject: [PATCH] [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 --- deckhand/engine/layering.py | 8 +++++--- .../engine/test_document_layering_negative.py | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/deckhand/engine/layering.py b/deckhand/engine/layering.py index 603481eb..dbb899c4 100644 --- a/deckhand/engine/layering.py +++ b/deckhand/engine/layering.py @@ -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. diff --git a/deckhand/tests/unit/engine/test_document_layering_negative.py b/deckhand/tests/unit/engine/test_document_layering_negative.py index aaa17026..aca187f5 100644 --- a/deckhand/tests/unit/engine/test_document_layering_negative.py +++ b/deckhand/tests/unit/engine/test_document_layering_negative.py @@ -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])