From 4d5a93a2a1e3a419351e75ecb7f14b92ec5d6eb8 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 28 Jun 2017 16:05:26 -0700 Subject: [PATCH] Allow compose node without properties Valence should allow user to compose node without properties, and let podm to assign one by default, but validation schema block it. So fix it in schema for node composition. Change-Id: I00e08aae3d33bbd37c0bac633345c09eb19342af Closes-Bug: #1701122 --- .../tests/unit/validation/test_validation.py | 1 + valence/validation/schemas.py | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/valence/tests/unit/validation/test_validation.py b/valence/tests/unit/validation/test_validation.py index 77e290a..af388a8 100644 --- a/valence/tests/unit/validation/test_validation.py +++ b/valence/tests/unit/validation/test_validation.py @@ -168,6 +168,7 @@ class TestNodeApi(TestApiValidation): def test_compose_request_invalid_params(self): req = { "name": "test_request1", + "properties": {"invalid_key": "invalid_value"} } resp = self.app.post('/v1/nodes', content_type='application/json', diff --git a/valence/validation/schemas.py b/valence/validation/schemas.py index 3c59f8a..185a7cd 100644 --- a/valence/validation/schemas.py +++ b/valence/validation/schemas.py @@ -95,10 +95,42 @@ compose_node_with_flavor = { 'additionalProperties': False, } +compose_node_with_properties = { + 'type': 'object', + 'properties': { + 'name': {'type': 'string'}, + 'description': {'type': 'string'}, + 'properties': { + 'type': 'object', + 'properties': { + 'memory': { + 'type': 'object', + 'properties': { + 'capacity_mib': {'type': 'string'}, + 'type': {'type': 'string'} + }, + 'additionalProperties': False, + }, + 'processor': { + 'type': 'object', + 'properties': { + 'total_cores': {'type': 'string'}, + 'model': {'type': 'string'}, + }, + 'additionalProperties': False, + }, + }, + 'additionalProperties': False, + }, + }, + 'required': ['name'], + 'additionalProperties': False, +} + compose_node_schema = { 'anyOf': [ compose_node_with_flavor, - flavor_schema, + compose_node_with_properties ] }