20319: Merge branch 'main' into 20319-container-request-logs
[arvados.git] / services / api / test / functional / arvados / v1 / container_requests_controller_test.rb
index 95c477f4118adc269684dd3cbdbab3d81b51600a..f287a11fafe6d0bc95917647624de813bbf4e3d4 100644 (file)
@@ -8,8 +8,9 @@ class Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
   def minimal_cr
     {
       command: ['echo', 'hello'],
-      container_image: 'test',
+      container_image: 'arvados/apitestfixture:latest',
       output_path: 'test',
+      runtime_constraints: {vcpus: 1, ram: 1}
     }
   end
 
@@ -18,13 +19,28 @@ class Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
 
     sp = {'partitions' => ['test1', 'test2']}
     post :create, params: {
-           container_request: minimal_cr.merge(scheduling_parameters: sp.dup)
+           container_request: minimal_cr.merge(scheduling_parameters: sp.dup, state: "Committed")
          }
     assert_response :success
 
     cr = JSON.parse(@response.body)
     assert_not_nil cr, 'Expected container request'
-    assert_equal sp, cr['scheduling_parameters']
+    assert_equal sp['partitions'], cr['scheduling_parameters']['partitions']
+    assert_equal false, cr['scheduling_parameters']['preemptible']
+    assert_equal false, cr['scheduling_parameters']['supervisor']
+  end
+
+  test 'create a-c-r should be supervisor' do
+    authorize_with :active
+
+    post :create, params: {
+           container_request: minimal_cr.merge(command: ["arvados-cwl-runner", "my-workflow.cwl"], state: "Committed")
+         }
+    assert_response :success
+
+    cr = JSON.parse(@response.body)
+    assert_not_nil cr, 'Expected container request'
+    assert_equal true, cr['scheduling_parameters']['supervisor']
   end
 
   test "secret_mounts not in #create responses" do
@@ -62,6 +78,28 @@ class Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
     assert_equal 'bar', req.secret_mounts['/foo']['content']
   end
 
+  test "cancel with runtime_constraints and scheduling_params with default values" do
+    authorize_with :active
+    req = container_requests(:queued)
+
+    patch :update, params: {
+      id: req.uuid,
+      container_request: {
+        state: 'Final',
+        priority: 0,
+        runtime_constraints: {
+          'vcpus' => 1,
+          'ram' => 123,
+          'keep_cache_ram' => 0,
+        },
+        scheduling_parameters: {
+          "preemptible"=>false
+        }
+      },
+    }
+    assert_response :success
+  end
+
   test "update without deleting secret_mounts" do
     authorize_with :active
     req = container_requests(:uncommitted)