From 69730d80b20d5da8bf163b40e58345016fb007cc Mon Sep 17 00:00:00 2001 From: Yumeng_Bao Date: Fri, 9 Jun 2017 12:01:23 +0800 Subject: [PATCH] Replace voluptuous with JSONSchema to validate nop action Now in watcher,both JSONSchema and voluptuous are used to validate JSON payloads. We want to remove voluptuous and Use JSONSchema as our only JSON validation tool to keep consistence and also to make it easier to expose the validation schema through our API in future work. In this patch, we replace voluptuous with JSONSchema to validate the nop action in watcher applier. Partially Implements: blueprint jsonschema-validation Change-Id: Idf42b3359c36ac9480bd1f1bdd31e756214628ef --- watcher/applier/actions/nop.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/watcher/applier/actions/nop.py b/watcher/applier/actions/nop.py index 0a4969b18..ee4ac8c7e 100644 --- a/watcher/applier/actions/nop.py +++ b/watcher/applier/actions/nop.py @@ -17,9 +17,8 @@ # limitations under the License. # +import jsonschema from oslo_log import log -import six -import voluptuous from watcher.applier.actions import base @@ -43,10 +42,23 @@ class Nop(base.BaseAction): @property def schema(self): - return voluptuous.Schema({ - voluptuous.Required(self.MESSAGE): voluptuous.Any( - voluptuous.Any(*six.string_types), None) - }) + return { + 'type': 'object', + 'properties': { + 'message': { + 'type': ['string', 'null'] + } + }, + 'required': ['message'], + 'additionalProperties': False, + } + + def validate_parameters(self): + try: + jsonschema.validate(self.input_parameters, self.schema) + return True + except jsonschema.ValidationError as e: + raise e @property def message(self):