1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 import arvados_fuse as fuse
10 import multiprocessing
12 import run_test_server
22 logger = logging.getLogger('arvados.arv-mount')
24 from .integration_test import workerPool
26 class MountTestBase(unittest.TestCase):
27 def setUp(self, api=None, local_store=True):
28 # The underlying C implementation of open() makes a fstat() syscall
29 # with the GIL still held. When the GETATTR message comes back to
30 # llfuse (which in these tests is in the same interpreter process) it
31 # can't acquire the GIL, so it can't service the fstat() call, so it
32 # deadlocks. The workaround is to run some of our test code in a
33 # separate process. Forturnately the multiprocessing module makes this
36 self.pool = workerPool()
38 self.keeptmp = tempfile.mkdtemp()
39 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
42 self.mounttmp = tempfile.mkdtemp()
44 run_test_server.authorize_with("admin")
45 self.api = api if api else arvados.safeapi.ThreadSafeApiCache(arvados.config.settings())
46 self.llfuse_thread = None
48 # This is a copy of Mount's method. TODO: Refactor MountTestBase
49 # to use a Mount instead of copying its code.
50 def _llfuse_main(self):
54 llfuse.close(unmount=False)
58 def make_mount(self, root_class, **root_kwargs):
59 self.operations = fuse.Operations(
60 os.getuid(), os.getgid(),
63 self.operations.inodes.add_entry(root_class(
64 llfuse.ROOT_INODE, self.operations.inodes, self.api, 0, **root_kwargs))
65 llfuse.init(self.operations, self.mounttmp, [])
66 self.llfuse_thread = threading.Thread(None, lambda: self._llfuse_main())
67 self.llfuse_thread.daemon = True
68 self.llfuse_thread.start()
69 # wait until the driver is finished initializing
70 self.operations.initlock.wait()
71 return self.operations.inodes[llfuse.ROOT_INODE]
74 if self.llfuse_thread:
75 if self.operations.events:
76 self.operations.events.close(timeout=10)
77 subprocess.call(["fusermount", "-u", "-z", self.mounttmp])
79 self.llfuse_thread.join(timeout=10)
80 if self.llfuse_thread.is_alive():
81 logger.warning("MountTestBase.tearDown():"
82 " llfuse thread still alive 10s after umount"
83 " -- exiting with SIGKILL")
84 os.kill(os.getpid(), signal.SIGKILL)
85 waited = time.time() - t0
87 logger.warning("MountTestBase.tearDown(): waited %f s for llfuse thread to end", waited)
89 os.rmdir(self.mounttmp)
91 shutil.rmtree(self.keeptmp)
92 os.environ.pop('KEEP_LOCAL_STORE')
93 run_test_server.reset()
95 def assertDirContents(self, subdir, expect_content):
98 path = os.path.join(path, subdir)
99 self.assertEqual(sorted(expect_content), sorted(llfuse.listdir(path)))