X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/346a55897f4e4a2a26a1a84665f860c000b3da7d..85782d1376ba94714088499b064ba3e43aefe722:/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..bfefc674d7 100644 --- a/services/fuse/tests/test_command_args.py +++ b/services/fuse/tests/test_command_args.py @@ -187,3 +187,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)