3 import arvados.fuse as fuse
13 class FuseMountTest(unittest.TestCase):
15 self.keeptmp = tempfile.mkdtemp()
16 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
18 cw = arvados.CollectionWriter()
20 cw.start_new_file('thing1.txt')
22 cw.start_new_file('thing2.txt')
24 cw.start_new_stream('dir1')
26 cw.start_new_file('thing3.txt')
28 cw.start_new_file('thing4.txt')
31 cw.start_new_stream('dir2')
32 cw.start_new_file('thing5.txt')
34 cw.start_new_file('thing6.txt')
37 cw.start_new_stream('dir2/dir3')
38 cw.start_new_file('thing7.txt')
41 cw.start_new_file('thing8.txt')
44 self.testcollection = cw.finish()
47 # Create the request handler
48 operations = fuse.Operations(os.getuid(), os.getgid())
49 e = operations.inodes.add_entry(fuse.Directory(llfuse.ROOT_INODE))
50 operations.inodes.load_collection(e, arvados.CollectionReader(arvados.Keep.get(self.testcollection)))
52 self.mounttmp = tempfile.mkdtemp()
54 llfuse.init(operations, self.mounttmp, [])
55 t = threading.Thread(None, lambda: llfuse.main())
58 # wait until the driver is finished initializing
59 operations.initlock.wait()
61 # now check some stuff
62 d1 = os.listdir(self.mounttmp)
64 self.assertEqual(d1, ['dir1', 'dir2', 'thing1.txt', 'thing2.txt'])
66 d2 = os.listdir(os.path.join(self.mounttmp, 'dir1'))
68 self.assertEqual(d2, ['thing3.txt', 'thing4.txt'])
70 d3 = os.listdir(os.path.join(self.mounttmp, 'dir2'))
72 self.assertEqual(d3, ['dir3', 'thing5.txt', 'thing6.txt'])
74 d4 = os.listdir(os.path.join(self.mounttmp, 'dir2/dir3'))
76 self.assertEqual(d4, ['thing7.txt', 'thing8.txt'])
78 files = {'thing1.txt': 'data 1',
79 'thing2.txt': 'data 2',
80 'dir1/thing3.txt': 'data 3',
81 'dir1/thing4.txt': 'data 4',
82 'dir2/thing5.txt': 'data 5',
83 'dir2/thing6.txt': 'data 6',
84 'dir2/dir3/thing7.txt': 'data 7',
85 'dir2/dir3/thing8.txt': 'data 8'}
87 for k, v in files.items():
88 with open(os.path.join(self.mounttmp, k)) as f:
89 self.assertEqual(f.read(), v)
93 # llfuse.close is buggy, so use fusermount instead.
94 #llfuse.close(unmount=True)
95 subprocess.call(["fusermount", "-u", self.mounttmp])
97 os.rmdir(self.mounttmp)
98 shutil.rmtree(self.keeptmp)
100 class FuseMagicTest(unittest.TestCase):
102 self.keeptmp = tempfile.mkdtemp()
103 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
105 cw = arvados.CollectionWriter()
107 cw.start_new_file('thing1.txt')
110 self.testcollection = cw.finish()
113 # Create the request handler
114 operations = fuse.Operations(os.getuid(), os.getgid())
115 e = operations.inodes.add_entry(fuse.MagicDirectory(llfuse.ROOT_INODE, operations.inodes))
117 self.mounttmp = tempfile.mkdtemp()
119 llfuse.init(operations, self.mounttmp, [])
120 t = threading.Thread(None, lambda: llfuse.main())
123 # wait until the driver is finished initializing
124 operations.initlock.wait()
126 # now check some stuff
127 d1 = os.listdir(self.mounttmp)
129 self.assertEqual(d1, [])
131 d2 = os.listdir(os.path.join(self.mounttmp, self.testcollection))
133 self.assertEqual(d2, ['thing1.txt'])
135 d3 = os.listdir(self.mounttmp)
137 self.assertEqual(d3, [self.testcollection])
140 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
142 for k, v in files.items():
143 with open(os.path.join(self.mounttmp, k)) as f:
144 self.assertEqual(f.read(), v)
148 # llfuse.close is buggy, so use fusermount instead.
149 #llfuse.close(unmount=True)
150 subprocess.call(["fusermount", "-u", self.mounttmp])
152 os.rmdir(self.mounttmp)
153 shutil.rmtree(self.keeptmp)