Add Voluptuous to validate the action parameters

We want a simplest way to validate the input parameters of an
Action through a schema.

APIImpact
DocImpact
Partially implements: blueprint watcher-add-actions-via-conf

Change-Id: I139775f467fe7778c7354b0cfacf796fc27ffcb2
This commit is contained in:
Jean-Emile DARTOIS
2016-01-26 15:31:18 +01:00
committed by Vincent Françoise
parent 33ee575936
commit e3198d25a5
32 changed files with 771 additions and 503 deletions

View File

@@ -87,13 +87,13 @@ class BaseSolution(object):
@abc.abstractmethod
def add_action(self,
action_type,
applies_to,
resource_id,
input_parameters=None):
"""Add a new Action in the Action Plan
:param action_type: the unique id of an action type defined in
entry point 'watcher_actions'
:param applies_to: the unique id of the resource to which the
:param resource_id: the unique id of the resource to which the
`Action` applies.
:param input_parameters: An array of input parameters provided as
key-value pairs of strings. Each key-pair contains names and

View File

@@ -18,12 +18,14 @@
#
from oslo_log import log
from watcher.decision_engine.solution.base import BaseSolution
from watcher.applier.actions import base as baction
from watcher.common import exception
from watcher.decision_engine.solution import base
LOG = log.getLogger(__name__)
class DefaultSolution(BaseSolution):
class DefaultSolution(base.BaseSolution):
def __init__(self):
"""Stores a set of actions generated by a strategy
@@ -34,12 +36,17 @@ class DefaultSolution(BaseSolution):
self._actions = []
def add_action(self, action_type,
applies_to,
input_parameters=None):
# todo(jed) add https://pypi.python.org/pypi/schema
input_parameters=None,
resource_id=None):
if input_parameters is not None:
if baction.BaseAction.RESOURCE_ID in input_parameters.keys():
raise exception.ReservedWord(name=baction.BaseAction.
RESOURCE_ID)
if resource_id is not None:
input_parameters[baction.BaseAction.RESOURCE_ID] = resource_id
action = {
'action_type': action_type,
'applies_to': applies_to,
'input_parameters': input_parameters
}
self._actions.append(action)