11209: Replace "--unmount /path/..." with "--unmount-all /path".
[arvados.git] / services / fuse / tests / test_unmount.py
1 import os
2 import subprocess
3 import time
4
5 from integration_test import IntegrationTest
6
7 class UnmountTest(IntegrationTest):
8     def setUp(self):
9         super(UnmountTest, self).setUp()
10         self.tmp = self.mnt
11         self.to_delete = []
12
13     def tearDown(self):
14         for d in self.to_delete:
15             os.rmdir(d)
16         super(UnmountTest, self).tearDown()
17
18     def test_replace(self):
19         subprocess.check_call(
20             ['arv-mount', '--subtype', 'test', '--replace',
21              self.mnt])
22         subprocess.check_call(
23             ['arv-mount', '--subtype', 'test', '--replace',
24              '--unmount-timeout', '10',
25              self.mnt])
26         subprocess.check_call(
27             ['arv-mount', '--subtype', 'test', '--replace',
28              '--unmount-timeout', '10',
29              self.mnt,
30              '--exec', 'true'])
31         for m in subprocess.check_output(['mount']).splitlines():
32             self.assertNotIn(' '+self.mnt+' ', m)
33
34     def _mounted(self, mounts):
35         all_mounts = subprocess.check_output(['mount', '-t', 'fuse.test'])
36         return [m for m in mounts
37                 if ' '+m+' ' in all_mounts]
38
39     def test_unmount_children(self):
40         for d in ['foo', 'foo/bar', 'bar']:
41             mnt = self.tmp+'/'+d
42             os.mkdir(mnt)
43             self.to_delete.insert(0, mnt)
44         mounts = []
45         for d in ['bar', 'foo/bar']:
46             mnt = self.tmp+'/'+d
47             mounts.append(mnt)
48             subprocess.check_call(
49                 ['arv-mount', '--subtype', 'test', mnt])
50
51         # Wait for mounts to attach
52         deadline = time.time() + 10
53         while self._mounted(mounts) != mounts:
54             time.sleep(0.1)
55             self.assertLess(time.time(), deadline)
56
57         self.assertEqual(mounts, self._mounted(mounts))
58         subprocess.check_call(['arv-mount', '--unmount', self.tmp])
59         self.assertEqual(mounts, self._mounted(mounts))
60         subprocess.check_call(['arv-mount', '--unmount-all', self.tmp])
61         self.assertEqual([], self._mounted(mounts))