[ARVADOS] created: b1578a5e964e1a04d8c96c541017c44498e966cb
Git user
git at public.curoverse.com
Wed Oct 19 14:08:47 EDT 2016
at b1578a5e964e1a04d8c96c541017c44498e966cb (commit)
commit b1578a5e964e1a04d8c96c541017c44498e966cb
Author: Lucas Di Pentima <lucas at curoverse.com>
Date: Wed Oct 19 15:06:44 2016 -0300
10216: Added use_existing field to Container Request. When false and CR is committed, a new container will always be created.
Added test case for this new behaviour.
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 696b873..1798150 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -41,6 +41,7 @@ class ContainerRequest < ArvadosModel
t.add :requesting_container_uuid
t.add :runtime_constraints
t.add :state
+ t.add :use_existing
end
# Supported states for a container request
@@ -120,7 +121,8 @@ class ContainerRequest < ArvadosModel
container_image: c_container_image,
mounts: c_mounts,
runtime_constraints: c_runtime_constraints}
- reusable = Container.find_reusable(c_attrs)
+
+ reusable = self.use_existing ? Container.find_reusable(c_attrs) : nil
if not reusable.nil?
reusable
else
@@ -234,7 +236,7 @@ class ContainerRequest < ArvadosModel
:container_image, :cwd, :description, :environment,
:filters, :mounts, :name, :output_path, :priority,
:properties, :requesting_container_uuid, :runtime_constraints,
- :state, :container_uuid
+ :state, :container_uuid, :use_existing
when Committed
if container_uuid.nil?
diff --git a/services/api/db/migrate/20161019171346_add_use_existing_to_container_requests.rb b/services/api/db/migrate/20161019171346_add_use_existing_to_container_requests.rb
new file mode 100644
index 0000000..100b83d
--- /dev/null
+++ b/services/api/db/migrate/20161019171346_add_use_existing_to_container_requests.rb
@@ -0,0 +1,9 @@
+class AddUseExistingToContainerRequests < ActiveRecord::Migration
+ def up
+ add_column :container_requests, :use_existing, :boolean, :default => true
+ end
+
+ def down
+ remove_column :container_requests, :use_existing
+ end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index fa4760d..0db782a 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -290,7 +290,8 @@ CREATE TABLE container_requests (
expires_at timestamp without time zone,
filters text,
updated_at timestamp without time zone NOT NULL,
- container_count integer DEFAULT 0
+ container_count integer DEFAULT 0,
+ use_existing boolean DEFAULT true
);
@@ -2691,4 +2692,6 @@ INSERT INTO schema_migrations (version) VALUES ('20160901210110');
INSERT INTO schema_migrations (version) VALUES ('20160909181442');
-INSERT INTO schema_migrations (version) VALUES ('20160926194129');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20160926194129');
+
+INSERT INTO schema_migrations (version) VALUES ('20161019171346');
\ No newline at end of file
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 1c5c7ae..46029ed 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -437,6 +437,26 @@ class ContainerRequestTest < ActiveSupport::TestCase
end
end
+ test "Container request doesn't reuse container when explicitly asked" do
+ common_attrs = {cwd: "test",
+ priority: 1,
+ command: ["echo", "hello"],
+ output_path: "test",
+ runtime_constraints: {"vcpus" => 4,
+ "ram" => 12000000000},
+ mounts: {"test" => {"kind" => "json"}}}
+ set_user_from_auth :active
+ cr1 = create_minimal_req!(common_attrs.merge({state: ContainerRequest::Committed}))
+ cr2 = create_minimal_req!(common_attrs.merge({state: ContainerRequest::Uncommitted,
+ use_existing: false}))
+ assert_not_nil cr1.container_uuid
+ assert_nil cr2.container_uuid
+
+ # Update cr2 to commited state and check for container equality.
+ cr2.update_attributes!({state: ContainerRequest::Committed})
+ assert_not_equal cr1.container_uuid, cr2.container_uuid
+ end
+
test "requesting_container_uuid at create is not allowed" do
set_user_from_auth :active
assert_raises(ActiveRecord::RecordNotSaved) do
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list