mirror of
https://github.com/krkn-chaos/krkn.git
synced 2026-08-25 09:27:36 +00:00
Signed-off-by: varun-ai69 <kushwahavarun86@gmail.com> Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com>
This commit is contained in:
co-authored by
Paige Patton
parent
5973f56d20
commit
01f6b467ee
@@ -249,6 +249,15 @@ class RollbackConfig(metaclass=SingletonMeta):
|
||||
logger.warning(
|
||||
f"File {file} does not match expected pattern of <{scenario_type or '*'}>_<timestamp>_<hash_suffix>.py"
|
||||
)
|
||||
def get_rollback_timestamp(filepath: str) -> int:
|
||||
filename = os.path.basename(filepath)
|
||||
parts = filename.rsplit("_", 2)
|
||||
try:
|
||||
return int(parts[-2])
|
||||
except (IndexError, ValueError):
|
||||
return 0
|
||||
# Execute rollback version files in reverse chronological order (LIFO).
|
||||
version_files.sort(key=get_rollback_timestamp, reverse=True)
|
||||
return version_files
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
@@ -189,6 +189,39 @@ class TestRollbackConfig:
|
||||
def test_is_rollback_version_file_format(self, file_name, expected):
|
||||
assert RollbackConfig.is_rollback_version_file_format(file_name) == expected
|
||||
|
||||
def test_search_rollback_version_files_order(self, tmpdir):
|
||||
from unittest.mock import patch
|
||||
|
||||
run_uuid = "abcdefgh"
|
||||
versions_dir = str(tmpdir.mkdir("versions_test_order"))
|
||||
|
||||
with patch.object(RollbackConfig, 'versions_directory', versions_dir):
|
||||
context_dir_name = f"123456789-{run_uuid}"
|
||||
context_dir = os.path.join(versions_dir, context_dir_name)
|
||||
os.makedirs(context_dir)
|
||||
|
||||
# Files with different timestamps
|
||||
files = [
|
||||
"scenario_1000_12345678.py",
|
||||
"scenario_3000_12345678.py",
|
||||
"scenario_2000_12345678.py",
|
||||
"scenario_500_12345678.py",
|
||||
]
|
||||
for file in files:
|
||||
with open(os.path.join(context_dir, file), "w") as f:
|
||||
f.write("# dummy content")
|
||||
|
||||
result = RollbackConfig.search_rollback_version_files(run_uuid, "scenario")
|
||||
result_filenames = [os.path.basename(f) for f in result]
|
||||
|
||||
expected_order = [
|
||||
"scenario_3000_12345678.py",
|
||||
"scenario_2000_12345678.py",
|
||||
"scenario_1000_12345678.py",
|
||||
"scenario_500_12345678.py",
|
||||
]
|
||||
assert result_filenames == expected_order
|
||||
|
||||
class TestRollbackCommand:
|
||||
|
||||
@pytest.mark.parametrize("auto_rollback", [True, False], ids=["enabled_rollback", "disabled_rollback"])
|
||||
|
||||
Reference in New Issue
Block a user