Skip to content

Commit 4a9de03

Browse files
committed
Add compability test for config
cherry-pich ff32dad and a150730
1 parent 50bdaf8 commit 4a9de03

File tree

9 files changed

+181
-29
lines changed

9 files changed

+181
-29
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"test_defaults.test_compare_config_default_values[stable-25-1-3-current]": ""
3+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from __future__ import annotations
2+
import json
3+
import yatest.common
4+
import pytest
5+
6+
7+
class ConfigDefaultValuesComparator:
8+
def __init__(self, old_version: str, new_version: str):
9+
self.errors: list[tuple[str, str]] = []
10+
self.old_version = old_version
11+
self.new_version = new_version
12+
13+
def __compare_field(self, old, new, path: list[str]) -> None:
14+
if type(old) is not type(new):
15+
self.errors.append(('.'.join(path), f'types differ, in {self.old_version} was {type(old)}, but in {self.new_version} is {type(new)}'))
16+
if isinstance(old, list):
17+
for i in range(len(old)):
18+
new_path = path + [str(i)]
19+
if i < len(new):
20+
self.__compare_field(old[i], new[i], new_path)
21+
else:
22+
self.errors.append(('.'.join(new_path), f'field was in {self.old_version}, but is deleted in {self.new_version}'))
23+
elif isinstance(old, dict):
24+
for key in sorted(old.keys()):
25+
old_field = old[key]
26+
new_field = new.get(key)
27+
new_path = path + [key]
28+
if new_field is None:
29+
self.errors.append(('.'.join(new_path), f'field was in {self.old_version}, but is deleted in {self.new_version}'))
30+
continue
31+
old_id = old_field.get('id')
32+
new_id = new_field.get('id')
33+
if old_id is not None and new_id is not None:
34+
if old_id != new_id:
35+
self.errors.append(('.'.join(new_path), f'ids differ, in {self.old_version} was {old_id}, but in {self.new_version} is {new_id}'))
36+
else:
37+
if old_id is None:
38+
self.errors.append(('.'.join(new_path), f'no id for field in {self.old_version}'))
39+
if new_id is None:
40+
self.errors.append(('.'.join(new_path), f'no id for field in {self.new_version}'))
41+
old_value = old_field.get('default-value')
42+
new_value = new_field.get('default-value')
43+
if old_value is not None and new_value is not None:
44+
self.__compare_field(old_value, new_value, new_path)
45+
else:
46+
if old_value is None:
47+
self.errors.append(('.'.join(new_path), f'no value for field in {self.old_version}'))
48+
if new_value is None:
49+
self.errors.append(('.'.join(new_path), f'no value for field in {self.new_version}'))
50+
else:
51+
if old != new:
52+
if isinstance(old, bool) and len(path) > 0 and path[0] == 'FeatureFlags':
53+
if old:
54+
self.errors.append(('.'.join(path), f'feature flag was switched on in {self.old_version}, but is switched off in {self.new_version}'))
55+
56+
def compare_versions(self) -> str:
57+
with open(yatest.common.binary_path(f'ydb/tests/library/compatibility/configs/{self.old_version}')) as f:
58+
old = json.load(f).get('proto')
59+
assert old is not None
60+
61+
with open(yatest.common.binary_path(f'ydb/tests/library/compatibility/configs/{self.new_version}')) as f:
62+
new = json.load(f).get('proto')
63+
assert new is not None
64+
65+
self.__compare_field(old, new, [])
66+
return '\n'.join([f'{path}: {msg}' for path, msg in self.errors])
67+
68+
69+
@pytest.mark.parametrize(['old_version', 'new_version'], [['stable-25-1-3', 'current']])
70+
def test_compare_config_default_values(old_version: str, new_version: str) -> str:
71+
return ConfigDefaultValuesComparator(old_version, new_version).compare_versions()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PY3TEST()
2+
3+
SIZE(LARGE)
4+
TAG(ya:fat)
5+
6+
DEPENDS(ydb/tests/library/compatibility/configs)
7+
8+
TEST_SRCS(
9+
test_defaults.py
10+
)
11+
12+
END()

