Drop concept of '?validation' parameter
We had planned to introduce a 'validation' parameter to the various extra spec APIs in change If67f0d924ea372746a6dc440ea7bdc655e4f0bea to configure a policy for extra spec validation. Following reviews, we've decided to instead go with a strict policy for all known namespaces and no validation for any unknown namespaces. Update the tests we had in place for this. Part of blueprint flavor-extra-spec-validators Change-Id: If30990ec1c43177b7d13bd8ee1c5dc481265e47b Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -26,19 +26,16 @@ from nova import exception
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
VALIDATORS: ty.Dict[str, base.ExtraSpecValidator] = {}
|
||||
NAMESPACES: ty.Set[str] = set()
|
||||
|
||||
|
||||
def validate(name: str, value: str, mode: str):
|
||||
def validate(name: str, value: str):
|
||||
"""Validate a given extra spec.
|
||||
|
||||
:param name: Extra spec name.
|
||||
:param value: Extra spec value.
|
||||
:param mode: Validation mode; one of: strict, permissive, disabled
|
||||
:raises: exception.ValidationError if validation fails.
|
||||
"""
|
||||
if mode == 'disabled':
|
||||
return
|
||||
|
||||
# attempt a basic lookup for extra specs without embedded parameters
|
||||
if name in VALIDATORS:
|
||||
VALIDATORS[name].validate(name, value)
|
||||
@@ -50,7 +47,8 @@ def validate(name: str, value: str, mode: str):
|
||||
validator.validate(name, value)
|
||||
return
|
||||
|
||||
if mode == 'permissive': # unregistered extra spec, ignore
|
||||
namespace = name.split(':', 1)[0].split('{')[0] if ':' in name else None
|
||||
if not namespace or namespace not in NAMESPACES: # unregistered namespace
|
||||
return
|
||||
|
||||
raise exception.ValidationError(
|
||||
@@ -74,6 +72,8 @@ def load_validators():
|
||||
# TODO(stephenfin): Make 'register' return a dict rather than a list?
|
||||
for validator in ext.plugin.register():
|
||||
VALIDATORS[validator.name] = validator
|
||||
if ':' in validator.name:
|
||||
NAMESPACES.add(validator.name.split(':', 1)[0].split('{')[0])
|
||||
|
||||
|
||||
load_validators()
|
||||
|
||||
Reference in New Issue
Block a user