Merge branch 'master' into 16007-permission-table-rb
[arvados.git] / services / api / test / functional / arvados / v1 / jobs_controller_test.rb
index a9a49a0d5fa700a7ec7d2eeaf589391c1f9fec80..9298f23d5436c0f7d9420cda89884b4e0401b6fa 100644 (file)
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 require 'helpers/git_test_helper'
 
 class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
-  include GitTestHelper
-
-  test "submit a job" do
-    authorize_with :active
-    post :create, job: {
-      script: "hash",
-      script_version: "master",
-      repository: "foo",
-      script_parameters: {}
-    }
-    assert_response :success
-    assert_not_nil assigns(:object)
-    new_job = JSON.parse(@response.body)
-    assert_not_nil new_job['uuid']
-    assert_not_nil new_job['script_version'].match(/^[0-9a-f]{40}$/)
-    assert_equal 0, new_job['priority']
-  end
-
-  test "normalize output and log uuids when creating job" do
-    authorize_with :active
-    post :create, job: {
-      script: "hash",
-      script_version: "master",
-      script_parameters: {},
-      repository: "foo",
-      started_at: Time.now,
-      finished_at: Time.now,
-      running: false,
-      success: true,
-      output: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy',
-      log: 'd41d8cd98f00b204e9800998ecf8427e+0+K@xyzzy'
-    }
-    assert_response :success
-    assert_not_nil assigns(:object)
-    new_job = JSON.parse(@response.body)
-    assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['log']
-    assert_equal 'd41d8cd98f00b204e9800998ecf8427e+0', new_job['output']
-    version = new_job['script_version']
-
-    # Make sure version doesn't get mangled by normalize
-    assert_not_nil version.match(/^[0-9a-f]{40}$/)
-    put :update, {
-      id: new_job['uuid'],
-      job: {
-        log: new_job['log']
-      }
-    }
-    assert_equal version, JSON.parse(@response.body)['script_version']
-  end
-
-  test "cancel a running job" do
-    # We need to verify that "cancel" creates a trigger file, so first
-    # let's make sure there is no stale trigger file.
-    begin
-      File.unlink(Rails.configuration.crunch_refresh_trigger)
-    rescue Errno::ENOENT
-    end
-
-    authorize_with :active
-    put :update, {
-      id: jobs(:running).uuid,
-      job: {
-        cancelled_at: 4.day.ago
-      }
-    }
-    assert_response :success
-    assert_not_nil assigns(:object)
-    job = JSON.parse(@response.body)
-    assert_not_nil job['uuid']
-    assert_not_nil job['cancelled_at']
-    assert_not_nil job['cancelled_by_user_uuid']
-    assert_not_nil job['cancelled_by_client_uuid']
-    assert_equal(true, Time.parse(job['cancelled_at']) > 1.minute.ago,
-                 'server should correct bogus cancelled_at ' +
-                 job['cancelled_at'])
-    assert_equal(true,
-                 File.exists?(Rails.configuration.crunch_refresh_trigger),
-                 'trigger file should be created when job is cancelled')
-
-    put :update, {
-      id: jobs(:running).uuid,
-      job: {
-        cancelled_at: nil
-      }
-    }
-    job = JSON.parse(@response.body)
-    assert_not_nil job['cancelled_at'], 'un-cancelled job stays cancelled'
-  end
-
-  test "update a job without failing script_version check" do
-    authorize_with :admin
-    put :update, {
-      id: jobs(:uses_nonexistent_script_version).uuid,
-      job: {
-        owner_uuid: users(:admin).uuid
-      }
-    }
-    assert_response :success
-    put :update, {
-      id: jobs(:uses_nonexistent_script_version).uuid,
-      job: {
-        owner_uuid: users(:active).uuid
-      }
-    }
-    assert_response :success
-  end
-
   test "search jobs by uuid with >= query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
     }
     assert_response :success
@@ -123,7 +20,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by uuid with <= query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
     }
     assert_response :success
@@ -134,7 +31,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by uuid with >= and <= query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', '>=', 'zzzzz-8i9sb-pshmckwoma9plh7'],
               ['uuid', '<=', 'zzzzz-8i9sb-pshmckwoma9plh7']]
     }
