1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 import arvados_fuse.command
14 from .integration_test import IntegrationTest
15 from .mount_test_base import MountTestBase
17 logger = logging.getLogger('arvados.arv-mount')
20 class TmpCollectionArgsTest(unittest.TestCase):
22 self.tmpdir = tempfile.mkdtemp()
27 def test_tmp_only(self):
28 args = arvados_fuse.command.ArgumentParser().parse_args([
29 '--mount-tmp', 'tmp1',
30 '--mount-tmp', 'tmp2',
33 self.assertIn(args.mode, [None, 'custom'])
34 self.assertEqual(['tmp1', 'tmp2'], args.mount_tmp)
35 for mtype in ['home', 'shared', 'by_id', 'by_pdh', 'by_tag']:
36 self.assertEqual([], getattr(args, 'mount_'+mtype))
38 def test_tmp_and_home(self):
39 args = arvados_fuse.command.ArgumentParser().parse_args([
40 '--mount-tmp', 'test_tmp',
41 '--mount-home', 'test_home',
44 self.assertIn(args.mode, [None, 'custom'])
45 self.assertEqual(['test_tmp'], args.mount_tmp)
46 self.assertEqual(['test_home'], args.mount_home)
48 def test_no_tmp(self):
49 args = arvados_fuse.command.ArgumentParser().parse_args([
52 self.assertEqual([], args.mount_tmp)
55 def current_manifest(tmpdir):
56 return json.load(open(
57 os.path.join(tmpdir, '.arvados#collection')
61 class TmpCollectionTest(IntegrationTest):
67 @IntegrationTest.mount(argv=mnt_args+['--mount-tmp', 'yyy'])
68 def test_two_tmp(self):
69 self.pool_test(os.path.join(self.mnt, 'zzz'),
70 os.path.join(self.mnt, 'yyy'))
72 def _test_two_tmp(self, zzz, yyy):
73 self.assertEqual(current_manifest(zzz), "")
74 self.assertEqual(current_manifest(yyy), "")
75 with open(os.path.join(zzz, 'foo'), 'w') as f:
77 self.assertNotEqual(current_manifest(zzz), "")
78 self.assertEqual(current_manifest(yyy), "")
79 os.unlink(os.path.join(zzz, 'foo'))
80 with open(os.path.join(yyy, 'bar'), 'w') as f:
82 self.assertEqual(current_manifest(zzz), "")
83 self.assertNotEqual(current_manifest(yyy), "")
85 @IntegrationTest.mount(argv=mnt_args)
86 def test_tmp_empty(self):
87 self.pool_test(os.path.join(self.mnt, 'zzz'))
89 def _test_tmp_empty(self, tmpdir):
90 self.assertEqual(current_manifest(tmpdir), "")
92 @IntegrationTest.mount(argv=mnt_args)
93 def test_tmp_onefile(self):
94 self.pool_test(os.path.join(self.mnt, 'zzz'))
96 def _test_tmp_onefile(self, tmpdir):
97 with open(os.path.join(tmpdir, 'foo'), 'w') as f:
99 self.assertRegexpMatches(
100 current_manifest(tmpdir),
101 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$')
103 @IntegrationTest.mount(argv=mnt_args)
104 def test_tmp_snapshots(self):
105 self.pool_test(os.path.join(self.mnt, 'zzz'))
107 def _test_tmp_snapshots(self, tmpdir):
110 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:foo\n$'),
112 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$'),
114 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:bar 3:3:foo\n$'),
116 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:bar\n$'),
121 for fn, content, expect in ops:
122 path = os.path.join(tmpdir, fn)
126 with open(path, 'w') as f:
128 self.assertRegexpMatches(current_manifest(tmpdir), expect)
130 @IntegrationTest.mount(argv=mnt_args)
131 def test_tmp_rewrite(self):
132 self.pool_test(os.path.join(self.mnt, 'zzz'))
134 def _test_tmp_rewrite(self, tmpdir):
135 with open(os.path.join(tmpdir, "b1"), 'w') as f:
137 with open(os.path.join(tmpdir, "b2"), 'w') as f:
139 with open(os.path.join(tmpdir, "b1"), 'w') as f:
141 self.assertRegexpMatches(current_manifest(tmpdir), "^\. ed4f3f67c70b02b29c50ce1ea26666bd\+4(\+\S+)? 0:2:b1 2:2:b2\n$")