18842: Fix tests
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 25 Oct 2022 20:12:44 +0000 (16:12 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 25 Oct 2022 20:12:44 +0000 (16:12 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

sdk/go/arvados/config.go
services/api/app/models/arvados_model.rb
services/api/app/models/container.rb
services/api/test/fixtures/containers.yml
services/api/test/unit/container_request_test.rb
services/api/test/unit/container_test.rb

index 3c1ef4826f91b4007f03c0cb96324f9ce51fbe3a..6360b7b31a47fb851e8cdf3cc47607ddb61497be 100644 (file)
@@ -446,6 +446,7 @@ type ContainersConfig struct {
        CrunchRunCommand              string
        CrunchRunArgumentsList        []string
        DefaultKeepCacheRAM           ByteSize
+       DefaultKeepCacheDisk          ByteSize
        DispatchPrivateKey            string
        LogReuseDecisions             bool
        MaxComputeVMs                 int
index 7143378d2ff3779e50be6c7d766c4655f6e45564..fe4f5bcec517fd42a02984ff8288dce075e770bb 100644 (file)
@@ -951,6 +951,10 @@ class ArvadosModel < ApplicationRecord
   # value in the database to an implicit zero/false value in an update
   # request.
   def fill_container_defaults
+    # Make sure this is correctly sorted by key, because we merge in
+    # whatever is in the database on top of it, this will be the order
+    # that gets used downstream rather than the order the keys appear
+    # in the database.
     self.runtime_constraints = {
       'API' => false,
       'cuda' => {
@@ -958,8 +962,8 @@ class ArvadosModel < ApplicationRecord
         'driver_version' => '',
         'hardware_capability' => '',
       },
-      'keep_cache_ram' => 0,
       'keep_cache_disk' => 0,
+      'keep_cache_ram' => 0,
       'ram' => 0,
       'vcpus' => 0,
     }.merge(attributes['runtime_constraints'] || {})
index 3334fdcac99802c0c370e51eb4621a48b87cbcb4..4b02ad52e56dc55925d9418e528434917897379e 100644 (file)
@@ -310,6 +310,15 @@ class Container < ArvadosModel
       # records that don't have a 'cuda' section in runtime_constraints
       resolved_runtime_constraints << resolved_runtime_constraints[0].except('cuda')
     end
+    if resolved_runtime_constraints[0]['keep_cache_disk'] == 0
+      # If no disk cache requested, extend search to include older container
+      # records that don't have a 'keep_cache_disk' field in runtime_constraints
+      if resolved_runtime_constraints.length == 2
+        # exclude the one that also excludes CUDA
+        resolved_runtime_constraints << resolved_runtime_constraints[1].except('keep_cache_disk')
+      end
+      resolved_runtime_constraints << resolved_runtime_constraints[0].except('keep_cache_disk')
+    end
 
     candidates = candidates.where_serialized(:runtime_constraints, resolved_runtime_constraints, md5: true, multivalue: true)
     log_reuse_info(candidates) { "after filtering on runtime_constraints #{attrs[:runtime_constraints].inspect}" }
index a61fb07177bba1045aca1f949bcdaa9632efb1ff..73b17280bb28db534c7802b90b3df5061bd5b14a 100644 (file)
@@ -170,6 +170,7 @@ diagnostics_completed_requester:
            ]
   runtime_constraints:
     API: true
+    keep_cache_disk: 0
     keep_cache_ram: 268435456
     ram: 1342177280
     vcpus: 1
@@ -195,6 +196,7 @@ diagnostics_completed_hasher1:
            ]
   runtime_constraints:
     API: true
+    keep_cache_disk: 0
     keep_cache_ram: 268435456
     ram: 268435456
     vcpus: 1
@@ -220,6 +222,7 @@ diagnostics_completed_hasher2:
            ]
   runtime_constraints:
     API: true
+    keep_cache_disk: 0
     keep_cache_ram: 268435456
     ram: 268435456
     vcpus: 2
@@ -245,6 +248,7 @@ diagnostics_completed_hasher3:
            ]
   runtime_constraints:
     API: true
+    keep_cache_disk: 0
     keep_cache_ram: 268435456
     ram: 268435456
     vcpus: 1
@@ -281,6 +285,7 @@ diagnostics_completed_requester2:
            ]
   runtime_constraints:
     API: true
