mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-31 10:11:17 +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,
|
list_of_strings, toggle_set,
|
||||||
obj_dict)
|
obj_dict)
|
||||||
from wlauto.core.configuration.tree import SectionNode
|
from wlauto.core.configuration.tree import SectionNode
|
||||||
|
from wlauto.utils.serializer import is_pod
|
||||||
|
|
||||||
# Mapping for kind conversion; see docs for convert_types below
|
# Mapping for kind conversion; see docs for convert_types below
|
||||||
KIND_MAP = {
|
KIND_MAP = {
|
||||||
@ -228,6 +229,9 @@ class ConfigurationPoint(object):
|
|||||||
raise ValueError('Kind must be callable.')
|
raise ValueError('Kind must be callable.')
|
||||||
self.kind = kind
|
self.kind = kind
|
||||||
self.mandatory = mandatory
|
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.default = default
|
||||||
self.override = override
|
self.override = override
|
||||||
self.allowed_values = allowed_values
|
self.allowed_values = allowed_values
|
||||||
@ -798,7 +802,7 @@ class RunConfiguration(Configuration):
|
|||||||
the connected device. Obviously, this must match your setup.
|
the connected device. Obviously, this must match your setup.
|
||||||
'''),
|
'''),
|
||||||
ConfigurationPoint('retry_on_status', kind=status_list,
|
ConfigurationPoint('retry_on_status', kind=status_list,
|
||||||
default=status_list(['FAILED', 'PARTIAL']),
|
default=['FAILED', 'PARTIAL'],
|
||||||
allowed_values=ITERATION_STATUS,
|
allowed_values=ITERATION_STATUS,
|
||||||
description='''
|
description='''
|
||||||
This is list of statuses on which a job will be cosidered to have failed and
|
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:
|
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
|
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
|
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).
|
as a dict, and they will be written in the order specified in the config).
|
||||||
@ -61,15 +61,27 @@ __all__ = [
|
|||||||
'read_pod',
|
'read_pod',
|
||||||
'dump',
|
'dump',
|
||||||
'load',
|
'load',
|
||||||
|
'is_pod',
|
||||||
|
'POD_TYPES',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
POD_TYPES = [
|
||||||
|
list,
|
||||||
|
tuple,
|
||||||
|
dict,
|
||||||
|
set,
|
||||||
|
basestring,
|
||||||
|
int,
|
||||||
|
float,
|
||||||
|
bool,
|
||||||
|
datetime,
|
||||||
|
regex_type
|
||||||
|
]
|
||||||
|
|
||||||
class WAJSONEncoder(_json.JSONEncoder):
|
class WAJSONEncoder(_json.JSONEncoder):
|
||||||
|
|
||||||
def default(self, obj): # pylint: disable=method-hidden
|
def default(self, obj): # pylint: disable=method-hidden
|
||||||
if hasattr(obj, 'to_pod'):
|
if isinstance(obj, regex_type):
|
||||||
return obj.to_pod()
|
|
||||||
elif isinstance(obj, regex_type):
|
|
||||||
return 'REGEX:{}:{}'.format(obj.flags, obj.pattern)
|
return 'REGEX:{}:{}'.format(obj.flags, obj.pattern)
|
||||||
elif isinstance(obj, datetime):
|
elif isinstance(obj, datetime):
|
||||||
return 'DATET:{}'.format(obj.isoformat())
|
return 'DATET:{}'.format(obj.isoformat())
|
||||||
@ -241,3 +253,7 @@ def _read_pod(fh, fmt=None):
|
|||||||
return python.load(fh)
|
return python.load(fh)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown format "{}": {}'.format(fmt, getattr(fh, 'name', '<none>')))
|
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