ydb/tests/compatibility/ya.make

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RECURSE(
2+
configs
3+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import stat
3+
import sys
4+
5+
import boto3
6+
from botocore import UNSIGNED
7+
from botocore.client import Config
8+
9+
AWS_ENDPOINT = "https://storage.yandexcloud.net"
10+
AWS_BUCKET = "ydb-builds"
11+
12+
13+
def main():
14+
mode = sys.argv[1]
15+
if mode == 'download':
16+
s3_client = boto3.client(
17+
service_name="s3",
18+
endpoint_url=AWS_ENDPOINT,
19+
config=Config(signature_version=UNSIGNED)
20+
)
21+
s3_bucket = AWS_BUCKET
22+
remote_src = sys.argv[2]
23+
local_dst = sys.argv[3]
24+
binary_name = sys.argv[4] if len(sys.argv) > 4 else None
25+
s3_client.download_file(s3_bucket, remote_src, local_dst)
26+
27+
# chmod +x
28+
st = os.stat(local_dst)
29+
os.chmod(local_dst, st.st_mode | stat.S_IEXEC)
30+
if binary_name:
31+
with open(local_dst + "-name", "w") as f:
32+
f.write(binary_name)
33+
elif mode == 'append-version':
34+
local_dst = sys.argv[2]
35+
binary_name = sys.argv[3]
36+
with open(local_dst, "w") as f:
37+
f.write(binary_name)
38+
39+
40+
if __name__ == "__main__":
41+
main()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PY3_PROGRAM()
2+
PEERDIR(
3+
contrib/python/boto3
4+
contrib/python/botocore
5+
)
6+
7+
PY_SRCS(
8+
__main__.py
9+
)
10+
END()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RECURSE(downloader)
Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
RECURSE(dump)
22

3-
INCLUDE(${ARCADIA_ROOT}/ydb/tests/library/compatibility/versions.inc)
3+
UNION()
4+
5+
RUN_PROGRAM(
6+
ydb/tests/library/compatibility/binaries/downloader download stable-25-1/release/config-meta.json stable-25-1
7+
OUT_NOAUTO stable-25-1
8+
)
9+
10+
RUN_PROGRAM(
11+
ydb/tests/library/compatibility/binaries/downloader download stable-25-1-1/release/config-meta.json stable-25-1-1
12+
OUT_NOAUTO stable-25-1-1
13+
)
14+
15+
RUN_PROGRAM(
16+
ydb/tests/library/compatibility/binaries/downloader download stable-25-1-2/release/config-meta.json stable-25-1-2
17+
OUT_NOAUTO stable-25-1-2
18+
)
19+
20+
RUN_PROGRAM(
21+
ydb/tests/library/compatibility/binaries/downloader download stable-25-1-3/release/config-meta.json stable-25-1-3
22+
OUT_NOAUTO stable-25-1-3
23+
)
424

5-
# UNION()
6-
#
7-
#
8-
# RUN_PROGRAM(
9-
# ydb/tests/library/compatibility/binaries/downloader download $YDB_COMPAT_INTER_REF/release/config-meta.json inter $YDB_COMPAT_INTER_REF
10-
# OUT_NOAUTO inter inter-name
11-
# )
12-
#
1325
# RUN_PROGRAM(
14-
# ydb/tests/library/compatibility/binaries/downloader download $YDB_COMPAT_INIT_REF/release/config-meta.json init $YDB_COMPAT_INIT_REF
15-
# OUT_NOAUTO init init-name
26+
# ydb/tests/library/compatibility/binaries/downloader download prestable-25-2/release/config-meta.json prestable-25-2
27+
# OUT_NOAUTO prestable-25-2
1628
# )
17-
#
18-
# IF(${YDB_COMPAT_TARGET_REF} != "current")
19-
# RUN_PROGRAM(
20-
# ydb/tests/library/compatibility/binaries/downloader download $YDB_COMPAT_TARGET_REF/release/config-meta.json target $YDB_COMPAT_TARGET_REF
21-
# OUT_NOAUTO target target-name
22-
# )
23-
# ELSE()
24-
# RUN_PROGRAM(
25-
# ydb/tests/library/compatibility/configs/dump/dumper
26-
# STDOUT_NOAUTO target
27-
# )
28-
# RUN(
29-
# echo current
30-
# STDOUT_NOAUTO target-name
31-
# )
32-
# ENDIF()
33-
#
34-
# END()
29+
30+
RUN_PROGRAM(
31+
ydb/tests/library/compatibility/binaries/downloader download prestable-25-3/release/config-meta.json prestable-25-3
32+
OUT_NOAUTO prestable-25-3
33+
)
34+
35+
RUN_PROGRAM(
36+
ydb/tests/library/compatibility/configs/dump/dumper
37+
STDOUT_NOAUTO current
38+
)
39+
RUN(
40+
echo current
41+
STDOUT_NOAUTO current-name
42+
)
43+
44+
END()

ydb/tests/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
RECURSE(
2+
compatibility
23
example
34
fq
45
functional

0 commit comments

Comments
 (0)