From 92b422e9418c14a945aa532cbab741fcd10b3392 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:56:45 +0100 Subject: [PATCH 1/2] fix: shorten test ids > 255 chars --- src/beku/kuttl.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/beku/kuttl.py b/src/beku/kuttl.py index 83162ad..9bf9bc2 100644 --- a/src/beku/kuttl.py +++ b/src/beku/kuttl.py @@ -5,6 +5,7 @@ import logging import os import re +import hashlib from dataclasses import dataclass, field from functools import cached_property from hashlib import sha256 @@ -94,6 +95,10 @@ def make_test_source_with_context( return TestFile(file_name=file_name, source_dir=source_dir, dest_dir=dest_dir) +def tid_short_hash(tid: str) -> str: + return hashlib.sha256(tid.encode()).hexdigest()[:10] + + @dataclass(frozen=True) class TestCase: """A test case is an instance of test definition together with a set of Jinja variables used to render all @@ -114,7 +119,7 @@ def tid(self) -> str: The result is part of a full directory name of the test case. Therefore, the OS filesystem directory separator is replaced with underscore. """ - return re.sub( + name = re.sub( f"[{os.sep}:]", "_", "_".join( @@ -124,6 +129,11 @@ def tid(self) -> str: ) ), ) + if len(name) > 255: + hash = tid_short_hash(name) + return f"{name[:244]}_{hash}" + else: + return name def expand(self, template_dir: str, target_dir: str, namespace: str) -> None: """Expand test case This will create the target folder, copy files and render render templates.""" From f6b1bfbf09a509fba824d586af9074e265ec293c Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:50:13 +0100 Subject: [PATCH 2/2] cleanup and changelog --- CHANGELOG.md | 6 ++++++ src/beku/kuttl.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4b67f4..2d58af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## Fixed + +- Cap generated test ids to 255 characters to avoid file system errors ([#35]). + +[#35]: https://github.com/stackabletech/beku.py/pull/35 + ## 0.0.10 - 2024-11-06 ## Added diff --git a/src/beku/kuttl.py b/src/beku/kuttl.py index 9bf9bc2..0f0690c 100644 --- a/src/beku/kuttl.py +++ b/src/beku/kuttl.py @@ -96,6 +96,7 @@ def make_test_source_with_context( def tid_short_hash(tid: str) -> str: + """Take the first 10 chars of the hash of the given `tid`.""" return hashlib.sha256(tid.encode()).hexdigest()[:10] @@ -118,6 +119,9 @@ def tid(self) -> str: """Return the test id. Used as destination folder name for the generated test case. The result is part of a full directory name of the test case. Therefore, the OS filesystem directory separator is replaced with underscore. + + Since the result is also used as a folder name, we restrict it's length to 255 characters. + This is because some filesystems complain if the name is longer that that. """ name = re.sub( f"[{os.sep}:]", @@ -129,9 +133,10 @@ def tid(self) -> str: ) ), ) - if len(name) > 255: - hash = tid_short_hash(name) - return f"{name[:244]}_{hash}" + max_len = 255 + if len(name) > max_len: + name_hash = tid_short_hash(name) + return f"{name[: max_len - len(name_hash) - 1]}_{name_hash}" else: return name