blob: ce32e0e6c834fafd7879fd89c2a5cc74fc98c56a [file] [log] [blame]
koder aka kdanilovf90de852017-01-20 18:12:27 +02001import abc
2from typing import Dict, Any, Tuple
3from 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
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
40class 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