mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 20:11:20 +00:00
ConfigurationPoints: Added check that default values are POD's
Default config values will now need to be a Plain Old Data type. This commit includes some ultility functions to help with this check
This commit is contained in:
parent
d6735db364
commit
9905bb3162
@ -24,6 +24,7 @@ from wlauto.utils.types import (identifier, integer, boolean,
|
||||
list_of_strings, toggle_set,
|
||||
obj_dict)
|
||||
from wlauto.core.configuration.tree import SectionNode
|
||||
from wlauto.utils.serializer import is_pod
|
||||
|
||||
# Mapping for kind conversion; see docs for convert_types below
|
||||
KIND_MAP = {
|
||||
@ -228,6 +229,9 @@ class ConfigurationPoint(object):
|
||||
raise ValueError('Kind must be callable.')
|
||||
self.kind = kind
|
||||
self.mandatory = mandatory
|
||||
if not is_pod(default):
|
||||
msg = "The default for '{}' must be a Plain Old Data type, but it is of type '{}' instead."
|
||||
raise TypeError(msg.format(self.name, type(default)))
|
||||
self.default = default
|
||||
self.override = override
|
||||
self.allowed_values = allowed_values
|
||||
@ -798,7 +802,7 @@ class RunConfiguration(Configuration):
|
||||
the connected device. Obviously, this must match your setup.
|
||||
'''),
|
||||
ConfigurationPoint('retry_on_status', kind=status_list,
|
||||
default=status_list(['FAILED', 'PARTIAL']),
|
||||
default=['FAILED', 'PARTIAL'],
|
||||
allowed_values=ITERATION_STATUS,
|
||||
description='''
|
||||
This is list of statuses on which a job will be cosidered to have failed and
|
||||
|
@ -7,7 +7,7 @@ structures and Python class instances).
|
||||
|
||||
The modifications to standard serilization procedures are:
|
||||
|
||||
- mappings are deserialized as ``OrderedDict``\ 's are than standard
|
||||
- mappings are deserialized as ``OrderedDict``\ 's rather than standard
|
||||
Python ``dict``\ 's. This allows for cleaner syntax in certain parts
|
||||
of WA configuration (e.g. values to be written to files can be specified
|
||||
as a dict, and they will be written in the order specified in the config).
|
||||
@ -61,15 +61,27 @@ __all__ = [
|
||||
'read_pod',
|
||||
'dump',
|
||||
'load',
|
||||
'is_pod',
|
||||
'POD_TYPES',
|
||||
]
|
||||
|
||||
POD_TYPES = [
|
||||
list,
|
||||
tuple,
|
||||
dict,
|
||||
set,
|
||||
basestring,
|
||||
int,
|
||||
float,
|
||||
bool,
|
||||
datetime,
|
||||
regex_type
|
||||
]
|
||||
|
||||
class WAJSONEncoder(_json.JSONEncoder):
|
||||
|
||||
def default(self, obj): # pylint: disable=method-hidden
|
||||
if hasattr(obj, 'to_pod'):
|
||||
return obj.to_pod()
|
||||
elif isinstance(obj, regex_type):
|
||||
if isinstance(obj, regex_type):
|
||||
return 'REGEX:{}:{}'.format(obj.flags, obj.pattern)
|
||||
elif isinstance(obj, datetime):
|
||||
return 'DATET:{}'.format(obj.isoformat())
|
||||
@ -241,3 +253,7 @@ def _read_pod(fh, fmt=None):
|
||||
return python.load(fh)
|
||||
else:
|
||||
raise ValueError('Unknown format "{}": {}'.format(fmt, getattr(fh, 'name', '<none>')))
|
||||
|
||||
|
||||
def is_pod(obj):
|
||||
return type(obj) in POD_TYPES
|
||||
|
Loading…
x
Reference in New Issue
Block a user