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, 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))
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))
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, 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, 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 d1 = os.listdir(self.mounttmp)
255 self.assertIn('Active User', d1)
257 d2 = os.listdir(os.path.join(self.mounttmp, 'Active User'))
259 self.assertEqual(['A Project',
261 "Empty collection.link",
262 "Pipeline Template with Input Parameter with Search.pipelineTemplate",
263 "Pipeline Template with Jobspec Components.pipelineTemplate",
264 "pipeline_with_job.pipelineInstance"
267 d3 = os.listdir(os.path.join(self.mounttmp, 'Active User', 'A Project'))
269 self.assertEqual(["A Subproject",
270 "Two Part Pipeline Template.pipelineTemplate",
271 "collection_to_move_around",
272 "zzzzz-4zz18-fy296fx3hot09f7 added sometime"
275 with open(os.path.join(self.mounttmp, 'Active User', "A Project", "Two Part Pipeline Template.pipelineTemplate")) as f:
277 self.assertEqual("Two Part Pipeline Template", j['name'])
280 class FuseHomeTest(MountTestBase):
282 operations = fuse.Operations(os.getuid(), os.getgid())
283 e = operations.inodes.add_entry(fuse.ProjectDirectory(llfuse.ROOT_INODE, operations.inodes, self.api, self.api.users().current().execute()))
285 llfuse.init(operations, self.mounttmp, [])
286 t = threading.Thread(None, lambda: llfuse.main())
289 # wait until the driver is finished initializing
290 operations.initlock.wait()
292 d1 = os.listdir(self.mounttmp)
294 self.assertIn('Unrestricted public data', d1)
296 d2 = os.listdir(os.path.join(self.mounttmp, 'Unrestricted public data'))
298 self.assertEqual(['GNU General Public License, version 3'], d2)
300 d3 = os.listdir(os.path.join(self.mounttmp, 'Unrestricted public data', 'GNU General Public License, version 3'))
302 self.assertEqual(["GNU_General_Public_License,_version_3.pdf"], d3)