-
Notifications
You must be signed in to change notification settings - Fork 38.8k
test: enable reindex readonly test on *BSD #28660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |||||
| """ | ||||||
|
|
||||||
| import os | ||||||
| import platform | ||||||
| import stat | ||||||
| import subprocess | ||||||
| from test_framework.test_framework import BitcoinTestFramework | ||||||
|
|
@@ -34,11 +33,13 @@ def reindex_readonly(self): | |||||
| filename = self.nodes[0].chain_path / "blocks" / "blk00000.dat" | ||||||
| filename.chmod(stat.S_IREAD) | ||||||
|
|
||||||
| used_chattr = False | ||||||
| if platform.system() == "Linux": | ||||||
| undo_immutable = lambda: None | ||||||
| # Linux | ||||||
| try: | ||||||
| subprocess.run(['chattr'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | ||||||
| try: | ||||||
| subprocess.run(['chattr', '+i', filename], capture_output=True, check=True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Ubuntu 22.04.3 LTS, this line throws an exception for me In spite of this, the file is still changed to readonly, so the test still works as intended (it just doesn't set
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but this seems unrelated to the changes here, and the warning can be ignored. I guess it should just be a |
||||||
| used_chattr = True | ||||||
| undo_immutable = lambda: subprocess.check_call(['chattr', '-i', filename]) | ||||||
| self.log.info("Made file immutable with chattr") | ||||||
| except subprocess.CalledProcessError as e: | ||||||
| self.log.warning(str(e)) | ||||||
|
|
@@ -50,15 +51,33 @@ def reindex_readonly(self): | |||||
| 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("Make sure to --cap-add LINUX_IMMUTABLE if you want to run this test.") | ||||||
| return | ||||||
|
|
||||||
| self.log.debug("Attempt to restart and reindex the node with the unwritable block file") | ||||||
| with self.nodes[0].assert_debug_log(expected_msgs=['FlushStateToDisk', 'failed to open file'], unexpected_msgs=[]): | ||||||
| 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") | ||||||
| undo_immutable = False | ||||||
|
||||||
| undo_immutable = False | |
| undo_immutable = lambda: None |
(also in the macOS/BSD branch below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this works. This will break running the test in a Linux container without --cap-add LINUX_IMMUTABLE, no?
See also the log line immediately above this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, indeed. In my mind lambda: None was falsy and thought the if condition below wouldn't be executed, my bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be possible to type lambda: pass, which should be equal to lambda: None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be possible to type
lambda: pass, which should be equal tolambda: None?
Unfortunately not:
$ python3
Python 3.10.11 (main, Apr 13 2023, 01:52:20) [Clang 13.0.0 ] on openbsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> x = lambda: pass
File "<stdin>", line 1
x = lambda: pass
^^^^
SyntaxError: invalid syntax
I wonder what type checkers like mypy would consider as the correct falsy value for a lambda. Maybe None would be slightly better than False? (or maybe both would be rejected, idk). Anyways, False seems to do its job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I guess the comment isn't applicable, given that chattr can be installed on FreeBSD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the comment is already removed in #28116 (which I'll be updating).