11 import arvados_fuse as fuse
12 import run_test_server
14 from mount_test_base import MountTestBase
16 logger = logging.getLogger('arvados.arv-mount')
19 class AssertWithTimeout(object):
20 """Allow some time for an assertion to pass."""
22 def __init__(self, timeout=0):
23 self.timeout = timeout
26 self.deadline = time.time() + self.timeout
35 def attempt(self, fn, *args, **kwargs):
38 except AssertionError:
39 if time.time() > self.deadline:
46 class FuseMountTest(MountTestBase):
48 super(FuseMountTest, self).setUp()
50 cw = arvados.CollectionWriter()
52 cw.start_new_file('thing1.txt')
54 cw.start_new_file('thing2.txt')
57 cw.start_new_stream('dir1')
58 cw.start_new_file('thing3.txt')
60 cw.start_new_file('thing4.txt')
63 cw.start_new_stream('dir2')
64 cw.start_new_file('thing5.txt')
66 cw.start_new_file('thing6.txt')
69 cw.start_new_stream('dir2/dir3')
70 cw.start_new_file('thing7.txt')
73 cw.start_new_file('thing8.txt')
76 cw.start_new_stream('edgecases')
77 for f in ":/.../-/*/\x01\\/ ".split("/"):
81 for f in ":/.../-/*/\x01\\/ ".split("/"):
82 cw.start_new_stream('edgecases/dirs/' + f)
83 cw.start_new_file('x/x')
86 self.testcollection = cw.finish()
87 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
90 self.make_mount(fuse.CollectionDirectory, collection_record=self.testcollection)
92 self.assertDirContents(None, ['thing1.txt', 'thing2.txt',
93 'edgecases', 'dir1', 'dir2'])
94 self.assertDirContents('dir1', ['thing3.txt', 'thing4.txt'])
95 self.assertDirContents('dir2', ['thing5.txt', 'thing6.txt', 'dir3'])
96 self.assertDirContents('dir2/dir3', ['thing7.txt', 'thing8.txt'])
97 self.assertDirContents('edgecases',
98 "dirs/:/.../-/*/\x01\\/ ".split("/"))
99 self.assertDirContents('edgecases/dirs',
100 ":/.../-/*/\x01\\/ ".split("/"))
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 FuseNoAPITest(MountTestBase):
118 super(FuseNoAPITest, self).setUp()
119 keep = arvados.keep.KeepClient(local_store=self.keeptmp)
120 self.file_data = "API-free text\n"
121 self.file_loc = keep.put(self.file_data)
122 self.coll_loc = keep.put(". {} 0:{}:api-free.txt\n".format(
123 self.file_loc, len(self.file_data)))
126 self.make_mount(fuse.MagicDirectory)
127 self.assertDirContents(self.coll_loc, ['api-free.txt'])
128 with open(os.path.join(
129 self.mounttmp, self.coll_loc, 'api-free.txt')) as keep_file:
130 actual = keep_file.read(-1)
131 self.assertEqual(self.file_data, actual)
134 class FuseMagicTest(MountTestBase):
135 def setUp(self, api=None):
136 super(FuseMagicTest, self).setUp(api=api)
138 cw = arvados.CollectionWriter()
140 cw.start_new_file('thing1.txt')
143 self.testcollection = cw.finish()
144 self.test_manifest = cw.manifest_text()
145 self.api.collections().create(body={"manifest_text":self.test_manifest}).execute()
148 self.make_mount(fuse.MagicDirectory)
150 mount_ls = llfuse.listdir(self.mounttmp)
151 self.assertIn('README', mount_ls)
152 self.assertFalse(any(arvados.util.keep_locator_pattern.match(fn) or
153 arvados.util.uuid_pattern.match(fn)
155 "new FUSE MagicDirectory lists Collection")
156 self.assertDirContents(self.testcollection, ['thing1.txt'])
157 self.assertDirContents(os.path.join('by_id', self.testcollection),
159 mount_ls = llfuse.listdir(self.mounttmp)
160 self.assertIn('README', mount_ls)
161 self.assertIn(self.testcollection, mount_ls)
162 self.assertIn(self.testcollection,
163 llfuse.listdir(os.path.join(self.mounttmp, 'by_id')))
166 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
168 for k, v in files.items():
169 with open(os.path.join(self.mounttmp, k)) as f:
170 self.assertEqual(v, f.read())
173 class FuseTagsTest(MountTestBase):
175 self.make_mount(fuse.TagsDirectory)
177 d1 = llfuse.listdir(self.mounttmp)
179 self.assertEqual(['foo_tag'], d1)
181 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag'))
183 self.assertEqual(['zzzzz-4zz18-fy296fx3hot09f7'], d2)
185 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag', 'zzzzz-4zz18-fy296fx3hot09f7'))
187 self.assertEqual(['foo'], d3)
190 class FuseTagsUpdateTest(MountTestBase):
191 def tag_collection(self, coll_uuid, tag_name):
192 return self.api.links().create(
193 body={'link': {'head_uuid': coll_uuid,
199 self.make_mount(fuse.TagsDirectory, poll_time=1)
201 self.assertIn('foo_tag', llfuse.listdir(self.mounttmp))
203 bar_uuid = run_test_server.fixture('collections')['bar_file']['uuid']
204 self.tag_collection(bar_uuid, 'fuse_test_tag')
205 for attempt in AssertWithTimeout(10):
206 attempt(self.assertIn, 'fuse_test_tag', llfuse.listdir(self.mounttmp))
207 self.assertDirContents('fuse_test_tag', [bar_uuid])
209 baz_uuid = run_test_server.fixture('collections')['baz_file']['uuid']
210 l = self.tag_collection(baz_uuid, 'fuse_test_tag')
211 for attempt in AssertWithTimeout(10):
212 attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid, baz_uuid])
214 self.api.links().delete(uuid=l['uuid']).execute()
215 for attempt in AssertWithTimeout(10):
216 attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid])
219 class FuseSharedTest(MountTestBase):
221 self.make_mount(fuse.SharedDirectory,
222 exclude=self.api.users().current().execute()['uuid'])
224 # shared_dirs is a list of the directories exposed
225 # by fuse.SharedDirectory (i.e. any object visible
226 # to the current user)
227 shared_dirs = llfuse.listdir(self.mounttmp)
229 self.assertIn('FUSE User', shared_dirs)
231 # fuse_user_objs is a list of the objects owned by the FUSE
232 # test user (which present as files in the 'FUSE User'
234 fuse_user_objs = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User'))
235 fuse_user_objs.sort()
236 self.assertEqual(['FUSE Test Project', # project owned by user
237 'collection #1 owned by FUSE', # collection owned by user
238 'collection #2 owned by FUSE', # collection owned by user
239 'pipeline instance owned by FUSE.pipelineInstance', # pipeline instance owned by user
242 # test_proj_files is a list of the files in the FUSE Test Project.
243 test_proj_files = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User', 'FUSE Test Project'))
244 test_proj_files.sort()
245 self.assertEqual(['collection in FUSE project',
246 'pipeline instance in FUSE project.pipelineInstance',
247 'pipeline template in FUSE project.pipelineTemplate'
250 # Double check that we can open and read objects in this folder as a file,
251 # and that its contents are what we expect.
252 pipeline_template_path = os.path.join(
256 'pipeline template in FUSE project.pipelineTemplate')
257 with open(pipeline_template_path) as f:
259 self.assertEqual("pipeline template in FUSE project", j['name'])
261 # check mtime on template
262 st = os.stat(pipeline_template_path)
264 mtime = st.st_mtime_ns / 1000000000
265 except AttributeError:
267 self.assertEqual(mtime, 1397493304)
269 # check mtime on collection
270 st = os.stat(os.path.join(
273 'collection #1 owned by FUSE'))
275 mtime = st.st_mtime_ns / 1000000000
276 except AttributeError:
278 self.assertEqual(mtime, 1391448174)
281 class FuseHomeTest(MountTestBase):
283 self.make_mount(fuse.ProjectDirectory,
284 project_object=self.api.users().current().execute())
286 d1 = llfuse.listdir(self.mounttmp)
287 self.assertIn('Unrestricted public data', d1)
289 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data'))
290 public_project = run_test_server.fixture('groups')[
291 'anonymously_accessible_project']
294 for name, item in run_test_server.fixture('collections').iteritems():
295 if 'name' not in item:
297 elif item['owner_uuid'] == public_project['uuid']:
298 self.assertIn(item['name'], d2)
301 # Artificial assumption here: there is no public
302 # collection fixture with the same name as a
303 # non-public collection.
304 self.assertNotIn(item['name'], d2)
306 self.assertNotEqual(0, found_in)
307 self.assertNotEqual(0, found_not_in)
309 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data', 'GNU General Public License, version 3'))
310 self.assertEqual(["GNU_General_Public_License,_version_3.pdf"], d3)
313 def fuseModifyFileTestHelperReadStartContents(mounttmp):
314 class Test(unittest.TestCase):
316 d1 = llfuse.listdir(mounttmp)
317 self.assertEqual(["file1.txt"], d1)
318 with open(os.path.join(mounttmp, "file1.txt")) as f:
319 self.assertEqual("blub", f.read())
322 def fuseModifyFileTestHelperReadEndContents(mounttmp):
323 class Test(unittest.TestCase):
325 d1 = llfuse.listdir(mounttmp)
326 self.assertEqual(["file1.txt"], d1)
327 with open(os.path.join(mounttmp, "file1.txt")) as f:
328 self.assertEqual("plnp", f.read())
331 class FuseModifyFileTest(MountTestBase):
333 collection = arvados.collection.Collection(api_client=self.api)
334 with collection.open("file1.txt", "w") as f:
337 collection.save_new()
339 m = self.make_mount(fuse.CollectionDirectory)
341 m.new_collection(collection.api_response(), collection)
343 self.pool.apply(fuseModifyFileTestHelperReadStartContents, (self.mounttmp,))
345 with collection.open("file1.txt", "w") as f:
348 self.pool.apply(fuseModifyFileTestHelperReadEndContents, (self.mounttmp,))
351 class FuseAddFileToCollectionTest(MountTestBase):
353 collection = arvados.collection.Collection(api_client=self.api)
354 with collection.open("file1.txt", "w") as f:
357 collection.save_new()
359 m = self.make_mount(fuse.CollectionDirectory)
361 m.new_collection(collection.api_response(), collection)
363 d1 = llfuse.listdir(self.mounttmp)
364 self.assertEqual(["file1.txt"], d1)
366 with collection.open("file2.txt", "w") as f:
369 d1 = llfuse.listdir(self.mounttmp)
370 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
373 class FuseRemoveFileFromCollectionTest(MountTestBase):
375 collection = arvados.collection.Collection(api_client=self.api)
376 with collection.open("file1.txt", "w") as f:
379 with collection.open("file2.txt", "w") as f:
382 collection.save_new()
384 m = self.make_mount(fuse.CollectionDirectory)
386 m.new_collection(collection.api_response(), collection)
388 d1 = llfuse.listdir(self.mounttmp)
389 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
391 collection.remove("file2.txt")
393 d1 = llfuse.listdir(self.mounttmp)
394 self.assertEqual(["file1.txt"], d1)
397 def fuseCreateFileTestHelper(mounttmp):
398 class Test(unittest.TestCase):
400 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
404 class FuseCreateFileTest(MountTestBase):
406 collection = arvados.collection.Collection(api_client=self.api)
407 collection.save_new()
409 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
410 self.assertEqual(collection2["manifest_text"], "")
412 collection.save_new()
414 m = self.make_mount(fuse.CollectionDirectory)
416 m.new_collection(collection.api_response(), collection)
417 self.assertTrue(m.writable())
419 self.assertNotIn("file1.txt", collection)
421 self.pool.apply(fuseCreateFileTestHelper, (self.mounttmp,))
423 self.assertIn("file1.txt", collection)
425 d1 = llfuse.listdir(self.mounttmp)
426 self.assertEqual(["file1.txt"], d1)
428 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
429 self.assertRegexpMatches(collection2["manifest_text"],
430 r'\. d41d8cd98f00b204e9800998ecf8427e\+0\+A\S+ 0:0:file1\.txt$')
433 def fuseWriteFileTestHelperWriteFile(mounttmp):
434 class Test(unittest.TestCase):
436 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
437 f.write("Hello world!")
440 def fuseWriteFileTestHelperReadFile(mounttmp):
441 class Test(unittest.TestCase):
443 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
444 self.assertEqual(f.read(), "Hello world!")
447 class FuseWriteFileTest(MountTestBase):
449 collection = arvados.collection.Collection(api_client=self.api)
450 collection.save_new()
452 m = self.make_mount(fuse.CollectionDirectory)
454 m.new_collection(collection.api_response(), collection)
455 self.assertTrue(m.writable())
457 self.assertNotIn("file1.txt", collection)
459 self.assertEqual(0, self.operations.write_counter.get())
460 self.pool.apply(fuseWriteFileTestHelperWriteFile, (self.mounttmp,))
461 self.assertEqual(12, self.operations.write_counter.get())
463 with collection.open("file1.txt") as f:
464 self.assertEqual(f.read(), "Hello world!")
466 self.assertEqual(0, self.operations.read_counter.get())
467 self.pool.apply(fuseWriteFileTestHelperReadFile, (self.mounttmp,))
468 self.assertEqual(12, self.operations.read_counter.get())
470 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
471 self.assertRegexpMatches(collection2["manifest_text"],
472 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
475 def fuseUpdateFileTestHelper(mounttmp):
476 class Test(unittest.TestCase):
478 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
479 f.write("Hello world!")
481 with open(os.path.join(mounttmp, "file1.txt"), "r+") as f:
483 self.assertEqual(fr, "Hello world!")
485 f.write("Hola mundo!")
488 self.assertEqual(fr, "Hola mundo!!")
490 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
491 self.assertEqual(f.read(), "Hola mundo!!")
495 class FuseUpdateFileTest(MountTestBase):
497 collection = arvados.collection.Collection(api_client=self.api)
498 collection.save_new()
500 m = self.make_mount(fuse.CollectionDirectory)
502 m.new_collection(collection.api_response(), collection)
503 self.assertTrue(m.writable())
505 # See note in MountTestBase.setUp
506 self.pool.apply(fuseUpdateFileTestHelper, (self.mounttmp,))
508 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
509 self.assertRegexpMatches(collection2["manifest_text"],
510 r'\. daaef200ebb921e011e3ae922dd3266b\+11\+A\S+ 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:11:file1\.txt 22:1:file1\.txt$')
513 def fuseMkdirTestHelper(mounttmp):
514 class Test(unittest.TestCase):
516 with self.assertRaises(IOError):
517 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
518 f.write("Hello world!")
520 os.mkdir(os.path.join(mounttmp, "testdir"))
522 with self.assertRaises(OSError):
523 os.mkdir(os.path.join(mounttmp, "testdir"))
525 d1 = llfuse.listdir(mounttmp)
526 self.assertEqual(["testdir"], d1)
528 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
529 f.write("Hello world!")
531 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
532 self.assertEqual(["file1.txt"], d1)
536 class FuseMkdirTest(MountTestBase):
538 collection = arvados.collection.Collection(api_client=self.api)
539 collection.save_new()
541 m = self.make_mount(fuse.CollectionDirectory)
543 m.new_collection(collection.api_response(), collection)
544 self.assertTrue(m.writable())
546 self.pool.apply(fuseMkdirTestHelper, (self.mounttmp,))
548 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
549 self.assertRegexpMatches(collection2["manifest_text"],
550 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
553 def fuseRmTestHelperWriteFile(mounttmp):
554 class Test(unittest.TestCase):
556 os.mkdir(os.path.join(mounttmp, "testdir"))
558 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
559 f.write("Hello world!")
563 def fuseRmTestHelperDeleteFile(mounttmp):
564 class Test(unittest.TestCase):
566 # Can't delete because it's not empty
567 with self.assertRaises(OSError):
568 os.rmdir(os.path.join(mounttmp, "testdir"))
570 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
571 self.assertEqual(["file1.txt"], d1)
574 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
576 # Make sure it's empty
577 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
578 self.assertEqual([], d1)
580 # Try to delete it again
581 with self.assertRaises(OSError):
582 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
586 def fuseRmTestHelperRmdir(mounttmp):
587 class Test(unittest.TestCase):
589 # Should be able to delete now that it is empty
590 os.rmdir(os.path.join(mounttmp, "testdir"))
592 # Make sure it's empty
593 d1 = llfuse.listdir(os.path.join(mounttmp))
594 self.assertEqual([], d1)
596 # Try to delete it again
597 with self.assertRaises(OSError):
598 os.rmdir(os.path.join(mounttmp, "testdir"))
602 class FuseRmTest(MountTestBase):
604 collection = arvados.collection.Collection(api_client=self.api)
605 collection.save_new()
607 m = self.make_mount(fuse.CollectionDirectory)
609 m.new_collection(collection.api_response(), collection)
610 self.assertTrue(m.writable())
612 self.pool.apply(fuseRmTestHelperWriteFile, (self.mounttmp,))
615 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
616 self.assertRegexpMatches(collection2["manifest_text"],
617 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
618 self.pool.apply(fuseRmTestHelperDeleteFile, (self.mounttmp,))
620 # Can't have empty directories :-( so manifest will be empty.
621 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
622 self.assertEqual(collection2["manifest_text"], "")
624 self.pool.apply(fuseRmTestHelperRmdir, (self.mounttmp,))
626 # manifest should be empty now.
627 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
628 self.assertEqual(collection2["manifest_text"], "")
631 def fuseMvFileTestHelperWriteFile(mounttmp):
632 class Test(unittest.TestCase):
634 os.mkdir(os.path.join(mounttmp, "testdir"))
636 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
637 f.write("Hello world!")
641 def fuseMvFileTestHelperMoveFile(mounttmp):
642 class Test(unittest.TestCase):
644 d1 = llfuse.listdir(os.path.join(mounttmp))
645 self.assertEqual(["testdir"], d1)
646 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
647 self.assertEqual(["file1.txt"], d1)
649 os.rename(os.path.join(mounttmp, "testdir", "file1.txt"), os.path.join(mounttmp, "file1.txt"))
651 d1 = llfuse.listdir(os.path.join(mounttmp))
652 self.assertEqual(["file1.txt", "testdir"], sorted(d1))
653 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
654 self.assertEqual([], d1)
658 class FuseMvFileTest(MountTestBase):
660 collection = arvados.collection.Collection(api_client=self.api)
661 collection.save_new()
663 m = self.make_mount(fuse.CollectionDirectory)
665 m.new_collection(collection.api_response(), collection)
666 self.assertTrue(m.writable())
668 self.pool.apply(fuseMvFileTestHelperWriteFile, (self.mounttmp,))
671 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
672 self.assertRegexpMatches(collection2["manifest_text"],
673 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
675 self.pool.apply(fuseMvFileTestHelperMoveFile, (self.mounttmp,))
677 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
678 self.assertRegexpMatches(collection2["manifest_text"],
679 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
682 def fuseRenameTestHelper(mounttmp):
683 class Test(unittest.TestCase):
685 os.mkdir(os.path.join(mounttmp, "testdir"))
687 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
688 f.write("Hello world!")
692 class FuseRenameTest(MountTestBase):
694 collection = arvados.collection.Collection(api_client=self.api)
695 collection.save_new()
697 m = self.make_mount(fuse.CollectionDirectory)
699 m.new_collection(collection.api_response(), collection)
700 self.assertTrue(m.writable())
702 self.pool.apply(fuseRenameTestHelper, (self.mounttmp,))
705 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
706 self.assertRegexpMatches(collection2["manifest_text"],
707 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
709 d1 = llfuse.listdir(os.path.join(self.mounttmp))
710 self.assertEqual(["testdir"], d1)
711 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
712 self.assertEqual(["file1.txt"], d1)
714 os.rename(os.path.join(self.mounttmp, "testdir"), os.path.join(self.mounttmp, "testdir2"))
716 d1 = llfuse.listdir(os.path.join(self.mounttmp))
717 self.assertEqual(["testdir2"], sorted(d1))
718 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir2"))
719 self.assertEqual(["file1.txt"], d1)
721 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
722 self.assertRegexpMatches(collection2["manifest_text"],
723 r'\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
726 class FuseUpdateFromEventTest(MountTestBase):
728 collection = arvados.collection.Collection(api_client=self.api)
729 collection.save_new()
731 m = self.make_mount(fuse.CollectionDirectory)
733 m.new_collection(collection.api_response(), collection)
735 self.operations.listen_for_events()
737 d1 = llfuse.listdir(os.path.join(self.mounttmp))
738 self.assertEqual([], sorted(d1))
740 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
741 with collection2.open("file1.txt", "w") as f:
744 for attempt in AssertWithTimeout(10):
745 attempt(self.assertEqual, ["file1.txt"], llfuse.listdir(os.path.join(self.mounttmp)))
748 def fuseFileConflictTestHelper(mounttmp):
749 class Test(unittest.TestCase):
751 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
754 d1 = sorted(llfuse.listdir(os.path.join(mounttmp)))
755 self.assertEqual(len(d1), 2)
757 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
758 self.assertEqual(f.read(), "bar")
760 self.assertRegexpMatches(d1[1],
761 r'file1\.txt~\d\d\d\d\d\d\d\d-\d\d\d\d\d\d~conflict~')
763 with open(os.path.join(mounttmp, d1[1]), "r") as f:
764 self.assertEqual(f.read(), "foo")
768 class FuseFileConflictTest(MountTestBase):
770 collection = arvados.collection.Collection(api_client=self.api)
771 collection.save_new()
773 m = self.make_mount(fuse.CollectionDirectory)
775 m.new_collection(collection.api_response(), collection)
777 d1 = llfuse.listdir(os.path.join(self.mounttmp))
778 self.assertEqual([], sorted(d1))
780 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
781 with collection2.open("file1.txt", "w") as f:
784 # See note in MountTestBase.setUp
785 self.pool.apply(fuseFileConflictTestHelper, (self.mounttmp,))
788 def fuseUnlinkOpenFileTest(mounttmp):
789 class Test(unittest.TestCase):
791 with open(os.path.join(mounttmp, "file1.txt"), "w+") as f:
794 d1 = llfuse.listdir(os.path.join(mounttmp))
795 self.assertEqual(["file1.txt"], sorted(d1))
797 os.remove(os.path.join(mounttmp, "file1.txt"))
799 d1 = llfuse.listdir(os.path.join(mounttmp))
800 self.assertEqual([], sorted(d1))
803 self.assertEqual(f.read(), "foo")
807 self.assertEqual(f.read(), "foobar")
811 class FuseUnlinkOpenFileTest(MountTestBase):
813 collection = arvados.collection.Collection(api_client=self.api)
814 collection.save_new()
816 m = self.make_mount(fuse.CollectionDirectory)
818 m.new_collection(collection.api_response(), collection)
820 # See note in MountTestBase.setUp
821 self.pool.apply(fuseUnlinkOpenFileTest, (self.mounttmp,))
823 self.assertEqual(collection.manifest_text(), "")
826 def fuseMvFileBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
827 class Test(unittest.TestCase):
829 with open(os.path.join(mounttmp, uuid1, "file1.txt"), "w") as f:
830 f.write("Hello world!")
832 d1 = os.listdir(os.path.join(mounttmp, uuid1))
833 self.assertEqual(["file1.txt"], sorted(d1))
834 d1 = os.listdir(os.path.join(mounttmp, uuid2))
835 self.assertEqual([], sorted(d1))
839 def fuseMvFileBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
840 class Test(unittest.TestCase):
842 os.rename(os.path.join(mounttmp, uuid1, "file1.txt"), os.path.join(mounttmp, uuid2, "file2.txt"))
844 d1 = os.listdir(os.path.join(mounttmp, uuid1))
845 self.assertEqual([], sorted(d1))
846 d1 = os.listdir(os.path.join(mounttmp, uuid2))
847 self.assertEqual(["file2.txt"], sorted(d1))
851 class FuseMvFileBetweenCollectionsTest(MountTestBase):
853 collection1 = arvados.collection.Collection(api_client=self.api)
854 collection1.save_new()
856 collection2 = arvados.collection.Collection(api_client=self.api)
857 collection2.save_new()
859 m = self.make_mount(fuse.MagicDirectory)
861 # See note in MountTestBase.setUp
862 self.pool.apply(fuseMvFileBetweenCollectionsTest1, (self.mounttmp,
863 collection1.manifest_locator(),
864 collection2.manifest_locator()))
869 self.assertRegexpMatches(collection1.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
870 self.assertEqual(collection2.manifest_text(), "")
872 self.pool.apply(fuseMvFileBetweenCollectionsTest2, (self.mounttmp,
873 collection1.manifest_locator(),
874 collection2.manifest_locator()))
879 self.assertEqual(collection1.manifest_text(), "")
880 self.assertRegexpMatches(collection2.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file2\.txt$")
882 collection1.stop_threads()
883 collection2.stop_threads()
886 def fuseMvDirBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
887 class Test(unittest.TestCase):
889 os.mkdir(os.path.join(mounttmp, uuid1, "testdir"))
890 with open(os.path.join(mounttmp, uuid1, "testdir", "file1.txt"), "w") as f:
891 f.write("Hello world!")
893 d1 = os.listdir(os.path.join(mounttmp, uuid1))
894 self.assertEqual(["testdir"], sorted(d1))
895 d1 = os.listdir(os.path.join(mounttmp, uuid1, "testdir"))
896 self.assertEqual(["file1.txt"], sorted(d1))
898 d1 = os.listdir(os.path.join(mounttmp, uuid2))
899 self.assertEqual([], sorted(d1))
904 def fuseMvDirBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
905 class Test(unittest.TestCase):
907 os.rename(os.path.join(mounttmp, uuid1, "testdir"), os.path.join(mounttmp, uuid2, "testdir2"))
909 d1 = os.listdir(os.path.join(mounttmp, uuid1))
910 self.assertEqual([], sorted(d1))
912 d1 = os.listdir(os.path.join(mounttmp, uuid2))
913 self.assertEqual(["testdir2"], sorted(d1))
914 d1 = os.listdir(os.path.join(mounttmp, uuid2, "testdir2"))
915 self.assertEqual(["file1.txt"], sorted(d1))
917 with open(os.path.join(mounttmp, uuid2, "testdir2", "file1.txt"), "r") as f:
918 self.assertEqual(f.read(), "Hello world!")
922 class FuseMvDirBetweenCollectionsTest(MountTestBase):
924 collection1 = arvados.collection.Collection(api_client=self.api)
925 collection1.save_new()
927 collection2 = arvados.collection.Collection(api_client=self.api)
928 collection2.save_new()
930 m = self.make_mount(fuse.MagicDirectory)
932 # See note in MountTestBase.setUp
933 self.pool.apply(fuseMvDirBetweenCollectionsTest1, (self.mounttmp,
934 collection1.manifest_locator(),
935 collection2.manifest_locator()))
940 self.assertRegexpMatches(collection1.manifest_text(), r"\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
941 self.assertEqual(collection2.manifest_text(), "")
943 self.pool.apply(fuseMvDirBetweenCollectionsTest2, (self.mounttmp,
944 collection1.manifest_locator(),
945 collection2.manifest_locator()))
950 self.assertEqual(collection1.manifest_text(), "")
951 self.assertRegexpMatches(collection2.manifest_text(), r"\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
953 collection1.stop_threads()
954 collection2.stop_threads()
956 def fuseProjectMkdirTestHelper1(mounttmp):
957 class Test(unittest.TestCase):
959 os.mkdir(os.path.join(mounttmp, "testcollection"))
960 with self.assertRaises(OSError):
961 os.mkdir(os.path.join(mounttmp, "testcollection"))
964 def fuseProjectMkdirTestHelper2(mounttmp):
965 class Test(unittest.TestCase):
967 with open(os.path.join(mounttmp, "testcollection", "file1.txt"), "w") as f:
968 f.write("Hello world!")
969 with self.assertRaises(OSError):
970 os.rmdir(os.path.join(mounttmp, "testcollection"))
971 os.remove(os.path.join(mounttmp, "testcollection", "file1.txt"))
972 with self.assertRaises(OSError):
973 os.remove(os.path.join(mounttmp, "testcollection"))
974 os.rmdir(os.path.join(mounttmp, "testcollection"))
977 class FuseProjectMkdirRmdirTest(MountTestBase):
979 self.make_mount(fuse.ProjectDirectory,
980 project_object=self.api.users().current().execute())
982 d1 = llfuse.listdir(self.mounttmp)
983 self.assertNotIn('testcollection', d1)
985 self.pool.apply(fuseProjectMkdirTestHelper1, (self.mounttmp,))
987 d1 = llfuse.listdir(self.mounttmp)
988 self.assertIn('testcollection', d1)
990 self.pool.apply(fuseProjectMkdirTestHelper2, (self.mounttmp,))
992 d1 = llfuse.listdir(self.mounttmp)
993 self.assertNotIn('testcollection', d1)
996 def fuseProjectMvTestHelper1(mounttmp):
997 class Test(unittest.TestCase):
999 d1 = llfuse.listdir(mounttmp)
1000 self.assertNotIn('testcollection', d1)
1002 os.mkdir(os.path.join(mounttmp, "testcollection"))
1004 d1 = llfuse.listdir(mounttmp)
1005 self.assertIn('testcollection', d1)
1007 with self.assertRaises(OSError):
1008 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data'))
1010 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data', 'testcollection'))
1012 d1 = llfuse.listdir(mounttmp)
1013 self.assertNotIn('testcollection', d1)
1015 d1 = llfuse.listdir(os.path.join(mounttmp, 'Unrestricted public data'))
1016 self.assertIn('testcollection', d1)
1020 class FuseProjectMvTest(MountTestBase):
1022 self.make_mount(fuse.ProjectDirectory,
1023 project_object=self.api.users().current().execute())
1025 self.pool.apply(fuseProjectMvTestHelper1, (self.mounttmp,))
1028 def fuseFsyncTestHelper(mounttmp, k):
1029 class Test(unittest.TestCase):
1031 fd = os.open(os.path.join(mounttmp, k), os.O_RDONLY)
1037 class FuseFsyncTest(FuseMagicTest):
1039 self.make_mount(fuse.MagicDirectory)
1040 self.pool.apply(fuseFsyncTestHelper, (self.mounttmp, self.testcollection))
1043 class MagicDirApiError(FuseMagicTest):
1045 api = mock.MagicMock()
1046 super(MagicDirApiError, self).setUp(api=api)
1047 api.collections().get().execute.side_effect = iter([Exception('API fail'), {"manifest_text": self.test_manifest}])
1048 api.keep.get.side_effect = Exception('Keep fail')
1051 self.make_mount(fuse.MagicDirectory)
1053 self.operations.inodes.inode_cache.cap = 1
1054 self.operations.inodes.inode_cache.min_entries = 2
1056 with self.assertRaises(OSError):
1057 llfuse.listdir(os.path.join(self.mounttmp, self.testcollection))
1059 llfuse.listdir(os.path.join(self.mounttmp, self.testcollection))
1062 class FuseUnitTest(unittest.TestCase):
1063 def test_sanitize_filename(self):
1082 for f in acceptable:
1083 self.assertEqual(f, fuse.sanitize_filename(f))
1084 for f in unacceptable:
1085 self.assertNotEqual(f, fuse.sanitize_filename(f))
1086 # The sanitized filename should be the same length, though.
1087 self.assertEqual(len(f), len(fuse.sanitize_filename(f)))
1089 self.assertEqual("_", fuse.sanitize_filename(""))
1090 self.assertEqual("_", fuse.sanitize_filename("."))
1091 self.assertEqual("__", fuse.sanitize_filename(".."))
1094 class FuseMagicTestPDHOnly(MountTestBase):
1095 def setUp(self, api=None):
1096 super(FuseMagicTestPDHOnly, self).setUp(api=api)
1098 cw = arvados.CollectionWriter()
1100 cw.start_new_file('thing1.txt')
1103 self.testcollection = cw.finish()
1104 self.test_manifest = cw.manifest_text()
1105 created = self.api.collections().create(body={"manifest_text":self.test_manifest}).execute()
1106 self.testcollectionuuid = str(created['uuid'])
1108 def verify_pdh_only(self, pdh_only=False, skip_pdh_only=False):
1109 if skip_pdh_only is True:
1110 self.make_mount(fuse.MagicDirectory) # in this case, the default by_id applies
1112 self.make_mount(fuse.MagicDirectory, pdh_only=pdh_only)
1114 mount_ls = llfuse.listdir(self.mounttmp)
1115 self.assertIn('README', mount_ls)
1116 self.assertFalse(any(arvados.util.keep_locator_pattern.match(fn) or
1117 arvados.util.uuid_pattern.match(fn)
1118 for fn in mount_ls),
1119 "new FUSE MagicDirectory lists Collection")
1121 # look up using pdh should succeed in all cases
1122 self.assertDirContents(self.testcollection, ['thing1.txt'])
1123 self.assertDirContents(os.path.join('by_id', self.testcollection),
1125 mount_ls = llfuse.listdir(self.mounttmp)
1126 self.assertIn('README', mount_ls)
1127 self.assertIn(self.testcollection, mount_ls)
1128 self.assertIn(self.testcollection,
1129 llfuse.listdir(os.path.join(self.mounttmp, 'by_id')))
1132 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
1134 for k, v in files.items():
1135 with open(os.path.join(self.mounttmp, k)) as f:
1136 self.assertEqual(v, f.read())
1138 # look up using uuid should fail when pdh_only is set
1139 if pdh_only is True:
1140 with self.assertRaises(OSError):
1141 self.assertDirContents(os.path.join('by_id', self.testcollectionuuid),
1144 self.assertDirContents(os.path.join('by_id', self.testcollectionuuid),
1147 def test_with_pdh_only_true(self):
1148 self.verify_pdh_only(pdh_only=True)
1150 def test_with_pdh_only_false(self):
1151 self.verify_pdh_only(pdh_only=False)
1153 def test_with_default_by_id(self):
1154 self.verify_pdh_only(skip_pdh_only=True)