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)
26 while (count < 9 and success != 0):
27 success = subprocess.call(["fusermount", "-u", self.mounttmp])
31 os.rmdir(self.mounttmp)
32 shutil.rmtree(self.keeptmp)
35 class FuseMountTest(MountTestBase):
37 super(FuseMountTest, self).setUp()
39 cw = arvados.CollectionWriter()
41 cw.start_new_file('thing1.txt')
43 cw.start_new_file('thing2.txt')
45 cw.start_new_stream('dir1')
47 cw.start_new_file('thing3.txt')
49 cw.start_new_file('thing4.txt')
52 cw.start_new_stream('dir2')
53 cw.start_new_file('thing5.txt')
55 cw.start_new_file('thing6.txt')
58 cw.start_new_stream('dir2/dir3')
59 cw.start_new_file('thing7.txt')
62 cw.start_new_file('thing8.txt')
65 self.testcollection = cw.finish()
68 # Create the request handler
69 operations = fuse.Operations(os.getuid(), os.getgid())
70 e = operations.inodes.add_entry(fuse.CollectionDirectory(llfuse.ROOT_INODE, operations.inodes, self.testcollection))
72 llfuse.init(operations, self.mounttmp, [])
73 t = threading.Thread(None, lambda: llfuse.main())
76 # wait until the driver is finished initializing
77 operations.initlock.wait()
79 # now check some stuff
80 d1 = os.listdir(self.mounttmp)
82 self.assertEqual(['dir1', 'dir2', 'thing1.txt', 'thing2.txt'], d1)
84 d2 = os.listdir(os.path.join(self.mounttmp, 'dir1'))
86 self.assertEqual(['thing3.txt', 'thing4.txt'], d2)
88 d3 = os.listdir(os.path.join(self.mounttmp, 'dir2'))
90 self.assertEqual(['dir3', 'thing5.txt', 'thing6.txt'], d3)
92 d4 = os.listdir(os.path.join(self.mounttmp, 'dir2/dir3'))
94 self.assertEqual(['thing7.txt', 'thing8.txt'], d4)
96 files = {'thing1.txt': 'data 1',
97 'thing2.txt': 'data 2',
98 'dir1/thing3.txt': 'data 3',
99 'dir1/thing4.txt': 'data 4',
100 'dir2/thing5.txt': 'data 5',
101 'dir2/thing6.txt': 'data 6',
102 'dir2/dir3/thing7.txt': 'data 7',
103 'dir2/dir3/thing8.txt': 'data 8'}
105 for k, v in files.items():
106 with open(os.path.join(self.mounttmp, k)) as f:
107 self.assertEqual(v, f.read())
110 class FuseMagicTest(MountTestBase):
112 super(FuseMagicTest, self).setUp()
114 cw = arvados.CollectionWriter()
116 cw.start_new_file('thing1.txt')
119 self.testcollection = cw.finish()
122 # Create the request handler
123 operations = fuse.Operations(os.getuid(), os.getgid())
124 e = operations.inodes.add_entry(fuse.MagicDirectory(llfuse.ROOT_INODE, operations.inodes))
126 self.mounttmp = tempfile.mkdtemp()
128 llfuse.init(operations, self.mounttmp, [])
129 t = threading.Thread(None, lambda: llfuse.main())
132 # wait until the driver is finished initializing
133 operations.initlock.wait()
135 # now check some stuff
136 d1 = os.listdir(self.mounttmp)
138 self.assertEqual([], d1)
140 d2 = os.listdir(os.path.join(self.mounttmp, self.testcollection))
142 self.assertEqual(['thing1.txt'], d2)
144 d3 = os.listdir(self.mounttmp)
146 self.assertEqual([self.testcollection], d3)
149 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
151 for k, v in files.items():
152 with open(os.path.join(self.mounttmp, k)) as f:
153 self.assertEqual(v, f.read())
156 # Restore these tests when working on issue #3644
158 # class FuseTagsTest(MountTestBase):
160 # super(FuseTagsTest, self).setUp()
162 # cw = arvados.CollectionWriter()
164 # cw.start_new_file('foo')
167 # self.testcollection = cw.finish()
169 # run_test_server.run()
172 # run_test_server.authorize_with("admin")
173 # api = arvados.api('v1', cache=False)
175 # operations = fuse.Operations(os.getuid(), os.getgid())
176 # e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, api))
178 # llfuse.init(operations, self.mounttmp, [])
179 # t = threading.Thread(None, lambda: llfuse.main())
182 # # wait until the driver is finished initializing
183 # operations.initlock.wait()
185 # d1 = os.listdir(self.mounttmp)
187 # self.assertEqual(['foo_tag'], d1)
189 # d2 = os.listdir(os.path.join(self.mounttmp, 'foo_tag'))
191 # self.assertEqual(['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'], d2)
193 # d3 = os.listdir(os.path.join(self.mounttmp, 'foo_tag', '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'))
195 # self.assertEqual(['foo'], d3)
198 # files[os.path.join(self.mounttmp, 'foo_tag', '1f4b0bc7583c2a7f9102c395f4ffc5e3+45', 'foo')] = 'foo'
200 # for k, v in files.items():
201 # with open(os.path.join(self.mounttmp, k)) as f:
202 # self.assertEqual(v, f.read())
205 # def tearDown(self):
206 # run_test_server.stop()
208 # super(FuseTagsTest, self).tearDown()
210 # class FuseTagsUpdateTestBase(MountTestBase):
212 # def runRealTest(self):
213 # run_test_server.authorize_with("admin")
214 # api = arvados.api('v1', cache=False)
216 # operations = fuse.Operations(os.getuid(), os.getgid())
217 # e = operations.inodes.add_entry(fuse.TagsDirectory(llfuse.ROOT_INODE, operations.inodes, api, poll_time=1))
219 # llfuse.init(operations, self.mounttmp, [])
220 # t = threading.Thread(None, lambda: llfuse.main())
223 # # wait until the driver is finished initializing
224 # operations.initlock.wait()
226 # d1 = os.listdir(self.mounttmp)
228 # self.assertEqual(['foo_tag'], d1)
230 # api.links().create(body={'link': {
231 # 'head_uuid': 'fa7aeb5140e2848d39b416daeef4ffc5+45',
232 # 'link_class': 'tag',
238 # d2 = os.listdir(self.mounttmp)
240 # self.assertEqual(['bar_tag', 'foo_tag'], d2)
242 # d3 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
244 # self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d3)
246 # l = api.links().create(body={'link': {
247 # 'head_uuid': 'ea10d51bcf88862dbcc36eb292017dfd+45',
248 # 'link_class': 'tag',
254 # d4 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
256 # self.assertEqual(['ea10d51bcf88862dbcc36eb292017dfd+45', 'fa7aeb5140e2848d39b416daeef4ffc5+45'], d4)
258 # api.links().delete(uuid=l['uuid']).execute()
262 # d5 = os.listdir(os.path.join(self.mounttmp, 'bar_tag'))
264 # self.assertEqual(['fa7aeb5140e2848d39b416daeef4ffc5+45'], d5)
267 # class FuseTagsUpdateTestWebsockets(FuseTagsUpdateTestBase):
269 # super(FuseTagsUpdateTestWebsockets, self).setUp()
270 # run_test_server.run(True)
275 # def tearDown(self):
276 # run_test_server.stop()
277 # super(FuseTagsUpdateTestWebsockets, self).tearDown()
280 # class FuseTagsUpdateTestPoll(FuseTagsUpdateTestBase):
282 # super(FuseTagsUpdateTestPoll, self).setUp()
283 # run_test_server.run(False)
288 # def tearDown(self):
289 # run_test_server.stop()
290 # super(FuseTagsUpdateTestPoll, self).tearDown()
293 # class FuseGroupsTest(MountTestBase):
295 # super(FuseGroupsTest, self).setUp()
296 # run_test_server.run()
299 # run_test_server.authorize_with("admin")
300 # api = arvados.api('v1', cache=False)
302 # operations = fuse.Operations(os.getuid(), os.getgid())
303 # e = operations.inodes.add_entry(fuse.GroupsDirectory(llfuse.ROOT_INODE, operations.inodes, api))
305 # llfuse.init(operations, self.mounttmp, [])
306 # t = threading.Thread(None, lambda: llfuse.main())
309 # # wait until the driver is finished initializing
310 # operations.initlock.wait()
312 # d1 = os.listdir(self.mounttmp)
314 # self.assertIn('zzzzz-j7d0g-v955i6s2oi1cbso', d1)
316 # d2 = os.listdir(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso'))
318 # self.assertEqual(['1f4b0bc7583c2a7f9102c395f4ffc5e3+45 added sometime',
319 # "I'm a job in a project",
320 # "I'm a template in a project",
321 # "zzzzz-j58dm-5gid26432uujf79",
322 # "zzzzz-j58dm-7r18rnd5nzhg5yk",
323 # "zzzzz-j58dm-ypsjlol9dofwijz",
324 # "zzzzz-j7d0g-axqo7eu9pwvna1x"
327 # d3 = os.listdir(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso', 'zzzzz-j7d0g-axqo7eu9pwvna1x'))
329 # self.assertEqual(["I'm in a subproject, too",
330 # "ea10d51bcf88862dbcc36eb292017dfd+45 added sometime",
331 # "zzzzz-j58dm-c40lddwcqqr1ffs"
334 # with open(os.path.join(self.mounttmp, 'zzzzz-j7d0g-v955i6s2oi1cbso', "I'm a template in a project")) as f:
336 # self.assertEqual("Two Part Pipeline Template", j['name'])
338 # def tearDown(self):
339 # run_test_server.stop()
340 # super(FuseGroupsTest, self).tearDown()