16589: Properly reports error when a name collision happens.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 13 Jul 2020 21:58:47 +0000 (18:58 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 13 Jul 2020 21:58:47 +0000 (18:58 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

sdk/python/arvados/commands/federation_migrate.py

index 0d39f4fc25b0e7d4172d193b6d4fef7b7be2b361..5140d25293176784eefbf4602838087f5e40e24d 100755 (executable)
@@ -22,6 +22,7 @@ import hmac
 import urllib.parse
 import os
 import hashlib
+import re
 from arvados._version import __version__
 
 EMAIL=0
@@ -316,7 +317,12 @@ def migrate_user(args, migratearv, email, new_user_uuid, old_user_uuid):
                                     new_owner_uuid=new_owner_uuid,
                                     redirect_to_new_user=True).execute()
     except arvados.errors.ApiError as e:
-        print("(%s) Skipping user migration because of error: %s" % (email, e))
+        name_collision = re.search(r'Key \(owner_uuid, name\)=\((.*?), (.*?)\) already exists\.\n.*UPDATE "(.*?)"', e)
+        if name_collision:
+            target_owner, rsc_name, rsc_type = name_collision.groups()
+            print("(%s) Target owner %s already has a %s named '%s', skipping. Please rename it or use --data-into-subproject to migrate all users' data into a special subproject." % (email, target_owner, rsc_type[:-1], rsc_name))
+        else:
+            print("(%s) Skipping user migration because of error: %s" % (email, e))
 
 
 def main():