apache-ignite
263 строки · 7.3 Кб
1# Licensed to the Apache Software Foundation (ASF) under one or more
2# contributor license agreements. See the NOTICE file distributed with
3# this work for additional information regarding copyright ownership.
4# The ASF licenses this file to You under the Apache License, Version 2.0
5# (the "License"); you may not use this file except in compliance with
6# the License. You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""
17This module contains classes that represent persistent artifacts of tests
18"""
19
20import os21from abc import abstractmethod, ABCMeta22
23from ignitetest.utils.version import DEV_BRANCH24
25
26def get_home_dir(install_root, product):27"""28Get path to binary release (home) directory.
29"""
30return os.path.join(install_root, product)31
32
33def get_shared_root_path(test_globals):34"""35Get path to shared root directory.
36"""
37return os.path.join(test_globals.get("persistent_root", "/mnt/service"), "shared")38
39
40class PathAware:41"""42Basic class for path configs.
43"""
44def init_persistent(self, node):45"""46Init persistent directory.
47:param node: Service node.
48"""
49node.account.mkdirs(50f"{self.persistent_root} {self.temp_dir} {self.work_dir} {self.log_dir} {self.config_dir} {self.jfr_dir}")51
52def init_logs_attribute(self):53"""54Initialize logs attribute for collecting logs by ducktape.
55After changing to property based logs, will be removed.
56"""
57setattr(self, 'logs', {58"log": {59"path": self.log_dir,60"collect_default": True61},62"config": {63"path": self.config_dir,64"collect_default": True65},66"shared": {67"path": self.shared_root,68"collect_default": True69},70"jfr": {71"path": self.jfr_dir,72"collect_default": True73}74})75
76@property77@abstractmethod78def config_file(self):79"""80:return: path to project configuration file
81"""
82
83@property84@abstractmethod85def log_config_file(self):86"""87:return: path to logger configuration file
88"""
89
90@property91def work_dir(self):92"""93:return: path to work directory
94"""
95return os.path.join(self.persistent_root, "work")96
97@property98def config_dir(self):99"""100:return: path to config directory
101"""
102return os.path.join(self.persistent_root, "config")103
104@property105def jfr_dir(self):106"""107:return: path to jfr directory
108"""
109return os.path.join(self.persistent_root, "jfr")110
111@property112def log_dir(self):113"""114:return: path to log directory
115"""
116return os.path.join(self.persistent_root, "logs")117
118@property119def shared_root(self):120"""121:return: path to directory with shared files - same files on all nodes
122"""
123return get_shared_root_path(self.globals)124
125@property126@abstractmethod127def product(self):128"""129:return: Represents product (folder name), typically project/fork name with version.
130"""
131
132@property133@abstractmethod134def globals(self):135"""136:return: dictionary of globals variable (usually from test context).
137"""
138
139@property140def home_dir(self):141"""142:return: path to binary release (home) directory
143"""
144return get_home_dir(self.install_root, self.product)145
146@property147def temp_dir(self):148"""149:return: path to temp directory
150"""
151return os.path.join(self.persistent_root, "tmp")152
153@property154def persistent_root(self):155"""156:return: path to persistent root
157"""
158return self.globals.get("persistent_root", "/mnt/service")159
160@property161def install_root(self):162"""163:return: path to distributive installation root
164"""
165return self.globals.get("install_root", "/opt")166
167
168class IgnitePathAware(PathAware, metaclass=ABCMeta):169"""170This class contains Ignite path configs.
171"""
172IGNITE_CONFIG_NAME = "ignite-config.xml"173
174IGNITE_THIN_CLIENT_CONFIG_NAME = "ignite-thin-config.xml"175
176IGNITE_LOG_CONFIG_NAME = "ignite-ducktape-log4j2.xml"177
178@property179def config_file(self):180"""181:return: path to config file
182"""
183return os.path.join(self.config_dir, IgnitePathAware.IGNITE_CONFIG_NAME)184
185@property186def thin_client_config_file(self):187"""188:return: path to thin client config file
189"""
190return os.path.join(self.config_dir, IgnitePathAware.IGNITE_THIN_CLIENT_CONFIG_NAME)191
192@property193def log_config_file(self):194"""195:return: path to log config file
196"""
197return os.path.join(self.config_dir, IgnitePathAware.IGNITE_LOG_CONFIG_NAME)198
199@property200def database_dir(self):201"""202:return: path to database directory
203"""
204return os.path.join(self.work_dir, "db")205
206@property207def perf_stat_dir(self):208"""209:return: path to performance statistics directory
210"""
211return os.path.join(self.work_dir, "perf_stat")212
213@property214def wal_dir(self):215"""216:return: path to wal directory
217"""
218return os.path.join(self.database_dir, "wal")219
220@property221def snapshots_dir(self):222"""223:return: path to snapshots directory
224"""
225return os.path.join(self.work_dir, "snapshots")226
227@property228def certificate_dir(self):229"""230:return: path to the certificate directory.
231"""
232return os.path.join(get_home_dir(self.install_root, str(DEV_BRANCH)), "modules", "ducktests", "tests", "certs")233
234def script(self, script_name):235"""236:param script_name: name of Ignite script
237:return: absolute path to the specified script
238"""
239return os.path.join(self.home_dir, "bin", script_name)240
241@staticmethod242def consistent_dir(consistent_id):243"""244:param consistent_id: consistent ID
245:return: correct file name for consistent ID directory
246"""
247return "".join([c if c.isdigit() or c.isalpha() else '_' for c in consistent_id])248
249def cache_dir(self, consistent_dir, cache_name):250"""251:param consistent_dir: consistent ID directory.
252:param cache_name: cache name.
253:return: absolute path to the cache directory.
254"""
255return os.path.join(self.database_dir, consistent_dir, f'cache-{cache_name}')256
257def index_file(self, consistent_dir, cache_name):258"""259:param consistent_dir: consistent ID directory.
260:param cache_name: cache name.
261:return: absolute path to the index file of cache.
262"""
263return os.path.join(self.cache_dir(consistent_dir, cache_name), 'index.bin')264