blob: 9f660301076b2f2c6d8c73356edb36e700fe26b2 [file] [log] [blame]
koder aka kdanilov108ac362017-01-19 20:17:16 +02001import os
kdanylov aka koder150b2192017-04-01 16:53:01 +03002import pprint
koder aka kdanilov108ac362017-01-19 20:17:16 +02003import logging
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +03004from typing import cast, Iterator, Tuple, Type, Dict, Optional, List, Any
koder aka kdanilov108ac362017-01-19 20:17:16 +02005
6import numpy
7
koder aka kdanilova732a602017-02-01 20:29:56 +02008from .suits.job import JobConfig
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +03009from .result_classes import SuiteConfig, TimeSeries, DataSource, StatProps, IResultStorage, ArrayData
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +030010from .storage import Storage
11from .utils import StopTestError
koder aka kdanilov108ac362017-01-19 20:17:16 +020012from .suits.all_suits import all_suits
13
14
15logger = logging.getLogger('wally')
16
17
18class DB_re:
19 node_id = r'\d+.\d+.\d+.\d+:\d+'
koder aka kdanilova732a602017-02-01 20:29:56 +020020 job_id = r'[-a-zA-Z0-9_]+_\d+'
21 suite_id = r'[a-z_]+_\d+'
22 sensor = r'[-a-z_]+'
koder aka kdanilov108ac362017-01-19 20:17:16 +020023 dev = r'[-a-zA-Z0-9_]+'
koder aka kdanilov108ac362017-01-19 20:17:16 +020024 tag = r'[a-z_.]+'
koder aka kdanilova732a602017-02-01 20:29:56 +020025 metric = r'[a-z_.]+'
koder aka kdanilov108ac362017-01-19 20:17:16 +020026
27
28class DB_paths:
koder aka kdanilova732a602017-02-01 20:29:56 +020029 suite_cfg_r = r'results/{suite_id}\.info\.yml'
koder aka kdanilov108ac362017-01-19 20:17:16 +020030
kdanylov aka koder150b2192017-04-01 16:53:01 +030031 job_root = r'results/{suite_id}\.{job_id}/'
koder aka kdanilova732a602017-02-01 20:29:56 +020032 job_cfg_r = job_root + r'info\.yml'
33
34 # time series, data from load tool, sensor is a tool name
kdanylov aka koder150b2192017-04-01 16:53:01 +030035 ts_r = job_root + r'{node_id}\.{sensor}\.{metric}\.{tag}'
koder aka kdanilova732a602017-02-01 20:29:56 +020036
37 # statistica data for ts
kdanylov aka koder150b2192017-04-01 16:53:01 +030038 stat_r = job_root + r'{node_id}\.{sensor}\.{metric}\.stat\.yaml'
koder aka kdanilova732a602017-02-01 20:29:56 +020039
40 # sensor data
kdanylov aka koder45183182017-04-30 23:55:40 +030041 sensor_data_r = r'sensors/{node_id}_{sensor}\.{dev}\.{metric}\.{tag}'
koder aka kdanilova732a602017-02-01 20:29:56 +020042 sensor_time_r = r'sensors/{node_id}_collected_at\.csv'
43
44 report_root = 'report/'
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +030045 plot_r = r'{suite_id}\.{job_id}/{node_id}\.{sensor}\.{dev}\.{metric}\.{tag}'
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +030046 txt_report = report_root + '{suite_id}_report.txt'
47
48 job_extra = 'meta/{suite_id}.{job_id}/{tag}'
koder aka kdanilova732a602017-02-01 20:29:56 +020049
koder aka kdanilov108ac362017-01-19 20:17:16 +020050 job_cfg = job_cfg_r.replace("\\.", '.')
koder aka kdanilova732a602017-02-01 20:29:56 +020051 suite_cfg = suite_cfg_r.replace("\\.", '.')
koder aka kdanilov108ac362017-01-19 20:17:16 +020052 ts = ts_r.replace("\\.", '.')
koder aka kdanilov108ac362017-01-19 20:17:16 +020053 stat = stat_r.replace("\\.", '.')
koder aka kdanilova732a602017-02-01 20:29:56 +020054 sensor_data = sensor_data_r.replace("\\.", '.')
55 sensor_time = sensor_time_r.replace("\\.", '.')
koder aka kdanilov108ac362017-01-19 20:17:16 +020056 plot = plot_r.replace("\\.", '.')
57
koder aka kdanilova732a602017-02-01 20:29:56 +020058
59DB_rr = {name: r"(?P<{}>{})".format(name, rr)
60 for name, rr in DB_re.__dict__.items()
61 if not name.startswith("__")}
koder aka kdanilov108ac362017-01-19 20:17:16 +020062
63
koder aka kdanilova732a602017-02-01 20:29:56 +020064def fill_path(path: str, **params) -> str:
65 for name, val in params.items():
66 if val is not None:
67 path = path.replace("{" + name + "}", val)
68 return path
koder aka kdanilov108ac362017-01-19 20:17:16 +020069
70
71class ResultStorage(IResultStorage):
72 # TODO: check that all path components match required patterns
73
koder aka kdanilova732a602017-02-01 20:29:56 +020074 ts_header_size = 64
koder aka kdanilov108ac362017-01-19 20:17:16 +020075 ts_header_format = "!IIIcc"
koder aka kdanilova732a602017-02-01 20:29:56 +020076 ts_arr_tag = 'csv'
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +030077 csv_file_encoding = 'ascii'
koder aka kdanilov108ac362017-01-19 20:17:16 +020078
79 def __init__(self, storage: Storage) -> None:
80 self.storage = storage
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030081 self.cache = {} # type: Dict[str, Tuple[int, int, ArrayData]]
koder aka kdanilov108ac362017-01-19 20:17:16 +020082
83 def sync(self) -> None:
84 self.storage.sync()
85
koder aka kdanilova732a602017-02-01 20:29:56 +020086 # ----------------- SERIALIZATION / DESERIALIZATION -------------------------------------------------------------
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +030087 def read_headers(self, fd) -> Tuple[str, List[str], List[str], Optional[numpy.ndarray]]:
88 header = fd.readline().decode(self.csv_file_encoding).rstrip().split(",")
89 dtype, has_header2, header2_dtype, *ext_header = header
90
91 if has_header2 == 'true':
92 ln = fd.readline().decode(self.csv_file_encoding).strip()
93 header2 = numpy.fromstring(ln, sep=',', dtype=header2_dtype)
94 else:
95 assert has_header2 == 'false', \
96 "In file {} has_header2 is not true/false, but {!r}".format(fd.name, has_header2)
97 header2 = None
98 return dtype, ext_header, header, header2
99
100 def load_array(self, path: str) -> ArrayData:
101 """
102 Load array from file, shoult not be called directly
103 :param path: file path
104 :return: ArrayData
105 """
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300106 with self.storage.get_fd(path, "rb") as fd:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300107 fd.seek(0, os.SEEK_SET)
108
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300109 stats = os.fstat(fd.fileno())
110 if path in self.cache:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300111 size, atime, arr_info = self.cache[path]
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300112 if size == stats.st_size and atime == stats.st_atime_ns:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300113 return arr_info
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300114
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300115 data_dtype, header, _, header2 = self.read_headers(fd)
116 assert data_dtype == 'uint64', path
117 dt = fd.read().decode(self.csv_file_encoding).strip()
kdanylov aka koder150b2192017-04-01 16:53:01 +0300118
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300119 if len(dt) != 0:
120 arr = numpy.fromstring(dt.replace("\n", ','), sep=',', dtype=data_dtype)
121 lines = dt.count("\n") + 1
122 assert len(set(ln.count(',') for ln in dt.split("\n"))) == 1, \
123 "Data lines in {!r} have different element count".format(path)
124 arr.shape = [lines] if lines == arr.size else [lines, -1]
125 else:
126 arr = None
kdanylov aka koder150b2192017-04-01 16:53:01 +0300127
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300128 arr_data = ArrayData(header, header2, arr)
129 self.cache[path] = (stats.st_size, stats.st_atime_ns, arr_data)
130 return arr_data
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300131
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300132 def put_array(self, path: str, data: numpy.array, header: List[str], header2: numpy.ndarray = None,
133 append_on_exists: bool = False) -> None:
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300134
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300135 header = [data.dtype.name] + \
136 (['false', ''] if header2 is None else ['true', header2.dtype.name]) + \
137 header
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300138
139 exists = append_on_exists and path in self.storage
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300140 vw = data.view().reshape((data.shape[0], 1)) if len(data.shape) == 1 else data
141 mode = "cb" if not exists else "rb+"
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300142
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300143 with self.storage.get_fd(path, mode) as fd:
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300144 if exists:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300145 data_dtype, _, full_header, curr_header2 = self.read_headers(fd)
146
147 assert data_dtype == data.dtype.name, \
148 "Path {!r}. Passed data type ({!r}) and current data type ({!r}) doesn't match"\
149 .format(path, data.dtype.name, data_dtype)
150
151 assert header == full_header, \
152 "Path {!r}. Passed header ({!r}) and current header ({!r}) doesn't match"\
153 .format(path, header, full_header)
154
155 assert header2 == curr_header2, \
156 "Path {!r}. Passed header2 != current header2: {!r}\n{!r}"\
157 .format(path, header2, curr_header2)
158
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300159 fd.seek(0, os.SEEK_END)
160 else:
161 fd.write((",".join(header) + "\n").encode(self.csv_file_encoding))
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300162 if header2 is not None:
163 fd.write((",".join(map(str, header2)) + "\n").encode(self.csv_file_encoding))
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300164
165 numpy.savetxt(fd, vw, delimiter=',', newline="\n", fmt="%lu")
koder aka kdanilova732a602017-02-01 20:29:56 +0200166
167 def load_ts(self, ds: DataSource, path: str) -> TimeSeries:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300168 """
169 Load time series, generated by fio or other tool, should not be called directly,
170 use iter_ts istead.
171 :param ds: data source path
172 :param path: path in data storage
173 :return: TimeSeries
174 """
175 (units, time_units), header2, data = self.load_array(path)
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +0300176 times = data[:,0].copy()
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300177 ts_data = data[:,1:]
koder aka kdanilova732a602017-02-01 20:29:56 +0200178
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300179 if ts_data.shape[1] == 1:
180 ts_data.shape = (ts_data.shape[0],)
koder aka kdanilova732a602017-02-01 20:29:56 +0200181
182 return TimeSeries("{}.{}".format(ds.dev, ds.sensor),
183 raw=None,
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300184 data=ts_data,
185 times=times,
koder aka kdanilova732a602017-02-01 20:29:56 +0200186 source=ds,
187 units=units,
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300188 time_units=time_units,
189 histo_bins=header2)
koder aka kdanilova732a602017-02-01 20:29:56 +0200190
kdanylov aka koder45183182017-04-30 23:55:40 +0300191 def load_sensor_raw(self, ds: DataSource) -> bytes:
192 path = DB_paths.sensor_data.format(**ds.__dict__)
193 with self.storage.get_fd(path, "rb") as fd:
194 return fd.read()
195
koder aka kdanilova732a602017-02-01 20:29:56 +0200196 def load_sensor(self, ds: DataSource) -> TimeSeries:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300197 # sensors has no shape
198 path = DB_paths.sensor_time.format(**ds.__dict__)
199 collect_header, must_be_none, collected_at = self.load_array(path)
200
201 # cut 'collection end' time
kdanylov aka koder45183182017-04-30 23:55:40 +0300202 # .copy needed to really remove 'collection end' element to make c_interpolate_.. works correctly
203 collected_at = collected_at[::2].copy()
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300204
205 # there must be no histogram for collected_at
206 assert must_be_none is None, "Extra header2 {!r} in collect_at file at {!r}".format(must_be_none, path)
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +0300207 node, tp, units = collect_header
208 assert node == ds.node_id and tp == 'collected_at' and units in ('ms', 'us'),\
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300209 "Unexpected collect_at header {!r} at {!r}".format(collect_header, path)
210 assert len(collected_at.shape) == 1, "Collected_at must be 1D at {!r}".format(path)
211
212 data_path = DB_paths.sensor_data.format(**ds.__dict__)
213 data_header, must_be_none, data = self.load_array(data_path)
214
215 # there must be no histogram for any sensors
216 assert must_be_none is None, "Extra header2 {!r} in sensor data file {!r}".format(must_be_none, data_path)
koder aka kdanilova732a602017-02-01 20:29:56 +0200217
218 data_units = data_header[2]
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300219 assert data_header == [ds.node_id, ds.metric_fqdn, data_units], \
220 "Unexpected data header {!r} at {!r}".format(data_header, data_path)
221 assert len(data.shape) == 1, "Sensor data must be 1D at {!r}".format(data_path)
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300222
koder aka kdanilova732a602017-02-01 20:29:56 +0200223 return TimeSeries(ds.metric_fqdn,
224 raw=None,
225 data=data,
226 times=collected_at,
227 source=ds,
228 units=data_units,
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +0300229 time_units=units)
koder aka kdanilova732a602017-02-01 20:29:56 +0200230
231 # ------------- CHECK DATA IN STORAGE ----------------------------------------------------------------------------
232
233 def check_plot_file(self, source: DataSource) -> Optional[str]:
234 path = DB_paths.plot.format(**source.__dict__)
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300235 fpath = self.storage.resolve_raw(DB_paths.report_root + path)
koder aka kdanilova732a602017-02-01 20:29:56 +0200236 return path if os.path.exists(fpath) else None
237
238 # ------------- PUT DATA INTO STORAGE --------------------------------------------------------------------------
239
240 def put_or_check_suite(self, suite: SuiteConfig) -> None:
koder aka kdanilov108ac362017-01-19 20:17:16 +0200241 path = DB_paths.suite_cfg.format(suite_id=suite.storage_id)
242 if path in self.storage:
kdanylov aka koder150b2192017-04-01 16:53:01 +0300243 db_cfg = self.storage.load(SuiteConfig, path)
koder aka kdanilov108ac362017-01-19 20:17:16 +0200244 if db_cfg != suite:
245 logger.error("Current suite %s config is not equal to found in storage at %s", suite.test_type, path)
kdanylov aka koder150b2192017-04-01 16:53:01 +0300246 logger.debug("Current: \n%s\nStorage:\n%s", pprint.pformat(db_cfg), pprint.pformat(suite))
koder aka kdanilov108ac362017-01-19 20:17:16 +0200247 raise StopTestError()
kdanylov aka koder150b2192017-04-01 16:53:01 +0300248 else:
249 self.storage.put(suite, path)
koder aka kdanilov108ac362017-01-19 20:17:16 +0200250
koder aka kdanilova732a602017-02-01 20:29:56 +0200251 def put_job(self, suite: SuiteConfig, job: JobConfig) -> None:
koder aka kdanilov108ac362017-01-19 20:17:16 +0200252 path = DB_paths.job_cfg.format(suite_id=suite.storage_id, job_id=job.storage_id)
253 self.storage.put(job, path)
254
255 def put_ts(self, ts: TimeSeries) -> None:
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300256 assert ts.data.dtype == ts.times.dtype, "Data type {!r} != time type {!r}".format(ts.data.dtype, ts.times.dtype)
257 assert ts.data.dtype.kind == 'u', "Only unsigned ints are accepted"
258 assert ts.source.tag == self.ts_arr_tag, "Incorrect source tag == {!r}, must be {!r}".format(ts.source.tag,
259 self.ts_arr_tag)
koder aka kdanilova732a602017-02-01 20:29:56 +0200260 csv_path = DB_paths.ts.format(**ts.source.__dict__)
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300261 header = [ts.units, ts.time_units]
koder aka kdanilov108ac362017-01-19 20:17:16 +0200262
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300263 tv = ts.times.view().reshape((-1, 1))
264 if len(ts.data.shape) == 1:
265 dv = ts.data.view().reshape((ts.times.shape[0], -1))
266 else:
267 dv = ts.data
koder aka kdanilov108ac362017-01-19 20:17:16 +0200268
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300269 result = numpy.concatenate((tv, dv), axis=1)
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300270 if ts.histo_bins is not None:
271 self.put_array(csv_path, result, header, header2=ts.histo_bins)
272 else:
273 self.put_array(csv_path, result, header)
koder aka kdanilov108ac362017-01-19 20:17:16 +0200274
275 if ts.raw:
koder aka kdanilova732a602017-02-01 20:29:56 +0200276 raw_path = DB_paths.ts.format(**ts.source(tag=ts.raw_tag).__dict__)
koder aka kdanilov108ac362017-01-19 20:17:16 +0200277 self.storage.put_raw(ts.raw, raw_path)
278
279 def put_extra(self, data: bytes, source: DataSource) -> None:
kdanylov aka koder150b2192017-04-01 16:53:01 +0300280 self.storage.put_raw(data, DB_paths.ts.format(**source.__dict__))
koder aka kdanilov108ac362017-01-19 20:17:16 +0200281
282 def put_stat(self, data: StatProps, source: DataSource) -> None:
koder aka kdanilova732a602017-02-01 20:29:56 +0200283 self.storage.put(data, DB_paths.stat.format(**source.__dict__))
koder aka kdanilov108ac362017-01-19 20:17:16 +0200284
285 # return path to file to be inserted into report
286 def put_plot_file(self, data: bytes, source: DataSource) -> str:
287 path = DB_paths.plot.format(**source.__dict__)
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300288 self.storage.put_raw(data, DB_paths.report_root + path)
289 return path
koder aka kdanilov108ac362017-01-19 20:17:16 +0200290
koder aka kdanilov108ac362017-01-19 20:17:16 +0200291 def put_report(self, report: str, name: str) -> str:
kdanylov aka koder0e0cfcb2017-03-27 22:19:09 +0300292 return self.storage.put_raw(report.encode(self.csv_file_encoding), DB_paths.report_root + name)
koder aka kdanilova732a602017-02-01 20:29:56 +0200293
kdanylov aka koder45183182017-04-30 23:55:40 +0300294 def put_sensor_raw(self, data: bytes, ds: DataSource) -> None:
295 path = DB_paths.sensor_data.format(**ds.__dict__)
296 with self.storage.get_fd(path, "cb") as fd:
297 fd.write(data)
298
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300299 def append_sensor(self, data: numpy.array, ds: DataSource, units: str, histo_bins: numpy.ndarray = None) -> None:
koder aka kdanilova732a602017-02-01 20:29:56 +0200300 if ds.metric == 'collected_at':
301 path = DB_paths.sensor_time
302 metrics_fqn = 'collected_at'
303 else:
304 path = DB_paths.sensor_data
305 metrics_fqn = ds.metric_fqdn
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300306
307 if ds.metric == 'lat':
308 assert len(data.shape) == 2, "Latency should be histo array"
309 assert histo_bins is not None, "Latency should have histo bins"
310
311 path = path.format(**ds.__dict__)
312 self.put_array(path, data, [ds.node_id, metrics_fqn, units], header2=histo_bins, append_on_exists=True)
koder aka kdanilova732a602017-02-01 20:29:56 +0200313
314 # ------------- GET DATA FROM STORAGE --------------------------------------------------------------------------
315
316 def get_stat(self, stat_cls: Type[StatProps], source: DataSource) -> StatProps:
317 return self.storage.load(stat_cls, DB_paths.stat.format(**source.__dict__))
318
319 # ------------- ITER OVER STORAGE ------------------------------------------------------------------------------
320
321 def iter_paths(self, path_glob) -> Iterator[Tuple[bool, str, Dict[str, str]]]:
322 path = path_glob.format(**DB_rr).split("/")
323 yield from self.storage._iter_paths("", path, {})
324
325 def iter_suite(self, suite_type: str = None) -> Iterator[SuiteConfig]:
326 for is_file, suite_info_path, groups in self.iter_paths(DB_paths.suite_cfg_r):
327 assert is_file
328 suite = self.storage.load(SuiteConfig, suite_info_path)
329 # suite = cast(SuiteConfig, self.storage.load(SuiteConfig, suite_info_path))
330 assert suite.storage_id == groups['suite_id']
331 if not suite_type or suite.test_type == suite_type:
332 yield suite
333
334 def iter_job(self, suite: SuiteConfig) -> Iterator[JobConfig]:
335 job_glob = fill_path(DB_paths.job_cfg_r, suite_id=suite.storage_id)
336 job_config_cls = all_suits[suite.test_type].job_config_cls
337 for is_file, path, groups in self.iter_paths(job_glob):
338 assert is_file
339 job = cast(JobConfig, self.storage.load(job_config_cls, path))
340 assert job.storage_id == groups['job_id']
341 yield job
342
343 # iterate over test tool data
344 def iter_ts(self, suite: SuiteConfig, job: JobConfig, **filters) -> Iterator[TimeSeries]:
345 filters.update(suite_id=suite.storage_id, job_id=job.storage_id)
346 ts_glob = fill_path(DB_paths.ts_r, **filters)
koder aka kdanilova732a602017-02-01 20:29:56 +0200347 for is_file, path, groups in self.iter_paths(ts_glob):
kdanylov aka koder150b2192017-04-01 16:53:01 +0300348 tag = groups["tag"]
349 if tag != 'csv':
350 continue
koder aka kdanilova732a602017-02-01 20:29:56 +0200351 assert is_file
352 groups = groups.copy()
353 groups.update(filters)
354 ds = DataSource(suite_id=suite.storage_id,
355 job_id=job.storage_id,
356 node_id=groups["node_id"],
357 sensor=groups["sensor"],
358 dev=None,
359 metric=groups["metric"],
kdanylov aka koder150b2192017-04-01 16:53:01 +0300360 tag=tag)
koder aka kdanilova732a602017-02-01 20:29:56 +0200361 yield self.load_ts(ds, path)
362
363 def iter_sensors(self, node_id: str = None, sensor: str = None, dev: str = None, metric: str = None) -> \
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300364 Iterator[Tuple[str, DataSource]]:
365 vls = dict(node_id=node_id, sensor=sensor, dev=dev, metric=metric)
366 path = fill_path(DB_paths.sensor_data_r, **vls)
koder aka kdanilova732a602017-02-01 20:29:56 +0200367 for is_file, path, groups in self.iter_paths(path):
kdanylov aka kodercdfcdaf2017-04-29 10:03:39 +0300368 cvls = vls.copy()
369 cvls.update(groups)
370 yield path, DataSource(**cvls)
koder aka kdanilova732a602017-02-01 20:29:56 +0200371
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +0300372 def get_txt_report(self, suite: SuiteConfig) -> Optional[str]:
373 path = DB_paths.txt_report.format(suite_id=suite.storage_id)
374 if path in self.storage:
375 return self.storage.get_raw(path).decode('utf8')
koder aka kdanilova732a602017-02-01 20:29:56 +0200376
kdanylov aka koder3a9e5db2017-05-09 20:00:44 +0300377 def put_txt_report(self, suite: SuiteConfig, report: str) -> None:
378 path = DB_paths.txt_report.format(suite_id=suite.storage_id)
379 self.storage.put_raw(report.encode('utf8'), path)
380
381 def put_job_info(self, suite: SuiteConfig, job: JobConfig, key: str, data: Any) -> None:
382 path = DB_paths.job_extra.format(suite_id=suite.storage_id, job_id=job.storage_id, tag=key)
383 self.storage.put(data, path)
384
385 def get_job_info(self, suite: SuiteConfig, job: JobConfig, key: str) -> Any:
386 path = DB_paths.job_extra.format(suite_id=suite.storage_id, job_id=job.storage_id, tag=key)
387 return self.storage.get(path, None)