3 import arvados_fuse as fuse
14 import multiprocessing
15 import run_test_server
17 logger = logging.getLogger('arvados.arv-mount')
19 class MountTestBase(unittest.TestCase):
20 def setUp(self, api=None, local_store=True):
21 # The underlying C implementation of open() makes a fstat() syscall
22 # with the GIL still held. When the GETATTR message comes back to
23 # llfuse (which in these tests is in the same interpreter process) it
24 # can't acquire the GIL, so it can't service the fstat() call, so it
25 # deadlocks. The workaround is to run some of our test code in a
26 # separate process. Forturnately the multiprocessing module makes this
28 self.pool = multiprocessing.Pool(1)
31 self.keeptmp = tempfile.mkdtemp()
32 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
35 self.mounttmp = tempfile.mkdtemp()
37 run_test_server.authorize_with("admin")
38 self.api = api if api else arvados.safeapi.ThreadSafeApiCache(arvados.config.settings())
40 # This is a copy of Mount's method. TODO: Refactor MountTestBase
41 # to use a Mount instead of copying its code.
42 def _llfuse_main(self):
46 llfuse.close(unmount=False)
50 def make_mount(self, root_class, **root_kwargs):
51 self.operations = fuse.Operations(
52 os.getuid(), os.getgid(),
55 self.operations.inodes.add_entry(root_class(
56 llfuse.ROOT_INODE, self.operations.inodes, self.api, 0, **root_kwargs))
57 llfuse.init(self.operations, self.mounttmp, [])
58 self.llfuse_thread = threading.Thread(None, lambda: self._llfuse_main())
59 self.llfuse_thread.daemon = True
60 self.llfuse_thread.start()
61 # wait until the driver is finished initializing
62 self.operations.initlock.wait()
63 return self.operations.inodes[llfuse.ROOT_INODE]
70 subprocess.call(["fusermount", "-u", "-z", self.mounttmp])
71 self.llfuse_thread.join(timeout=0.1)
72 if self.llfuse_thread.is_alive():
73 logger.warning("MountTestBase.tearDown():"
74 " llfuse thread still alive 100ms after umount"
75 " -- resorting to operations.destroy()")
76 self.operations.destroy()
78 os.rmdir(self.mounttmp)
80 shutil.rmtree(self.keeptmp)
81 os.environ.pop('KEEP_LOCAL_STORE')
82 run_test_server.reset()
84 def assertDirContents(self, subdir, expect_content):
87 path = os.path.join(path, subdir)
88 self.assertEqual(sorted(expect_content), sorted(llfuse.listdir(path)))