14323: Lookup collection mount by uuid when pdh is not given. Update tests.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 7 Nov 2018 17:48:31 +0000 (14:48 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Wed, 7 Nov 2018 17:48:31 +0000 (14:48 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/app/models/container.rb
services/api/test/unit/container_request_test.rb

index 6ef9d7cbd338661a687d6a529574d09f8f4f7bc5..38c4ba6c71424dc9438747d22ab71b099f47a20b 100644 (file)
@@ -224,26 +224,10 @@ class Container < ArvadosModel
         next
       end
 
-      pdh = mount['portable_data_hash']
-      uuid = mount['uuid']
+      uuid = mount.delete '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
+      if mount['portable_data_hash'].nil?
+        # PDH not supplied, try by UUID
         c = Collection.
           readable_by(current_user).
           where(uuid: uuid).
index f98a64cd7c7825bf56c6c61774bcb3b1a9415a5c..06c36e6c437219737bbf0f3d2f080b28e2fb556b 100644 (file)
@@ -425,7 +425,6 @@ class ContainerRequestTest < ActiveSupport::TestCase
     lambda do |resolved|
       resolved["/out"] == {
         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
-        "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
         "kind" => "collection",
         "path" => "/foo",
       }
@@ -438,22 +437,21 @@ class ContainerRequestTest < ActiveSupport::TestCase
     lambda do |resolved|
       resolved["/out"] == {
         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
-        "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
         "kind" => "collection",
         "path" => "/foo",
       }
     end],
-    [{"/out" => {
+   [{"/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],
+    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
@@ -487,9 +485,8 @@ class ContainerRequestTest < ActiveSupport::TestCase
         "path" => "/foo",
       },
     }
-    assert_raises(ArgumentError) do
-      Container.resolve_mounts(m)
-    end
+    resolved_mounts = Container.resolve_mounts(m)
+    assert_equal m['portable_data_hash'], resolved_mounts['portable_data_hash']
   end
 
   ['arvados/apitestfixture:latest',