mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-21 12:28:44 +00:00
Merge pull request #503 from setrofim/energy-backend-param-fix
energy instrument backends parameter validation fix
This commit is contained in:
commit
1fe3ed9f96
@ -118,6 +118,10 @@ class LoggingConfig(dict):
|
|||||||
'color': True,
|
'color': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_pod(pod):
|
||||||
|
return LoggingConfig(pod)
|
||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
if isinstance(config, dict):
|
if isinstance(config, dict):
|
||||||
@ -136,6 +140,9 @@ class LoggingConfig(dict):
|
|||||||
else:
|
else:
|
||||||
raise ValueError(config)
|
raise ValueError(config)
|
||||||
|
|
||||||
|
def to_pod(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
def get_type_name(kind):
|
def get_type_name(kind):
|
||||||
typename = str(kind)
|
typename = str(kind)
|
||||||
@ -254,7 +261,7 @@ class ConfigurationPoint(object):
|
|||||||
def set_value(self, obj, value=None, check_mandatory=True):
|
def set_value(self, obj, value=None, check_mandatory=True):
|
||||||
if value is None:
|
if value is None:
|
||||||
if self.default is not None:
|
if self.default is not None:
|
||||||
value = self.default
|
value = self.kind(self.default)
|
||||||
elif check_mandatory and self.mandatory:
|
elif check_mandatory and self.mandatory:
|
||||||
msg = 'No values specified for mandatory parameter "{}" in {}'
|
msg = 'No values specified for mandatory parameter "{}" in {}'
|
||||||
raise ConfigError(msg.format(self.name, obj.name))
|
raise ConfigError(msg.format(self.name, obj.name))
|
||||||
|
@ -29,7 +29,7 @@ from wa import Instrument, Parameter
|
|||||||
from wa.framework import pluginloader
|
from wa.framework import pluginloader
|
||||||
from wa.framework.plugin import Plugin
|
from wa.framework.plugin import Plugin
|
||||||
from wa.framework.exception import ConfigError
|
from wa.framework.exception import ConfigError
|
||||||
from wa.utils.types import list_of_strings, list_of_ints, list_or_string
|
from wa.utils.types import list_of_strings, list_of_ints, list_or_string, obj_dict
|
||||||
|
|
||||||
|
|
||||||
class EnergyInstrumentBackend(Plugin):
|
class EnergyInstrumentBackend(Plugin):
|
||||||
@ -214,18 +214,16 @@ class EnergyMeasurement(Instrument):
|
|||||||
self.measurement_csv = None
|
self.measurement_csv = None
|
||||||
self.loader = loader
|
self.loader = loader
|
||||||
self.backend = self.loader.get_plugin(self.instrument)
|
self.backend = self.loader.get_plugin(self.instrument)
|
||||||
self.params = {}
|
self.params = obj_dict()
|
||||||
|
|
||||||
if self.backend.instrument.mode != CONTINUOUS:
|
if self.backend.instrument.mode != CONTINUOUS:
|
||||||
msg = '{} instrument does not support continuous measurement collection'
|
msg = '{} instrument does not support continuous measurement collection'
|
||||||
raise ConfigError(msg.format(self.instrument))
|
raise ConfigError(msg.format(self.instrument))
|
||||||
|
|
||||||
supported_params = self.backend.get_parameters()
|
supported_params = self.backend.get_parameters()
|
||||||
for name, value in supported_params.iteritems():
|
for name, param in supported_params.iteritems():
|
||||||
if name in self.instrument_parameters:
|
value = self.instrument_parameters.get(name)
|
||||||
self.params[name] = self.instrument_parameters[name]
|
param.set_value(self.params, value)
|
||||||
elif value.default:
|
|
||||||
self.params[name] = value.default
|
|
||||||
self.backend.validate_parameters(self.params)
|
self.backend.validate_parameters(self.params)
|
||||||
|
|
||||||
def initialize(self, context):
|
def initialize(self, context):
|
||||||
|
@ -107,6 +107,12 @@ def list_of(type_):
|
|||||||
def extend(self, other):
|
def extend(self, other):
|
||||||
list.extend(self, map(type_, other))
|
list.extend(self, map(type_, other))
|
||||||
|
|
||||||
|
def from_pod(cls, pod):
|
||||||
|
return cls(map(type_, pod))
|
||||||
|
|
||||||
|
def _to_pod(self):
|
||||||
|
return self
|
||||||
|
|
||||||
def __setitem__(self, idx, value):
|
def __setitem__(self, idx, value):
|
||||||
list.__setitem__(self, idx, type_(value))
|
list.__setitem__(self, idx, type_(value))
|
||||||
|
|
||||||
@ -116,6 +122,8 @@ def list_of(type_):
|
|||||||
"__setitem__": __setitem__,
|
"__setitem__": __setitem__,
|
||||||
"append": append,
|
"append": append,
|
||||||
"extend": extend,
|
"extend": extend,
|
||||||
|
"to_pod": _to_pod,
|
||||||
|
"from_pod": classmethod(from_pod),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user