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()
22 # llfuse.close is buggy, so use fusermount instead.
23 #llfuse.close(unmount=True)
24 subprocess.call(["fusermount", "-u", self.mounttmp])
26 os.rmdir(self.mounttmp)
27 shutil.rmtree(self.keeptmp)
30 class FuseMountTest(MountTestBase):
32 super(FuseMountTest, self).setUp()
34 cw = arvados.CollectionWriter()
36 cw.start_new_file('thing1.txt')
38 cw.start_new_file('thing2.txt')
40 cw.start_new_stream('dir1')
42 cw.start_new_file('thing3.txt')
44 cw.start_new_file('thing4.txt')
47 cw.start_new_stream('dir2')
48 cw.start_new_file('thing5.txt')
50 cw.start_new_file('thing6.txt')
53 cw.start_new_stream('dir2/dir3')
54 cw.start_new_file('thing7.txt')
57 cw.start_new_file('thing8.txt')
60 self.testcollection = cw.finish()
63 # Create the request handler
64 operations = fuse.Operations(os.getuid(), os.getgid())
65 e = operations.inodes.add_entry(fuse.CollectionDirectory(llfuse.ROOT_INODE, operations.inodes, self.testcollection))
67 llfuse.init(operations, self.mounttmp, [])
68 t = threading.Thread(None, lambda: llfuse.main())
71 # wait until the driver is finished initializing
72 operations.initlock.wait()
74 # now check some stuff
75 d1 = os.listdir(self.mounttmp)
77 self.assertEqual(['dir1', 'dir2', 'thing1.txt', 'thing2.txt'], d1)
79 d2 = os.listdir(os.path.join(self.mounttmp, 'dir1'))
81 self.assertEqual(['thing3.txt', 'thing4.txt'], d2)
83 d3 = os.listdir(os.path.join(self.mounttmp, 'dir2'))
85 self.assertEqual(['dir3', 'thing5.txt', 'thing6.txt'], d3)
87 d4 = os.listdir(os.path.join(self.mounttmp, 'dir2/dir3'))
89 self.assertEqual(['thing7.txt', 'thing8.txt'], d4)
91 files = {'thing1.txt': 'data 1',
92 'thing2.txt': 'data 2',
93 'dir1/thing3.txt': 'data 3',
94 'dir1/thing4.txt': 'data 4',
95 'dir2/thing5.txt': 'data 5',
96 'dir2/thing6.txt': 'data 6',
97 'dir2/dir3/thing7.txt': 'data 7',
98 'dir2/dir3/thing8.txt': 'data 8'}
100 for k, v in files.items():
101 with open(os.path.join(self.mounttmp, k)) as f:
102 self.assertEqual(v, f.read())
105 class FuseMagicTest(MountTestBase):
107 super(FuseMagicTest, self).setUp()
109 cw = arvados.CollectionWriter()
111 cw.start_new_file('thing1.txt')
114 self.testcollection = cw.finish()
117 # Create the request handler
118 operations = fuse.Operations(os.getuid(), os.getgid())
119 e = operations.inodes.add_entry(fuse.MagicDirectory(llfuse.ROOT_INODE, operations.inodes))
121 self.mounttmp = tempfile.mkdtemp()
123 llfuse.init(operations, self.mounttmp, [])
124 t = threading.Thread(None, lambda: llfuse.main())
127 # wait until the driver is finished initializing
128 operations.initlock.wait()
130 # now check some stuff
131 d1 = os.listdir(self.mounttmp)
133 self.assertEqual([], d1)
135 d2 = os.listdir(os.path.join(self.mounttmp, self.testcollection))
137 self.assertEqual(['thing1.txt'], d2)
139 d3 = os.listdir(self.mounttmp)
141 self.assertEqual([self.testcollection], d3)
144 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
146 for k, v in files.items():
147 with open(os.path.join(self.mounttmp, k)) as f:
148 self.assertEqual(v, f.read())
151 class FuseTagsTest(MountTestBase):
153 super(FuseTagsTest, self).setUp()
155 cw = arvados.CollectionWriter()
157 cw.start_new_file('foo')
160 self.testcollection = cw.finish()
162 run_test_server.run()
165 run_test_server.authorize_with("admin")
166 api = arvados.api('v1', cache=False)
168 operations = fuse.Operations(os.getuid(), os.getgid())
169 e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, api))
171 llfuse.init(operations, self.mounttmp, [])
172 t = threading.Thread(None, lambda: llfuse.main())
175 # wait until the driver is finished initializing
176 operations.initlock.wait()
178 d1 = os.listdir(self.mounttmp)
180 self.assertEqual(['foo_tag'], d1)
182 d2 = os.listdir(os.path.join(self.mounttmp, 'foo_tag'))
184 self.assertEqual(['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'], d2)
186 d3 = os.listdir(os.path.join(self.mounttmp, 'foo_tag', '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'))
188 self.assertEqual(['foo'], d3)
191 files[os.path.join(self.mounttmp, 'foo_tag', '1f4b0bc7583c2a7f9102c395f4ffc5e3+45', 'foo')] = 'foo'
193 for k, v in files.items():
194 with open(os.path.join(self.mounttmp, k)) as f:
195 self.assertEqual(v, f.read())
199 run_test_server.stop()
201 super(FuseTagsTest, self).tearDown()
203 class FuseTagsUpdateTestBase(MountTestBase):
205 def runRealTest(self):
206 run_test_server.authorize_with("admin")
207 api = arvados.api('v1', cache=False)
209 operations = fuse.Operations(os.getuid(), os.getgid())
210 e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, api, poll_time=1))
212 llfuse.init(operations, self.mounttmp, [])
213 t = threading.Thread(None, lambda: llfuse.main())
216 # wait until the driver is finished initializing
217 operations.initlock.wait()
219 d1 = os.listdir(self.mounttmp)
221 self.assertEqual(['foo_tag'], d1)
223 api.links().create(body={'link': {
224 'head_uuid': 'fa7aeb5140e2848d39b416daeef4ffc5+45',
231 d2 = os.listdir(self.mounttmp)
233 self.assertEqual(['bar_tag', 'foo_tag'], d2)
235 d3 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
237 self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d3)
239 l = api.links().create(body={'link': {
240 'head_uuid': 'ea10d51bcf88862dbcc36eb292017dfd+45',
247 d4 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
249 self.assertEqual(['ea10d51bcf88862dbcc36eb292017dfd+45', 'fa7aeb5140e2848d39b416daeef4ffc5+45'], d4)
251 api.links().delete(uuid=l['uuid']).execute()
255 d5 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
257 self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d5)
260 class FuseTagsUpdateTestWebsockets(FuseTagsUpdateTestBase):
262 super(FuseTagsUpdateTestWebsockets, self).setUp()
263 run_test_server.run(True)
269 run_test_server.stop()
270 super(FuseTagsUpdateTestWebsockets, self).tearDown()
273 class FuseTagsUpdateTestPoll(FuseTagsUpdateTestBase):
275 super(FuseTagsUpdateTestPoll, self).setUp()
276 run_test_server.run(False)
282 run_test_server.stop()
283 super(FuseTagsUpdateTestPoll, self).tearDown()
286 class FuseGroupsTest(MountTestBase):
288 super(FuseGroupsTest, self).setUp()
289 run_test_server.run()
292 run_test_server.authorize_with("admin")
293 api = arvados.api('v1', cache=False)
295 operations = fuse.Operations(os.getuid(), os.getgid())
296 e = operations.inodes.add_entry(fuse.GroupsDirectory(llfuse.ROOT_INODE, operations.inodes, api))
298 llfuse.init(operations, self.mounttmp, [])
299 t = threading.Thread(None, lambda: llfuse.main())
302 # wait until the driver is finished initializing
303 operations.initlock.wait()
305 d1 = os.listdir(self.mounttmp)
307 self.assertIn('zzzzz-j7d0g-v955i6s2oi1cbso', d1)
309 d2 = os.listdir(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso'))
311 self.assertEqual(['1f4b0bc7583c2a7f9102c395f4ffc5e3+45 added sometime',
312 "I'm a job in a folder",
313 "I'm a template in a folder",
314 "zzzzz-j58dm-5gid26432uujf79",
315 "zzzzz-j58dm-7r18rnd5nzhg5yk",
316 "zzzzz-j58dm-ypsjlol9dofwijz",
317 "zzzzz-j7d0g-axqo7eu9pwvna1x"
320 d3 = os.listdir(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso', 'zzzzz-j7d0g-axqo7eu9pwvna1x'))
322 self.assertEqual(["I'm in a subfolder, too",
323 "zzzzz-j58dm-c40lddwcqqr1ffs"
326 with open(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso', "I'm a template in a folder")) as f:
328 self.assertEqual("Two Part Pipeline Template", j['name'])
331 run_test_server.stop()
332 super(FuseGroupsTest, self).tearDown()