[ARVADOS] updated: 2.1.0-225-g6e8af9119
Git user
git at public.arvados.org
Wed Dec 30 18:43:59 UTC 2020
Summary of changes:
services/api/app/models/container.rb | 9 ++++++-
services/api/app/models/container_request.rb | 33 +++++++++++++-----------
services/api/test/unit/container_request_test.rb | 10 +++----
3 files changed, 31 insertions(+), 21 deletions(-)
via 6e8af911900eaf3e402c45405353cb740c580cf2 (commit)
from 45acfa403ff0bc635443062e3f1577ba2256876a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 6e8af911900eaf3e402c45405353cb740c580cf2
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date: Wed Dec 30 15:43:38 2020 -0300
17014: Fixes almost all railsapi's unit tests.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>
diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 5833c2251..04ee3ab53 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -206,12 +206,19 @@ class Container < ArvadosModel
# is not implemented yet, or we have already found that no existing
# containers are suitable).
def self.resolve_runtime_constraints(runtime_constraints)
+ # Remove zero-values before merging to avoid stepping over other defaults.
+ cleaned_rc = {}
+ runtime_constraints.each do |k, v|
+ if ContainerRequest.runtime_constraints_defaults[k] != v
+ cleaned_rc[k] = v
+ end
+ end
rc = {}
defaults = {
'keep_cache_ram' =>
Rails.configuration.Containers.DefaultKeepCacheRAM,
}
- defaults.merge(runtime_constraints).each do |k, v|
+ defaults.merge(cleaned_rc).each do |k, v|
if v.is_a? Array
rc[k] = v[0]
else
diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb
index 02a54d8a2..350621544 100644
--- a/services/api/app/models/container_request.rb
+++ b/services/api/app/models/container_request.rb
@@ -106,8 +106,8 @@ class ContainerRequest < ArvadosModel
AttrsSchedulingParametersDefaults = {
"max_run_time"=>0,
- "partitions"=>nil,
- "preemptible"=>false
+ "partitions"=>[],
+ "preemptible"=>nil
}
def self.limit_index_columns_read
@@ -122,6 +122,14 @@ class ContainerRequest < ArvadosModel
State_transitions
end
+ def self.runtime_constraints_defaults
+ AttrsRuntimeConstraintsDefaults
+ end
+
+ def self.scheduling_parameters_defaults
+ AttrsSchedulingParametersDefaults
+ end
+
def skip_uuid_read_permission_check
# The uuid_read_permission_check prevents users from making
# references to objects they can't view. However, in this case we
@@ -342,7 +350,7 @@ class ContainerRequest < ArvadosModel
[['vcpus', true],
['ram', true],
['keep_cache_ram', false]].each do |k, required|
- if !required && !runtime_constraints.include?(k)
+ if !required && (!runtime_constraints.include?(k) || runtime_constraints[k] == 0)
next
end
v = runtime_constraints[k]
@@ -460,22 +468,17 @@ class ContainerRequest < ArvadosModel
# this will fill out default values that are not in the database,
# see https://dev.arvados.org/issues/17014#note-28 for details
- if self.runtime_constraints?
- AttrsRuntimeConstraintsDefaults.each do |key, value|
- if !self.runtime_constraints.key?(key)
- attributes["runtime_constraints"][key] = value
- self.clear_attribute_changes(["runtime_constraints"])
- end
+ AttrsRuntimeConstraintsDefaults.each do |key, value|
+ if !attributes["runtime_constraints"].key?(key)
+ attributes["runtime_constraints"][key] = value
end
end
- if self.scheduling_parameters?
- AttrsSchedulingParametersDefaults.each do |key, value|
- if !self.scheduling_parameters.key?(key)
- attributes["scheduling_parameters"][key] = value
- end
- self.clear_attribute_changes(["scheduling_parameters"])
+ AttrsSchedulingParametersDefaults.each do |key, value|
+ if !attributes["scheduling_parameters"].key?(key)
+ attributes["scheduling_parameters"][key] = value
end
end
+ self.clear_attribute_changes(["runtime_constraints", "scheduling_parameters"])
super
end
diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb
index 90de800b2..f841de6c3 100644
--- a/services/api/test/unit/container_request_test.rb
+++ b/services/api/test/unit/container_request_test.rb
@@ -153,7 +153,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
cr.reload
- assert_equal({"vcpus" => 2, "ram" => 30}, cr.runtime_constraints)
+ assert ({"vcpus" => 2, "ram" => 30}.to_a - cr.runtime_constraints.to_a).empty?
assert_not_nil cr.container_uuid
c = Container.find_by_uuid cr.container_uuid
@@ -164,7 +164,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_equal({"keep_cache_ram"=>268435456, "vcpus" => 2, "ram" => 30}, c.runtime_constraints)
+ assert ({"keep_cache_ram"=>268435456, "vcpus" => 2, "ram" => 30}.to_a - c.runtime_constraints.to_a).empty?
assert_operator 0, :<, c.priority
assert_raises(ActiveRecord::RecordInvalid) do
@@ -973,7 +973,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
end
else
cr.save!
- assert_equal sp, cr.scheduling_parameters
+ assert (sp.to_a - cr.scheduling_parameters.to_a).empty?
end
end
end
@@ -1068,11 +1068,11 @@ class ContainerRequestTest < ActiveSupport::TestCase
end
else
cr = create_minimal_req!(common_attrs.merge({state: state}))
- assert_equal sp, cr.scheduling_parameters
+ assert (sp.to_a - cr.scheduling_parameters.to_a).empty?
if state == ContainerRequest::Committed
c = Container.find_by_uuid(cr.container_uuid)
- assert_equal sp, c.scheduling_parameters
+ assert (sp.to_a - c.scheduling_parameters.to_a).empty?
end
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list