blob: 91822cb654957953abfdfddb96635f39a1dfa883 [file] [log] [blame]
koder aka kdanilovf90de852017-01-20 18:12:27 +02001import abc
koder aka kdanilova732a602017-02-01 20:29:56 +02002from typing import Dict, Any, Tuple, cast, Union
koder aka kdanilovf90de852017-01-20 18:12:27 +02003from collections import OrderedDict
4
5from ..common_types import Storable
6
7
8class 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
koder aka kdanilova732a602017-02-01 20:29:56 +020027 @abc.abstractmethod
28 def copy(self, **updated) -> 'JobParams':
29 pass
30
koder aka kdanilovf90de852017-01-20 18:12:27 +020031 def __getitem__(self, name: str) -> Any:
32 return self.params[name]
33
34 def __setitem__(self, name: str, val: Any) -> None:
35 self.params[name] = val
36
37 def __hash__(self) -> int:
koder aka kdanilova732a602017-02-01 20:29:56 +020038 return hash(self.char_tpl)
koder aka kdanilovf90de852017-01-20 18:12:27 +020039
koder aka kdanilova732a602017-02-01 20:29:56 +020040 def __eq__(self, o: object) -> bool:
41 if not isinstance(o, self.__class__):
42 raise TypeError("Can't compare {!r} to {!r}".format(self.__class__.__qualname__, type(o).__qualname__))
43 return sorted(self.params.items()) == sorted(cast(JobParams, o).params.items())
44
45 def __lt__(self, o: object) -> bool:
46 if not isinstance(o, self.__class__):
47 raise TypeError("Can't compare {!r} to {!r}".format(self.__class__.__qualname__, type(o).__qualname__))
48 return self.char_tpl < cast(JobParams, o).char_tpl
49
50 @abc.abstractproperty
51 def char_tpl(self) -> Tuple[Union[str, int, float, bool], ...]:
52 pass
koder aka kdanilovf90de852017-01-20 18:12:27 +020053
54
55class JobConfig(Storable, metaclass=abc.ABCMeta):
56 """Job config class"""
57
58 def __init__(self, idx: int) -> None:
59 # job id, used in storage to distinct jobs with same summary
60 self.idx = idx
61
62 # time interval, in seconds, when test was running on all nodes
koder aka kdanilova732a602017-02-01 20:29:56 +020063 self.reliable_info_range = None # type: Tuple[int, int]
koder aka kdanilovf90de852017-01-20 18:12:27 +020064
65 # all job parameters, both from suite file and config file
66 self.vals = OrderedDict() # type: Dict[str, Any]
67
68 @property
69 def storage_id(self) -> str:
70 """unique string, used as key in storage"""
koder aka kdanilova732a602017-02-01 20:29:56 +020071 return "{}_{}".format(self.summary, self.idx)
koder aka kdanilovf90de852017-01-20 18:12:27 +020072
73 @abc.abstractproperty
74 def params(self) -> JobParams:
75 """Should return a copy"""
76 pass
koder aka kdanilova732a602017-02-01 20:29:56 +020077
78 @property
79 def summary(self) -> str:
80 return self.params.summary