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):
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)
30 self.keeptmp = tempfile.mkdtemp()
31 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
32 self.mounttmp = tempfile.mkdtemp()
34 run_test_server.authorize_with("admin")
35 self.api = api if api else arvados.safeapi.ThreadSafeApiCache(arvados.config.settings())
37 def make_mount(self, root_class, **root_kwargs):
38 self.operations = fuse.Operations(
39 os.getuid(), os.getgid(),
42 self.operations.inodes.add_entry(root_class(
43 llfuse.ROOT_INODE, self.operations.inodes, self.api, 0, **root_kwargs))
44 llfuse.init(self.operations, self.mounttmp, [])
45 threading.Thread(None, llfuse.main).start()
46 # wait until the driver is finished initializing
47 self.operations.initlock.wait()
48 return self.operations.inodes[llfuse.ROOT_INODE]
55 # llfuse.close is buggy, so use fusermount instead.
56 #llfuse.close(unmount=True)
60 while (count < 9 and success != 0):
61 success = subprocess.call(["fusermount", "-u", self.mounttmp])
65 self.operations.destroy()
67 os.rmdir(self.mounttmp)
68 shutil.rmtree(self.keeptmp)
69 os.environ.pop('KEEP_LOCAL_STORE')
70 run_test_server.reset()
72 def assertDirContents(self, subdir, expect_content):
75 path = os.path.join(path, subdir)
76 self.assertEqual(sorted(expect_content), sorted(llfuse.listdir(path)))