mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
Merge bitcoin/bitcoin#28660: test: enable reindex readonly test on *BSD
5a0688a20d
test: enable reindex readonly test on *BSD and macOS as root (Matthew Zipkin) Pull request description: see https://github.com/bitcoin/bitcoin/pull/27850#discussion_r1349505585 OpenBSD and FreeBSD don't have `chattr` but they do have `chflags`, use that method to make the block file immutable for the reindex_readonly test. Written and tested on a VPS running FreeBSD: ``` FreeBSD freebsd-13-1 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64 ``` ACKs for top commit: maflcko: re-cr-lgtm-ACK5a0688a20d
jonatack: ACK5a0688a20d
tested on macOS only theStack: ACK5a0688a20d
Tree-SHA512: 8c88d282d09c00355d22c4c504b779f60e420327a5e07bcf80fa77b97fefcb04952af9ceaf439d9033a0a2448cb26a02663fe6bddcd4a74792857cfbaf1c5162
This commit is contained in:
commit
ab61087a7e
1 changed files with 31 additions and 12 deletions
|
@ -7,7 +7,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
@ -34,11 +33,13 @@ class BlockstoreReindexTest(BitcoinTestFramework):
|
||||||
filename = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
|
filename = self.nodes[0].chain_path / "blocks" / "blk00000.dat"
|
||||||
filename.chmod(stat.S_IREAD)
|
filename.chmod(stat.S_IREAD)
|
||||||
|
|
||||||
used_chattr = False
|
undo_immutable = lambda: None
|
||||||
if platform.system() == "Linux":
|
# Linux
|
||||||
|
try:
|
||||||
|
subprocess.run(['chattr'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
try:
|
try:
|
||||||
subprocess.run(['chattr', '+i', filename], capture_output=True, check=True)
|
subprocess.run(['chattr', '+i', filename], capture_output=True, check=True)
|
||||||
used_chattr = True
|
undo_immutable = lambda: subprocess.check_call(['chattr', '-i', filename])
|
||||||
self.log.info("Made file immutable with chattr")
|
self.log.info("Made file immutable with chattr")
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
self.log.warning(str(e))
|
self.log.warning(str(e))
|
||||||
|
@ -50,15 +51,33 @@ class BlockstoreReindexTest(BitcoinTestFramework):
|
||||||
self.log.warning("Return early on Linux under root, because chattr failed.")
|
self.log.warning("Return early on Linux under root, because chattr failed.")
|
||||||
self.log.warning("This should only happen due to missing capabilities in a container.")
|
self.log.warning("This should only happen due to missing capabilities in a container.")
|
||||||
self.log.warning("Make sure to --cap-add LINUX_IMMUTABLE if you want to run this test.")
|
self.log.warning("Make sure to --cap-add LINUX_IMMUTABLE if you want to run this test.")
|
||||||
return
|
undo_immutable = False
|
||||||
|
except Exception:
|
||||||
|
# macOS, and *BSD
|
||||||
|
try:
|
||||||
|
subprocess.run(['chflags'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
try:
|
||||||
|
subprocess.run(['chflags', 'uchg', filename], capture_output=True, check=True)
|
||||||
|
undo_immutable = lambda: subprocess.check_call(['chflags', 'nouchg', filename])
|
||||||
|
self.log.info("Made file immutable with chflags")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
self.log.warning(str(e))
|
||||||
|
if e.stdout:
|
||||||
|
self.log.warning(f"stdout: {e.stdout}")
|
||||||
|
if e.stderr:
|
||||||
|
self.log.warning(f"stderr: {e.stderr}")
|
||||||
|
if os.getuid() == 0:
|
||||||
|
self.log.warning("Return early on BSD under root, because chflags failed.")
|
||||||
|
undo_immutable = False
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
self.log.debug("Attempt to restart and reindex the node with the unwritable block file")
|
if undo_immutable:
|
||||||
with self.nodes[0].assert_debug_log(expected_msgs=['FlushStateToDisk', 'failed to open file'], unexpected_msgs=[]):
|
self.log.info("Attempt to restart and reindex the node with the unwritable block file")
|
||||||
self.nodes[0].assert_start_raises_init_error(extra_args=['-reindex', '-fastprune'],
|
with self.nodes[0].assert_debug_log(expected_msgs=['FlushStateToDisk', 'failed to open file'], unexpected_msgs=[]):
|
||||||
expected_msg="Error: A fatal internal error occurred, see debug.log for details")
|
self.nodes[0].assert_start_raises_init_error(extra_args=['-reindex', '-fastprune'],
|
||||||
|
expected_msg="Error: A fatal internal error occurred, see debug.log for details")
|
||||||
if used_chattr:
|
undo_immutable()
|
||||||
subprocess.check_call(['chattr', '-i', filename])
|
|
||||||
|
|
||||||
filename.chmod(0o777)
|
filename.chmod(0o777)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue