From d801f8930c20f82fbde6cd93686572ed190e7d12 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 9 Aug 2021 11:29:10 -0400 Subject: [PATCH] 17967: Test new behavior for default storage_classes_desired. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/api/app/models/collection.rb | 2 +- services/api/app/models/container.rb | 2 +- services/api/app/models/container_request.rb | 2 +- services/api/test/unit/collection_test.rb | 13 +++++++++++ .../api/test/unit/container_request_test.rb | 22 ++++++++++++------- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index 5edca82a04..d1d5ace0c3 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -17,7 +17,7 @@ class Collection < ArvadosModel # Posgresql JSONB columns should NOT be declared as serialized, Rails 5 # already know how to properly treat them. attribute :properties, :jsonbHash, default: {} - attribute :storage_classes_desired, :jsonbArray, default: Rails.configuration.DefaultStorageClasses + attribute :storage_classes_desired, :jsonbArray, default: lambda { Rails.configuration.DefaultStorageClasses } attribute :storage_classes_confirmed, :jsonbArray, default: [] before_validation :default_empty_manifest diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb index a880b65ac5..d6a44c8023 100644 --- a/services/api/app/models/container.rb +++ b/services/api/app/models/container.rb @@ -22,7 +22,7 @@ class Container < ArvadosModel attribute :secret_mounts, :jsonbHash, default: {} attribute :runtime_status, :jsonbHash, default: {} attribute :runtime_auth_scopes, :jsonbArray, default: [] - attribute :output_storage_classes, :jsonbArray, default: Rails.configuration.DefaultStorageClasses + attribute :output_storage_classes, :jsonbArray, default: lambda { Rails.configuration.DefaultStorageClasses } serialize :environment, Hash serialize :mounts, Hash diff --git a/services/api/app/models/container_request.rb b/services/api/app/models/container_request.rb index f603d4dd79..4a580816cd 100644 --- a/services/api/app/models/container_request.rb +++ b/services/api/app/models/container_request.rb @@ -23,7 +23,7 @@ class ContainerRequest < ArvadosModel # already know how to properly treat them. attribute :properties, :jsonbHash, default: {} attribute :secret_mounts, :jsonbHash, default: {} - attribute :output_storage_classes, :jsonbArray, default: Rails.configuration.DefaultStorageClasses + attribute :output_storage_classes, :jsonbArray, default: lambda { Rails.configuration.DefaultStorageClasses } serialize :environment, Hash serialize :mounts, Hash diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index 916ca09587..e6912217d5 100644 --- a/services/api/test/unit/collection_test.rb +++ b/services/api/test/unit/collection_test.rb @@ -693,6 +693,19 @@ class CollectionTest < ActiveSupport::TestCase end end + test "storage_classes_desired default respects config" do + saved = Rails.configuration.DefaultStorageClasses + Rails.configuration.DefaultStorageClasses = ["foo"] + begin + act_as_user users(:active) do + c = Collection.create! + assert_equal ["foo"], c.storage_classes_desired + end + ensure + Rails.configuration.DefaultStorageClasses = saved + end + end + test "storage_classes_desired cannot be empty" do act_as_user users(:active) do c = collections(:collection_owned_by_active) diff --git a/services/api/test/unit/container_request_test.rb b/services/api/test/unit/container_request_test.rb index 7686e1a140..9f412c7bb0 100644 --- a/services/api/test/unit/container_request_test.rb +++ b/services/api/test/unit/container_request_test.rb @@ -1292,14 +1292,20 @@ class ContainerRequestTest < ActiveSupport::TestCase end test "default output_storage_classes" do - act_as_user users(:active) do - cr = create_minimal_req!(priority: 1, - state: ContainerRequest::Committed, - output_name: 'foo') - run_container(cr) - cr.reload - output = Collection.find_by_uuid(cr.output_uuid) - assert_equal ["default"], output.storage_classes_desired + saved = Rails.configuration.DefaultStorageClasses + Rails.configuration.DefaultStorageClasses = ["foo"] + begin + act_as_user users(:active) do + cr = create_minimal_req!(priority: 1, + state: ContainerRequest::Committed, + output_name: 'foo') + run_container(cr) + cr.reload + output = Collection.find_by_uuid(cr.output_uuid) + assert_equal ["foo"], output.storage_classes_desired + end + ensure + Rails.configuration.DefaultStorageClasses = saved end end -- 2.30.2