Skip to content

Commit 2d45aa1

Browse files
committed
qa: add test checking 'journal import' from empty dump file
Fixes: https://tracker.ceph.com/issues/68928 Signed-off-by: Jos Collin <[email protected]>
1 parent 01db5d1 commit 2d45aa1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

qa/tasks/cephfs/test_journal_repair.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
from textwrap import dedent
99
import time
10+
import tempfile
1011

1112
from teuthology.exceptions import CommandFailedError, ConnectionLostError
1213
from tasks.cephfs.filesystem import ObjectNotFound, ROOT_INO
@@ -403,3 +404,49 @@ def test_journal_smoke(self):
403404
"timeout": "1h"
404405
})
405406

407+
def test_journal_import_from_empty_dump_file(self):
408+
"""
409+
That the 'journal import' recognizes empty file read and errors out.
410+
"""
411+
fname = tempfile.NamedTemporaryFile(delete=False).name
412+
self.mount_a.run_shell(["sudo", "touch", fname], omit_sudo=False)
413+
self.fs.fail()
414+
import_out = None
415+
try:
416+
import_out = self.fs.journal_tool(["journal", "import", fname], 0)
417+
except CommandFailedError as e:
418+
self.mount_a.run_shell(["sudo", "rm", fname], omit_sudo=False)
419+
raise RuntimeError(f"Unexpected journal import error: {str(e)}")
420+
self.fs.set_joinable()
421+
self.fs.wait_for_daemons()
422+
try:
423+
if import_out.endswith("done."):
424+
assert False
425+
except AssertionError:
426+
raise RuntimeError(f"Unexpected journal-tool result: '{import_out}'")
427+
finally:
428+
self.mount_a.run_shell(["sudo", "rm", fname], omit_sudo=False)
429+
430+
def test_journal_import_from_invalid_dump_file(self):
431+
"""
432+
That the 'journal import' recognizes invalid dump file and errors out.
433+
"""
434+
# Create an invalid dump file with partial header
435+
fname = tempfile.NamedTemporaryFile(delete=False).name
436+
self.mount_a.run_shell(["sudo", "sh", "-c", f'printf "Ceph mds0 journal dump\n\
437+
start offset 4194304 (0x400000)\n\
438+
length 940 (0x3ac)\nwrite_pos 4194304 (0x400000)\n" > {fname}'], omit_sudo=False)
439+
self.fs.fail()
440+
try:
441+
self.fs.journal_tool(["journal", "import", fname], 0)
442+
except CommandFailedError as e:
443+
self.fs.set_joinable()
444+
self.fs.wait_for_daemons()
445+
if e.exitstatus != 234:
446+
raise RuntimeError(f"Unexpected journal import error: {str(e)}")
447+
else:
448+
self.fs.set_joinable()
449+
self.fs.wait_for_daemons()
450+
raise RuntimeError("Expected journal import to fail")
451+
finally:
452+
self.mount_a.run_shell(["sudo", "rm", fname], omit_sudo=False)

0 commit comments

Comments
 (0)