[ARVADOS] created: 97d6365ee6a5f5bde1c8571fe1d2f3777a67cc3f
Git user
git at public.curoverse.com
Fri Aug 26 13:09:36 EDT 2016
at 97d6365ee6a5f5bde1c8571fe1d2f3777a67cc3f (commit)
commit 97d6365ee6a5f5bde1c8571fe1d2f3777a67cc3f
Author: Lucas Di Pentima <lucas at curoverse.com>
Date: Fri Aug 26 14:07:08 2016 -0300
9854: Added ArvadosModel::UnresolvableContainerError exception to return a 422 http status. Modified container resolving methods to raise this new exception instead of RecordNotFound. Updated related tests.
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 2908e40..6b6a709 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -50,6 +50,12 @@ class ArvadosModel < ActiveRecord::Base
end
end
+ class UnresolvableContainerError < StandardError
+ def http_status
+ 422
+ end
+ end
+
def self.kind_class(kind)
kind.match(/^arvados\#(.+)$/)[1].classify.safe_constantize rescue nil
end
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index bf244bd..a56c341 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -136,7 +136,7 @@ class ContainerRequest < ArvadosModel
select(:portable_data_hash).
first
if !c
- raise ActiveRecord::RecordNotFound.new "cannot mount collection #{uuid.inspect}: not found"
+ raise ArvadosModel::UnresolvableContainerError.new "cannot mount collection #{uuid.inspect}: not found"
end
if mount['portable_data_hash'].nil?
# PDH not supplied by client
@@ -154,7 +154,7 @@ class ContainerRequest < ArvadosModel
def container_image_for_container
coll = Collection.for_latest_docker_image(container_image)
if !coll
- raise ActiveRecord::RecordNotFound.new "docker image #{container_image.inspect} not found"
+ raise ArvadosModel::UnresolvableContainerError.new "docker image #{container_image.inspect} not found"
end
return coll.portable_data_hash
end
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index b0c55c1..3ab4a89 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -336,7 +336,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
},
}
cr = ContainerRequest.new(mounts: m)
- assert_raises(ActiveRecord::RecordNotFound) do
+ assert_raises(ArvadosModel::UnresolvableContainerError) do
cr.send :mounts_for_container
end
end
@@ -381,10 +381,10 @@ class ContainerRequestTest < ActiveSupport::TestCase
'ENOEXIST',
'arvados/apitestfixture:ENOEXIST',
].each do |img|
- test "container_image_for_container(#{img.inspect}) => 404" do
+ test "container_image_for_container(#{img.inspect}) => 422" do
set_user_from_auth :active
cr = ContainerRequest.new(container_image: img)
- assert_raises(ActiveRecord::RecordNotFound) do
+ assert_raises(ArvadosModel::UnresolvableContainerError) do
cr.send :container_image_for_container
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list