11502: Fix regression by writing a collection manifest with its access tokens in...
authorLucas Di Pentima <lucas@curoverse.com>
Tue, 18 Apr 2017 15:31:48 +0000 (12:31 -0300)
committerLucas Di Pentima <lucas@curoverse.com>
Tue, 18 Apr 2017 15:31:48 +0000 (12:31 -0300)
Added --strip-manifest argument to allow writing manifests without tokens.
Updated tests accordingly.

sdk/python/arvados/commands/get.py
sdk/python/tests/test_arv_get.py

index 3c7954da8e7fd0916c788e2fd9ed942e638dd674..e54fd87a193607c9da303d734ecd714c7de34a52 100755 (executable)
@@ -85,6 +85,11 @@ write *anything* if any files exist that would have to be
 overwritten. This option causes even devices, sockets, and fifos to be
 skipped.
 """)
+group.add_argument('--strip-manifest', action='store_true', default=False,
+                   help="""
+When getting a collection manifest, strip its access tokens before writing 
+it.
+""")
 
 def parse_arguments(arguments, stdout, stderr):
     args = parser.parse_args(arguments)
@@ -143,9 +148,6 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
         return 1
 
     # User asked to download the collection's manifest
-    should_strip_manifest = False
-    if re.match(util.keep_locator_pattern, col_loc):
-        should_strip_manifest = True
     if not get_prefix:
         if not args.n:
             open_flags = os.O_CREAT | os.O_WRONLY
@@ -153,11 +155,11 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
                 open_flags |= os.O_EXCL
             try:
                 if args.destination == "-":
-                    stdout.write(reader.manifest_text(strip=should_strip_manifest))
+                    stdout.write(reader.manifest_text(strip=args.strip_manifest))
                 else:
                     out_fd = os.open(args.destination, open_flags)
                     with os.fdopen(out_fd, 'wb') as out_file:
-                        out_file.write(reader.manifest_text(strip=should_strip_manifest))
+                        out_file.write(reader.manifest_text(strip=args.strip_manifest))
             except (IOError, OSError) as error:
                 logger.error("can't write to '{}': {}".format(args.destination, error))
                 return 1
index 1dbff37452157872e695e27d7f8fb30bfd4cfa7c..4feac0fd61e70687d9353a71f4f55c5afb871e53 100644 (file)
@@ -26,7 +26,7 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers):
         shutil.rmtree(self.tempdir)
 
     def write_test_collection(self,
-                              strip_manifest=True,
+                              strip_manifest=False,
                               contents = {
                                   'foo.txt' : 'foo',
                                   'bar.txt' : 'bar',
@@ -76,13 +76,31 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers):
         with open("{}/subdir/baz.txt".format(self.tempdir), "r") as f:
             self.assertEqual("baz", f.read())
 
-    def test_get_collection_manifest(self):
-        # Get the collection manifest
+    def test_get_collection_unstripped_manifest(self):
+        # Get the collection manifest by UUID
+        r = self.run_get([self.col_loc, self.tempdir])
+        self.assertEqual(0, r)
+        with open("{}/{}".format(self.tempdir, self.col_loc), "r") as f:
+            self.assertEqual(self.col_manifest, f.read())
+        # Get the collection manifest by PDH
         r = self.run_get([self.col_pdh, self.tempdir])
         self.assertEqual(0, r)
         with open("{}/{}".format(self.tempdir, self.col_pdh), "r") as f:
             self.assertEqual(self.col_manifest, f.read())
 
+    def test_get_collection_stripped_manifest(self):
+        col_loc, col_pdh, col_manifest = self.write_test_collection(strip_manifest=True)
+        # Get the collection manifest by UUID
+        r = self.run_get(['--strip-manifest', col_loc, self.tempdir])
+        self.assertEqual(0, r)
+        with open("{}/{}".format(self.tempdir, col_loc), "r") as f:
+            self.assertEqual(col_manifest, f.read())
+        # Get the collection manifest by PDH
+        r = self.run_get(['--strip-manifest', col_pdh, self.tempdir])
+        self.assertEqual(0, r)
+        with open("{}/{}".format(self.tempdir, col_pdh), "r") as f:
+            self.assertEqual(col_manifest, f.read())
+
     def test_invalid_collection(self):
         # Asking for an invalid collection should generate an error.
         r = self.run_get(['this-uuid-seems-to-be-fake', self.tempdir])