+    keep_cache_disk: 0
     keep_cache_ram: 268435456
     ram: 1342177280
     vcpus: 1
index e6db412179b663e39696e9c884af584af287ddbf..efc61eee8c80fcfa509478ebc0ec51e947e3cccb 100644 (file)
@@ -177,6 +177,9 @@ class ContainerRequestTest < ActiveSupport::TestCase
 
     assert ({"vcpus" => 2, "ram" => 30}.to_a - cr.runtime_constraints.to_a).empty?
 
+    assert_equal 0, Rails.configuration.Containers.DefaultKeepCacheRAM
+    assert_equal 8589934592, Rails.configuration.Containers.DefaultKeepCacheDisk
+
     assert_not_nil cr.container_uuid
     c = Container.find_by_uuid cr.container_uuid
     assert_not_nil c
@@ -186,7 +189,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_equal({}, c.environment)
     assert_equal({"/out" => {"kind"=>"tmp", "capacity"=>1000000}}, c.mounts)
     assert_equal "/out", c.output_path
-    assert ({"keep_cache_ram"=>268435456, "vcpus" => 2, "ram" => 30}.to_a - c.runtime_constraints.to_a).empty?
+    assert ({"keep_cache_disk"=>8589934592, "keep_cache_ram"=>0, "vcpus" => 2, "ram" => 30}.to_a - c.runtime_constraints.to_a).empty?
     assert_operator 0, :<, c.priority
 
     assert_raises(ActiveRecord::RecordInvalid) do
index a4c0ce17926092ec451583404a21f56374f79176..f804aca2d982fd8d000fcf10d19eec0d47173965 100644 (file)
@@ -24,6 +24,7 @@ class ContainerTest < ActiveSupport::TestCase
     output_path: "test",
     runtime_constraints: {
       "API" => false,
+      "keep_cache_disk" => 0,
       "keep_cache_ram" => 0,
       "ram" => 12000000000,
       "vcpus" => 4
@@ -229,7 +230,7 @@ class ContainerTest < ActiveSupport::TestCase
     set_user_from_auth :active
     env = {"C" => "3", "B" => "2", "A" => "1"}
     m = {"F" => {"kind" => "3"}, "E" => {"kind" => "2"}, "D" => {"kind" => "1"}}
-    rc = {"vcpus" => 1, "ram" => 1, "keep_cache_ram" => 1, "API" => true, "cuda" => {"device_count":0, "driver_version": "", "hardware_capability": ""}}
+    rc = {"vcpus" => 1, "ram" => 1, "keep_cache_ram" => 1, "keep_cache_disk" => 0, "API" => true, "cuda" => {"device_count":0, "driver_version": "", "hardware_capability": ""}}
     c, _ = minimal_new(environment: env, mounts: m, runtime_constraints: rc)
     c.reload
     assert_equal Container.deep_sort_hash(env).to_json, c.environment.to_json
@@ -594,14 +595,14 @@ class ContainerTest < ActiveSupport::TestCase
     set_user_from_auth :active
     # No cuda
     no_cuda_attrs = REUSABLE_COMMON_ATTRS.merge({use_existing:false, priority:1, environment:{"var" => "queued"},
-                                                runtime_constraints: {"vcpus" => 1, "ram" => 1, "keep_cache_ram"=>268435456, "API" => false,
+                                                runtime_constraints: {"vcpus" => 1, "ram" => 1, "keep_cache_disk"=>0, "keep_cache_ram"=>268435456, "API" => false,
                                                                       "cuda" => {"device_count":0, "driver_version": "", "hardware_capability": ""}},})
     c1, _ = minimal_new(no_cuda_attrs)
     assert_equal Container::Queued, c1.state
 
     # has cuda
     cuda_attrs = REUSABLE_COMMON_ATTRS.merge({use_existing:false, priority:1, environment:{"var" => "queued"},
-                                                runtime_constraints: {"vcpus" => 1, "ram" => 1, "keep_cache_ram"=>268435456, "API" => false,
+                                                runtime_constraints: {"vcpus" => 1, "ram" => 1, "keep_cache_disk"=>0, "keep_cache_ram"=>268435456, "API" => false,
                                                                       "cuda" => {"device_count":1, "driver_version": "11.0", "hardware_capability": "9.0"}},})
     c2, _ = minimal_new(cuda_attrs)
     assert_equal Container::Queued, c2.state