Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/defaults.py: 100%
44 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 22:23 -0600
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 22:23 -0600
1"""Default values and constants"""
3import typing as t
5EPILOG: str = 'Learn more at https://github.com/untergeek/es-testbed'
6"""Epilog for the Click CLI"""
8HELP_OPTIONS: dict = {'help_option_names': ['-h', '--help']}
9"""Default help options for Click commands"""
11COLD_PREFIX: str = 'restored-'
12"""Prefix for cold searchable snapshot indices"""
14FROZEN_PREFIX: str = 'partial-'
15"""Prefix for frozen searchable snapshot indices"""
17SS_PREFIX: t.Dict[str, str] = {'cold': COLD_PREFIX, 'frozen': FROZEN_PREFIX}
18"""Dictionary of prefixes for searchable snapshot indices"""
20NAMEMAPPER: t.Dict[str, str] = {
21 'index': 'idx',
22 'indices': 'idx', # This is to aid testing and other places where kind is indices
23 'data_stream': 'ds',
24 'component': 'cmp',
25 'ilm': 'ilm',
26 'template': 'tmpl',
27 'snapshot': 'snp',
28}
29"""Mapping of names to abbreviations for use in the CLI"""
31PAUSE_DEFAULT: str = '1.0'
32"""Default value for the pause time in seconds"""
33PAUSE_ENVVAR: str = 'ES_TESTBED_PAUSE'
34"""Environment variable for the pause time"""
36PLURALMAP: t.Dict[str, str] = {
37 'ilm': 'ILM Policies',
38 'index': 'indices',
39}
40"""Mapping of singular to plural names for use in the CLI"""
42TESTPLAN: dict = {
43 'type': 'indices',
44 'prefix': 'es-testbed',
45 'repository': None,
46 'rollover_alias': None,
47 'ilm': {
48 'enabled': False,
49 'phases': ['hot', 'delete'],
50 'readonly': None,
51 'forcemerge': False,
52 'max_num_segments': 1,
53 },
54 'entities': [],
55}
56"""Default values for the TestPlan settings"""
58TIER: dict = {
59 'hot': {'pref': 'data_hot,data_content'},
60 'warm': {'pref': 'data_warm,data_hot,data_content'},
61 'cold': {
62 'pref': 'data_cold,data_warm,data_hot,data_content',
63 'prefix': 'restored',
64 'storage': 'full_copy',
65 },
66 'frozen': {
67 'pref': 'data_frozen',
68 'prefix': 'partial',
69 'storage': 'shared_cache',
70 },
71}
72"""Default values for the ILM tiers"""
74TIMEOUT_DEFAULT: str = '30'
75"""Default timeout for the testbed in seconds"""
76TIMEOUT_ENVVAR: str = 'ES_TESTBED_TIMEOUT'
77"""Environment variable for the testbed timeout"""
79# Define IlmPhase as a typing alias to be reused multiple times
80#
81# In all currently supported Python versions (3.8 -> 3.12), the syntax:
82#
83# IlmPhase = t.Dict[
84#
85# is supported. In 3.10 and up, you can use the more explicit syntax:
86#
87# IlmPhase: t.TypeAlias = t.Dict[
88#
89# making use of the TypeAlias class.
90#
91# To support Python versions 3.8 and 3.9 (still), the older syntax is used.
92IlmPhase = t.Dict[
93 str, t.Union[str, t.Dict[str, str], t.Dict[str, t.Dict[str, t.Dict[str, str]]]]
94]
95"""ILM Phase type alias"""
98def ilmhot() -> IlmPhase:
99 """Return a default hot ILM phase"""
100 return {'actions': {'rollover': {'max_primary_shard_size': '1gb', 'max_age': '1d'}}}
103def ilmwarm() -> IlmPhase:
104 """Return a default warm ILM phase"""
105 return {'min_age': '2d', 'actions': {}}
108def ilmcold() -> IlmPhase:
109 """Return a default cold ILM phase"""
110 return {'min_age': '3d', 'actions': {}}
113def ilmfrozen() -> IlmPhase:
114 """Return a default frozen ILM phase"""
115 return {'min_age': '4d', 'actions': {}}
118def ilmdelete() -> IlmPhase:
119 """Return a default delete ILM phase"""
120 return {'min_age': '5d', 'actions': {'delete': {}}}
123def ilm_phase(value: str) -> IlmPhase:
124 """Return the default phase step based on 'value'"""
125 phase_map = {
126 'hot': ilmhot(),
127 'warm': ilmwarm(),
128 'cold': ilmcold(),
129 'frozen': ilmfrozen(),
130 'delete': ilmdelete(),
131 }
132 return {value: phase_map[value]}
135def ilm_force_merge(max_num_segments: int = 1) -> t.Dict[str, t.Dict[str, int]]:
136 """Return an ILM policy force merge action block using max_num_segments"""
137 return {'forcemerge': {'max_num_segments': max_num_segments}}