2 import arvados_fuse as fuse
8 from .. import run_test_server
9 from ..mount_test_base import MountTestBase
11 logger = logging.getLogger('arvados.arv-mount')
13 from performance_profiler import profiled
15 def fuse_CreateCollection(mounttmp, streams=1, files_per_stream=1, data='x'):
16 class Test(unittest.TestCase):
18 for i in range(0, streams):
19 os.mkdir(os.path.join(mounttmp, "./stream" + str(i)))
22 for j in range(0, files_per_stream):
23 with open(os.path.join(mounttmp, "./stream" + str(i), "file" + str(j) +".txt"), "w") as f:
28 def fuse_ReadContentsFromCollectionWithManyFiles(mounttmp, streams=1, files_per_stream=1, data='x'):
29 class Test(unittest.TestCase):
31 for i in range(0, streams):
32 d1 = llfuse.listdir(os.path.join(mounttmp, 'stream'+str(i)))
33 for j in range(0, files_per_stream):
34 with open(os.path.join(mounttmp, 'stream'+str(i), 'file'+str(i)+'.txt')) as f:
35 self.assertEqual(data, f.read())
39 def fuse_MoveFileFromCollectionWithManyFiles(mounttmp, stream, filename):
40 class Test(unittest.TestCase):
42 d1 = llfuse.listdir(os.path.join(mounttmp, stream))
43 self.assertIn(filename, d1)
45 os.rename(os.path.join(mounttmp, stream, filename), os.path.join(mounttmp, 'moved_from_'+stream+'_'+filename))
47 d1 = llfuse.listdir(os.path.join(mounttmp))
48 self.assertIn('moved_from_'+stream+'_'+filename, d1)
50 d1 = llfuse.listdir(os.path.join(mounttmp, stream))
51 self.assertNotIn(filename, d1)
55 def fuse_DeleteFileFromCollectionWithManyFiles(mounttmp, stream, filename):
56 class Test(unittest.TestCase):
58 os.remove(os.path.join(mounttmp, stream, filename))
62 # Create a collection with 2 streams, 3 files_per_stream, 2 blocks_per_file, 2**26 bytes_per_block
63 class CreateCollectionWithMultipleBlocksAndMoveAndDeleteFile(MountTestBase):
65 super(CreateCollectionWithMultipleBlocksAndMoveAndDeleteFile, self).setUp()
68 def createCollectionWithMultipleBlocks(self, streams, files_per_stream, data):
69 self.pool.apply(fuse_CreateCollection, (self.mounttmp, streams, files_per_stream, data,))
72 def readContentsOfCollectionWithMultipleBlocks(self, streams, files_per_stream, data):
73 self.pool.apply(fuse_ReadContentsFromCollectionWithManyFiles, (self.mounttmp, streams, files_per_stream, data,))
76 def moveFileFromCollectionWithMultipleBlocks(self, streams):
77 for i in range(0, streams):
78 self.pool.apply(fuse_MoveFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file0.txt',))
81 def removeFileFromCollectionWithMultipleBlocks(self, streams):
82 for i in range(0, streams):
83 self.pool.apply(fuse_DeleteFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file1.txt'))
85 def test_CreateCollectionWithManyBlocksAndMoveAndDeleteFile(self):
86 collection = arvados.collection.Collection(api_client=self.api)
89 m = self.make_mount(fuse.CollectionDirectory)
91 m.new_collection(collection.api_response(), collection)
92 self.assertTrue(m.writable())
97 bytes_per_block = 2**26
99 data = 'x' * blocks_per_file * bytes_per_block
101 self.createCollectionWithMultipleBlocks(streams, files_per_stream, data)
103 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
105 for i in range(0, streams):
106 self.assertIn('./stream' + str(i), collection2["manifest_text"])
108 for i in range(0, files_per_stream):
109 self.assertIn('file' + str(i) + '.txt', collection2["manifest_text"])
112 self.readContentsOfCollectionWithMultipleBlocks(streams, files_per_stream, data)
114 # Move file0.txt out of the streams into .
115 self.moveFileFromCollectionWithMultipleBlocks(streams)
117 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
119 manifest_streams = collection2['manifest_text'].split('\n')
120 self.assertEqual(4, len(manifest_streams))
122 for i in range(0, streams):
123 self.assertIn('file0.txt', manifest_streams[0])
125 for i in range(0, streams):
126 self.assertNotIn('file0.txt', manifest_streams[i+1])
128 for i in range(0, streams):
129 for j in range(1, files_per_stream):
130 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])
132 # Delete 'file1.txt' from all the streams
133 self.removeFileFromCollectionWithMultipleBlocks(streams)
135 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
137 manifest_streams = collection2['manifest_text'].split('\n')
138 self.assertEqual(4, len(manifest_streams))
140 for i in range(0, streams):
141 self.assertIn('file0.txt', manifest_streams[0])
143 self.assertNotIn('file1.txt', collection2['manifest_text'])
145 for i in range(0, streams):
146 for j in range(2, files_per_stream):
147 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])
149 # Create a collection with two streams, each with 200 files
150 class CreateCollectionWithManyFilesAndMoveAndDeleteFile(MountTestBase):
152 super(CreateCollectionWithManyFilesAndMoveAndDeleteFile, self).setUp()
155 def createCollectionWithManyFiles(self, streams, files_per_stream, data):
156 self.pool.apply(fuse_CreateCollection, (self.mounttmp, streams, files_per_stream, data,))
159 def readContentsOfCollectionWithManyFiles(self, streams, files_per_stream, data):
160 self.pool.apply(fuse_ReadContentsFromCollectionWithManyFiles, (self.mounttmp, streams, files_per_stream, data,))
163 def moveFileFromCollectionWithManyFiles(self, streams):
164 for i in range(0, streams):
165 self.pool.apply(fuse_MoveFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file0.txt',))
168 def removeFileFromCollectionWithManyFiles(self, streams):
169 for i in range(0, streams):
170 self.pool.apply(fuse_DeleteFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file1.txt'))
172 def test_CreateCollectionWithManyFilesAndMoveAndDeleteFile(self):
173 collection = arvados.collection.Collection(api_client=self.api)
174 collection.save_new()
176 m = self.make_mount(fuse.CollectionDirectory)
178 m.new_collection(collection.api_response(), collection)
179 self.assertTrue(m.writable())
182 files_per_stream = 200
186 self.createCollectionWithManyFiles(streams, files_per_stream, data)
188 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
190 for i in range(0, streams):
191 self.assertIn('./stream' + str(i), collection2["manifest_text"])
193 for i in range(0, files_per_stream):
194 self.assertIn('file' + str(i) + '.txt', collection2["manifest_text"])
197 self.readContentsOfCollectionWithManyFiles(streams, files_per_stream, data)
199 # Move file0.txt out of the streams into .
200 self.moveFileFromCollectionWithManyFiles(streams)
202 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
204 manifest_streams = collection2['manifest_text'].split('\n')
205 self.assertEqual(4, len(manifest_streams))
207 for i in range(0, streams):
208 self.assertIn('file0.txt', manifest_streams[0])
210 for i in range(0, streams):
211 self.assertNotIn('file0.txt', manifest_streams[i+1])
213 for i in range(0, streams):
214 for j in range(1, files_per_stream):
215 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])
217 # Delete 'file1.txt' from all the streams
218 self.removeFileFromCollectionWithManyFiles(streams)
220 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
222 manifest_streams = collection2['manifest_text'].split('\n')
223 self.assertEqual(4, len(manifest_streams))
225 for i in range(0, streams):
226 self.assertIn('file0.txt', manifest_streams[0])
228 self.assertNotIn('file1.txt', collection2['manifest_text'])
230 for i in range(0, streams):
231 for j in range(2, files_per_stream):
232 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])
234 def magicDirTest_MoveFileFromCollection(mounttmp, collection1, collection2, stream, filename):
235 class Test(unittest.TestCase):
237 #os.rename(os.path.join(mounttmp, collection1, stream, filename), os.path.join(mounttmp, collection2, stream, filename))
238 os.rename(os.path.join(mounttmp, collection1, filename), os.path.join(mounttmp, collection2, filename))
242 def magicDirTest_RemoveFileFromCollection(mounttmp, collection1, stream, filename):
243 class Test(unittest.TestCase):
245 os.remove(os.path.join(mounttmp, collection1, filename))
249 class UsingMagicDir_CreateCollectionWithManyFilesAndMoveAndDeleteFile(MountTestBase):
251 super(UsingMagicDir_CreateCollectionWithManyFilesAndMoveAndDeleteFile, self).setUp()
254 def magicDirTest_createCollectionWithManyFiles(self, streams=0, files_per_stream=0, data='x'):
256 collection = arvados.collection.Collection(api_client=self.api)
257 for j in range(0, files_per_stream):
258 with collection.open("file"+str(j)+".txt", "w") as f:
260 collection.save_new()
264 def magicDirTest_readCollectionContents(self, collection, streams=1, files_per_stream=1, data='x'):
265 mount_ls = os.listdir(os.path.join(self.mounttmp, collection))
268 for j in range(0, files_per_stream):
269 files[os.path.join(self.mounttmp, collection, 'file'+str(j)+'.txt')] = data
270 #files[os.path.join(self.mounttmp, collection, 'stream'+str(i)+'/file'+str(j)+'.txt')] = data
272 for k, v in files.items():
273 with open(os.path.join(self.mounttmp, collection, k)) as f:
274 self.assertEqual(v, f.read())
277 def magicDirTest_moveFileFromCollection(self, from_collection, to_collection):
278 self.pool.apply(magicDirTest_MoveFileFromCollection, (self.mounttmp, from_collection.manifest_locator(),
279 to_collection.manifest_locator(), 'stream0', 'file0.txt',))
280 from_collection.update()
281 to_collection.update()
284 def magicDirTest_removeFileFromCollection(self, collection):
285 self.pool.apply(magicDirTest_RemoveFileFromCollection, (self.mounttmp, collection.manifest_locator(), 'stream0', 'file1.txt',))
288 def test_UsingMagicDirCreateCollectionWithManyFilesAndMoveAndDeleteFile(self):
290 files_per_stream = 200
293 collection1 = self.magicDirTest_createCollectionWithManyFiles()
294 # Create collection with multiple files
295 collection2 = self.magicDirTest_createCollectionWithManyFiles(streams, files_per_stream, data)
298 self.make_mount(fuse.MagicDirectory)
300 self.magicDirTest_readCollectionContents(collection2.manifest_locator(), streams, files_per_stream, data)
302 # Move file0.txt out of the collection2 into collection1
303 self.magicDirTest_moveFileFromCollection(collection2, collection1)
304 updated_collection = self.api.collections().get(uuid=collection2.manifest_locator()).execute()
305 self.assertFalse('file0.txt' in updated_collection['manifest_text'])
306 self.assertTrue('file1.txt' in updated_collection['manifest_text'])
308 # Delete file1.txt from collection2
309 self.magicDirTest_removeFileFromCollection(collection2)
310 updated_collection = self.api.collections().get(uuid=collection2.manifest_locator()).execute()
311 self.assertFalse('file1.txt' in updated_collection['manifest_text'])
312 self.assertTrue('file2.txt' in updated_collection['manifest_text'])
315 class UsingMagicDir_CreateCollectionWithManyFilesAndMoveAllFilesIntoAnother(MountTestBase):
317 super(UsingMagicDir_CreateCollectionWithManyFilesAndMoveAllFilesIntoAnother, self).setUp()
320 def magicDirTestMoveAllFiles_createCollectionWithManyFiles(self, streams=0, files_per_stream=0,
321 blocks_per_file=0, bytes_per_block=0, data='x'):
323 collection = arvados.collection.Collection(api_client=self.api)
324 for j in range(0, files_per_stream):
325 with collection.open("file"+str(j)+".txt", "w") as f:
327 collection.save_new()
331 def magicDirTestMoveAllFiles_moveFilesFromCollection(self, from_collection, to_collection, files_per_stream):
332 for j in range(0, files_per_stream):
333 self.pool.apply(magicDirTest_MoveFileFromCollection, (self.mounttmp, from_collection.manifest_locator(),
334 to_collection.manifest_locator(), 'stream0', 'file'+str(j)+'.txt',))
335 from_collection.update()
336 to_collection.update()
338 def test_UsingMagicDirCreateCollectionWithManyFilesAndMoveAllFilesIntoAnother(self):
340 files_per_stream = 200
343 collection1 = self.magicDirTestMoveAllFiles_createCollectionWithManyFiles()
344 # Create collection with multiple files
345 collection2 = self.magicDirTestMoveAllFiles_createCollectionWithManyFiles(streams, files_per_stream, data)
348 self.make_mount(fuse.MagicDirectory)
350 # Move all files from collection2 into collection1
351 self.magicDirTestMoveAllFiles_moveFilesFromCollection(collection2, collection1, files_per_stream)
353 updated_collection = self.api.collections().get(uuid=collection2.manifest_locator()).execute()
354 file_names = ["file%i.txt" % i for i in range(0, files_per_stream)]
355 for name in file_names:
356 self.assertFalse(name in updated_collection['manifest_text'])
358 updated_collection = self.api.collections().get(uuid=collection1.manifest_locator()).execute()
359 for name in file_names:
360 self.assertTrue(name in updated_collection['manifest_text'])
363 # Move one file at a time from one collection into another
364 class UsingMagicDir_CreateCollectionWithManyFilesAndMoveEachFileIntoAnother(MountTestBase):
366 super(UsingMagicDir_CreateCollectionWithManyFilesAndMoveEachFileIntoAnother, self).setUp()
369 def magicDirTestMoveFiles_createCollectionWithManyFiles(self, streams=0, files_per_stream=0, data='x'):
371 collection = arvados.collection.Collection(api_client=self.api)
372 for j in range(0, files_per_stream):
373 with collection.open("file"+str(j)+".txt", "w") as f:
375 collection.save_new()
379 def magicDirTestMoveFiles_oneEachIntoAnother(self, from_collection, to_collection, files_per_stream):
380 for j in range(0, files_per_stream):
381 self.pool.apply(magicDirTest_MoveFileFromCollection, (self.mounttmp, from_collection.manifest_locator(),
382 to_collection.manifest_locator(), 'stream0', 'file'+str(j)+'.txt',))
383 from_collection.update()
384 to_collection.update()
386 def test_UsingMagicDirCreateCollectionWithManyFilesAndMoveEachFileIntoAnother(self):
388 files_per_stream = 200
391 collection1 = self.magicDirTestMoveFiles_createCollectionWithManyFiles()
392 # Create collection with multiple files
393 collection2 = self.magicDirTestMoveFiles_createCollectionWithManyFiles(streams, files_per_stream, data)
396 self.make_mount(fuse.MagicDirectory)
398 # Move all files from collection2 into collection1
399 self.magicDirTestMoveFiles_oneEachIntoAnother(collection2, collection1, files_per_stream)
401 updated_collection = self.api.collections().get(uuid=collection2.manifest_locator()).execute()
402 file_names = ["file%i.txt" % i for i in range(0, files_per_stream)]
403 for name in file_names:
404 self.assertFalse(name in updated_collection['manifest_text'])
406 updated_collection = self.api.collections().get(uuid=collection1.manifest_locator()).execute()
407 for name in file_names:
408 self.assertTrue(name in updated_collection['manifest_text'])
410 class FuseListLargeProjectContents(MountTestBase):
412 def listLargeProjectContents(self):
413 project_contents = llfuse.listdir(self.mounttmp)
414 self.assertEqual(201, len(project_contents))
415 self.assertIn('Collection_1', project_contents)
417 for collection_name in project_contents:
418 collection_contents = llfuse.listdir(os.path.join(self.mounttmp, collection_name))
419 self.assertIn('baz', collection_contents)
421 def test_listLargeProjectContents(self):
422 self.make_mount(fuse.ProjectDirectory,
423 project_object=run_test_server.fixture('groups')['project_with_201_collections'])
424 self.listLargeProjectContents()