[ARVADOS] created: 1.2.0-313-gd8a9500ef

Git user git at public.curoverse.com
Wed Nov 7 09:08:36 EST 2018


        at  d8a9500ef903c96ea46bf2a2932fc30389ad46dc (commit)


commit d8a9500ef903c96ea46bf2a2932fc30389ad46dc
Author: Lucas Di Pentima <ldipentima at veritasgenetics.com>
Date:   Wed Nov 7 11:05:03 2018 -0300

    14323: Prioritize PDH over UUID for mount resolving when both provided.
    
    * Don't delete uuid after mount resolving.
    * Update tests
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima at veritasgenetics.com>

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index cd763a8e7..6ef9d7cbd 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -223,7 +223,27 @@ class Container < ArvadosModel
       if mount['kind'] != 'collection'
         next
       end
-      if (uuid = mount.delete 'uuid')
+
+      pdh = mount['portable_data_hash']
+      uuid = mount['uuid']
+
+      # Prioritize PDH over UUID for mount selection
+      if not pdh.nil?
+        c = Collection.
+          readable_by(current_user).
+          where(portable_data_hash: pdh)
+        if c.count > 0
+          if uuid && c.where(uuid: uuid).count == 0
+            raise ArgumentError.new "cannot mount collection #{uuid.inspect}: current portable_data_hash #{pdh.inspect} does not match #{c.first.portable_data_hash.inspect} in request"
+          end
+          # mount.delete 'uuid'
+          next
+        end
+        raise ArgumentError.new "cannot mount collection #{pdh.inspect}: not found"
+      end
+
+      # PDH not supplied, try by UUID
+      if uuid
         c = Collection.
           readable_by(current_user).
           where(uuid: uuid).
@@ -232,13 +252,7 @@ class Container < ArvadosModel
         if !c
           raise ArvadosModel::UnresolvableContainerError.new "cannot mount collection #{uuid.inspect}: not found"
         end
-        if mount['portable_data_hash'].nil?
-          # PDH not supplied by client
-          mount['portable_data_hash'] = c.portable_data_hash
-        elsif mount['portable_data_hash'] != c.portable_data_hash
-          # UUID and PDH supplied by client, but they don't agree
-          raise ArgumentError.new "cannot mount collection #{uuid.inspect}: current portable_data_hash #{c.portable_data_hash.inspect} does not match #{c['portable_data_hash'].inspect} in request"
-        end
+        mount['portable_data_hash'] = c.portable_data_hash
       end
     end
     return c_mounts
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 0fafb9903..f98a64cd7 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -425,6 +425,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     lambda do |resolved|
       resolved["/out"] == {
         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
+        "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
         "kind" => "collection",
         "path" => "/foo",
       }
@@ -437,11 +438,23 @@ class ContainerRequestTest < ActiveSupport::TestCase
     lambda do |resolved|
       resolved["/out"] == {
         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
+        "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
         "kind" => "collection",
         "path" => "/foo",
       }
     end],
-  ].each do |mounts, okfunc|
+    [{"/out" => {
+      "kind" => "collection",
+      "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
+      "path" => "/foo"}},
+  lambda do |resolved|
+    resolved["/out"] == {
+      "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
+      "kind" => "collection",
+      "path" => "/foo",
+    }
+  end],
+].each do |mounts, okfunc|
     test "resolve mounts #{mounts.inspect} to values" do
       set_user_from_auth :active
       resolved = Container.resolve_mounts(mounts)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list