3 import arvados_fuse as fuse
12 import run_test_server
15 class MountTestBase(unittest.TestCase):
17 self.keeptmp = tempfile.mkdtemp()
18 os.environ['KEEP_LOCAL_STORE'] = self.keeptmp
19 self.mounttmp = tempfile.mkdtemp()
20 run_test_server.run(False)
21 run_test_server.authorize_with("admin")
22 self.api = api = fuse.SafeApi(arvados.config)
25 run_test_server.stop()
27 # llfuse.close is buggy, so use fusermount instead.
28 #llfuse.close(unmount=True)
31 while (count < 9 and success != 0):
32 success = subprocess.call(["fusermount", "-u", self.mounttmp])
36 os.rmdir(self.mounttmp)
37 shutil.rmtree(self.keeptmp)
40 class FuseMountTest(MountTestBase):
42 super(FuseMountTest, self).setUp()
44 cw = arvados.CollectionWriter()
46 cw.start_new_file('thing1.txt')
48 cw.start_new_file('thing2.txt')
50 cw.start_new_stream('dir1')
52 cw.start_new_file('thing3.txt')
54 cw.start_new_file('thing4.txt')
57 cw.start_new_stream('dir2')
58 cw.start_new_file('thing5.txt')
60 cw.start_new_file('thing6.txt')
63 cw.start_new_stream('dir2/dir3')
64 cw.start_new_file('thing7.txt')
67 cw.start_new_file('thing8.txt')
70 self.testcollection = cw.finish()
71 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
74 # Create the request handler
75 operations = fuse.Operations(os.getuid(), os.getgid())
76 e = operations.inodes.add_entry(fuse.CollectionDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0, self.testcollection))
78 llfuse.init(operations, self.mounttmp, [])
79 t = threading.Thread(None, lambda: llfuse.main())
82 # wait until the driver is finished initializing
83 operations.initlock.wait()
85 # now check some stuff
86 d1 = os.listdir(self.mounttmp)
88 self.assertEqual(['dir1', 'dir2', 'thing1.txt', 'thing2.txt'], d1)
90 d2 = os.listdir(os.path.join(self.mounttmp, 'dir1'))
92 self.assertEqual(['thing3.txt', 'thing4.txt'], d2)
94 d3 = os.listdir(os.path.join(self.mounttmp, 'dir2'))
96 self.assertEqual(['dir3', 'thing5.txt', 'thing6.txt'], d3)
98 d4 = os.listdir(os.path.join(self.mounttmp, 'dir2/dir3'))
100 self.assertEqual(['thing7.txt', 'thing8.txt'], d4)
102 files = {'thing1.txt': 'data 1',
103 'thing2.txt': 'data 2',
104 'dir1/thing3.txt': 'data 3',
105 'dir1/thing4.txt': 'data 4',
106 'dir2/thing5.txt': 'data 5',
107 'dir2/thing6.txt': 'data 6',
108 'dir2/dir3/thing7.txt': 'data 7',
109 'dir2/dir3/thing8.txt': 'data 8'}
111 for k, v in files.items():
112 with open(os.path.join(self.mounttmp, k)) as f:
113 self.assertEqual(v, f.read())
116 class FuseMagicTest(MountTestBase):
118 super(FuseMagicTest, self).setUp()
120 cw = arvados.CollectionWriter()
122 cw.start_new_file('thing1.txt')
125 self.testcollection = cw.finish()
126 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
129 # Create the request handler
130 operations = fuse.Operations(os.getuid(), os.getgid())
131 e = operations.inodes.add_entry(fuse.MagicDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0))
133 self.mounttmp = tempfile.mkdtemp()
135 llfuse.init(operations, self.mounttmp, [])
136 t = threading.Thread(None, lambda: llfuse.main())
139 # wait until the driver is finished initializing
140 operations.initlock.wait()
142 # now check some stuff
143 d1 = os.listdir(self.mounttmp)
145 self.assertEqual(['README'], d1)
147 d2 = os.listdir(os.path.join(self.mounttmp, self.testcollection))
149 self.assertEqual(['thing1.txt'], d2)
151 d3 = os.listdir(self.mounttmp)
153 self.assertEqual([self.testcollection, 'README'], d3)
156 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
158 for k, v in files.items():
159 with open(os.path.join(self.mounttmp, k)) as f:
160 self.assertEqual(v, f.read())
163 class FuseTagsTest(MountTestBase):
165 operations = fuse.Operations(os.getuid(), os.getgid())
166 e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0))
168 llfuse.init(operations, self.mounttmp, [])
169 t = threading.Thread(None, lambda: llfuse.main())
172 # wait until the driver is finished initializing
173 operations.initlock.wait()
175 d1 = os.listdir(self.mounttmp)
177 self.assertEqual(['foo_tag'], d1)
179 d2 = os.listdir(os.path.join(self.mounttmp, 'foo_tag'))
181 self.assertEqual(['zzzzz-4zz18-fy296fx3hot09f7'], d2)
183 d3 = os.listdir(os.path.join(self.mounttmp, 'foo_tag', 'zzzzz-4zz18-fy296fx3hot09f7'))
185 self.assertEqual(['foo'], d3)
188 class FuseTagsUpdateTest(MountTestBase):
189 def runRealTest(self):
190 operations = fuse.Operations(os.getuid(), os.getgid())
191 e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0, poll_time=1))
193 llfuse.init(operations, self.mounttmp, [])
194 t = threading.Thread(None, lambda: llfuse.main())
197 # wait until the driver is finished initializing
198 operations.initlock.wait()
200 d1 = os.listdir(self.mounttmp)
202 self.assertEqual(['foo_tag'], d1)
204 self.api.links().create(body={'link': {
205 'head_uuid': 'fa7aeb5140e2848d39b416daeef4ffc5+45',
212 d2 = os.listdir(self.mounttmp)
214 self.assertEqual(['bar_tag', 'foo_tag'], d2)
216 d3 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
218 self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d3)
220 l = self.api.links().create(body={'link': {
221 'head_uuid': 'ea10d51bcf88862dbcc36eb292017dfd+45',
228 d4 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
230 self.assertEqual(['ea10d51bcf88862dbcc36eb292017dfd+45', 'fa7aeb5140e2848d39b416daeef4ffc5+45'], d4)
232 self.api.links().delete(uuid=l['uuid']).execute()
236 d5 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
238 self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d5)
241 class FuseSharedTest(MountTestBase):
243 operations = fuse.Operations(os.getuid(), os.getgid())
244 e = operations.inodes.add_entry(fuse.SharedDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0, self.api.users().current().execute()['uuid']))
246 llfuse.init(operations, self.mounttmp, [])
247 t = threading.Thread(None, lambda: llfuse.main())
250 # wait until the driver is finished initializing
251 operations.initlock.wait()
253 # shared_dirs is a list of the directories exposed
254 # by fuse.SharedDirectory (i.e. any object visible
255 # to the current user)
256 shared_dirs = os.listdir(self.mounttmp)
258 self.assertIn('FUSE User', shared_dirs)
260 # fuse_user_objs is a list of the objects owned by the FUSE
261 # test user (which present as files in the 'FUSE User'
263 fuse_user_objs = os.listdir(os.path.join(self.mounttmp, 'FUSE User'))
264 fuse_user_objs.sort()
265 self.assertEqual(['Empty collection.link', # permission link on collection
266 'FUSE Test Project', # project owned by user
267 'collection #1 owned by FUSE', # collection owned by user
268 'collection #2 owned by FUSE', # collection owned by user
269 'pipeline instance owned by FUSE.pipelineInstance', # pipeline instance owned by user
272 # test_proj_files is a list of the files in the FUSE Test Project.
273 test_proj_files = os.listdir(os.path.join(self.mounttmp, 'FUSE User', 'FUSE Test Project'))
274 test_proj_files.sort()
275 self.assertEqual(['collection in FUSE project',
276 'pipeline instance in FUSE project.pipelineInstance',
277 'pipeline template in FUSE project.pipelineTemplate'
280 # Double check that we can open and read objects in this folder as a file,
281 # and that its contents are what we expect.
282 with open(os.path.join(
286 'pipeline template in FUSE project.pipelineTemplate')) as f:
288 self.assertEqual("pipeline template in FUSE project", j['name'])
291 class FuseHomeTest(MountTestBase):
293 operations = fuse.Operations(os.getuid(), os.getgid())
294 e = operations.inodes.add_entry(fuse.ProjectDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, 0, self.api.users().current().execute()))
296 llfuse.init(operations, self.mounttmp, [])
297 t = threading.Thread(None, lambda: llfuse.main())
300 # wait until the driver is finished initializing
301 operations.initlock.wait()
303 d1 = os.listdir(self.mounttmp)
305 self.assertIn('Unrestricted public data', d1)
307 d2 = os.listdir(os.path.join(self.mounttmp, 'Unrestricted public data'))
309 self.assertEqual(['GNU General Public License, version 3'], d2)
311 d3 = os.listdir(os.path.join(self.mounttmp, 'Unrestricted public data', 'GNU General Public License, version 3'))
313 self.assertEqual(["GNU_General_Public_License,_version_3.pdf"], d3)