3 import arvados_fuse as fuse
16 import multiprocessing
17 from .. import run_test_server
18 from ..mount_test_base import MountTestBase
20 logger = logging.getLogger('arvados.arv-mount')
22 from performance_profiler import profiled
25 def fuseCreateCollectionWithManyFiles(mounttmp, streams=1, files_per_stream=1, blocks_per_file=1, bytes_per_block=1, data='x'):
26 class Test(unittest.TestCase):
29 for i in range(1, files_per_stream):
30 names += ',file' + str(i) + '.txt'
31 file_names = names.split(',')
33 for i in range(0, streams):
34 with self.assertRaises(IOError):
35 with open(os.path.join(mounttmp, "./stream", "file0.txt"), "w") as f:
38 os.mkdir(os.path.join(mounttmp, "./stream" + str(i)))
40 with self.assertRaises(OSError):
41 os.mkdir(os.path.join(mounttmp, "./stream" + str(i)))
44 for j in range(0, files_per_stream):
45 with open(os.path.join(mounttmp, "./stream" + str(i), "file" + str(j) +".txt"), "w") as f:
48 d1 = llfuse.listdir(os.path.join(mounttmp, "./stream" + str(i)))
49 self.assertEqual(sorted(file_names), sorted(d1))
54 def fuseReadContentsFromCollectionWithManyFiles(mounttmp, streams, files_per_stream, content):
55 class Test(unittest.TestCase):
57 for i in range(0, streams):
58 d1 = llfuse.listdir(os.path.join(mounttmp, 'stream'+str(i)))
59 for j in range(0, files_per_stream):
60 with open(os.path.join(mounttmp, 'stream'+str(i), 'file'+str(i)+'.txt')) as f:
61 self.assertEqual(content, f.read())
66 def fuseMoveFileFromCollectionWithManyFiles(mounttmp, stream, filename):
67 class Test(unittest.TestCase):
69 d1 = llfuse.listdir(os.path.join(mounttmp, stream))
70 self.assertIn(filename, d1)
72 os.rename(os.path.join(mounttmp, stream, filename), os.path.join(mounttmp, 'moved-from-'+stream+'-'+filename))
74 d1 = llfuse.listdir(os.path.join(mounttmp))
75 self.assertIn('moved-from-'+stream+'-'+filename, d1)
77 d1 = llfuse.listdir(os.path.join(mounttmp, stream))
78 self.assertNotIn(filename, d1)
83 def fuseDeleteFileFromCollectionWithManyFiles(mounttmp, stream, filename):
84 class Test(unittest.TestCase):
86 d1 = llfuse.listdir(os.path.join(mounttmp, stream))
89 os.remove(os.path.join(mounttmp, stream, filename))
91 # Try to delete it again
92 with self.assertRaises(OSError):
93 os.remove(os.path.join(mounttmp, "testdir", "file1.txt"))
97 # Create a collection with two streams, each with 200 files
98 class CreateCollectionWithManyFilesAndRenameMoveAndDeleteFile(MountTestBase):
100 collection = arvados.collection.Collection(api_client=self.api)
101 collection.save_new()
103 m = self.make_mount(fuse.CollectionDirectory)
105 m.new_collection(collection.api_response(), collection)
106 self.assertTrue(m.writable())
109 files_per_stream = 200
113 data = 'x' * blocks_per_file * bytes_per_block
115 self.pool.apply(fuseCreateCollectionWithManyFiles, (self.mounttmp, streams, files_per_stream, blocks_per_file, bytes_per_block, data))
117 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
119 for i in range(0, streams):
120 self.assertIn('./stream' + str(i), collection2["manifest_text"])
122 for i in range(0, files_per_stream):
123 self.assertIn('file' + str(i) + '.txt', collection2["manifest_text"])
126 self.pool.apply(fuseReadContentsFromCollectionWithManyFiles, (self.mounttmp, streams, files_per_stream, data,))
128 # Move file0.txt out of the streams into .
129 for i in range(0, streams):
130 self.pool.apply(fuseMoveFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file0.txt',))
132 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
134 manifest_streams = collection2['manifest_text'].split('\n')
135 self.assertEqual(4, len(manifest_streams))
137 for i in range(0, streams):
138 self.assertIn('moved-from-stream'+str(i)+'-file0.txt', manifest_streams[0])
140 for i in range(0, streams):
141 self.assertNotIn('file0.txt', manifest_streams[i+1])
143 for i in range(0, streams):
144 for j in range(1, files_per_stream):
145 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])
147 # Delete 'file1.txt' from all the streams
148 for i in range(0, streams):
149 self.pool.apply(fuseDeleteFileFromCollectionWithManyFiles, (self.mounttmp, 'stream'+str(i), 'file1.txt'))
151 collection2 = self.api.collections().get(uuid=collection.manifest_locator()).execute()
153 manifest_streams = collection2['manifest_text'].split('\n')
154 self.assertEqual(4, len(manifest_streams))
156 for i in range(0, streams):
157 self.assertIn('moved-from-stream'+str(i)+'-file0.txt', manifest_streams[0])
159 self.assertNotIn('file1.txt', collection2['manifest_text'])
161 for i in range(0, streams):
162 for j in range(2, files_per_stream):
163 self.assertIn('file' + str(j) + '.txt', manifest_streams[i+1])