X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2a5d2064c5399f209bcf1bf1a47f2807ff5e16f1..6de67b677d281b99b53ee9a25c9228523fdf7ee2:/services/fuse/tests/test_command_args.py diff --git a/services/fuse/tests/test_command_args.py b/services/fuse/tests/test_command_args.py index 19d56a9baf..bb80d0a2fc 100644 --- a/services/fuse/tests/test_command_args.py +++ b/services/fuse/tests/test_command_args.py @@ -6,6 +6,7 @@ import functools import json import llfuse import logging +import mock import os import run_test_server import sys @@ -82,6 +83,7 @@ class MountArgsTest(unittest.TestCase): self.mnt = arvados_fuse.command.Mount(args) e = self.check_ent_type(arvados_fuse.MagicDirectory) self.assertEqual(e.pdh_only, False) + self.assertEqual(True, self.mnt.listen_for_events) @noexit def test_by_pdh(self): @@ -92,6 +94,7 @@ class MountArgsTest(unittest.TestCase): self.mnt = arvados_fuse.command.Mount(args) e = self.check_ent_type(arvados_fuse.MagicDirectory) self.assertEqual(e.pdh_only, True) + self.assertEqual(False, self.mnt.listen_for_events) @noexit def test_by_tag(self): @@ -101,6 +104,7 @@ class MountArgsTest(unittest.TestCase): self.assertEqual(args.mode, 'by_tag') self.mnt = arvados_fuse.command.Mount(args) e = self.check_ent_type(arvados_fuse.TagsDirectory) + self.assertEqual(True, self.mnt.listen_for_events) @noexit def test_collection(self, id_type='uuid'): @@ -112,6 +116,7 @@ class MountArgsTest(unittest.TestCase): self.mnt = arvados_fuse.command.Mount(args) e = self.check_ent_type(arvados_fuse.CollectionDirectory) self.assertEqual(e.collection_locator, cid) + self.assertEqual(id_type == 'uuid', self.mnt.listen_for_events) def test_collection_pdh(self): self.test_collection('portable_data_hash') @@ -126,6 +131,7 @@ class MountArgsTest(unittest.TestCase): e = self.check_ent_type(arvados_fuse.ProjectDirectory) self.assertEqual(e.project_object['uuid'], run_test_server.fixture('users')['active']['uuid']) + self.assertEqual(True, self.mnt.listen_for_events) def test_mutually_exclusive_args(self): cid = run_test_server.fixture('collections')['public_text_file']['uuid'] @@ -162,9 +168,11 @@ class MountArgsTest(unittest.TestCase): e = self.check_ent_type(arvados_fuse.SharedDirectory) self.assertEqual(e.current_user['uuid'], run_test_server.fixture('users')['active']['uuid']) + self.assertEqual(True, self.mnt.listen_for_events) @noexit - def test_custom(self): + @mock.patch('arvados.events.subscribe') + def test_custom(self, mock_subscribe): args = arvados_fuse.command.ArgumentParser().parse_args([ '--mount-tmp', 'foo', '--mount-tmp', 'bar', @@ -178,6 +186,24 @@ class MountArgsTest(unittest.TestCase): e = self.check_ent_type(arvados_fuse.ProjectDirectory, 'my_home') self.assertEqual(e.project_object['uuid'], run_test_server.fixture('users')['active']['uuid']) + self.assertEqual(True, self.mnt.listen_for_events) + with self.mnt: + pass + self.assertEqual(1, mock_subscribe.call_count) + + @noexit + @mock.patch('arvados.events.subscribe') + def test_custom_no_listen(self, mock_subscribe): + args = arvados_fuse.command.ArgumentParser().parse_args([ + '--mount-by-pdh', 'pdh', + '--mount-tmp', 'foo', + '--mount-tmp', 'bar', + '--foreground', self.mntdir]) + self.mnt = arvados_fuse.command.Mount(args) + self.assertEqual(False, self.mnt.listen_for_events) + with self.mnt: + pass + self.assertEqual(0, mock_subscribe.call_count) def test_custom_unsupported_layouts(self): for name in ['.', '..', '', 'foo/bar', '/foo']: @@ -187,3 +213,78 @@ class MountArgsTest(unittest.TestCase): '--mount-tmp', name, '--foreground', self.mntdir]) arvados_fuse.command.Mount(args) + +class MountErrorTest(unittest.TestCase): + def setUp(self): + self.mntdir = tempfile.mkdtemp() + run_test_server.run() + run_test_server.authorize_with("active") + self.logger = logging.getLogger("null") + self.logger.setLevel(logging.CRITICAL+1) + + def tearDown(self): + if os.path.exists(self.mntdir): + # If the directory was not unmounted, this will raise an exception. + os.rmdir(self.mntdir) + run_test_server.reset() + + def test_no_token(self): + del arvados.config._settings["ARVADOS_API_TOKEN"] + arvados.config._settings = {} + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_no_host(self): + del arvados.config._settings["ARVADOS_API_HOST"] + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_bogus_host(self): + arvados.config._settings["ARVADOS_API_HOST"] = "100::" + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_bogus_token(self): + arvados.config._settings["ARVADOS_API_TOKEN"] = "zzzzzzzzzzzzz" + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_bogus_mount_dir(self): + # All FUSE errors in llfuse.init() are raised as RuntimeError + # An easy error to trigger is to supply a nonexistent mount point, + # so test that one. + # + # Other possible errors that also raise RuntimeError (but are much + # harder to test automatically because they depend on operating + # system configuration): + # + # The user doesn't have permission to use FUSE + # The user specified --allow-other but user_allow_other is not set + # in /etc/fuse.conf + os.rmdir(self.mntdir) + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_unreadable_collection(self): + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([ + "--collection", "zzzzz-4zz18-zzzzzzzzzzzzzzz", self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code) + + def test_unreadable_project(self): + with self.assertRaises(SystemExit) as ex: + args = arvados_fuse.command.ArgumentParser().parse_args([ + "--project", "zzzzz-j7d0g-zzzzzzzzzzzzzzz", self.mntdir]) + arvados_fuse.command.Mount(args, logger=self.logger).run() + self.assertEqual(1, ex.exception.code)