after_save :update_priority
after_save :finalize_if_needed
before_create :set_requesting_container_uuid
+ before_destroy :set_priority_zero
api_accessible :user, extend: :common do |t|
t.add :command
end
end
+ def set_priority_zero
+ self.update_attributes!(priority: 0) if self.state != Final
+ end
+
def set_requesting_container_uuid
return !new_record? if self.requesting_container_uuid # already set
vcpus: 1
ram: 123
+running_to_be_deleted:
+ uuid: zzzzz-xvhdp-cr5runningcntnr
+ owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+ name: running to be deleted
+ state: Committed
+ priority: 1
+ created_at: <%= 2.days.ago.to_s(:db) %>
+ updated_at: <%= 1.days.ago.to_s(:db) %>
+ modified_at: <%= 1.days.ago.to_s(:db) %>
+ modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+ container_image: test
+ cwd: test
+ output_path: test
+ command: ["echo", "hello"]
+ container_uuid: zzzzz-dz642-runnincntrtodel
+ runtime_constraints:
+ vcpus: 1
+ ram: 123
+
completed_with_input_mounts:
uuid: zzzzz-xvhdp-crwithinputmnts
owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
runtime_constraints:
ram: 12000000000
vcpus: 4
+
+running_to_be_deleted:
+ uuid: zzzzz-dz642-runnincntrtodel
+ owner_uuid: zzzzz-tpzed-000000000000000
+ state: Running
+ priority: 1
+ created_at: <%= 1.minute.ago.to_s(:db) %>
+ updated_at: <%= 1.minute.ago.to_s(:db) %>
+ started_at: <%= 1.minute.ago.to_s(:db) %>
+ container_image: test
+ cwd: test
+ output_path: test
+ command: ["echo", "hello"]
+ runtime_constraints:
+ ram: 12000000000
+ vcpus: 4
+ auth_uuid: zzzzz-gj3su-077z32aux8dg2s2
end
end
end
+
+ test "delete container_request and check its container's priority" do
+ act_as_user users(:active) do
+ cr = ContainerRequest.find_by_uuid container_requests(:running_to_be_deleted).uuid
+
+ # initially the cr's container has priority > 0
+ c = Container.find_by_uuid(cr.container_uuid)
+ assert_equal 1, c.priority
+
+ # destroy the cr
+ assert_nothing_raised {cr.destroy}
+
+ # the cr's container now has priority of 0
+ c = Container.find_by_uuid(cr.container_uuid)
+ assert_equal 0, c.priority
+ end
+ end
+
+ test "delete container_request in final state and expect no error due to before_destroy callback" do
+ act_as_user users(:active) do
+ cr = ContainerRequest.find_by_uuid container_requests(:completed).uuid
+ assert_nothing_raised {cr.destroy}
+ end
+ end
end