[ARVADOS] created: eb98d5ff700b0352f0886cb60ecf1c16d4f5e0ab

git at public.curoverse.com git at public.curoverse.com
Tue Dec 29 17:02:22 EST 2015


        at  eb98d5ff700b0352f0886cb60ecf1c16d4f5e0ab (commit)


commit eb98d5ff700b0352f0886cb60ecf1c16d4f5e0ab
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue Dec 29 17:01:24 2015 -0500

    7816: Add exit_code field to Container model.  Can only be set when container
    is marked "Complete".

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 48f4916..787047d 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -25,6 +25,7 @@ class Container < ArvadosModel
     t.add :container_image
     t.add :cwd
     t.add :environment
+    t.add :exit_code
     t.add :finished_at
     t.add :log
     t.add :mounts
@@ -124,7 +125,7 @@ class Container < ArvadosModel
 
     when Complete
       if self.state_changed?
-        permitted.push :state, :finished_at, :output, :log
+        permitted.push :state, :finished_at, :output, :log, :exit_code
       else
         errors.add :state, "cannot update record"
       end
diff --git a/services/api/db/migrate/20151229214707_add_exit_code_to_containers.rb b/services/api/db/migrate/20151229214707_add_exit_code_to_containers.rb
new file mode 100644
index 0000000..b6e41f0
--- /dev/null
+++ b/services/api/db/migrate/20151229214707_add_exit_code_to_containers.rb
@@ -0,0 +1,5 @@
+class AddExitCodeToContainers < ActiveRecord::Migration
+  def change
+    add_column :containers, :exit_code, :integer
+  end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index 7600313..0492c87 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -337,7 +337,8 @@ CREATE TABLE containers (
     container_image character varying(255),
     progress double precision,
     priority integer,
-    updated_at timestamp without time zone NOT NULL
+    updated_at timestamp without time zone NOT NULL,
+    exit_code integer
 );
 
 
@@ -2565,4 +2566,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150526180251');
 
 INSERT INTO schema_migrations (version) VALUES ('20151202151426');
 
-INSERT INTO schema_migrations (version) VALUES ('20151215134304');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20151215134304');
+
+INSERT INTO schema_migrations (version) VALUES ('20151229214707');
\ No newline at end of file
diff --git a/services/api/test/unit/container_test.rb b/services/api/test/unit/container_test.rb
index d3216fc..9264544 100644
--- a/services/api/test/unit/container_test.rb
+++ b/services/api/test/unit/container_test.rb
@@ -197,4 +197,38 @@ class ContainerTest < ActiveSupport::TestCase
     end
   end
 
+  test "Container only set exit code on complete" do
+    act_as_system_user do
+      c = Container.new
+      c.command = ["echo", "foo"]
+      c.container_image = "img"
+      c.output_path = "/tmp"
+      c.save!
+
+      c.reload
+      c.state = "Running"
+      c.save!
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        c.reload
+        c.exit_code = 1
+        c.save!
+      end
+
+      assert_raises(ActiveRecord::RecordInvalid) do
+        c.reload
+        c.exit_code = 1
+        c.state = "Cancelled"
+        c.save!
+      end
+
+      c.reload
+      c.exit_code = 1
+      c.state = "Complete"
+      c.save!
+
+    end
+  end
+
+
 end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list