3 import arvados_fuse as fuse
16 import multiprocessing
17 import run_test_server
19 from mount_test_base import MountTestBase
21 logger = logging.getLogger('arvados.arv-mount')
24 class FuseMountTest(MountTestBase):
26 super(FuseMountTest, self).setUp()
28 cw = arvados.CollectionWriter()
30 cw.start_new_file('thing1.txt')
32 cw.start_new_file('thing2.txt')
34 cw.start_new_stream('dir1')
36 cw.start_new_file('thing3.txt')
38 cw.start_new_file('thing4.txt')
41 cw.start_new_stream('dir2')
42 cw.start_new_file('thing5.txt')
44 cw.start_new_file('thing6.txt')
47 cw.start_new_stream('dir2/dir3')
48 cw.start_new_file('thing7.txt')
51 cw.start_new_file('thing8.txt')
54 cw.start_new_stream('edgecases')
55 for f in ":/./../.../-/*/\x01\\/ ".split("/"):
59 for f in ":/../.../-/*/\x01\\/ ".split("/"):
60 cw.start_new_stream('edgecases/dirs/' + f)
61 cw.start_new_file('x/x')
64 self.testcollection = cw.finish()
65 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
68 self.make_mount(fuse.CollectionDirectory, collection_record=self.testcollection)
70 self.assertDirContents(None, ['thing1.txt', 'thing2.txt',
71 'edgecases', 'dir1', 'dir2'])
72 self.assertDirContents('dir1', ['thing3.txt', 'thing4.txt'])
73 self.assertDirContents('dir2', ['thing5.txt', 'thing6.txt', 'dir3'])
74 self.assertDirContents('dir2/dir3', ['thing7.txt', 'thing8.txt'])
75 self.assertDirContents('edgecases',
76 "dirs/:/_/__/.../-/*/\x01\\/ ".split("/"))
77 self.assertDirContents('edgecases/dirs',
78 ":/__/.../-/*/\x01\\/ ".split("/"))
80 files = {'thing1.txt': 'data 1',
81 'thing2.txt': 'data 2',
82 'dir1/thing3.txt': 'data 3',
83 'dir1/thing4.txt': 'data 4',
84 'dir2/thing5.txt': 'data 5',
85 'dir2/thing6.txt': 'data 6',
86 'dir2/dir3/thing7.txt': 'data 7',
87 'dir2/dir3/thing8.txt': 'data 8'}
89 for k, v in files.items():
90 with open(os.path.join(self.mounttmp, k)) as f:
91 self.assertEqual(v, f.read())
94 class FuseNoAPITest(MountTestBase):
96 super(FuseNoAPITest, self).setUp()
97 keep = arvados.keep.KeepClient(local_store=self.keeptmp)
98 self.file_data = "API-free text\n"
99 self.file_loc = keep.put(self.file_data)
100 self.coll_loc = keep.put(". {} 0:{}:api-free.txt\n".format(
101 self.file_loc, len(self.file_data)))
104 self.make_mount(fuse.MagicDirectory)
105 self.assertDirContents(self.coll_loc, ['api-free.txt'])
106 with open(os.path.join(
107 self.mounttmp, self.coll_loc, 'api-free.txt')) as keep_file:
108 actual = keep_file.read(-1)
109 self.assertEqual(self.file_data, actual)
112 class FuseMagicTest(MountTestBase):
114 super(FuseMagicTest, self).setUp()
116 cw = arvados.CollectionWriter()
118 cw.start_new_file('thing1.txt')
121 self.testcollection = cw.finish()
122 self.api.collections().create(body={"manifest_text":cw.manifest_text()}).execute()
125 self.make_mount(fuse.MagicDirectory)
127 mount_ls = llfuse.listdir(self.mounttmp)
128 self.assertIn('README', mount_ls)
129 self.assertFalse(any(arvados.util.keep_locator_pattern.match(fn) or
130 arvados.util.uuid_pattern.match(fn)
132 "new FUSE MagicDirectory lists Collection")
133 self.assertDirContents(self.testcollection, ['thing1.txt'])
134 self.assertDirContents(os.path.join('by_id', self.testcollection),
136 mount_ls = llfuse.listdir(self.mounttmp)
137 self.assertIn('README', mount_ls)
138 self.assertIn(self.testcollection, mount_ls)
139 self.assertIn(self.testcollection,
140 llfuse.listdir(os.path.join(self.mounttmp, 'by_id')))
143 files[os.path.join(self.mounttmp, self.testcollection, 'thing1.txt')] = 'data 1'
145 for k, v in files.items():
146 with open(os.path.join(self.mounttmp, k)) as f:
147 self.assertEqual(v, f.read())
150 class FuseTagsTest(MountTestBase):
152 self.make_mount(fuse.TagsDirectory)
154 d1 = llfuse.listdir(self.mounttmp)
156 self.assertEqual(['foo_tag'], d1)
158 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag'))
160 self.assertEqual(['zzzzz-4zz18-fy296fx3hot09f7'], d2)
162 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'foo_tag', 'zzzzz-4zz18-fy296fx3hot09f7'))
164 self.assertEqual(['foo'], d3)
167 class FuseTagsUpdateTest(MountTestBase):
168 def tag_collection(self, coll_uuid, tag_name):
169 return self.api.links().create(
170 body={'link': {'head_uuid': coll_uuid,
176 self.make_mount(fuse.TagsDirectory, poll_time=1)
178 self.assertIn('foo_tag', llfuse.listdir(self.mounttmp))
180 bar_uuid = run_test_server.fixture('collections')['bar_file']['uuid']
181 self.tag_collection(bar_uuid, 'fuse_test_tag')
183 self.assertIn('fuse_test_tag', llfuse.listdir(self.mounttmp))
184 self.assertDirContents('fuse_test_tag', [bar_uuid])
186 baz_uuid = run_test_server.fixture('collections')['baz_file']['uuid']
187 l = self.tag_collection(baz_uuid, 'fuse_test_tag')
189 self.assertDirContents('fuse_test_tag', [bar_uuid, baz_uuid])
191 self.api.links().delete(uuid=l['uuid']).execute()
193 self.assertDirContents('fuse_test_tag', [bar_uuid])
196 class FuseSharedTest(MountTestBase):
198 self.make_mount(fuse.SharedDirectory,
199 exclude=self.api.users().current().execute()['uuid'])
201 # shared_dirs is a list of the directories exposed
202 # by fuse.SharedDirectory (i.e. any object visible
203 # to the current user)
204 shared_dirs = llfuse.listdir(self.mounttmp)
206 self.assertIn('FUSE User', shared_dirs)
208 # fuse_user_objs is a list of the objects owned by the FUSE
209 # test user (which present as files in the 'FUSE User'
211 fuse_user_objs = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User'))
212 fuse_user_objs.sort()
213 self.assertEqual(['FUSE Test Project', # project owned by user
214 'collection #1 owned by FUSE', # collection owned by user
215 'collection #2 owned by FUSE', # collection owned by user
216 'pipeline instance owned by FUSE.pipelineInstance', # pipeline instance owned by user
219 # test_proj_files is a list of the files in the FUSE Test Project.
220 test_proj_files = llfuse.listdir(os.path.join(self.mounttmp, 'FUSE User', 'FUSE Test Project'))
221 test_proj_files.sort()
222 self.assertEqual(['collection in FUSE project',
223 'pipeline instance in FUSE project.pipelineInstance',
224 'pipeline template in FUSE project.pipelineTemplate'
227 # Double check that we can open and read objects in this folder as a file,
228 # and that its contents are what we expect.
229 pipeline_template_path = os.path.join(
233 'pipeline template in FUSE project.pipelineTemplate')
234 with open(pipeline_template_path) as f:
236 self.assertEqual("pipeline template in FUSE project", j['name'])
238 # check mtime on template
239 st = os.stat(pipeline_template_path)
240 self.assertEqual(st.st_mtime, 1397493304)
242 # check mtime on collection
243 st = os.stat(os.path.join(
246 'collection #1 owned by FUSE'))
247 self.assertEqual(st.st_mtime, 1391448174)
250 class FuseHomeTest(MountTestBase):
252 self.make_mount(fuse.ProjectDirectory,
253 project_object=self.api.users().current().execute())
255 d1 = llfuse.listdir(self.mounttmp)
256 self.assertIn('Unrestricted public data', d1)
258 d2 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data'))
259 public_project = run_test_server.fixture('groups')[
260 'anonymously_accessible_project']
263 for name, item in run_test_server.fixture('collections').iteritems():
264 if 'name' not in item:
266 elif item['owner_uuid'] == public_project['uuid']:
267 self.assertIn(item['name'], d2)
270 # Artificial assumption here: there is no public
271 # collection fixture with the same name as a
272 # non-public collection.
273 self.assertNotIn(item['name'], d2)
275 self.assertNotEqual(0, found_in)
276 self.assertNotEqual(0, found_not_in)
278 d3 = llfuse.listdir(os.path.join(self.mounttmp, 'Unrestricted public data', 'GNU General Public License, version 3'))
279 self.assertEqual(["GNU_General_Public_License,_version_3.pdf"], d3)
282 def fuseModifyFileTestHelperReadStartContents(mounttmp):
283 class Test(unittest.TestCase):
285 d1 = llfuse.listdir(mounttmp)
286 self.assertEqual(["file1.txt"], d1)
287 with open(os.path.join(mounttmp, "file1.txt")) as f:
288 self.assertEqual("blub", f.read())
291 def fuseModifyFileTestHelperReadEndContents(mounttmp):
292 class Test(unittest.TestCase):
294 d1 = llfuse.listdir(mounttmp)
295 self.assertEqual(["file1.txt"], d1)
296 with open(os.path.join(mounttmp, "file1.txt")) as f:
297 self.assertEqual("plnp", f.read())
300 class FuseModifyFileTest(MountTestBase):
302 collection = arvados.collection.Collection(api_client=self.api)
303 with collection.open("file1.txt", "w") as f:
306 collection.save_new()
308 m = self.make_mount(fuse.CollectionDirectory)
310 m.new_collection(collection.api_response(), collection)
312 self.pool.apply(fuseModifyFileTestHelperReadStartContents, (self.mounttmp,))
314 with collection.open("file1.txt", "w") as f:
317 self.pool.apply(fuseModifyFileTestHelperReadEndContents, (self.mounttmp,))
320 class FuseAddFileToCollectionTest(MountTestBase):
322 collection = arvados.collection.Collection(api_client=self.api)
323 with collection.open("file1.txt", "w") as f:
326 collection.save_new()
328 m = self.make_mount(fuse.CollectionDirectory)
330 m.new_collection(collection.api_response(), collection)
332 d1 = llfuse.listdir(self.mounttmp)
333 self.assertEqual(["file1.txt"], d1)
335 with collection.open("file2.txt", "w") as f:
338 d1 = llfuse.listdir(self.mounttmp)
339 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
342 class FuseRemoveFileFromCollectionTest(MountTestBase):
344 collection = arvados.collection.Collection(api_client=self.api)
345 with collection.open("file1.txt", "w") as f:
348 with collection.open("file2.txt", "w") as f:
351 collection.save_new()
353 m = self.make_mount(fuse.CollectionDirectory)
355 m.new_collection(collection.api_response(), collection)
357 d1 = llfuse.listdir(self.mounttmp)
358 self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
360 collection.remove("file2.txt")
362 d1 = llfuse.listdir(self.mounttmp)
363 self.assertEqual(["file1.txt"], d1)
366 def fuseCreateFileTestHelper(mounttmp):
367 class Test(unittest.TestCase):
369 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
373 class FuseCreateFileTest(MountTestBase):
375 collection = arvados.collection.Collection(api_client=self.api)
376 collection.save_new()
378 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
379 self.assertEqual(collection2["manifest_text"], "")
381 collection.save_new()
383 m = self.make_mount(fuse.CollectionDirectory)
385 m.new_collection(collection.api_response(), collection)
386 self.assertTrue(m.writable())
388 self.assertNotIn("file1.txt", collection)
390 self.pool.apply(fuseCreateFileTestHelper, (self.mounttmp,))
392 self.assertIn("file1.txt", collection)
394 d1 = llfuse.listdir(self.mounttmp)
395 self.assertEqual(["file1.txt"], d1)
397 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
398 self.assertRegexpMatches(collection2["manifest_text"],
399 r'\. d41d8cd98f00b204e9800998ecf8427e\+0\+A\S+ 0:0:file1\.txt$')
402 def fuseWriteFileTestHelperWriteFile(mounttmp):
403 class Test(unittest.TestCase):
405 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
406 f.write("Hello world!")
409 def fuseWriteFileTestHelperReadFile(mounttmp):
410 class Test(unittest.TestCase):
412 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
413 self.assertEqual(f.read(), "Hello world!")
416 class FuseWriteFileTest(MountTestBase):
418 collection = arvados.collection.Collection(api_client=self.api)
419 collection.save_new()
421 m = self.make_mount(fuse.CollectionDirectory)
423 m.new_collection(collection.api_response(), collection)
424 self.assertTrue(m.writable())
426 self.assertNotIn("file1.txt", collection)
428 self.pool.apply(fuseWriteFileTestHelperWriteFile, (self.mounttmp,))
430 with collection.open("file1.txt") as f:
431 self.assertEqual(f.read(), "Hello world!")
433 self.pool.apply(fuseWriteFileTestHelperReadFile, (self.mounttmp,))
435 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
436 self.assertRegexpMatches(collection2["manifest_text"],
437 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
440 def fuseUpdateFileTestHelper(mounttmp):
441 class Test(unittest.TestCase):
443 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
444 f.write("Hello world!")
446 with open(os.path.join(mounttmp, "file1.txt"), "r+") as f:
448 self.assertEqual(fr, "Hello world!")
450 f.write("Hola mundo!")
453 self.assertEqual(fr, "Hola mundo!!")
455 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
456 self.assertEqual(f.read(), "Hola mundo!!")
460 class FuseUpdateFileTest(MountTestBase):
462 collection = arvados.collection.Collection(api_client=self.api)
463 collection.save_new()
465 m = self.make_mount(fuse.CollectionDirectory)
467 m.new_collection(collection.api_response(), collection)
468 self.assertTrue(m.writable())
470 # See note in MountTestBase.setUp
471 self.pool.apply(fuseUpdateFileTestHelper, (self.mounttmp,))
473 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
474 self.assertRegexpMatches(collection2["manifest_text"],
475 r'\. daaef200ebb921e011e3ae922dd3266b\+11\+A\S+ 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:11:file1\.txt 22:1:file1\.txt$')
478 def fuseMkdirTestHelper(mounttmp):
479 class Test(unittest.TestCase):
481 with self.assertRaises(IOError):
482 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
483 f.write("Hello world!")
485 os.mkdir(os.path.join(mounttmp, "testdir"))
487 with self.assertRaises(OSError):
488 os.mkdir(os.path.join(mounttmp, "testdir"))
490 d1 = llfuse.listdir(mounttmp)
491 self.assertEqual(["testdir"], d1)
493 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
494 f.write("Hello world!")
496 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
497 self.assertEqual(["file1.txt"], d1)
501 class FuseMkdirTest(MountTestBase):
503 collection = arvados.collection.Collection(api_client=self.api)
504 collection.save_new()
506 m = self.make_mount(fuse.CollectionDirectory)
508 m.new_collection(collection.api_response(), collection)
509 self.assertTrue(m.writable())
511 self.pool.apply(fuseMkdirTestHelper, (self.mounttmp,))
513 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
514 self.assertRegexpMatches(collection2["manifest_text"],
515 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
518 def fuseRmTestHelperWriteFile(mounttmp):
519 class Test(unittest.TestCase):
521 os.mkdir(os.path.join(mounttmp, "testdir"))
523 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
524 f.write("Hello world!")
528 def fuseRmTestHelperDeleteFile(mounttmp):
529 class Test(unittest.TestCase):
531 # Can't delete because it's not empty
532 with self.assertRaises(OSError):
533 os.rmdir(os.path.join(mounttmp, "testdir"))
535 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
536 self.assertEqual(["file1.txt"], d1)
539 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
541 # Make sure it's empty
542 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
543 self.assertEqual([], d1)
545 # Try to delete it again
546 with self.assertRaises(OSError):
547 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
551 def fuseRmTestHelperRmdir(mounttmp):
552 class Test(unittest.TestCase):
554 # Should be able to delete now that it is empty
555 os.rmdir(os.path.join(mounttmp, "testdir"))
557 # Make sure it's empty
558 d1 = llfuse.listdir(os.path.join(mounttmp))
559 self.assertEqual([], d1)
561 # Try to delete it again
562 with self.assertRaises(OSError):
563 os.rmdir(os.path.join(mounttmp, "testdir"))
567 class FuseRmTest(MountTestBase):
569 collection = arvados.collection.Collection(api_client=self.api)
570 collection.save_new()
572 m = self.make_mount(fuse.CollectionDirectory)
574 m.new_collection(collection.api_response(), collection)
575 self.assertTrue(m.writable())
577 self.pool.apply(fuseRmTestHelperWriteFile, (self.mounttmp,))
580 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
581 self.assertRegexpMatches(collection2["manifest_text"],
582 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
583 self.pool.apply(fuseRmTestHelperDeleteFile, (self.mounttmp,))
585 # Can't have empty directories :-( so manifest will be empty.
586 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
587 self.assertEqual(collection2["manifest_text"], "")
589 self.pool.apply(fuseRmTestHelperRmdir, (self.mounttmp,))
591 # manifest should be empty now.
592 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
593 self.assertEqual(collection2["manifest_text"], "")
596 def fuseMvFileTestHelperWriteFile(mounttmp):
597 class Test(unittest.TestCase):
599 os.mkdir(os.path.join(mounttmp, "testdir"))
601 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
602 f.write("Hello world!")
606 def fuseMvFileTestHelperMoveFile(mounttmp):
607 class Test(unittest.TestCase):
609 d1 = llfuse.listdir(os.path.join(mounttmp))
610 self.assertEqual(["testdir"], d1)
611 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
612 self.assertEqual(["file1.txt"], d1)
614 os.rename(os.path.join(mounttmp, "testdir", "file1.txt"), os.path.join(mounttmp, "file1.txt"))
616 d1 = llfuse.listdir(os.path.join(mounttmp))
617 self.assertEqual(["file1.txt", "testdir"], sorted(d1))
618 d1 = llfuse.listdir(os.path.join(mounttmp, "testdir"))
619 self.assertEqual([], d1)
623 class FuseMvFileTest(MountTestBase):
625 collection = arvados.collection.Collection(api_client=self.api)
626 collection.save_new()
628 m = self.make_mount(fuse.CollectionDirectory)
630 m.new_collection(collection.api_response(), collection)
631 self.assertTrue(m.writable())
633 self.pool.apply(fuseMvFileTestHelperWriteFile, (self.mounttmp,))
636 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
637 self.assertRegexpMatches(collection2["manifest_text"],
638 r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
640 self.pool.apply(fuseMvFileTestHelperMoveFile, (self.mounttmp,))
642 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
643 self.assertRegexpMatches(collection2["manifest_text"],
644 r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
647 def fuseRenameTestHelper(mounttmp):
648 class Test(unittest.TestCase):
650 os.mkdir(os.path.join(mounttmp, "testdir"))
652 with open(os.path.join(mounttmp, "testdir", "file1.txt"), "w") as f:
653 f.write("Hello world!")
657 class FuseRenameTest(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(fuseRenameTestHelper, (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 d1 = llfuse.listdir(os.path.join(self.mounttmp))
675 self.assertEqual(["testdir"], d1)
676 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
677 self.assertEqual(["file1.txt"], d1)
679 os.rename(os.path.join(self.mounttmp, "testdir"), os.path.join(self.mounttmp, "testdir2"))
681 d1 = llfuse.listdir(os.path.join(self.mounttmp))
682 self.assertEqual(["testdir2"], sorted(d1))
683 d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir2"))
684 self.assertEqual(["file1.txt"], d1)
686 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
687 self.assertRegexpMatches(collection2["manifest_text"],
688 r'\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$')
691 class FuseUpdateFromEventTest(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)
700 self.operations.listen_for_events(self.api)
702 d1 = llfuse.listdir(os.path.join(self.mounttmp))
703 self.assertEqual([], sorted(d1))
705 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
706 with collection2.open("file1.txt", "w") as f:
711 # should show up via event bus notify
713 d1 = llfuse.listdir(os.path.join(self.mounttmp))
714 self.assertEqual(["file1.txt"], sorted(d1))
717 def fuseFileConflictTestHelper(mounttmp):
718 class Test(unittest.TestCase):
720 with open(os.path.join(mounttmp, "file1.txt"), "w") as f:
723 d1 = sorted(llfuse.listdir(os.path.join(mounttmp)))
724 self.assertEqual(len(d1), 2)
726 with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
727 self.assertEqual(f.read(), "bar")
729 self.assertRegexpMatches(d1[1],
730 r'file1\.txt~\d\d\d\d\d\d\d\d-\d\d\d\d\d\d~conflict~')
732 with open(os.path.join(mounttmp, d1[1]), "r") as f:
733 self.assertEqual(f.read(), "foo")
737 class FuseFileConflictTest(MountTestBase):
739 collection = arvados.collection.Collection(api_client=self.api)
740 collection.save_new()
742 m = self.make_mount(fuse.CollectionDirectory)
744 m.new_collection(collection.api_response(), collection)
746 d1 = llfuse.listdir(os.path.join(self.mounttmp))
747 self.assertEqual([], sorted(d1))
749 with arvados.collection.Collection(collection.manifest_locator(), api_client=self.api) as collection2:
750 with collection2.open("file1.txt", "w") as f:
753 # See note in MountTestBase.setUp
754 self.pool.apply(fuseFileConflictTestHelper, (self.mounttmp,))
757 def fuseUnlinkOpenFileTest(mounttmp):
758 class Test(unittest.TestCase):
760 with open(os.path.join(mounttmp, "file1.txt"), "w+") as f:
763 d1 = llfuse.listdir(os.path.join(mounttmp))
764 self.assertEqual(["file1.txt"], sorted(d1))
766 os.remove(os.path.join(mounttmp, "file1.txt"))
768 d1 = llfuse.listdir(os.path.join(mounttmp))
769 self.assertEqual([], sorted(d1))
772 self.assertEqual(f.read(), "foo")
776 self.assertEqual(f.read(), "foobar")
780 class FuseUnlinkOpenFileTest(MountTestBase):
782 collection = arvados.collection.Collection(api_client=self.api)
783 collection.save_new()
785 m = self.make_mount(fuse.CollectionDirectory)
787 m.new_collection(collection.api_response(), collection)
789 # See note in MountTestBase.setUp
790 self.pool.apply(fuseUnlinkOpenFileTest, (self.mounttmp,))
792 self.assertEqual(collection.manifest_text(), "")
795 def fuseMvFileBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
796 class Test(unittest.TestCase):
798 with open(os.path.join(mounttmp, uuid1, "file1.txt"), "w") as f:
799 f.write("Hello world!")
801 d1 = os.listdir(os.path.join(mounttmp, uuid1))
802 self.assertEqual(["file1.txt"], sorted(d1))
803 d1 = os.listdir(os.path.join(mounttmp, uuid2))
804 self.assertEqual([], sorted(d1))
808 def fuseMvFileBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
809 class Test(unittest.TestCase):
811 os.rename(os.path.join(mounttmp, uuid1, "file1.txt"), os.path.join(mounttmp, uuid2, "file2.txt"))
813 d1 = os.listdir(os.path.join(mounttmp, uuid1))
814 self.assertEqual([], sorted(d1))
815 d1 = os.listdir(os.path.join(mounttmp, uuid2))
816 self.assertEqual(["file2.txt"], sorted(d1))
820 class FuseMvFileBetweenCollectionsTest(MountTestBase):
822 collection1 = arvados.collection.Collection(api_client=self.api)
823 collection1.save_new()
825 collection2 = arvados.collection.Collection(api_client=self.api)
826 collection2.save_new()
828 m = self.make_mount(fuse.MagicDirectory)
830 # See note in MountTestBase.setUp
831 self.pool.apply(fuseMvFileBetweenCollectionsTest1, (self.mounttmp,
832 collection1.manifest_locator(),
833 collection2.manifest_locator()))
838 self.assertRegexpMatches(collection1.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
839 self.assertEqual(collection2.manifest_text(), "")
841 self.pool.apply(fuseMvFileBetweenCollectionsTest2, (self.mounttmp,
842 collection1.manifest_locator(),
843 collection2.manifest_locator()))
848 self.assertEqual(collection1.manifest_text(), "")
849 self.assertRegexpMatches(collection2.manifest_text(), r"\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file2\.txt$")
851 collection1.stop_threads()
852 collection2.stop_threads()
855 def fuseMvDirBetweenCollectionsTest1(mounttmp, uuid1, uuid2):
856 class Test(unittest.TestCase):
858 os.mkdir(os.path.join(mounttmp, uuid1, "testdir"))
859 with open(os.path.join(mounttmp, uuid1, "testdir", "file1.txt"), "w") as f:
860 f.write("Hello world!")
862 d1 = os.listdir(os.path.join(mounttmp, uuid1))
863 self.assertEqual(["testdir"], sorted(d1))
864 d1 = os.listdir(os.path.join(mounttmp, uuid1, "testdir"))
865 self.assertEqual(["file1.txt"], sorted(d1))
867 d1 = os.listdir(os.path.join(mounttmp, uuid2))
868 self.assertEqual([], sorted(d1))
873 def fuseMvDirBetweenCollectionsTest2(mounttmp, uuid1, uuid2):
874 class Test(unittest.TestCase):
876 os.rename(os.path.join(mounttmp, uuid1, "testdir"), os.path.join(mounttmp, uuid2, "testdir2"))
878 d1 = os.listdir(os.path.join(mounttmp, uuid1))
879 self.assertEqual([], sorted(d1))
881 d1 = os.listdir(os.path.join(mounttmp, uuid2))
882 self.assertEqual(["testdir2"], sorted(d1))
883 d1 = os.listdir(os.path.join(mounttmp, uuid2, "testdir2"))
884 self.assertEqual(["file1.txt"], sorted(d1))
886 with open(os.path.join(mounttmp, uuid2, "testdir2", "file1.txt"), "r") as f:
887 self.assertEqual(f.read(), "Hello world!")
891 class FuseMvDirBetweenCollectionsTest(MountTestBase):
893 collection1 = arvados.collection.Collection(api_client=self.api)
894 collection1.save_new()
896 collection2 = arvados.collection.Collection(api_client=self.api)
897 collection2.save_new()
899 m = self.make_mount(fuse.MagicDirectory)
901 # See note in MountTestBase.setUp
902 self.pool.apply(fuseMvDirBetweenCollectionsTest1, (self.mounttmp,
903 collection1.manifest_locator(),
904 collection2.manifest_locator()))
909 self.assertRegexpMatches(collection1.manifest_text(), r"\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
910 self.assertEqual(collection2.manifest_text(), "")
912 self.pool.apply(fuseMvDirBetweenCollectionsTest2, (self.mounttmp,
913 collection1.manifest_locator(),
914 collection2.manifest_locator()))
919 self.assertEqual(collection1.manifest_text(), "")
920 self.assertRegexpMatches(collection2.manifest_text(), r"\./testdir2 86fb269d190d2c85f6e0468ceca42a20\+12\+A\S+ 0:12:file1\.txt$")
922 collection1.stop_threads()
923 collection2.stop_threads()
925 def fuseProjectMkdirTestHelper1(mounttmp):
926 class Test(unittest.TestCase):
928 os.mkdir(os.path.join(mounttmp, "testcollection"))
929 with self.assertRaises(OSError):
930 os.mkdir(os.path.join(mounttmp, "testcollection"))
933 def fuseProjectMkdirTestHelper2(mounttmp):
934 class Test(unittest.TestCase):
936 with open(os.path.join(mounttmp, "testcollection", "file1.txt"), "w") as f:
937 f.write("Hello world!")
938 with self.assertRaises(OSError):
939 os.rmdir(os.path.join(mounttmp, "testcollection"))
940 os.remove(os.path.join(mounttmp, "testcollection", "file1.txt"))
941 with self.assertRaises(OSError):
942 os.remove(os.path.join(mounttmp, "testcollection"))
943 os.rmdir(os.path.join(mounttmp, "testcollection"))
946 class FuseProjectMkdirRmdirTest(MountTestBase):
948 self.make_mount(fuse.ProjectDirectory,
949 project_object=self.api.users().current().execute())
951 d1 = llfuse.listdir(self.mounttmp)
952 self.assertNotIn('testcollection', d1)
954 self.pool.apply(fuseProjectMkdirTestHelper1, (self.mounttmp,))
956 d1 = llfuse.listdir(self.mounttmp)
957 self.assertIn('testcollection', d1)
959 self.pool.apply(fuseProjectMkdirTestHelper2, (self.mounttmp,))
961 d1 = llfuse.listdir(self.mounttmp)
962 self.assertNotIn('testcollection', d1)
965 def fuseProjectMvTestHelper1(mounttmp):
966 class Test(unittest.TestCase):
968 d1 = llfuse.listdir(mounttmp)
969 self.assertNotIn('testcollection', d1)
971 os.mkdir(os.path.join(mounttmp, "testcollection"))
973 d1 = llfuse.listdir(mounttmp)
974 self.assertIn('testcollection', d1)
976 with self.assertRaises(OSError):
977 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data'))
979 os.rename(os.path.join(mounttmp, "testcollection"), os.path.join(mounttmp, 'Unrestricted public data', 'testcollection'))
981 d1 = llfuse.listdir(mounttmp)
982 self.assertNotIn('testcollection', d1)
984 d1 = llfuse.listdir(os.path.join(mounttmp, 'Unrestricted public data'))
985 self.assertIn('testcollection', d1)
989 class FuseProjectMvTest(MountTestBase):
991 self.make_mount(fuse.ProjectDirectory,
992 project_object=self.api.users().current().execute())
994 self.pool.apply(fuseProjectMvTestHelper1, (self.mounttmp,))
997 class FuseUnitTest(unittest.TestCase):
998 def test_sanitize_filename(self):
1017 for f in acceptable:
1018 self.assertEqual(f, fuse.sanitize_filename(f))
1019 for f in unacceptable:
1020 self.assertNotEqual(f, fuse.sanitize_filename(f))
1021 # The sanitized filename should be the same length, though.
1022 self.assertEqual(len(f), len(fuse.sanitize_filename(f)))
1024 self.assertEqual("_", fuse.sanitize_filename(""))
1025 self.assertEqual("_", fuse.sanitize_filename("."))
1026 self.assertEqual("__", fuse.sanitize_filename(".."))