3 import arvados_fuse as fuse
16 import multiprocessing
17 import run_test_server
21 from mount_test_base import MountTestBase
23 logger = logging.getLogger('arvados.arv-mount')
26 class AssertWithTimeout(object):
27 """Allow some time for an assertion to pass."""
29 def __init__(self, timeout=0):
30 self.timeout = timeout
33 self.deadline = time.time() + self.timeout
42 def attempt(self, fn, *args, **kwargs):
45 except AssertionError:
46 if time.time() > self.deadline:
53 class FuseMountTest(MountTestBase):
55 super(FuseMountTest, self).setUp()
57 cw = arvados.CollectionWriter()
59 cw.start_new_file('thing1.txt')
61 cw.start_new_file('thing2.txt')
64 cw.start_new_stream('dir1')
65 cw.start_new_file('thing3.txt')
67 cw.start_new_file('thing4.txt')
70 cw.start_new_stream('dir2')
71 cw.start_new_file('thing5.txt')
73 cw.start_new_file('thing6.txt')
76 cw.start_new_stream('dir2/dir3')
77 cw.start_new_file('thing7.txt')
80 cw.start_new_file('thing8.txt')
83 cw.start_new_stream('edgecases')
84 for f in ":/.../-/*/\x01\\/ ".split("/"):
88 for f in ":/.../-/*/\x01\\/ ".split("/"):
89 cw.start_new_stream('edgecases/dirs/' + f)
90 cw.start_new_file('x/x')
93 self.testcollection = cw.finish()
94 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
97 self.make_mount(fuse.CollectionDirectory, collection_record=self.testcollection)
99 self.assertDirContents(None, ['thing1.txt', 'thing2.txt',
100 'edgecases', 'dir1', 'dir2'])
101 self.assertDirContents('dir1', ['thing3.txt', 'thing4.txt'])
102 self.assertDirContents('dir2', ['thing5.txt', 'thing6.txt', 'dir3'])
103 self.assertDirContents('dir2/dir3', ['thing7.txt', 'thing8.txt'])
104 self.assertDirContents('edgecases',
105 "dirs/:/.../-/*/\x01\\/ ".split("/"))
106 self.assertDirContents('edgecases/dirs',
107 ":/.../-/*/\x01\\/ ".split("/"))
109 files = {'thing1.txt': 'data 1',
110 'thing2.txt': 'data 2',
111 'dir1/thing3.txt': 'data 3',
112 'dir1/thing4.txt': 'data 4',
113 'dir2/thing5.txt': 'data 5',
114 'dir2/thing6.txt': 'data 6',
115 'dir2/dir3/thing7.txt': 'data 7',
116 'dir2/dir3/thing8.txt': 'data 8'}
118 for k, v in files.items():
119 with open(os.path.join(self.mounttmp, k)) as f:
120 self.assertEqual(v, f.read())
123 class FuseNoAPITest(MountTestBase):
125 super(FuseNoAPITest, self).setUp()
126 keep = arvados.keep.KeepClient(local_store=self.keeptmp)
127 self.file_data = "API-free text\n"
128 self.file_loc = keep.put(self.file_data)
129 self.coll_loc = keep.put(". {} 0:{}:api-free.txt\n".format(
130 self.file_loc, len(self.file_data)))
133 self.make_mount(fuse.MagicDirectory)
134 self.assertDirContents(self.coll_loc, ['api-free.txt'])
135 with open(os.path.join(
136 self.mounttmp, self.coll_loc, 'api-free.txt')) as keep_file:
137 actual = keep_file.read(-1)
138 self.assertEqual(self.file_data, actual)
141 class FuseMagicTest(MountTestBase):
142 def setUp(self, api=None):
143 super(FuseMagicTest, self).setUp(api=api)
145 cw = arvados.CollectionWriter()
147 cw.start_new_file('thing1.txt')
150 self.testcollection = cw.finish()
151 self.test_manifest = cw.manifest_text()
152 self.api.collections().create(body={"manifest_text":self.test_manifest}).execute()
155 self.make_mount(fuse.MagicDirectory)
157 mount_ls = llfuse.listdir(self.mounttmp)
158 self.assertIn('README', mount_ls)
159 self.assertFalse(any(arvados.util.keep_locator_pattern.match(fn) or
160 arvados.util.uuid_pattern.match(fn)
162 "new FUSE MagicDirectory lists Collection")
163 self.assertDirContents(self.testcollection, ['thing1.txt'])
164 self.assertDirContents(os.path.join('by_id', self.testcollection),
166 mount_ls = llfuse.listdir(self.mounttmp)
167 self.assertIn('README', mount_ls)
168 self.assertIn(self.testcollection, mount_ls)
169 self.assertIn(self.testcollection,
170 llfuse.listdir(os.path.join(self.mounttmp, 'by_id')))
173 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
175 for k, v in files.items():
176 with open(os.path.join(self.mounttmp, k)) as f:
177 self.assertEqual(v, f.read())
180 class FuseTagsTest(MountTestBase):
182 self.make_mount(fuse.TagsDirectory)
184 d1 = llfuse.listdir(self.mounttmp)
186 self.assertEqual(['foo_tag'], d1)
188 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag'))
190 self.assertEqual(['zzzzz-4zz18-fy296fx3hot09f7'], d2)
192 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag', 'zzzzz-4zz18-fy296fx3hot09f7'))
194 self.assertEqual(['foo'], d3)
197 class FuseTagsUpdateTest(MountTestBase):
198 def tag_collection(self, coll_uuid, tag_name):
199 return self.api.links().create(
200 body={'link': {'head_uuid': coll_uuid,
206 self.make_mount(fuse.TagsDirectory, poll_time=1)
208 self.assertIn('foo_tag', llfuse.listdir(self.mounttmp))
210 bar_uuid = run_test_server.fixture('collections')['bar_file']['uuid']
211 self.tag_collection(bar_uuid, 'fuse_test_tag')
212 for attempt in AssertWithTimeout(10):
213 attempt(self.assertIn, 'fuse_test_tag', llfuse.listdir(self.mounttmp))
214 self.assertDirContents('fuse_test_tag', [bar_uuid])
216 baz_uuid = run_test_server.fixture('collections')['baz_file']['uuid']
217 l = self.tag_collection(baz_uuid, 'fuse_test_tag')
218 for attempt in AssertWithTimeout(10):
219 attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid, baz_uuid])
221 self.api.links().delete(uuid=l['uuid']).execute()
222 for attempt in AssertWithTimeout(10):
223 attempt(self.assertDirContents, 'fuse_test_tag', [bar_uuid])
226 class FuseSharedTest(MountTestBase):
228 self.make_mount(fuse.SharedDirectory,
229 exclude=self.api.users().current().execute()['uuid'])
231 # shared_dirs is a list of the directories exposed
232 # by fuse.SharedDirectory (i.e. any object visible
233 # to the current user)
234 shared_dirs = llfuse.listdir(self.mounttmp)
236 self.assertIn('FUSE User', shared_dirs)
238 # fuse_user_objs is a list of the objects owned by the FUSE
239 # test user (which present as files in the 'FUSE User'
241 fuse_user_objs = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User'))
242 fuse_user_objs.sort()
243 self.assertEqual(['FUSE Test Project', # project owned by user
244 'collection #1 owned by FUSE', # collection owned by user
245 'collection #2 owned by FUSE', # collection owned by user
246 'pipeline instance owned by FUSE.pipelineInstance', # pipeline instance owned by user
249 # test_proj_files is a list of the files in the FUSE Test Project.
250 test_proj_files = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User', 'FUSE Test Project'))
251 test_proj_files.sort()
252 self.assertEqual(['collection in FUSE project',
253 'pipeline instance in FUSE project.pipelineInstance',
254 'pipeline template in FUSE project.pipelineTemplate'
257 # Double check that we can open and read objects in this folder as a file,
258 # and that its contents are what we expect.
259 pipeline_template_path = os.path.join(
263 'pipeline template in FUSE project.pipelineTemplate')
264 with open(pipeline_template_path) as f:
266 self.assertEqual("pipeline template in FUSE project", j['name'])
268 # check mtime on template
269 st = os.stat(pipeline_template_path)
270 self.assertEqual(st.st_mtime, 1397493304)
272 # check mtime on collection
273 st = os.stat(os.path.join(
276 'collection #1 owned by FUSE'))
277 self.assertEqual(st.st_mtime, 1391448174)
280 class FuseHomeTest(MountTestBase):
282 self.make_mount(fuse.ProjectDirectory,
283 project_object=self.api.users().current().execute())
285 d1 = llfuse.listdir(self.mounttmp)
286 self.assertIn('Unrestricted public data', d1)
288 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data'))
289 public_project = run_test_server.fixture('groups')[
290 'anonymously_accessible_project']
293 for name, item in run_test_server.fixture('collections').iteritems():
294 if 'name' not in item:
296 elif item['owner_uuid'] == public_project['uuid']:
297 self.assertIn(item['name'], d2)
300 # Artificial assumption here: there is no public
301 # collection fixture with the same name as a
302 # non-public collection.
303 self.assertNotIn(item['name'], d2)
305 self.assertNotEqual(0, found_in)
306 self.assertNotEqual(0, found_not_in)
308 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data', 'GNU General Public License, version 3'))
309 self.assertEqual(["GNU_General_Public_License,_version_3.pdf"], d3)
312 def fuseModifyFileTestHelperReadStartContents(mounttmp):
313 class Test(unittest.TestCase):
315 d1 = llfuse.listdir(mounttmp)
316 self.assertEqual(["file1.txt"], d1)
317 with open(os.path.join(mounttmp, "file1.txt")) as f:
318 self.assertEqual("blub", f.read())
321 def fuseModifyFileTestHelperReadEndContents(mounttmp):
322 class Test(unittest.TestCase):
324 d1 = llfuse.listdir(mounttmp)
325 self.assertEqual(["file1.txt"], d1)
326 with open(os.path.join(mounttmp, "file1.txt")) as f:
327 self.assertEqual("plnp", f.read())
330 class FuseModifyFileTest(MountTestBase):
332 collection = arvados.collection.Collection(api_client=self.api)
333 with collection.open("file1.txt", "w") as f:
336 collection.save_new()
338 m = self.make_mount(fuse.CollectionDirectory)
340 m.new_collection(collection.api_response(), collection)
342 self.pool.apply(fuseModifyFileTestHelperReadStartContents, (self.mounttmp,))
344 with collection.open("file1.txt", "w") as f:
347 self.pool.apply(fuseModifyFileTestHelperReadEndContents, (self.mounttmp,))
350 class FuseAddFileToCollectionTest(MountTestBase):
352 collection = arvados.collection.Collection(api_client=self.api)
353 with collection.open("file1.txt", "w") as f:
356 collection.save_new()
358 m = self.make_mount(fuse.CollectionDirectory)
360 m.new_collection(collection.api_response(), collection)
362 d1 = llfuse.listdir(self.mounttmp)
363 self.assertEqual(["file1.txt"], d1)
365 with collection.open("file2.txt", "w") as f:
368 d1 = llfuse.listdir(self.mounttmp)
369 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
372 class FuseRemoveFileFromCollectionTest(MountTestBase):
374 collection = arvados.collection.Collection(api_client=self.api)
375 with collection.open("file1.txt", "w") as f:
378 with collection.open("file2.txt", "w") as f:
381 collection.save_new()
383 m = self.make_mount(fuse.CollectionDirectory)
385 m.new_collection(collection.api_response(), collection)
387 d1 = llfuse.listdir(self.mounttmp)
388 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
390 collection.remove("file2.txt")
392 d1 = llfuse.listdir(self.mounttmp)
393 self.assertEqual(["file1.txt"], d1)
396 def fuseCreateFileTestHelper(mounttmp):
397 class Test(unittest.TestCase):
399 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
403 class FuseCreateFileTest(MountTestBase):
405 collection = arvados.collection.Collection(api_client=self.api)
406 collection.save_new()
408 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
409 self.assertEqual(collection2["manifest_text"], "")
411 collection.save_new()
413 m = self.make_mount(fuse.CollectionDirectory)
415 m.new_collection(collection.api_response(), collection)
416 self.assertTrue(m.writable())
418 self.assertNotIn("file1.txt", collection)
420 self.pool.apply(fuseCreateFileTestHelper, (self.mounttmp,))
422 self.assertIn("file1.txt", collection)
424 d1 = llfuse.listdir(self.mounttmp)
425 self.assertEqual(["file1.txt"], d1)
427 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
428 self.assertRegexpMatches(collection2["manifest_text"],
429 r'\. d41d8cd98f00b204e9800998ecf8427e\+0\+A\S+ 0:0:file1\.txt$')
432 def fuseWriteFileTestHelperWriteFile(mounttmp):
433 class Test(unittest.TestCase):
435 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
436 f.write("Hello world!")
439 def fuseWriteFileTestHelperReadFile(mounttmp):
440 class Test(unittest.TestCase):
442 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
443 self.assertEqual(f.read(), "Hello world!")
446 class FuseWriteFileTest(MountTestBase):
448 collection = arvados.collection.Collection(api_client=self.api)
449 collection.save_new()
451 m = self.make_mount(fuse.CollectionDirectory)
453 m.new_collection(collection.api_response(), collection)
454 self.assertTrue(m.writable())
456 self.assertNotIn("file1.txt", collection)
458 self.assertEqual(0, self.operations.write_counter.get())
459 self.pool.apply(fuseWriteFileTestHelperWriteFile, (self.mounttmp,))
460 self.assertEqual(12, self.operations.write_counter.get())
462 with collection.open("file1.txt") as f:
463 self.assertEqual(f.read(), "Hello world!")
465 self.assertEqual(0, self.operations.read_counter.get())
466 self.pool.apply(fuseWriteFileTestHelperReadFile, (self.mounttmp,))
467 self.assertEqual(12, self.operations.read_counter.get())
469 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
470 self.assertRegexpMatches(collection2["manifest_text"],
471 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
474 def fuseUpdateFileTestHelper(mounttmp):
475 class Test(unittest.TestCase):
477 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
478 f.write("Hello world!")
480 with open(os.path.join(mounttmp, "file1.txt"), "r+") as f:
482 self.assertEqual(fr, "Hello world!")
484 f.write("Hola mundo!")
487 self.assertEqual(fr, "Hola mundo!!")
489 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
490 self.assertEqual(f.read(), "Hola mundo!!")
494 class FuseUpdateFileTest(MountTestBase):
496 collection = arvados.collection.Collection(api_client=self.api)
497 collection.save_new()
499 m = self.make_mount(fuse.CollectionDirectory)
501 m.new_collection(collection.api_response(), collection)
502 self.assertTrue(m.writable())
504 # See note in MountTestBase.setUp
505 self.pool.apply(fuseUpdateFileTestHelper, (self.mounttmp,))
507 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
508 self.assertRegexpMatches(collection2["manifest_text"],
509 r'\. daaef200ebb921e011e3ae922dd3266b\+11\+A\S+ 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:11:file1\.txt 22:1:file1\.txt$')
512 def fuseMkdirTestHelper(mounttmp):
513 class Test(unittest.TestCase):
515 with self.assertRaises(IOError):
516 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
517 f.write("Hello world!")
519 os.mkdir(os.path.join(mounttmp, "testdir"))
521 with self.assertRaises(OSError):
522 os.mkdir(os.path.join(mounttmp, "testdir"))
524 d1 = llfuse.listdir(mounttmp)
525 self.assertEqual(["testdir"], d1)
527 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
528 f.write("Hello world!")
530 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
531 self.assertEqual(["file1.txt"], d1)
535 class FuseMkdirTest(MountTestBase):
537 collection = arvados.collection.Collection(api_client=self.api)
538 collection.save_new()
540 m = self.make_mount(fuse.CollectionDirectory)
542 m.new_collection(collection.api_response(), collection)
543 self.assertTrue(m.writable())
545 self.pool.apply(fuseMkdirTestHelper, (self.mounttmp,))
547 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
548 self.assertRegexpMatches(collection2["manifest_text"],
549 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
552 def fuseRmTestHelperWriteFile(mounttmp):
553 class Test(unittest.TestCase):
555 os.mkdir(os.path.join(mounttmp, "testdir"))
557 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
558 f.write("Hello world!")
562 def fuseRmTestHelperDeleteFile(mounttmp):
563 class Test(unittest.TestCase):
565 # Can't delete because it's not empty
566 with self.assertRaises(OSError):
567 os.rmdir(os.path.join(mounttmp, "testdir"))
569 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
570 self.assertEqual(["file1.txt"], d1)
573 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
575 # Make sure it's empty
576 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
577 self.assertEqual([], d1)
579 # Try to delete it again
580 with self.assertRaises(OSError):
581 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
585 def fuseRmTestHelperRmdir(mounttmp):
586 class Test(unittest.TestCase):
588 # Should be able to delete now that it is empty
589 os.rmdir(os.path.join(mounttmp, "testdir"))
591 # Make sure it's empty
592 d1 = llfuse.listdir(os.path.join(mounttmp))
593 self.assertEqual([], d1)
595 # Try to delete it again
596 with self.assertRaises(OSError):
597 os.rmdir(os.path.join(mounttmp, "testdir"))
601 class FuseRmTest(MountTestBase):
603 collection = arvados.collection.Collection(api_client=self.api)
604 collection.save_new()
606 m = self.make_mount(fuse.CollectionDirectory)
608 m.new_collection(collection.api_response(), collection)
609 self.assertTrue(m.writable())
611 self.pool.apply(fuseRmTestHelperWriteFile, (self.mounttmp,))
614 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
615 self.assertRegexpMatches(collection2["manifest_text"],
616 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
617 self.pool.apply(fuseRmTestHelperDeleteFile, (self.mounttmp,))
619 # Can't have empty directories :-( so manifest will be empty.
620 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
621 self.assertEqual(collection2["manifest_text"], "")
623 self.pool.apply(fuseRmTestHelperRmdir, (self.mounttmp,))
625 # manifest should be empty now.
626 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
627 self.assertEqual(collection2["manifest_text"], "")
630 def fuseMvFileTestHelperWriteFile(mounttmp):
631 class Test(unittest.TestCase):
633 os.mkdir(os.path.join(mounttmp, "testdir"))
635 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
636 f.write("Hello world!")
640 def fuseMvFileTestHelperMoveFile(mounttmp):
641 class Test(unittest.TestCase):
643 d1 = llfuse.listdir(os.path.join(mounttmp))
644 self.assertEqual(["testdir"], d1)
645 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
646 self.assertEqual(["file1.txt"], d1)
648 os.rename(os.path.join(mounttmp, "testdir", "file1.txt"), os.path.join(mounttmp, "file1.txt"))
650 d1 = llfuse.listdir(os.path.join(mounttmp))
651 self.assertEqual(["file1.txt", "testdir"], sorted(d1))
652 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
653 self.assertEqual([], d1)
657 class FuseMvFileTest(MountTestBase):
659 collection = arvados.collection.Collection(api_client=self.api)
660 collection.save_new()
662 m = self.make_mount(fuse.CollectionDirectory)
664 m.new_collection(collection.api_response(), collection)
665 self.assertTrue(m.writable())
667 self.pool.apply(fuseMvFileTestHelperWriteFile, (self.mounttmp,))
670 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
671 self.assertRegexpMatches(collection2["manifest_text"],
672 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
674 self.pool.apply(fuseMvFileTestHelperMoveFile, (self.mounttmp,))
676 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
677 self.assertRegexpMatches(collection2["manifest_text"],
678 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
681 def fuseRenameTestHelper(mounttmp):
682 class Test(unittest.TestCase):
684 os.mkdir(os.path.join(mounttmp, "testdir"))
686 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
687 f.write("Hello world!")
691 class FuseRenameTest(MountTestBase):
693 collection = arvados.collection.Collection(api_client=self.api)
694 collection.save_new()
696 m = self.make_mount(fuse.CollectionDirectory)
698 m.new_collection(collection.api_response(), collection)
699 self.assertTrue(m.writable())
701 self.pool.apply(fuseRenameTestHelper, (self.mounttmp,))
704 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
705 self.assertRegexpMatches(collection2["manifest_text"],
706 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
708 d1 = llfuse.listdir(os.path.join(self.mounttmp))
709 self.assertEqual(["testdir"], d1)
710 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
711 self.assertEqual(["file1.txt"], d1)
713 os.rename(os.path.join(self.mounttmp, "testdir"), os.path.join(self.mounttmp, "testdir2"))
715 d1 = llfuse.listdir(os.path.join(self.mounttmp))
716 self.assertEqual(["testdir2"], sorted(d1))
717 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir2"))
718 self.assertEqual(["file1.txt"], d1)
720 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
721 self.assertRegexpMatches(collection2["manifest_text"],
722 r'\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
725 class FuseUpdateFromEventTest(MountTestBase):
727 collection = arvados.collection.Collection(api_client=self.api)
728 collection.save_new()
730 m = self.make_mount(fuse.CollectionDirectory)
732 m.new_collection(collection.api_response(), collection)
734 self.operations.listen_for_events()
736 d1 = llfuse.listdir(os.path.join(self.mounttmp))
737 self.assertEqual([], sorted(d1))
739 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
740 with collection2.open("file1.txt", "w") as f:
743 for attempt in AssertWithTimeout(10):
744 attempt(self.assertEqual, ["file1.txt"], llfuse.listdir(os.path.join(self.mounttmp)))
747 def fuseFileConflictTestHelper(mounttmp):
748 class Test(unittest.TestCase):
750 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
753 d1 = sorted(llfuse.listdir(os.path.join(mounttmp)))
754 self.assertEqual(len(d1), 2)
756 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
757 self.assertEqual(f.read(), "bar")
759 self.assertRegexpMatches(d1[1],
760 r'file1\.txt~\d\d\d\d\d\d\d\d-\d\d\d\d\d\d~conflict~')
762 with open(os.path.join(mounttmp, d1[1]), "r") as f:
763 self.assertEqual(f.read(), "foo")
767 class FuseFileConflictTest(MountTestBase):
769 collection = arvados.collection.Collection(api_client=self.api)
770 collection.save_new()
772 m = self.make_mount(fuse.CollectionDirectory)
774 m.new_collection(collection.api_response(), collection)
776 d1 = llfuse.listdir(os.path.join(self.mounttmp))
777 self.assertEqual([], sorted(d1))
779 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
780 with collection2.open("file1.txt", "w") as f:
783 # See note in MountTestBase.setUp
784 self.pool.apply(fuseFileConflictTestHelper, (self.mounttmp,))
787 def fuseUnlinkOpenFileTest(mounttmp):
788 class Test(unittest.TestCase):
790 with open(os.path.join(mounttmp, "file1.txt"), "w+") as f:
793 d1 = llfuse.listdir(os.path.join(mounttmp))
794 self.assertEqual(["file1.txt"], sorted(d1))
796 os.remove(os.path.join(mounttmp, "file1.txt"))
798 d1 = llfuse.listdir(os.path.join(mounttmp))
799 self.assertEqual([], sorted(d1))
802 self.assertEqual(f.read(), "foo")
806 self.assertEqual(f.read(), "foobar")
810 class FuseUnlinkOpenFileTest(MountTestBase):
812 collection = arvados.collection.Collection(api_client=self.api)
813 collection.save_new()
815 m = self.make_mount(fuse.CollectionDirectory)
817 m.new_collection(collection.api_response(), collection)
819 # See note in MountTestBase.setUp
820 self.pool.apply(fuseUnlinkOpenFileTest, (self.mounttmp,))
822 self.assertEqual(collection.manifest_text(), "")
825 def fuseMvFileBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
826 class Test(unittest.TestCase):
828 with open(os.path.join(mounttmp, uuid1, "file1.txt"), "w") as f:
829 f.write("Hello world!")
831 d1 = os.listdir(os.path.join(mounttmp, uuid1))
832 self.assertEqual(["file1.txt"], sorted(d1))
833 d1 = os.listdir(os.path.join(mounttmp, uuid2))
834 self.assertEqual([], sorted(d1))
838 def fuseMvFileBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
839 class Test(unittest.TestCase):
841 os.rename(os.path.join(mounttmp, uuid1, "file1.txt"), os.path.join(mounttmp, uuid2, "file2.txt"))
843 d1 = os.listdir(os.path.join(mounttmp, uuid1))
844 self.assertEqual([], sorted(d1))
845 d1 = os.listdir(os.path.join(mounttmp, uuid2))
846 self.assertEqual(["file2.txt"], sorted(d1))
850 class FuseMvFileBetweenCollectionsTest(MountTestBase):
852 collection1 = arvados.collection.Collection(api_client=self.api)
853 collection1.save_new()
855 collection2 = arvados.collection.Collection(api_client=self.api)
856 collection2.save_new()
858 m = self.make_mount(fuse.MagicDirectory)
860 # See note in MountTestBase.setUp
861 self.pool.apply(fuseMvFileBetweenCollectionsTest1, (self.mounttmp,
862 collection1.manifest_locator(),
863 collection2.manifest_locator()))
868 self.assertRegexpMatches(collection1.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
869 self.assertEqual(collection2.manifest_text(), "")
871 self.pool.apply(fuseMvFileBetweenCollectionsTest2, (self.mounttmp,
872 collection1.manifest_locator(),
873 collection2.manifest_locator()))
878 self.assertEqual(collection1.manifest_text(), "")
879 self.assertRegexpMatches(collection2.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file2\.txt$")
881 collection1.stop_threads()
882 collection2.stop_threads()
885 def fuseMvDirBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
886 class Test(unittest.TestCase):
888 os.mkdir(os.path.join(mounttmp, uuid1, "testdir"))
889 with open(os.path.join(mounttmp, uuid1, "testdir", "file1.txt"), "w") as f:
890 f.write("Hello world!")
892 d1 = os.listdir(os.path.join(mounttmp, uuid1))
893 self.assertEqual(["testdir"], sorted(d1))
894 d1 = os.listdir(os.path.join(mounttmp, uuid1, "testdir"))
895 self.assertEqual(["file1.txt"], sorted(d1))
897 d1 = os.listdir(os.path.join(mounttmp, uuid2))
898 self.assertEqual([], sorted(d1))
903 def fuseMvDirBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
904 class Test(unittest.TestCase):
906 os.rename(os.path.join(mounttmp, uuid1, "testdir"), os.path.join(mounttmp, uuid2, "testdir2"))
908 d1 = os.listdir(os.path.join(mounttmp, uuid1))
909 self.assertEqual([], sorted(d1))
911 d1 = os.listdir(os.path.join(mounttmp, uuid2))
912 self.assertEqual(["testdir2"], sorted(d1))
913 d1 = os.listdir(os.path.join(mounttmp, uuid2, "testdir2"))
914 self.assertEqual(["file1.txt"], sorted(d1))
916 with open(os.path.join(mounttmp, uuid2, "testdir2", "file1.txt"), "r") as f:
917 self.assertEqual(f.read(), "Hello world!")
921 class FuseMvDirBetweenCollectionsTest(MountTestBase):
923 collection1 = arvados.collection.Collection(api_client=self.api)
924 collection1.save_new()
926 collection2 = arvados.collection.Collection(api_client=self.api)
927 collection2.save_new()
929 m = self.make_mount(fuse.MagicDirectory)
931 # See note in MountTestBase.setUp
932 self.pool.apply(fuseMvDirBetweenCollectionsTest1, (self.mounttmp,
933 collection1.manifest_locator(),
934 collection2.manifest_locator()))
939 self.assertRegexpMatches(collection1.manifest_text(), r"\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
940 self.assertEqual(collection2.manifest_text(), "")
942 self.pool.apply(fuseMvDirBetweenCollectionsTest2, (self.mounttmp,
943 collection1.manifest_locator(),
944 collection2.manifest_locator()))
949 self.assertEqual(collection1.manifest_text(), "")
950 self.assertRegexpMatches(collection2.manifest_text(), r"\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
952 collection1.stop_threads()
953 collection2.stop_threads()
955 def fuseProjectMkdirTestHelper1(mounttmp):
956 class Test(unittest.TestCase):
958 os.mkdir(os.path.join(mounttmp, "testcollection"))
959 with self.assertRaises(OSError):
960 os.mkdir(os.path.join(mounttmp, "testcollection"))
963 def fuseProjectMkdirTestHelper2(mounttmp):
964 class Test(unittest.TestCase):
966 with open(os.path.join(mounttmp, "testcollection", "file1.txt"), "w") as f:
967 f.write("Hello world!")
968 with self.assertRaises(OSError):
969 os.rmdir(os.path.join(mounttmp, "testcollection"))
970 os.remove(os.path.join(mounttmp, "testcollection", "file1.txt"))
971 with self.assertRaises(OSError):
972 os.remove(os.path.join(mounttmp, "testcollection"))
973 os.rmdir(os.path.join(mounttmp, "testcollection"))
976 class FuseProjectMkdirRmdirTest(MountTestBase):
978 self.make_mount(fuse.ProjectDirectory,
979 project_object=self.api.users().current().execute())
981 d1 = llfuse.listdir(self.mounttmp)
982 self.assertNotIn('testcollection', d1)
984 self.pool.apply(fuseProjectMkdirTestHelper1, (self.mounttmp,))
986 d1 = llfuse.listdir(self.mounttmp)
987 self.assertIn('testcollection', d1)
989 self.pool.apply(fuseProjectMkdirTestHelper2, (self.mounttmp,))
991 d1 = llfuse.listdir(self.mounttmp)
992 self.assertNotIn('testcollection', d1)
995 def fuseProjectMvTestHelper1(mounttmp):
996 class Test(unittest.TestCase):
998 d1 = llfuse.listdir(mounttmp)
999 self.assertNotIn('testcollection', d1)
1001 os.mkdir(os.path.join(mounttmp, "testcollection"))
1003 d1 = llfuse.listdir(mounttmp)
1004 self.assertIn('testcollection', d1)
1006 with self.assertRaises(OSError):
1007 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data'))
1009 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data', 'testcollection'))
1011 d1 = llfuse.listdir(mounttmp)
1012 self.assertNotIn('testcollection', d1)
1014 d1 = llfuse.listdir(os.path.join(mounttmp, 'Unrestricted public data'))
1015 self.assertIn('testcollection', d1)
1019 class FuseProjectMvTest(MountTestBase):
1021 self.make_mount(fuse.ProjectDirectory,
1022 project_object=self.api.users().current().execute())
1024 self.pool.apply(fuseProjectMvTestHelper1, (self.mounttmp,))
1027 def fuseFsyncTestHelper(mounttmp, k):
1028 class Test(unittest.TestCase):
1030 fd = os.open(os.path.join(mounttmp, k), os.O_RDONLY)
1036 class FuseFsyncTest(FuseMagicTest):
1038 self.make_mount(fuse.MagicDirectory)
1039 self.pool.apply(fuseFsyncTestHelper, (self.mounttmp, self.testcollection))
1042 class MagicDirApiError(FuseMagicTest):
1044 api = mock.MagicMock()
1045 super(MagicDirApiError, self).setUp(api=api)
1046 api.collections().get().execute.side_effect = iter([Exception('API fail'), {"manifest_text": self.test_manifest}])
1047 api.keep.get.side_effect = Exception('Keep fail')
1050 self.make_mount(fuse.MagicDirectory)
1052 self.operations.inodes.inode_cache.cap = 1
1053 self.operations.inodes.inode_cache.min_entries = 2
1055 with self.assertRaises(OSError):
1056 llfuse.listdir(os.path.join(self.mounttmp, self.testcollection))
1058 llfuse.listdir(os.path.join(self.mounttmp, self.testcollection))
1061 class FuseUnitTest(unittest.TestCase):
1062 def test_sanitize_filename(self):
1081 for f in acceptable:
1082 self.assertEqual(f, fuse.sanitize_filename(f))
1083 for f in unacceptable:
1084 self.assertNotEqual(f, fuse.sanitize_filename(f))
1085 # The sanitized filename should be the same length, though.
1086 self.assertEqual(len(f), len(fuse.sanitize_filename(f)))
1088 self.assertEqual("_", fuse.sanitize_filename(""))
1089 self.assertEqual("_", fuse.sanitize_filename("."))
1090 self.assertEqual("__", fuse.sanitize_filename(".."))
1093 class FuseMagicTestPDHOnly(MountTestBase):
1094 def setUp(self, api=None):
1095 super(FuseMagicTestPDHOnly, self).setUp(api=api)
1097 cw = arvados.CollectionWriter()
1099 cw.start_new_file('thing1.txt')
1102 self.testcollection = cw.finish()
1103 self.test_manifest = cw.manifest_text()
1104 created = self.api.collections().create(body={"manifest_text":self.test_manifest}).execute()
1105 self.testcollectionuuid = str(created['uuid'])
1107 def verify_pdh_only(self, pdh_only=False, skip_pdh_only=False):
1108 if skip_pdh_only is True:
1109 self.make_mount(fuse.MagicDirectory) # in this case, the default by_id applies
1111 self.make_mount(fuse.MagicDirectory, pdh_only=pdh_only)
1113 mount_ls = llfuse.listdir(self.mounttmp)
1114 self.assertIn('README', mount_ls)
1115 self.assertFalse(any(arvados.util.keep_locator_pattern.match(fn) or
1116 arvados.util.uuid_pattern.match(fn)
1117 for fn in mount_ls),
1118 "new FUSE MagicDirectory lists Collection")
1120 # look up using pdh should succeed in all cases
1121 self.assertDirContents(self.testcollection, ['thing1.txt'])
1122 self.assertDirContents(os.path.join('by_id', self.testcollection),
1124 mount_ls = llfuse.listdir(self.mounttmp)
1125 self.assertIn('README', mount_ls)
1126 self.assertIn(self.testcollection, mount_ls)
1127 self.assertIn(self.testcollection,
1128 llfuse.listdir(os.path.join(self.mounttmp, 'by_id')))
1131 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
1133 for k, v in files.items():
1134 with open(os.path.join(self.mounttmp, k)) as f:
1135 self.assertEqual(v, f.read())
1137 # look up using uuid should fail when pdh_only is set
1138 if pdh_only is True:
1139 with self.assertRaises(OSError):
1140 self.assertDirContents(os.path.join('by_id', self.testcollectionuuid),
1143 self.assertDirContents(os.path.join('by_id', self.testcollectionuuid),
1146 def test_with_pdh_only_true(self):
1147 self.verify_pdh_only(pdh_only=True)
1149 def test_with_pdh_only_false(self):
1150 self.verify_pdh_only(pdh_only=False)
1152 def test_with_default_by_id(self):
1153 self.verify_pdh_only(skip_pdh_only=True)