summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Monteiro <felipe.monteiro@att.com>2018-10-28 22:37:26 -0400
committerFelipe Monteiro <felipe.monteiro@att.com>2019-01-18 21:52:04 +0000
commitd5462d0c7046a8e5a134348c0c23cd0b073183e0 (patch)
tree0119ad9af018a822392ddeaa77c66f4f3f6db194
parentf745e4b6e76f2b6aa5edf22e33a3f2d26e3c27c9 (diff)
schema: Fix metadata schema patterns
This patch set fixes the schema pattern enforced by metadata_document and metadata_control. Currently, both allow a schema with either pattern: - ^metadata/Control/v\d+$ - ^metadata/Document/v\d+$ However, the metadata_control schema should only allow the former and the metadata_document schema should only allow the latter. Change-Id: Ic1b88a7158755818002de4c88cdf2d7b716f656d
Notes
Notes (review): Code-Review+2: Aaron Sheffield <ajs@sheffieldfamily.net> Code-Review+1: Rick Bartra <rb560u@att.com> Workflow+1: Felipe Monteiro <felipe.monteiro@att.com> Code-Review+2: Felipe Monteiro <felipe.monteiro@att.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 18 Jan 2019 23:05:22 +0000 Reviewed-on: https://review.openstack.org/613824 Project: openstack/airship-deckhand Branch: refs/heads/master
-rw-r--r--deckhand/engine/document_validation.py16
-rw-r--r--deckhand/engine/schemas/metadata_control.yaml7
-rw-r--r--deckhand/engine/schemas/metadata_document.yaml7
3 files changed, 12 insertions, 18 deletions
diff --git a/deckhand/engine/document_validation.py b/deckhand/engine/document_validation.py
index d994781..37bd547 100644
--- a/deckhand/engine/document_validation.py
+++ b/deckhand/engine/document_validation.py
@@ -192,7 +192,7 @@ class GenericValidator(BaseValidator):
192class DataSchemaValidator(GenericValidator): 192class DataSchemaValidator(GenericValidator):
193 """Validator for validating ``DataSchema`` documents.""" 193 """Validator for validating ``DataSchema`` documents."""
194 194
195 __slots__ = ('_default_schema_map', '_external_data_schemas') 195 __slots__ = ('_default_schema_map', '_current_data_schemas')
196 196
197 def _build_schema_map(self, data_schemas): 197 def _build_schema_map(self, data_schemas):
198 schema_map = copy.deepcopy(self._default_schema_map) 198 schema_map = copy.deepcopy(self._default_schema_map)
@@ -218,7 +218,7 @@ class DataSchemaValidator(GenericValidator):
218 global _DEFAULT_SCHEMAS 218 global _DEFAULT_SCHEMAS
219 219
220 self._default_schema_map = _DEFAULT_SCHEMAS 220 self._default_schema_map = _DEFAULT_SCHEMAS
221 self._external_data_schemas = [d.data for d in data_schemas] 221 self._current_data_schemas = [d.data for d in data_schemas]
222 self._schema_map = self._build_schema_map(data_schemas) 222 self._schema_map = self._build_schema_map(data_schemas)
223 223
224 def _generate_validation_error_output(self, schema, document, error, 224 def _generate_validation_error_output(self, schema, document, error,
@@ -424,9 +424,9 @@ class DocumentValidation(object):
424 """ 424 """
425 425
426 self._documents = [] 426 self._documents = []
427 self._external_data_schemas = [document_wrapper.DocumentDict(d) 427 self._current_data_schemas = [document_wrapper.DocumentDict(d)
428 for d in existing_data_schemas or []] 428 for d in existing_data_schemas or []]
429 data_schema_map = {d.meta: d for d in self._external_data_schemas} 429 data_schema_map = {d.meta: d for d in self._current_data_schemas}
430 430
431 raw_properties = ('data', 'metadata', 'schema') 431 raw_properties = ('data', 'metadata', 'schema')
432 432
@@ -441,11 +441,11 @@ class DocumentValidation(object):
441 441
442 document = document_wrapper.DocumentDict(raw_document) 442 document = document_wrapper.DocumentDict(raw_document)
443 if document.schema.startswith(types.DATA_SCHEMA_SCHEMA): 443 if document.schema.startswith(types.DATA_SCHEMA_SCHEMA):
444 self._external_data_schemas.append(document) 444 self._current_data_schemas.append(document)
445 # If a newer version of the same DataSchema was passed in, 445 # If a newer version of the same DataSchema was passed in,
446 # only use the new one and discard the old one. 446 # only use the new one and discard the old one.
447 if document.meta in data_schema_map: 447 if document.meta in data_schema_map:
448 self._external_data_schemas.remove( 448 self._current_data_schemas.remove(
449 data_schema_map.pop(document.meta)) 449 data_schema_map.pop(document.meta))
450 450
451 self._documents.append(document) 451 self._documents.append(document)
@@ -453,7 +453,7 @@ class DocumentValidation(object):
453 self._pre_validate = pre_validate 453 self._pre_validate = pre_validate
454 454
455 self._validators = [ 455 self._validators = [
456 DataSchemaValidator(self._external_data_schemas), 456 DataSchemaValidator(self._current_data_schemas),
457 ] 457 ]
458 if self._pre_validate: 458 if self._pre_validate:
459 # Only perform this additional validation "offline". The controller 459 # Only perform this additional validation "offline". The controller
diff --git a/deckhand/engine/schemas/metadata_control.yaml b/deckhand/engine/schemas/metadata_control.yaml
index 8a7adb1..3a86515 100644
--- a/deckhand/engine/schemas/metadata_control.yaml
+++ b/deckhand/engine/schemas/metadata_control.yaml
@@ -8,11 +8,8 @@ data:
8 type: object 8 type: object
9 properties: 9 properties:
10 schema: 10 schema:
11 anyOf: 11 type: string
12 - type: string 12 pattern: ^metadata/Control/v\d+$
13 pattern: ^metadata/Document/v\d+$
14 - type: string
15 pattern: ^metadata/Control/v\d+$
16 name: 13 name:
17 type: string 14 type: string
18 labels: 15 labels:
diff --git a/deckhand/engine/schemas/metadata_document.yaml b/deckhand/engine/schemas/metadata_document.yaml
index a64067b..dbd2463 100644
--- a/deckhand/engine/schemas/metadata_document.yaml
+++ b/deckhand/engine/schemas/metadata_document.yaml
@@ -44,11 +44,8 @@ data:
44 type: object 44 type: object
45 properties: 45 properties:
46 schema: 46 schema:
47 anyOf: 47 type: string
48 - type: string 48 pattern: ^metadata/Document/v\d+$
49 pattern: ^metadata/Document/v\d+$
50 - type: string
51 pattern: ^metadata/Control/v\d+$
52 name: 49 name:
53 type: string 50 type: string
54 labels: 51 labels: