test/data: add mount_flags.py helper script
Add a new helper script to check if a mount / file-system was mounted with specific flags. Currently only "ro", "nosuid", "nodev" and "noexec" flags are supported. This script is in test/data since it will be used from other tests and is itself not a test per se.
This commit is contained in:
parent
28cea491bd
commit
bcfc2ca29a
2 changed files with 54 additions and 0 deletions
|
|
@ -41,3 +41,7 @@ do not allow comments, this file shortly describes their purpose.
|
||||||
This directory contains test-data for runtime tests of the source-engines. It
|
This directory contains test-data for runtime tests of the source-engines. It
|
||||||
contains a directory that is served via HTTP in the tests, and a directory of
|
contains a directory that is served via HTTP in the tests, and a directory of
|
||||||
test-cases what to expect when using the attached `sources.json`.
|
test-cases what to expect when using the attached `sources.json`.
|
||||||
|
|
||||||
|
* `scripts`:
|
||||||
|
This directory contains scripts used from other tests, i.e. although they are
|
||||||
|
executables they are at the same time test-data to the actual (unit) tests.
|
||||||
|
|
|
||||||
50
test/data/scripts/mount_flags.py
Executable file
50
test/data/scripts/mount_flags.py
Executable file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
#
|
||||||
|
# Small script that returns 0 if all the requested mount flags
|
||||||
|
# are present for a given mount and returns 1 otherwise
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
# from /usr/include/sys/mount.h
|
||||||
|
# these are file-system independent
|
||||||
|
MS_RDONLY = 1
|
||||||
|
MS_NOSUID = 2
|
||||||
|
MS_NODEV = 4
|
||||||
|
MS_NOEXEC = 8
|
||||||
|
|
||||||
|
KNOWN_FLAGS = {
|
||||||
|
"ro": MS_RDONLY,
|
||||||
|
"nosuid": MS_NOSUID,
|
||||||
|
"nodev": MS_NODEV,
|
||||||
|
"noexec": MS_NOEXEC
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description="Check for mount flags")
|
||||||
|
parser.add_argument("path", metavar="PATH",
|
||||||
|
help="path for the file-system to check for read-only status")
|
||||||
|
parser.add_argument("flags", metavar="FLAGS",
|
||||||
|
help="comma separated list of flags to check for")
|
||||||
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
|
want = 0
|
||||||
|
strflags = [x.strip() for x in args.flags.split(",")]
|
||||||
|
for flag in strflags:
|
||||||
|
num = KNOWN_FLAGS.get(flag, None)
|
||||||
|
if flag is None:
|
||||||
|
print(f"Unknown flag: '{flag}'")
|
||||||
|
sys.exit(2)
|
||||||
|
want |= num
|
||||||
|
|
||||||
|
sb = os.statvfs(args.path)
|
||||||
|
have = sb.f_flag
|
||||||
|
ok = (have & want) == want
|
||||||
|
sys.exit(0 if ok else 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue