blob: 5cb27b51a1b2adf007540b32201ca8309a8f3445 [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
kdanylov aka koder150b2192017-04-01 16:53:01 +030017 @property
18 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +020019 def summary(self) -> str:
20 """Test short summary, used mostly for file names and short image description"""
21 pass
22
kdanylov aka koder150b2192017-04-01 16:53:01 +030023 @property
24 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +020025 def long_summary(self) -> str:
26 """Readable long summary for management and deployment engineers"""
27 pass
28
koder aka kdanilova732a602017-02-01 20:29:56 +020029 @abc.abstractmethod
30 def copy(self, **updated) -> 'JobParams':
31 pass
32
koder aka kdanilovf90de852017-01-20 18:12:27 +020033 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 kdanilova732a602017-02-01 20:29:56 +020040 return hash(self.char_tpl)
koder aka kdanilovf90de852017-01-20 18:12:27 +020041
koder aka kdanilova732a602017-02-01 20:29:56 +020042 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 koder150b2192017-04-01 16:53:01 +030052 @property
53 @abc.abstractmethod
koder aka kdanilova732a602017-02-01 20:29:56 +020054 def char_tpl(self) -> Tuple[Union[str, int, float, bool], ...]:
55 pass
koder aka kdanilovf90de852017-01-20 18:12:27 +020056
57
58class 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 kdanilova732a602017-02-01 20:29:56 +020066 self.reliable_info_range = None # type: Tuple[int, int]
koder aka kdanilovf90de852017-01-20 18:12:27 +020067
kdanylov aka koder45183182017-04-30 23:55:40 +030068
koder aka kdanilovf90de852017-01-20 18:12:27 +020069 # all job parameters, both from suite file and config file
70 self.vals = OrderedDict() # type: Dict[str, Any]
71
72 @property
kdanylov aka koder45183182017-04-30 23:55:40 +030073 def reliable_info_range_s(self) -> Tuple[int, int]:
74 return (self.reliable_info_range[0] // 1000, self.reliable_info_range[1] // 1000)
75
76 @property
koder aka kdanilovf90de852017-01-20 18:12:27 +020077 def storage_id(self) -> str:
78 """unique string, used as key in storage"""
koder aka kdanilova732a602017-02-01 20:29:56 +020079 return "{}_{}".format(self.summary, self.idx)
koder aka kdanilovf90de852017-01-20 18:12:27 +020080
kdanylov aka koder150b2192017-04-01 16:53:01 +030081 @property
82 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +020083 def params(self) -> JobParams:
84 """Should return a copy"""
85 pass
koder aka kdanilova732a602017-02-01 20:29:56 +020086
87 @property
88 def summary(self) -> str:
89 return self.params.summary