@@ -145,7 +42,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by uuid with < query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', '<', 'zzzzz-8i9sb-pshmckwoma9plh7']]
     }
     assert_response :success
@@ -156,7 +53,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by uuid with like query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', 'like', '%hmckwoma9pl%']]
     }
     assert_response :success
@@ -166,7 +63,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by uuid with 'in' query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', 'in', ['zzzzz-8i9sb-4cf0nhn6xte809j',
                                 'zzzzz-8i9sb-pshmckwoma9plh7']]]
     }
@@ -180,7 +77,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
     exclude_uuids = [jobs(:running).uuid,
                      jobs(:running_cancelled).uuid]
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['uuid', 'not in', exclude_uuids]]
     }
     assert_response :success
@@ -195,7 +92,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
      ['output', nil]].each do |attr, operand|
       test "search jobs with #{attr} #{operator} #{operand.inspect} query" do
         authorize_with :active
-        get :index, {
+        get :index, params: {
           filters: [[attr, operator, operand]]
         }
         assert_response :success
@@ -212,7 +109,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by started_at with < query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['started_at', '<', Time.now.to_s]]
     }
     assert_response :success
@@ -222,7 +119,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by started_at with > query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['started_at', '>', Time.now.to_s]]
     }
     assert_response :success
@@ -231,7 +128,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by started_at with >= query on metric date" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['started_at', '>=', '2014-01-01']]
     }
     assert_response :success
@@ -241,7 +138,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by started_at with >= query on metric date and time" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['started_at', '>=', '2014-01-01 01:23:45']]
     }
     assert_response :success
@@ -251,7 +148,7 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs with 'any' operator" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       where: { any: ['contains', 'pshmckw'] }
     }
     assert_response :success
@@ -262,65 +159,33 @@ class Arvados::V1::JobsControllerTest < ActionController::TestCase
 
   test "search jobs by nonexistent column with < query" do
     authorize_with :active
-    get :index, {
+    get :index, params: {
       filters: [['is_borked', '<', 'fizzbuzz']]
     }
     assert_response 422
   end
 
-  test "finish a job" do
-    authorize_with :active
-    put :update, {
-      id: jobs(:nearly_finished_job).uuid,
-      job: {
-        output: '551392cc37a317abf865b95f66f4ef94+101',
-        log: '9215de2a951a721f5f156bc08cf63ad7+93',
-        tasks_summary: {done: 1, running: 0, todo: 0, failed: 0},
-        success: true,
-        running: false,
-        finished_at: Time.now.to_s
-      }
-    }
-    assert_response :success
-  end
-
   [:spectator, :admin].each_with_index do |which_token, i|
     test "get job queue as #{which_token} user" do
       authorize_with which_token
       get :queue
       assert_response :success
-      assert_equal i, assigns(:objects).count
+      assert_equal 0, assigns(:objects).count
     end
   end
 
-  test "get job queue as with a = filter" do
-    authorize_with :admin
-    get :queue, { filters: [['script','=','foo']] }
-    assert_response :success
-    assert_equal ['foo'], assigns(:objects).collect(&:script).uniq
-    assert_equal 0, assigns(:objects)[0].queue_position
-  end
-
-  test "get job queue as with a != filter" do
-    authorize_with :admin
-    get :queue, { filters: [['script','!=','foo']] }
+  test "job includes assigned nodes" do
+    authorize_with :active
+    get :show, params: {id: jobs(:nearly_finished_job).uuid}
     assert_response :success
-    assert_equal 0, assigns(:objects).count
-  end
-
-  [:spectator, :admin].each do |which_token|
-    test "get queue_size as #{which_token} user" do
-      authorize_with which_token
-      get :queue_size
-      assert_response :success
-      assert_equal 1, JSON.parse(@response.body)["queue_size"]
-    end
+    assert_equal([nodes(:busy).uuid], json_response["node_uuids"])
   end
 
-  test "job includes assigned nodes" do
+  test 'get job with components' do
     authorize_with :active
-    get :show, {id: jobs(:nearly_finished_job).uuid}
+    get :show, params: {id: jobs(:running_job_with_components).uuid}
     assert_response :success
-    assert_equal([nodes(:busy).uuid], json_response["node_uuids"])
+    assert_not_nil json_response["components"]
+    assert_equal ["component1", "component2"], json_response["components"].keys
   end
 end