koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 1 | import abc |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 2 | from typing import Dict, Any, Tuple, cast, Union |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 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 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame^] | 17 | @property |
| 18 | @abc.abstractmethod |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 19 | def summary(self) -> str: |
| 20 | """Test short summary, used mostly for file names and short image description""" |
| 21 | pass |
| 22 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame^] | 23 | @property |
| 24 | @abc.abstractmethod |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 25 | def long_summary(self) -> str: |
| 26 | """Readable long summary for management and deployment engineers""" |
| 27 | pass |
| 28 | |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 29 | @abc.abstractmethod |
| 30 | def copy(self, **updated) -> 'JobParams': |
| 31 | pass |
| 32 | |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 33 | def __getitem__(self, name: str) -> Any: |
| 34 | return self.params[name] |
| 35 | |
| 36 | def __setitem__(self, name: str, val: Any) -> None: |
| 37 | self.params[name] = val |
| 38 | |
| 39 | def __hash__(self) -> int: |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 40 | return hash(self.char_tpl) |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 41 | |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 42 | def __eq__(self, o: object) -> bool: |
| 43 | if not isinstance(o, self.__class__): |
| 44 | raise TypeError("Can't compare {!r} to {!r}".format(self.__class__.__qualname__, type(o).__qualname__)) |
| 45 | return sorted(self.params.items()) == sorted(cast(JobParams, o).params.items()) |
| 46 | |
| 47 | def __lt__(self, o: object) -> bool: |
| 48 | if not isinstance(o, self.__class__): |
| 49 | raise TypeError("Can't compare {!r} to {!r}".format(self.__class__.__qualname__, type(o).__qualname__)) |
| 50 | return self.char_tpl < cast(JobParams, o).char_tpl |
| 51 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame^] | 52 | @property |
| 53 | @abc.abstractmethod |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 54 | def char_tpl(self) -> Tuple[Union[str, int, float, bool], ...]: |
| 55 | pass |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 56 | |
| 57 | |
| 58 | class JobConfig(Storable, metaclass=abc.ABCMeta): |
| 59 | """Job config class""" |
| 60 | |
| 61 | def __init__(self, idx: int) -> None: |
| 62 | # job id, used in storage to distinct jobs with same summary |
| 63 | self.idx = idx |
| 64 | |
| 65 | # time interval, in seconds, when test was running on all nodes |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 66 | self.reliable_info_range = None # type: Tuple[int, int] |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 67 | |
| 68 | # all job parameters, both from suite file and config file |
| 69 | self.vals = OrderedDict() # type: Dict[str, Any] |
| 70 | |
| 71 | @property |
| 72 | def storage_id(self) -> str: |
| 73 | """unique string, used as key in storage""" |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 74 | return "{}_{}".format(self.summary, self.idx) |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 75 | |
kdanylov aka koder | 150b219 | 2017-04-01 16:53:01 +0300 | [diff] [blame^] | 76 | @property |
| 77 | @abc.abstractmethod |
koder aka kdanilov | f90de85 | 2017-01-20 18:12:27 +0200 | [diff] [blame] | 78 | def params(self) -> JobParams: |
| 79 | """Should return a copy""" |
| 80 | pass |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame] | 81 | |
| 82 | @property |
| 83 | def summary(self) -> str: |
| 84 | return self.params.summary |