1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from builtins import range
6 from six import assertRegex
9 import arvados_fuse.command
16 from .integration_test import IntegrationTest
17 from .mount_test_base import MountTestBase
19 logger = logging.getLogger('arvados.arv-mount')
22 class TmpCollectionArgsTest(unittest.TestCase):
24 self.tmpdir = tempfile.mkdtemp()
29 def test_tmp_only(self):
30 args = arvados_fuse.command.ArgumentParser().parse_args([
31 '--mount-tmp', 'tmp1',
32 '--mount-tmp', 'tmp2',
35 self.assertIn(args.mode, [None, 'custom'])
36 self.assertEqual(['tmp1', 'tmp2'], args.mount_tmp)
37 for mtype in ['home', 'shared', 'by_id', 'by_pdh', 'by_tag']:
38 self.assertEqual([], getattr(args, 'mount_'+mtype))
40 def test_tmp_and_home(self):
41 args = arvados_fuse.command.ArgumentParser().parse_args([
42 '--mount-tmp', 'test_tmp',
43 '--mount-home', 'test_home',
46 self.assertIn(args.mode, [None, 'custom'])
47 self.assertEqual(['test_tmp'], args.mount_tmp)
48 self.assertEqual(['test_home'], args.mount_home)
50 def test_no_tmp(self):
51 args = arvados_fuse.command.ArgumentParser().parse_args([
54 self.assertEqual([], args.mount_tmp)
57 def current_manifest(tmpdir):
58 with open(os.path.join(tmpdir, '.arvados#collection')) as tmp:
59 return json.load(tmp)['manifest_text']
62 class TmpCollectionTest(IntegrationTest):
68 @IntegrationTest.mount(argv=mnt_args+['--mount-tmp', 'yyy'])
69 def test_two_tmp(self):
70 self.pool_test(os.path.join(self.mnt, 'zzz'),
71 os.path.join(self.mnt, 'yyy'))
73 def _test_two_tmp(self, zzz, yyy):
74 self.assertEqual(current_manifest(zzz), "")
75 self.assertEqual(current_manifest(yyy), "")
76 with open(os.path.join(zzz, 'foo'), 'w') as f:
78 self.assertNotEqual(current_manifest(zzz), "")
79 self.assertEqual(current_manifest(yyy), "")
80 os.unlink(os.path.join(zzz, 'foo'))
81 with open(os.path.join(yyy, 'bar'), 'w') as f:
83 self.assertEqual(current_manifest(zzz), "")
84 self.assertNotEqual(current_manifest(yyy), "")
86 @IntegrationTest.mount(argv=mnt_args)
87 def test_tmp_empty(self):
88 self.pool_test(os.path.join(self.mnt, 'zzz'))
90 def _test_tmp_empty(self, tmpdir):
91 self.assertEqual(current_manifest(tmpdir), "")
93 @IntegrationTest.mount(argv=mnt_args)
94 def test_tmp_onefile(self):
95 self.pool_test(os.path.join(self.mnt, 'zzz'))
97 def _test_tmp_onefile(self, tmpdir):
98 with open(os.path.join(tmpdir, 'foo'), 'w') as f:
102 current_manifest(tmpdir),
103 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$')
105 @IntegrationTest.mount(argv=mnt_args)
106 def test_tmp_snapshots(self):
107 self.pool_test(os.path.join(self.mnt, 'zzz'))
109 def _test_tmp_snapshots(self, tmpdir):
112 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:foo\n$'),
114 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$'),
116 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:bar 3:3:foo\n$'),
118 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:bar\n$'),
123 for fn, content, expect in ops:
124 path = os.path.join(tmpdir, fn)
128 with open(path, 'w') as f:
130 assertRegex(self, current_manifest(tmpdir), expect)
132 @IntegrationTest.mount(argv=mnt_args)
133 def test_tmp_rewrite(self):
134 self.pool_test(os.path.join(self.mnt, 'zzz'))
136 def _test_tmp_rewrite(self, tmpdir):
137 with open(os.path.join(tmpdir, "b1"), 'w') as f:
139 with open(os.path.join(tmpdir, "b2"), 'w') as f:
141 with open(os.path.join(tmpdir, "b1"), 'w') as f:
143 assertRegex(self, current_manifest(tmpdir), "^\. ed4f3f67c70b02b29c50ce1ea26666bd\+4(\+\S+)? 0:2:b1 2:2:b2\n$")