11502: When getting a manifest using a PDH, the manifest is stripped.
authorLucas Di Pentima <lucas@curoverse.com>
Fri, 14 Apr 2017 20:04:35 +0000 (17:04 -0300)
committerLucas Di Pentima <lucas@curoverse.com>
Fri, 14 Apr 2017 20:04:35 +0000 (17:04 -0300)
Corrected test so that when comparing manifests, it does so by comparing stripped ones so that it doesn't intermittently fail.

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

index f39e092135aa6234c6318326dd8db654aa84aa04..3c7954da8e7fd0916c788e2fd9ed942e638dd674 100755 (executable)
@@ -10,6 +10,7 @@ import logging
 
 import arvados
 import arvados.commands._util as arv_cmd
+import arvados.util as util
 
 from arvados._version import __version__
 
@@ -131,17 +132,20 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
         api_client = arvados.api('v1')
 
     r = re.search(r'^(.*?)(/.*)?$', args.locator)
-    collection = r.group(1)
+    col_loc = r.group(1)
     get_prefix = r.group(2)
     if args.r and not get_prefix:
         get_prefix = os.sep
     try:
-        reader = arvados.CollectionReader(collection, num_retries=args.retries)
+        reader = arvados.CollectionReader(col_loc, num_retries=args.retries)
     except Exception as error:
         logger.error("failed to read collection: {}".format(error))
         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
@@ -149,16 +153,16 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
                 open_flags |= os.O_EXCL
             try:
                 if args.destination == "-":
-                    stdout.write(reader.manifest_text())
+                    stdout.write(reader.manifest_text(strip=should_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())
+                        out_file.write(reader.manifest_text(strip=should_strip_manifest))
             except (IOError, OSError) as error:
                 logger.error("can't write to '{}': {}".format(args.destination, error))
                 return 1
             except (arvados.errors.ApiError, arvados.errors.KeepReadError) as error:
-                logger.error("failed to download '{}': {}".format(collection, error))
+                logger.error("failed to download '{}': {}".format(col_loc, error))
                 return 1
         return 0
 
index 907c671822b16ed0929f5976c0a0c0ad5f9b6eac..1dbff37452157872e695e27d7f8fb30bfd4cfa7c 100644 (file)
@@ -26,6 +26,7 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers):
         shutil.rmtree(self.tempdir)
 
     def write_test_collection(self,
+                              strip_manifest=True,
                               contents = {
                                   'foo.txt' : 'foo',
                                   'bar.txt' : 'bar',
@@ -36,7 +37,9 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers):
             with c.open(path, 'w') as f:
                 f.write(data)
         c.save_new()
-        return (c.manifest_locator(), c.portable_data_hash(), c.manifest_text())
+        return (c.manifest_locator(),
+                c.portable_data_hash(),
+                c.manifest_text(strip=strip_manifest))
     
     def run_get(self, args):
         self.stdout = io.BytesIO()
@@ -75,9 +78,9 @@ class ArvadosGetTestCase(run_test_server.TestCaseWithServers):
 
     def test_get_collection_manifest(self):
         # Get the collection manifest
-        r = self.run_get([self.col_loc, self.tempdir])
+        r = self.run_get([self.col_pdh, self.tempdir])
         self.assertEqual(0, r)
-        with open("{}/{}".format(self.tempdir, self.col_loc), "r") as f:
+        with open("{}/{}".format(self.tempdir, self.col_pdh), "r") as f:
             self.assertEqual(self.col_manifest, f.read())
 
     def test_invalid_collection(self):