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')
19 class TmpCollectionArgsTest(unittest.TestCase):
21 self.tmpdir = tempfile.mkdtemp()
26 def test_tmp_only(self):
27 args = arvados_fuse.command.ArgumentParser().parse_args([
28 '--mount-tmp', 'tmp1',
29 '--mount-tmp', 'tmp2',
32 self.assertIn(args.mode, [None, 'custom'])
33 self.assertEqual(['tmp1', 'tmp2'], args.mount_tmp)
34 for mtype in ['home', 'shared', 'by_id', 'by_pdh', 'by_tag']:
35 self.assertEqual([], getattr(args, 'mount_'+mtype))
37 def test_tmp_and_home(self):
38 args = arvados_fuse.command.ArgumentParser().parse_args([
39 '--mount-tmp', 'test_tmp',
40 '--mount-home', 'test_home',
43 self.assertIn(args.mode, [None, 'custom'])
44 self.assertEqual(['test_tmp'], args.mount_tmp)
45 self.assertEqual(['test_home'], args.mount_home)
47 def test_no_tmp(self):
48 args = arvados_fuse.command.ArgumentParser().parse_args([
51 self.assertEqual([], args.mount_tmp)
54 def current_manifest(tmpdir):
55 with open(os.path.join(tmpdir, '.arvados#collection')) as tmp:
56 return json.load(tmp)['manifest_text']
58 def storage_classes_desired(tmpdir):
59 with open(os.path.join(tmpdir, '.arvados#collection')) as tmp:
60 return json.load(tmp)['storage_classes_desired']
62 class TmpCollectionTest(IntegrationTest):
68 @IntegrationTest.mount(argv=mnt_args+['--storage-classes', 'foo, bar'])
69 def test_storage_classes(self):
70 self.pool_test(os.path.join(self.mnt, 'zzz'))
72 def _test_storage_classes(self, zzz):
73 self.assertEqual(storage_classes_desired(zzz), ['foo', 'bar'])
75 @IntegrationTest.mount(argv=mnt_args+['--mount-tmp', 'yyy'])
76 def test_two_tmp(self):
77 self.pool_test(os.path.join(self.mnt, 'zzz'),
78 os.path.join(self.mnt, 'yyy'))
80 def _test_two_tmp(self, zzz, yyy):
81 self.assertEqual(current_manifest(zzz), "")
82 self.assertEqual(current_manifest(yyy), "")
83 with open(os.path.join(zzz, 'foo'), 'w') as f:
85 self.assertNotEqual(current_manifest(zzz), "")
86 self.assertEqual(current_manifest(yyy), "")
87 os.unlink(os.path.join(zzz, 'foo'))
88 with open(os.path.join(yyy, 'bar'), 'w') as f:
90 self.assertEqual(current_manifest(zzz), "")
91 self.assertNotEqual(current_manifest(yyy), "")
93 @IntegrationTest.mount(argv=mnt_args)
94 def test_tmp_empty(self):
95 self.pool_test(os.path.join(self.mnt, 'zzz'))
97 def _test_tmp_empty(self, tmpdir):
98 self.assertEqual(current_manifest(tmpdir), "")
100 @IntegrationTest.mount(argv=mnt_args)
101 def test_tmp_onefile(self):
102 self.pool_test(os.path.join(self.mnt, 'zzz'))
104 def _test_tmp_onefile(self, tmpdir):
105 with open(os.path.join(tmpdir, 'foo'), 'w') as f:
108 current_manifest(tmpdir),
109 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$')
111 @IntegrationTest.mount(argv=mnt_args)
112 def test_tmp_snapshots(self):
113 self.pool_test(os.path.join(self.mnt, 'zzz'))
115 def _test_tmp_snapshots(self, tmpdir):
118 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:foo\n$'),
120 r'^\. acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:foo\n$'),
122 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? acbd18db4cc2f85cedef654fccc4a4d8\+3(\+\S+)? 0:3:bar 3:3:foo\n$'),
124 r'^\. 37b51d194a7513e45b56f6524f2d51f2\+3(\+\S+)? 0:3:bar\n$'),
129 for fn, content, expect in ops:
130 path = os.path.join(tmpdir, fn)
134 with open(path, 'w') as f:
136 self.assertRegex(current_manifest(tmpdir), expect)
138 @IntegrationTest.mount(argv=mnt_args)
139 def test_tmp_rewrite(self):
140 self.pool_test(os.path.join(self.mnt, 'zzz'))
142 def _test_tmp_rewrite(self, tmpdir):
143 with open(os.path.join(tmpdir, "b1"), 'w') as f:
145 with open(os.path.join(tmpdir, "b2"), 'w') as f:
147 with open(os.path.join(tmpdir, "b1"), 'w') as f:
149 self.assertRegex(current_manifest(tmpdir), "^\. ed4f3f67c70b02b29c50ce1ea26666bd\+4(\+\S+)? 0:2:b1 2:2:b2\n$")