From 3083fcf6d3cc25de52812623d6286d68136a2c01 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Fri, 11 May 2018 14:43:27 -0400 Subject: [PATCH 1/5] added virtual column :storage which is entry in serialized Hash column :capacity. It will allow to show storage value on report as inumber instead of Hash entry. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576922 --- app/models/persistent_volume.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/persistent_volume.rb b/app/models/persistent_volume.rb index 7f2a2bbcd44..22b6b8bbcd8 100644 --- a/app/models/persistent_volume.rb +++ b/app/models/persistent_volume.rb @@ -6,4 +6,10 @@ class PersistentVolume < ContainerVolume has_many :container_volumes, -> { where(:type => 'ContainerVolume') }, :through => :persistent_volume_claim has_many :parents, -> { distinct }, :through => :container_volumes, :source_type => 'ContainerGroup' alias_attribute :container_groups, :parents + + virtual_column :storage, :type => :integer + + def storage + capacity[:storage] if capacity + end end From ed23031f9f4332596dae20768984f8ebb14d4a04 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Fri, 11 May 2018 14:44:03 -0400 Subject: [PATCH 2/5] added rspec for PersistentVolume#storage --- spec/models/persistent_volume_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/models/persistent_volume_spec.rb b/spec/models/persistent_volume_spec.rb index 2d506c8558d..f28bc018f35 100644 --- a/spec/models/persistent_volume_spec.rb +++ b/spec/models/persistent_volume_spec.rb @@ -40,4 +40,24 @@ def assert_pv_relationships(persistent_volume) expect(persistent_volume.container_groups.first.name).to eq("group") expect(persistent_volume.container_groups.count).to eq(1) end + + describe "#storage" do + let(:storage) { 123_456_789 } + + it "returns value for :storage key in Hash column :capacity" do + persistent_volume = FactoryGirl.create( + :persistent_volume, + :capacity => {:storage => storage, :foo => "something"} + ) + expect(persistent_volume.storage).to eq storage + end + + it "returns nil if there is no :storage key in Hash column :capacity" do + persistent_volume = FactoryGirl.create( + :persistent_volume, + :capacity => {:foo => "something"} + ) + expect(persistent_volume.storage).to be nil + end + end end From a7fc348fee47761577a6dc9c0e510c0644ac4c01 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Mon, 21 May 2018 14:49:59 -0400 Subject: [PATCH 3/5] renaming virtual column 'PersistentVolume#storage' to 'storage_capacity' --- app/models/persistent_volume.rb | 4 ++-- spec/models/persistent_volume_spec.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/persistent_volume.rb b/app/models/persistent_volume.rb index 22b6b8bbcd8..1818701d85c 100644 --- a/app/models/persistent_volume.rb +++ b/app/models/persistent_volume.rb @@ -7,9 +7,9 @@ class PersistentVolume < ContainerVolume has_many :parents, -> { distinct }, :through => :container_volumes, :source_type => 'ContainerGroup' alias_attribute :container_groups, :parents - virtual_column :storage, :type => :integer + virtual_column :storage_capacity, :type => :integer - def storage + def storage_capacity capacity[:storage] if capacity end end diff --git a/spec/models/persistent_volume_spec.rb b/spec/models/persistent_volume_spec.rb index f28bc018f35..011821357c2 100644 --- a/spec/models/persistent_volume_spec.rb +++ b/spec/models/persistent_volume_spec.rb @@ -41,15 +41,15 @@ def assert_pv_relationships(persistent_volume) expect(persistent_volume.container_groups.count).to eq(1) end - describe "#storage" do - let(:storage) { 123_456_789 } + describe "#storage_capacity" do + let(:storage_size) { 123_456_789 } it "returns value for :storage key in Hash column :capacity" do persistent_volume = FactoryGirl.create( :persistent_volume, - :capacity => {:storage => storage, :foo => "something"} + :capacity => {:storage => storage_size, :foo => "something"} ) - expect(persistent_volume.storage).to eq storage + expect(persistent_volume.storage_capacity).to eq storage_size end it "returns nil if there is no :storage key in Hash column :capacity" do @@ -57,7 +57,7 @@ def assert_pv_relationships(persistent_volume) :persistent_volume, :capacity => {:foo => "something"} ) - expect(persistent_volume.storage).to be nil + expect(persistent_volume.storage_capacity).to be nil end end end From 47f951eee9e07fcd42207d843778deba5ae30e39 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Mon, 21 May 2018 15:40:52 -0400 Subject: [PATCH 4/5] added virtual column PersistentVolumeClaim.storage_capacity --- app/models/persistent_volume_claim.rb | 6 ++++++ spec/models/persistent_volume_claim_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/models/persistent_volume_claim_spec.rb diff --git a/app/models/persistent_volume_claim.rb b/app/models/persistent_volume_claim.rb index 5091da6e5c8..7b4c49788dd 100644 --- a/app/models/persistent_volume_claim.rb +++ b/app/models/persistent_volume_claim.rb @@ -6,7 +6,13 @@ class PersistentVolumeClaim < ApplicationRecord serialize :requests, Hash serialize :limits, Hash + virtual_column :storage_capacity, :type => :integer + def persistent_volume container_volumes.find_by_type('PersistentVolume') end + + def storage_capacity + capacity[:storage] if capacity + end end diff --git a/spec/models/persistent_volume_claim_spec.rb b/spec/models/persistent_volume_claim_spec.rb new file mode 100644 index 00000000000..b48e8958a08 --- /dev/null +++ b/spec/models/persistent_volume_claim_spec.rb @@ -0,0 +1,21 @@ +describe PersistentVolumeClaim do + describe "#storage_capacity" do + let(:storage_size) { 123_456_789 } + + it "returns value for :storage key in Hash column :capacity" do + persistent_volume = FactoryGirl.create( + :persistent_volume_claim, + :capacity => {:storage => storage_size, :foo => "something"} + ) + expect(persistent_volume.storage_capacity).to eq storage_size + end + + it "returns nil if there is no :storage key in Hash column :capacity" do + persistent_volume = FactoryGirl.create( + :persistent_volume_claim, + :capacity => {:foo => "something"} + ) + expect(persistent_volume.storage_capacity).to be nil + end + end +end From d922fe1d8cc29126aff0c3354d070058e64f75b5 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Thu, 24 May 2018 11:19:30 -0400 Subject: [PATCH 5/5] removed not needed checking for nil --- app/models/persistent_volume.rb | 2 +- app/models/persistent_volume_claim.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/persistent_volume.rb b/app/models/persistent_volume.rb index 1818701d85c..bffb7fc88ed 100644 --- a/app/models/persistent_volume.rb +++ b/app/models/persistent_volume.rb @@ -10,6 +10,6 @@ class PersistentVolume < ContainerVolume virtual_column :storage_capacity, :type => :integer def storage_capacity - capacity[:storage] if capacity + capacity[:storage] end end diff --git a/app/models/persistent_volume_claim.rb b/app/models/persistent_volume_claim.rb index 7b4c49788dd..ffa8fcba665 100644 --- a/app/models/persistent_volume_claim.rb +++ b/app/models/persistent_volume_claim.rb @@ -13,6 +13,6 @@ def persistent_volume end def storage_capacity - capacity[:storage] if capacity + capacity[:storage] end end