From 88fe773cd7615ded05657329f39d2fd79af6ad7e Mon Sep 17 00:00:00 2001 From: Rick Bartra Date: Sun, 21 Oct 2018 21:24:41 -0400 Subject: [PATCH] Fix document is_control method The document.py `is_control` method incorrectly checks if a document is a Control document. Per the documentation [0], Control documents have `metadata.schema` of `metadata/Control/v1`. This commit updates the `is_control` method to correctly check for Control documents. [0] https://github.com/openstack/airship-deckhand/blob/1d4cc81dfaa9a5280625074e569fa4ab9dc7fd09/doc/source/users/document-types.rst#control-documents Change-Id: I60ca8f31a61987b4e756784fce0f5a751639ae9e --- deckhand/common/document.py | 2 +- .../engine/test_document_layering_negative.py | 24 +++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/deckhand/common/document.py b/deckhand/common/document.py index 739cfc3d..04877c5a 100644 --- a/deckhand/common/document.py +++ b/deckhand/common/document.py @@ -75,7 +75,7 @@ class DocumentDict(dict): @property def is_control(self): - return self.schema.startswith('deckhand/Control') + return self.metadata.get('schema', '').startswith('metadata/Control') @property def layering_definition(self): diff --git a/deckhand/tests/unit/engine/test_document_layering_negative.py b/deckhand/tests/unit/engine/test_document_layering_negative.py index 1ca1bc37..85a7f42e 100644 --- a/deckhand/tests/unit/engine/test_document_layering_negative.py +++ b/deckhand/tests/unit/engine/test_document_layering_negative.py @@ -221,31 +221,19 @@ class TestDocumentLayeringNegative( self.assertRaises( errors.InvalidDocumentParent, self._test_layering, documents) - def test_layering_invalid_layer_order_raises_exc(self): - """Validate that an invalid layerOrder (which means that the document + def test_layering_empty_layer_order_raises_exc(self): + """Validate that an empty layerOrder (which means that the document layer won't be found in the layerOrder) raises an exception. """ doc_factory = factories.DocumentFactory(1, [1]) - lp_template, document = doc_factory.gen_test({ - "_GLOBAL_SUBSTITUTIONS_1_": [{ - "dest": { - "path": ".c" - }, - "src": { - "schema": "deckhand/Certificate/v1", - "name": "global-cert", - "path": "." - } + layering_policy, document = doc_factory.gen_test( + {}, global_abstract=False) - }], - }, global_abstract=False) - - layering_policy = copy.deepcopy(lp_template) - del layering_policy['data']['layerOrder'] + layering_policy['data']['layerOrder'] = [] error_re = "layer \'global\' .* was not found in layerOrder.*" self.assertRaisesRegexp( errors.InvalidDocumentLayer, error_re, self._test_layering, - [layering_policy, document], validate=True) + [layering_policy, document]) class TestDocumentLayeringValidationNegative(