From 91b2e0f2b73505945f37df0fcbc595e5dc4eb53a Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 18 Jul 2017 16:35:14 -0700 Subject: [PATCH 1/7] Add a spec for virtual_column `v_supports_block_storage` --- spec/models/ext_management_system_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index 878f50900c0..3de4b93b81f 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -408,4 +408,11 @@ expect(ExtManagementSystem.count).to eq(1) end end + + context "#v_supports_block_storage" do + it "returns true for Amazon EBS" do + ems_amz_ebs = FactoryGirl.create(:ems_amazon_storage_manager_ebs) + expect(ems_amz_ebs.v_supports_block_storage).to eq(true) + end + end end From b2d0c011c503a476b00f775e4ac87c01fbb2f050 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 18 Jul 2017 17:05:50 -0700 Subject: [PATCH 2/7] Added a virtual column for `v_supports_block_storage` https://bugzilla.redhat.com/show_bug.cgi?id=1471162 --- app/models/ext_management_system.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index a2365752a00..9573a9ced5e 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -143,6 +143,7 @@ def hostname_uniqueness_valid? virtual_column :total_vms_never, :type => :integer virtual_column :total_vms_suspended, :type => :integer virtual_total :total_subnets, :cloud_subnets + virtual_column :v_supports_block_storage, :type => :boolean virtual_aggregate :total_vcpus, :hosts, :sum, :total_vcpus virtual_aggregate :total_memory, :hosts, :sum, :ram_size @@ -542,6 +543,8 @@ def total_vms_never; vm_count_by_state("never"); end def total_vms_suspended; vm_count_by_state("suspended"); end + def v_supports_block_storage; supports_block_storage?; end + def get_reserve(field) (hosts + ems_clusters).inject(0) { |v, obj| v + (obj.send(field) || 0) } end From f295650652e974a60124785f6dc187152ac0168a Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 18 Jul 2017 18:26:46 -0700 Subject: [PATCH 3/7] Address rubocop - Avoid single-line method definitions. --- app/models/ext_management_system.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 9573a9ced5e..eab6de72613 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -543,7 +543,9 @@ def total_vms_never; vm_count_by_state("never"); end def total_vms_suspended; vm_count_by_state("suspended"); end - def v_supports_block_storage; supports_block_storage?; end + def v_supports_block_storage + supports_block_storage? + end def get_reserve(field) (hosts + ems_clusters).inject(0) { |v, obj| v + (obj.send(field) || 0) } From 39799d32dc67cbe24dedad0de176f116926da2db Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 19 Jul 2017 10:16:03 -0700 Subject: [PATCH 4/7] PR feedback - dropping v_ prefix for the newly added virtual col --- app/models/ext_management_system.rb | 4 ++-- spec/models/ext_management_system_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index eab6de72613..28a7acabb41 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -143,7 +143,7 @@ def hostname_uniqueness_valid? virtual_column :total_vms_never, :type => :integer virtual_column :total_vms_suspended, :type => :integer virtual_total :total_subnets, :cloud_subnets - virtual_column :v_supports_block_storage, :type => :boolean + virtual_column :supports_block_storage, :type => :boolean virtual_aggregate :total_vcpus, :hosts, :sum, :total_vcpus virtual_aggregate :total_memory, :hosts, :sum, :ram_size @@ -543,7 +543,7 @@ def total_vms_never; vm_count_by_state("never"); end def total_vms_suspended; vm_count_by_state("suspended"); end - def v_supports_block_storage + def supports_block_storage supports_block_storage? end diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index 3de4b93b81f..7feed3023c7 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -409,10 +409,10 @@ end end - context "#v_supports_block_storage" do + context "virtual column :supports_block_storage" do it "returns true for Amazon EBS" do ems_amz_ebs = FactoryGirl.create(:ems_amazon_storage_manager_ebs) - expect(ems_amz_ebs.v_supports_block_storage).to eq(true) + expect(ems_amz_ebs.supports_block_storage).to eq(true) end end end From 2806c503419fe70190874f9af3b5098ec0b80536 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 19 Jul 2017 10:58:50 -0700 Subject: [PATCH 5/7] spec for virtual col `supports_cloud_object_store_container_create` --- spec/models/ext_management_system_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index 7feed3023c7..ac9fc8a9508 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -415,4 +415,11 @@ expect(ems_amz_ebs.supports_block_storage).to eq(true) end end + + context "virtual column :supports_cloud_object_store_container_create" do + it "returns true for Amazon S3" do + ems_amz_s3 = FactoryGirl.create(:ems_amazon_storage_manager_s3) + expect(ems_amz_s3.supports_cloud_object_store_container_create).to eq(true) + end + end end From 5636ee35e00ec541c6b9402c55eb765fa69ccf05 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 19 Jul 2017 11:00:58 -0700 Subject: [PATCH 6/7] Add a virtual col for supports_cloud_object_store_container_create --- app/models/ext_management_system.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 28a7acabb41..5c1c0af47db 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -144,6 +144,7 @@ def hostname_uniqueness_valid? virtual_column :total_vms_suspended, :type => :integer virtual_total :total_subnets, :cloud_subnets virtual_column :supports_block_storage, :type => :boolean + virtual_column :supports_cloud_object_store_container_create, :type => :boolean virtual_aggregate :total_vcpus, :hosts, :sum, :total_vcpus virtual_aggregate :total_memory, :hosts, :sum, :ram_size @@ -547,6 +548,10 @@ def supports_block_storage supports_block_storage? end + def supports_cloud_object_store_container_create + supports_cloud_object_store_container_create? + end + def get_reserve(field) (hosts + ems_clusters).inject(0) { |v, obj| v + (obj.send(field) || 0) } end From 35a5f2ca1609acf35697887fcfec0c81e17eea13 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 19 Jul 2017 12:57:45 -0700 Subject: [PATCH 7/7] PR feedback - Use mocks in lieu of actual storage factories --- spec/models/ext_management_system_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index ac9fc8a9508..096edab3402 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -410,16 +410,18 @@ end context "virtual column :supports_block_storage" do - it "returns true for Amazon EBS" do - ems_amz_ebs = FactoryGirl.create(:ems_amazon_storage_manager_ebs) - expect(ems_amz_ebs.supports_block_storage).to eq(true) + it "returns true if block storage is supported" do + ems = FactoryGirl.create(:ext_management_system) + allow(ems).to receive(:supports_block_storage).and_return(true) + expect(ems.supports_block_storage).to eq(true) end end context "virtual column :supports_cloud_object_store_container_create" do - it "returns true for Amazon S3" do - ems_amz_s3 = FactoryGirl.create(:ems_amazon_storage_manager_s3) - expect(ems_amz_s3.supports_cloud_object_store_container_create).to eq(true) + it "returns true if cloud_object_store_container_create is supported" do + ems = FactoryGirl.create(:ext_management_system) + allow(ems).to receive(:supports_cloud_object_store_container_create).and_return(true) + expect(ems.supports_cloud_object_store_container_create).to eq(true) end end end