koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame^] | 1 | import abc |
| 2 | from typing import Dict, Any, Tuple |
| 3 | from collections import OrderedDict |
| 4 | |
| 5 | from ..common_types import Storable |
| 6 | |
| 7 | |
| 8 | class JobParams(metaclass=abc.ABCMeta): |
| 9 | """Class contains all job parameters, which significantly affects job results. |
| 10 | Like block size or operation type, but not file name or file size. |
| 11 | Can be used as key in dictionary |
| 12 | """ |
| 13 | |
| 14 | def __init__(self, **params: Dict[str, Any]) -> None: |
| 15 | self.params = params |
| 16 | |
| 17 | @abc.abstractproperty |
| 18 | def summary(self) -> str: |
| 19 | """Test short summary, used mostly for file names and short image description""" |
| 20 | pass |
| 21 | |
| 22 | @abc.abstractproperty |
| 23 | def long_summary(self) -> str: |
| 24 | """Readable long summary for management and deployment engineers""" |
| 25 | pass |
| 26 | |
| 27 | def __getitem__(self, name: str) -> Any: |
| 28 | return self.params[name] |
| 29 | |
| 30 | def __setitem__(self, name: str, val: Any) -> None: |
| 31 | self.params[name] = val |
| 32 | |
| 33 | def __hash__(self) -> int: |
| 34 | return hash(tuple(sorted(self.params.items()))) |
| 35 | |
| 36 | def __eq__(self, o: 'JobParams') -> bool: |
| 37 | return sorted(self.params.items()) == sorted(o.params.items()) |
| 38 | |
| 39 | |
| 40 | class JobConfig(Storable, metaclass=abc.ABCMeta): |
| 41 | """Job config class""" |
| 42 | |
| 43 | def __init__(self, idx: int) -> None: |
| 44 | # job id, used in storage to distinct jobs with same summary |
| 45 | self.idx = idx |
| 46 | |
| 47 | # time interval, in seconds, when test was running on all nodes |
| 48 | self.reliable_info_time_range = None # type: Tuple[int, int] |
| 49 | |
| 50 | # all job parameters, both from suite file and config file |
| 51 | self.vals = OrderedDict() # type: Dict[str, Any] |
| 52 | |
| 53 | @property |
| 54 | def storage_id(self) -> str: |
| 55 | """unique string, used as key in storage""" |
| 56 | return "{}_{}".format(self.params.summary, self.idx) |
| 57 | |
| 58 | @abc.abstractproperty |
| 59 | def params(self) -> JobParams: |
| 60 | """Should return a copy""" |
| 61 | pass |