Files
datastore/ci/jobs/compatibility_check.py
Alexey MilovidovandClaude Opus 4.8 295ced78d1 Enable more Ruff checks (F401/F403/F405/F541/F841) and clean up tests
Follow-up to #105171, which added `ruff` with a deliberately narrow,
bug-class-only rule set and left the unused-name and star-import rules
off pending a dedicated cleanup pass. This enables that second batch in
`pyproject.toml` and fixes every violation across the tree (the bulk in
integration tests):

- `F401` unused-import and `F841` unused-variable: removed, preserving
  any side-effecting right-hand side (e.g. `result = node.query(...)`
  becomes `node.query(...)`). Two `try: import ...` feature probes are
  kept with `# noqa: F401`.
- `F541` f-string-missing-placeholders: dropped the redundant `f` prefix.
- `F403`/`F405` star imports: every `from module import *` is expanded
  into explicit imports of the names actually used, taken from each
  name's real origin, so stdlib/third-party names import from their real
  source rather than through a test "convenience bundle". The now-empty
  `tests/integration/helpers/kafka/common_direct.py` bundle is removed and
  its three remaining consumers import `_VarintBytes`/`KafkaAdminClient`
  directly.

Eliminating the star imports surfaced a real bug the wildcard had masked
from `F821`: `generate_presets.py` in `test_prometheus_protocols` called
an undefined `execute_instant_query_with_http_api`; fixed to the existing
`execute_query_via_http_api`.

No `black`/`isort` reformatting was applied (neither is enforced in the
style check), so the diff is limited to the lint fixes themselves.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-18 23:22:25 +00:00

123 lines
3.9 KiB
Python

import argparse
from pathlib import Path
from pip._vendor.packaging.version import Version
from ci.praktika.info import Info
from ci.praktika.result import Result
from ci.praktika.utils import Shell, Utils
IMAGE_UBUNTU = "clickhouse/test-old-ubuntu"
IMAGE_CENTOS = "clickhouse/test-old-centos"
DOWNLOAD_RETRIES_COUNT = 5
temp_path = Path(f"{Utils.cwd()}/ci/tmp")
def process_glibc_check():
# See https://sourceware.org/glibc/wiki/Glibc%20Timeline
if Utils.is_amd():
max_glibc_version = "2.4"
elif Utils.is_arm():
max_glibc_version = "2.18" # because of build with newer sysroot?
else:
raise RuntimeError("Can't determine max glibc version")
commands = (
[
f"readelf -s --wide {temp_path}/clickhouse | grep '@GLIBC_' > {temp_path}/glibc.log",
# FIXME: odbc bridge is not present in the deb package
# f"readelf -s --wide {temp_path}/clickhouse-odbc-bridge | grep '@GLIBC_' >> {temp_path}/glibc.log",
# FIXME: library bridge is not present in the deb package
# f"readelf -s --wide {temp_path}/clickhouse-library-bridge | grep '@GLIBC_' >> {temp_path}/glibc.log",
],
)
for command in commands:
Shell.check(command, verbose=True, strict=True)
ok = True
with open(f"{temp_path}/glibc.log", "r", encoding="utf-8") as log:
for line in log:
if line.strip():
columns = line.strip().split(" ")
symbol_with_glibc = columns[-2] # sysconf@GLIBC_2.2.5
_, version = symbol_with_glibc.split("@GLIBC_")
if version == "PRIVATE":
print(f"FAILED: PRIVATE version: {symbol_with_glibc}")
ok = False
elif Version(version) > Version(max_glibc_version):
print(
f"FAILED: version is more than max version [{max_glibc_version}]: [{symbol_with_glibc}]"
)
ok = False
return ok
def parse_args():
parser = argparse.ArgumentParser("Check compatibility with old distributions")
parser.add_argument("--check-name", required=False)
return parser.parse_args()
def main():
stopwatch = Utils.Stopwatch()
check_name = Info().job_name
assert check_name
check_glibc = True
# currently hardcoded to x86, don't enable for AARCH64
check_distributions = (
"aarch64" not in check_name.lower() and "arm" not in check_name.lower()
)
for package in temp_path.iterdir():
if package.suffix == ".deb":
Shell.check(
f"dpkg -x {package} {temp_path} && rm {package}",
verbose=True,
strict=True,
)
Shell.check(
f"mv {temp_path}/usr/bin/clickhouse {temp_path}/clickhouse",
verbose=True,
strict=True,
)
# Shell.check(f"chmod +x {temp_path}/clickhouse", verbose=True, strict=True)
test_results = []
if check_glibc:
test_results.append(
Result.from_commands_run(
name="glibc version",
command=process_glibc_check,
)
)
if check_distributions:
test_results.append(
Result.from_commands_run(
name="ubuntu12",
command=[
f"docker run --volume={temp_path}/clickhouse:/clickhouse ubuntu:12.04 /clickhouse local --query 'select 1'",
],
with_info=True,
)
)
test_results.append(
Result.from_commands_run(
name="centos5",
command=[
f"docker run --volume={temp_path}/clickhouse:/clickhouse centos:5 /clickhouse local --query 'select 1'"
],
with_info=True,
)
)
Result.create_from(results=test_results, stopwatch=stopwatch).complete_job()
if __name__ == "__main__":
main()