3 import arvados_fuse.command
10 from .integration_test import IntegrationTest
11 from .mount_test_base import MountTestBase
13 logger = logging.getLogger('arvados.arv-mount')
16 class TmpCollectionArgsTest(unittest.TestCase):
18 self.tmpdir = tempfile.mkdtemp()
23 def test_tmp_only(self):
24 args = arvados_fuse.command.ArgumentParser().parse_args([
25 '--mount-tmp', 'tmp1',
26 '--mount-tmp', 'tmp2',
29 self.assertIn(args.mode, [None, 'custom'])
30 self.assertEqual(['tmp1', 'tmp2'], args.mount_tmp)
31 for mtype in ['home', 'shared', 'by_id', 'by_pdh', 'by_tag']:
32 self.assertEqual([], getattr(args, 'mount_'+mtype))
34 def test_tmp_and_home(self):
35 args = arvados_fuse.command.ArgumentParser().parse_args([
36 '--mount-tmp', 'test_tmp',
37 '--mount-home', 'test_home',
40 self.assertIn(args.mode, [None, 'custom'])
41 self.assertEqual(['test_tmp'], args.mount_tmp)
42 self.assertEqual(['test_home'], args.mount_home)
44 def test_no_tmp(self):
45 args = arvados_fuse.command.ArgumentParser().parse_args([
48 self.assertEqual([], args.mount_tmp)
51 def current_manifest(tmpdir):
52 return json.load(open(
53 os.path.join(tmpdir, '.arvados#collection')
57 class TmpCollectionTest(IntegrationTest):
63 @IntegrationTest.mount(argv=mnt_args+['--mount-tmp', 'yyy'])
64 def test_two_tmp(self):
65 self.pool_test(os.path.join(self.mnt, 'zzz'),
66 os.path.join(self.mnt, 'yyy'))
68 def _test_two_tmp(self, zzz, yyy):
69 self.assertEqual(current_manifest(zzz), "")
70 self.assertEqual(current_manifest(yyy), "")
71 with open(os.path.join(zzz, 'foo'), 'w') as f:
73 self.assertNotEqual(current_manifest(zzz), "")
74 self.assertEqual(current_manifest(yyy), "")
75 os.unlink(os.path.join(zzz, 'foo'))
76 with open(os.path.join(yyy, 'bar'), 'w') as f:
78 self.assertEqual(current_manifest(zzz), "")
79 self.assertNotEqual(current_manifest(yyy), "")
81 @IntegrationTest.mount(argv=mnt_args)
82 def test_tmp_empty(self):
83 self.pool_test(os.path.join(self.mnt, 'zzz'))
85 def _test_tmp_empty(self, tmpdir):
86 self.assertEqual(current_manifest(tmpdir), "")
88 @IntegrationTest.mount(argv=mnt_args)
89 def test_tmp_onefile(self):
90 self.pool_test(os.path.join(self.mnt, 'zzz'))
92 def _test_tmp_onefile(self, tmpdir):
93 with open(os.path.join(tmpdir, 'foo'), 'w') as f:
95 self.assertRegexpMatches(
96 current_manifest(tmpdir),
97 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$')
99 @IntegrationTest.mount(argv=mnt_args)
100 def test_tmp_snapshots(self):
101 self.pool_test(os.path.join(self.mnt, 'zzz'))
103 def _test_tmp_snapshots(self, tmpdir):
106 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:foo\n$'),
108 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$'),
110 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:bar 3:3:foo\n$'),
112 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:bar\n$'),
117 for fn, content, expect in ops:
118 path = os.path.join(tmpdir, fn)
122 with open(path, 'w') as f:
124 self.assertRegexpMatches(current_manifest(tmpdir), expect)
126 @IntegrationTest.mount(argv=mnt_args)
127 def test_tmp_rewrite(self):
128 self.pool_test(os.path.join(self.mnt, 'zzz'))
130 def _test_tmp_rewrite(self, tmpdir):
131 with open(os.path.join(tmpdir, "b1"), 'w') as f:
133 with open(os.path.join(tmpdir, "b2"), 'w') as f:
135 with open(os.path.join(tmpdir, "b1"), 'w') as f:
137 self.assertRegexpMatches(current_manifest(tmpdir), "^\. ed4f3f67c70b02b29c50ce1ea26666bd\+4(\+\S+)? 0:2:b1 2:2:b2\n$")