blob: 9d59d421fd73dd20fbb984885fa8e55bfced37cb [file] [log] [blame]
koder aka kdanilov108ac362017-01-19 20:17:16 +02001import abc
kdanylov aka koderb0833332017-05-13 20:39:17 +03002from typing import Dict, List, Any, Tuple, cast, Type, Iterator, Union
koder aka kdanilovf2865172016-12-30 03:35:11 +02003
kdanylov aka koderb0833332017-05-13 20:39:17 +03004from cephlib.numeric_types import TimeSeries, DataSource
5from cephlib.statistic import StatProps
6from cephlib.istorage import IImagesStorage, Storable, ISensorStorage
kdanylov aka koder026e5f22017-05-15 01:04:39 +03007from cephlib.node import NodeInfo
8from cephlib.node_impl import IRPCNode
koder aka kdanilovffaf48d2016-12-27 02:25:29 +02009
koder aka kdanilovf90de852017-01-20 18:12:27 +020010from .suits.job import JobConfig
koder aka kdanilov70227062016-11-26 23:23:21 +020011
12
koder aka kdanilovf90de852017-01-20 18:12:27 +020013class SuiteConfig(Storable):
koder aka kdanilovf2865172016-12-30 03:35:11 +020014 """
15 Test suite input configuration.
16
17 test_type - test type name
18 params - parameters from yaml file for this test
19 run_uuid - UUID to be used to create file names & Co
20 nodes - nodes to run tests on
21 remote_dir - directory on nodes to be used for local files
22 """
koder aka kdanilovf90de852017-01-20 18:12:27 +020023 __ignore_fields__ = ['nodes', 'run_uuid', 'remote_dir']
24
koder aka kdanilovf2865172016-12-30 03:35:11 +020025 def __init__(self,
26 test_type: str,
27 params: Dict[str, Any],
28 run_uuid: str,
29 nodes: List[IRPCNode],
koder aka kdanilov108ac362017-01-19 20:17:16 +020030 remote_dir: str,
koder aka kdanilova732a602017-02-01 20:29:56 +020031 idx: int,
32 keep_raw_files: bool) -> None:
koder aka kdanilovf2865172016-12-30 03:35:11 +020033 self.test_type = test_type
34 self.params = params
35 self.run_uuid = run_uuid
36 self.nodes = nodes
koder aka kdanilov108ac362017-01-19 20:17:16 +020037 self.nodes_ids = [node.node_id for node in nodes]
koder aka kdanilovf2865172016-12-30 03:35:11 +020038 self.remote_dir = remote_dir
koder aka kdanilova732a602017-02-01 20:29:56 +020039 self.keep_raw_files = keep_raw_files
40
41 if 'load' in self.params:
42 self.storage_id = "{}_{}_{}".format(self.test_type, self.params['load'], idx)
43 else:
44 self.storage_id = "{}_{}".format(self.test_type, idx)
koder aka kdanilovf2865172016-12-30 03:35:11 +020045
koder aka kdanilov108ac362017-01-19 20:17:16 +020046 def __eq__(self, o: object) -> bool:
47 if type(o) is not self.__class__:
48 return False
49
koder aka kdanilovf90de852017-01-20 18:12:27 +020050 other = cast(SuiteConfig, o)
koder aka kdanilov108ac362017-01-19 20:17:16 +020051
koder aka kdanilovf2865172016-12-30 03:35:11 +020052 return (self.test_type == other.test_type and
53 self.params == other.params and
54 set(self.nodes_ids) == set(other.nodes_ids))
55
koder aka kdanilovf2865172016-12-30 03:35:11 +020056
koder aka kdanilovf2865172016-12-30 03:35:11 +020057# (node_name, source_dev, metric_name) => metric_results
58JobMetrics = Dict[Tuple[str, str, str], TimeSeries]
koder aka kdanilovf2865172016-12-30 03:35:11 +020059JobStatMetrics = Dict[Tuple[str, str, str], StatProps]
60
61
koder aka kdanilovf90de852017-01-20 18:12:27 +020062class JobResult:
koder aka kdanilovf2865172016-12-30 03:35:11 +020063 """Contains done test job information"""
64
65 def __init__(self,
koder aka kdanilovf90de852017-01-20 18:12:27 +020066 info: JobConfig,
koder aka kdanilovf2865172016-12-30 03:35:11 +020067 begin_time: int,
68 end_time: int,
69 raw: JobMetrics) -> None:
koder aka kdanilovffaf48d2016-12-27 02:25:29 +020070 self.info = info
koder aka kdanilovf2865172016-12-30 03:35:11 +020071 self.run_interval = (begin_time, end_time)
72 self.raw = raw # type: JobMetrics
73 self.processed = None # type: JobStatMetrics
koder aka kdanilov108ac362017-01-19 20:17:16 +020074
75
kdanylov aka koder026e5f22017-05-15 01:04:39 +030076class IWallyStorage(ISensorStorage, IImagesStorage, metaclass=abc.ABCMeta):
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030077
78 @abc.abstractmethod
kdanylov aka koder84de1e42017-05-22 14:00:07 +030079 def flush(self) -> None:
80 pass
81
82 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +020083 def put_or_check_suite(self, suite: SuiteConfig) -> None:
koder aka kdanilov108ac362017-01-19 20:17:16 +020084 pass
85
86 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +020087 def put_job(self, suite: SuiteConfig, job: JobConfig) -> None:
koder aka kdanilov108ac362017-01-19 20:17:16 +020088 pass
89
90 @abc.abstractmethod
koder aka kdanilov108ac362017-01-19 20:17:16 +020091 def put_extra(self, data: bytes, source: DataSource) -> None:
92 pass
93
94 @abc.abstractmethod
95 def put_stat(self, data: StatProps, source: DataSource) -> None:
96 pass
97
98 @abc.abstractmethod
99 def get_stat(self, stat_cls: Type[StatProps], source: DataSource) -> StatProps:
100 pass
101
102 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +0200103 def iter_suite(self, suite_type: str = None) -> Iterator[SuiteConfig]:
koder aka kdanilov108ac362017-01-19 20:17:16 +0200104 pass
105
106 @abc.abstractmethod
koder aka kdanilovf90de852017-01-20 18:12:27 +0200107 def iter_job(self, suite: SuiteConfig) -> Iterator[JobConfig]:
koder aka kdanilov108ac362017-01-19 20:17:16 +0200108 pass
109
koder aka kdanilov108ac362017-01-19 20:17:16 +0200110 # return path to file to be inserted into report
111 @abc.abstractmethod
112 def put_plot_file(self, data: bytes, source: DataSource) -> str:
113 pass
kdanylov aka koderb0833332017-05-13 20:39:17 +0300114
115 @abc.abstractmethod
116 def get_job_info(self, suite: SuiteConfig, job: JobConfig, key: str) -> Any:
117 pass
118
119 @abc.abstractmethod
120 def get_ts(self, ds: DataSource) -> TimeSeries:
121 pass
122
123 @abc.abstractmethod
124 def put_ts(self, ts: TimeSeries) -> None:
125 pass
126
127 @abc.abstractmethod
128 def iter_ts(self, **ds_parts) -> Iterator[DataSource]:
129 pass
130
131 @abc.abstractmethod
132 def put_job_info(self, suite: SuiteConfig, job: JobConfig, key: str, data: Any) -> None:
133 pass
134
135 @abc.abstractmethod
kdanylov aka koder026e5f22017-05-15 01:04:39 +0300136 def load_nodes(self) -> List[NodeInfo]:
kdanylov aka koderb0833332017-05-13 20:39:17 +0300137 pass