+class FuseUpdateFileTest(MountTestBase):
+ def runTest(self):
+ collection = arvados.collection.Collection(api_client=self.api)
+ with collection.open("file1.txt", "w") as f:
+ f.write("blub")
+
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt"], d1)
+ with open(os.path.join(self.mounttmp, "file1.txt")) as f:
+ self.assertEqual("blub", f.read())
+
+ with collection.open("file1.txt", "w") as f:
+ f.write("plnp")
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt"], d1)
+ with open(os.path.join(self.mounttmp, "file1.txt")) as f:
+ self.assertEqual("plnp", f.read())
+
+class FuseAddFileToCollectionTest(MountTestBase):
+ def runTest(self):
+ collection = arvados.collection.Collection(api_client=self.api)
+ with collection.open("file1.txt", "w") as f:
+ f.write("blub")
+
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt"], d1)
+
+ with collection.open("file2.txt", "w") as f:
+ f.write("plnp")
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
+
+class FuseRemoveFileFromCollectionTest(MountTestBase):
+ def runTest(self):
+ collection = arvados.collection.Collection(api_client=self.api)
+ with collection.open("file1.txt", "w") as f:
+ f.write("blub")
+
+ with collection.open("file2.txt", "w") as f:
+ f.write("plnp")
+
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt", "file2.txt"], sorted(d1))
+
+ collection.remove("file2.txt")
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt"], d1)
+
+class FuseCreateFileTest(MountTestBase):
+ def runTest(self):
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertEqual(collection2["manifest_text"], "")
+
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ self.assertNotIn("file1.txt", collection)
+
+ with open(os.path.join(self.mounttmp, "file1.txt"), "w") as f:
+ pass
+
+ self.assertIn("file1.txt", collection)
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["file1.txt"], d1)
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\. d41d8cd98f00b204e9800998ecf8427e\+0\+A[a-f0-9]{40}@[a-f0-9]{8} 0:0:file1\.txt$')
+
+def fuseWriteFileTestHelper(mounttmp):
+ with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
+ return f.read() == "Hello world!"
+
+class FuseWriteFileTest(MountTestBase):
+ def runTest(self):
+ arvados.logger.setLevel(logging.DEBUG)
+
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ self.assertNotIn("file1.txt", collection)
+
+ with open(os.path.join(self.mounttmp, "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ with collection.open("file1.txt") as f:
+ self.assertEqual(f.read(), "Hello world!")
+
+ # We can't just open the collection for reading because the underlying
+ # C implementation of open() makes a fstat() syscall with the GIL still
+ # held. When the GETATTR message comes back to llfuse (which in these
+ # tests is in the same interpreter process) it can't acquire the GIL,
+ # so it can't service the fstat() call, so it deadlocks. The
+ # workaround is to run some of our test code in a separate process.
+ # Forturnately the multiprocessing module makes this relatively easy.
+ pool = multiprocessing.Pool(1)
+ self.assertTrue(pool.apply(fuseWriteFileTestHelper, (self.mounttmp,)))
+ pool.close()
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:12:file1\.txt$')
+
+def fuseUpdateFileTestHelper1(mounttmp):
+ with open(os.path.join(mounttmp, "file1.txt"), "r+") as f:
+ fr = f.read()
+ if fr != "Hello world!":
+ raise Exception("Got %s expected 'Hello world!'" % fr)
+ f.seek(0)
+ f.write("Hola mundo!")
+ f.seek(0)
+ fr = f.read()
+ if fr != "Hola mundo!!":
+ raise Exception("Got %s expected 'Hola mundo!!'" % fr)
+ return True
+
+def fuseUpdateFileTestHelper2(mounttmp):
+ with open(os.path.join(mounttmp, "file1.txt"), "r") as f:
+ return f.read() == "Hola mundo!!"
+
+class FuseUpdateFileTest(MountTestBase):
+ def runTest(self):
+ arvados.logger.setLevel(logging.DEBUG)
+
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ with open(os.path.join(self.mounttmp, "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ # See note in FuseWriteFileTest
+ pool = multiprocessing.Pool(1)
+ self.assertTrue(pool.apply(fuseUpdateFileTestHelper1, (self.mounttmp,)))
+ self.assertTrue(pool.apply(fuseUpdateFileTestHelper2, (self.mounttmp,)))
+ pool.close()
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\. daaef200ebb921e011e3ae922dd3266b\+11\+A[a-f0-9]{40}@[a-f0-9]{8} 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:11:file1\.txt 22:1:file1\.txt$')
+
+
+class FuseMkdirTest(MountTestBase):
+ def runTest(self):
+ arvados.logger.setLevel(logging.DEBUG)
+
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ with self.assertRaises(IOError):
+ with open(os.path.join(self.mounttmp, "testdir", "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ os.mkdir(os.path.join(self.mounttmp, "testdir"))
+
+ with self.assertRaises(OSError):
+ os.mkdir(os.path.join(self.mounttmp, "testdir"))
+
+ d1 = llfuse.listdir(self.mounttmp)
+ self.assertEqual(["testdir"], d1)
+
+ with open(os.path.join(self.mounttmp, "testdir", "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
+ self.assertEqual(["file1.txt"], d1)
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:12:file1\.txt$')
+
+
+class FuseRmTest(MountTestBase):
+ def runTest(self):
+ arvados.logger.setLevel(logging.DEBUG)
+
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ os.mkdir(os.path.join(self.mounttmp, "testdir"))
+
+ with open(os.path.join(self.mounttmp, "testdir", "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ # Starting manifest
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:12:file1\.txt$')
+
+ # Can't delete because it's not empty
+ with self.assertRaises(OSError):
+ os.rmdir(os.path.join(self.mounttmp, "testdir"))
+
+ d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
+ self.assertEqual(["file1.txt"], d1)
+
+ # Delete file
+ os.remove(os.path.join(self.mounttmp, "testdir", "file1.txt"))
+
+ # Make sure it's empty
+ d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
+ self.assertEqual([], d1)
+
+ # Try to delete it again
+ with self.assertRaises(OSError):
+ os.remove(os.path.join(self.mounttmp, "testdir", "file1.txt"))
+
+ # Can't have empty directories :-( so manifest will be empty.
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertEqual(collection2["manifest_text"], "")
+
+ # Should be able to delete now that it is empty
+ os.rmdir(os.path.join(self.mounttmp, "testdir"))
+
+ # Make sure it's empty
+ d1 = llfuse.listdir(os.path.join(self.mounttmp))
+ self.assertEqual([], d1)
+
+ # Try to delete it again
+ with self.assertRaises(OSError):
+ os.rmdir(os.path.join(self.mounttmp, "testdir"))
+
+ # manifest should be empty now.
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertEqual(collection2["manifest_text"], "")
+
+
+class FuseMvTest(MountTestBase):
+ def runTest(self):
+ arvados.logger.setLevel(logging.DEBUG)
+
+ collection = arvados.collection.Collection(api_client=self.api)
+ collection.save_new()
+
+ m = self.make_mount(fuse.CollectionDirectory)
+ with llfuse.lock:
+ m.new_collection(None, collection)
+ self.assertTrue(m.writable())
+
+ os.mkdir(os.path.join(self.mounttmp, "testdir"))
+
+ with open(os.path.join(self.mounttmp, "testdir", "file1.txt"), "w") as f:
+ f.write("Hello world!")
+
+ # Starting manifest
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\./testdir 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:12:file1\.txt$')
+
+ d1 = llfuse.listdir(os.path.join(self.mounttmp))
+ self.assertEqual(["testdir"], d1)
+ d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
+ self.assertEqual(["file1.txt"], d1)
+
+ os.rename(os.path.join(self.mounttmp, "testdir", "file1.txt"), os.path.join(self.mounttmp, "file1.txt"))
+
+ d1 = llfuse.listdir(os.path.join(self.mounttmp))
+ self.assertEqual(["file1.txt", "testdir"], sorted(d1))
+ d1 = llfuse.listdir(os.path.join(self.mounttmp, "testdir"))
+ self.assertEqual([], d1)
+
+ collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
+ self.assertRegexpMatches(collection2["manifest_text"],
+ r'\. 86fb269d190d2c85f6e0468ceca42a20\+12\+A[a-f0-9]{40}@[a-f0-9]{8} 0:12:file1\.txt$')
+