From: Brett Smith Date: Mon, 2 Jun 2014 14:23:42 +0000 (-0400) Subject: 2752: arv-put works when it can't write a cache file. X-Git-Tag: 1.1.0~2584^2~2 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/6029fb64fd6372c577f9f143e6f3dcaded127ac3?hp=c88315d6435332f5dababac62ff4d72dadde7c67 2752: arv-put works when it can't write a cache file. --- diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index 255021e775..01bae2fead 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -329,7 +329,6 @@ def exit_signal_handler(sigcode, frame): sys.exit(-sigcode) def main(arguments=None): - ResumeCache.setup_user_cache() args = parse_arguments(arguments) if args.progress: @@ -338,17 +337,23 @@ def main(arguments=None): reporter = progress_writer(machine_progress) else: reporter = None + bytes_expected = expected_bytes_for(args.paths) try: + ResumeCache.setup_user_cache() resume_cache = ResumeCache(ResumeCache.make_path(args)) - if not args.resume: - resume_cache.restart() + except (IOError, OSError): + # Couldn't open cache directory/file. Continue without it. + resume_cache = None + writer = ArvPutCollectionWriter(resume_cache, reporter, bytes_expected) except ResumeCacheConflict: print "arv-put: Another process is already uploading this data." sys.exit(1) - - writer = ArvPutCollectionWriter.from_cache( - resume_cache, reporter, expected_bytes_for(args.paths)) + else: + if not args.resume: + resume_cache.restart() + writer = ArvPutCollectionWriter.from_cache( + resume_cache, reporter, bytes_expected) # Install our signal handler for each code in CAUGHT_SIGNALS, and save # the originals. @@ -393,7 +398,8 @@ def main(arguments=None): for sigcode, orig_handler in orig_signal_handlers.items(): signal.signal(sigcode, orig_handler) - resume_cache.destroy() + if resume_cache is not None: + resume_cache.destroy() if __name__ == '__main__': main() diff --git a/sdk/python/tests/test_arv_put.py b/sdk/python/tests/test_arv_put.py index dd720dd230..bea622046a 100644 --- a/sdk/python/tests/test_arv_put.py +++ b/sdk/python/tests/test_arv_put.py @@ -322,7 +322,7 @@ class ArvadosPutReportTest(ArvadosBaseTestCase): class ArvadosPutTest(ArvadosKeepLocalStoreTestCase): - def test_simple_file_put(self): + def call_main_on_test_file(self): with self.make_test_file() as testfile: path = testfile.name arv_put.main(['--stream', '--no-progress', path]) @@ -331,6 +331,31 @@ class ArvadosPutTest(ArvadosKeepLocalStoreTestCase): '098f6bcd4621d373cade4e832627b4f6')), "did not find file stream in Keep store") + def test_simple_file_put(self): + self.call_main_on_test_file() + + def test_put_with_unwriteable_cache_dir(self): + orig_cachedir = arv_put.ResumeCache.CACHE_DIR + cachedir = self.make_tmpdir() + os.chmod(cachedir, 0o0) + arv_put.ResumeCache.CACHE_DIR = cachedir + try: + self.call_main_on_test_file() + finally: + arv_put.ResumeCache.CACHE_DIR = orig_cachedir + os.chmod(cachedir, 0o700) + + def test_put_with_unwritable_cache_subdir(self): + orig_cachedir = arv_put.ResumeCache.CACHE_DIR + cachedir = self.make_tmpdir() + os.chmod(cachedir, 0o0) + arv_put.ResumeCache.CACHE_DIR = os.path.join(cachedir, 'cachedir') + try: + self.call_main_on_test_file() + finally: + arv_put.ResumeCache.CACHE_DIR = orig_cachedir + os.chmod(cachedir, 0o700) + def test_short_put_from_stdin(self): # Have to run this separately since arv-put can't read from the # tests' stdin.