2752: arv-put works when it can't write a cache file.
authorBrett Smith <brett@curoverse.com>
Mon, 2 Jun 2014 14:23:42 +0000 (10:23 -0400)
committerBrett Smith <brett@curoverse.com>
Mon, 2 Jun 2014 14:23:42 +0000 (10:23 -0400)
sdk/python/arvados/commands/put.py
sdk/python/tests/test_arv_put.py

index 255021e7755ba93eaa0f2fbcfe3c3b69c57309eb..01bae2feade3e7345c1e57c352eba713cafe4a81 100644 (file)
@@ -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()
index dd720dd230927b21ea0a885cb70588df66a5fc97..bea622046a2784f32863d689767be5346beb5db5 100644 (file)
@@ -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.