3 import arvados_fuse as fuse
16 import multiprocessing
17 import run_test_server
19 logger = logging.getLogger('arvados.arv-mount')
21 class MountTestBase(unittest.TestCase):
23 # The underlying C implementation of open() makes a fstat() syscall
24 # with the GIL still held. When the GETATTR message comes back to
25 # llfuse (which in these tests is in the same interpreter process) it
26 # can't acquire the GIL, so it can't service the fstat() call, so it
27 # deadlocks. The workaround is to run some of our test code in a
28 # separate process. Forturnately the multiprocessing module makes this
30 self.pool = multiprocessing.Pool(1)
32 self.keeptmp = tempfile.mkdtemp()
33 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
34 self.mounttmp = tempfile.mkdtemp()
36 run_test_server.authorize_with("admin")
37 self.api = arvados.safeapi.ThreadSafeApiCache(arvados.config.settings())
39 def make_mount(self, root_class, **root_kwargs):
40 self.operations = fuse.Operations(os.getuid(), os.getgid(), enable_write=True)
41 self.operations.inodes.add_entry(root_class(
42 llfuse.ROOT_INODE, self.operations.inodes, self.api, 0, **root_kwargs))
43 llfuse.init(self.operations, self.mounttmp, [])
44 threading.Thread(None, llfuse.main).start()
45 # wait until the driver is finished initializing
46 self.operations.initlock.wait()
47 return self.operations.inodes[llfuse.ROOT_INODE]
54 # llfuse.close is buggy, so use fusermount instead.
55 #llfuse.close(unmount=True)
59 while (count < 9 and success != 0):
60 success = subprocess.call(["fusermount", "-u", self.mounttmp])
64 self.operations.destroy()
66 os.rmdir(self.mounttmp)
67 shutil.rmtree(self.keeptmp)
68 run_test_server.reset()
70 def assertDirContents(self, subdir, expect_content):
73 path = os.path.join(path, subdir)
74 self.assertEqual(sorted(expect_content), sorted(llfuse.listdir(path)))