From d56e35902db1f5de0d4f6c315fda132d95008653 Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Mon, 8 May 2017 14:02:35 +0300 Subject: [PATCH 1/2] Add Pod to PersistentVolume relationship refactoring --- app/models/container_group.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/container_group.rb b/app/models/container_group.rb index d15b20ec519..98afcf9d75a 100644 --- a/app/models/container_group.rb +++ b/app/models/container_group.rb @@ -24,6 +24,8 @@ class ContainerGroup < ApplicationRecord belongs_to :old_container_project, :foreign_key => "old_container_project_id", :class_name => 'ContainerProject' belongs_to :container_build_pod has_many :container_volumes, :as => :parent, :dependent => :destroy + has_many :persistent_volume_claim, :through => :container_volumes + has_many :persistent_volumes, -> { where(:type=>'PersistentVolume') }, :through => :persistent_volume_claim, :source => :container_volumes # Metrics destroy is handled by purger has_many :metrics, :as => :resource From be8ab10c7027e01db00c1c95288f5747b6f8c96f Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Mon, 8 May 2017 14:51:08 +0300 Subject: [PATCH 2/2] Added tests refactoring tests refactored tests refactored tests refactored some tests --- spec/models/container_group.rb | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/models/container_group.rb diff --git a/spec/models/container_group.rb b/spec/models/container_group.rb new file mode 100644 index 00000000000..a9830c07058 --- /dev/null +++ b/spec/models/container_group.rb @@ -0,0 +1,51 @@ +describe ContainerGroup do + it "has container volumes and pods" do + pvc = FactoryGirl.create( + :persistent_volume_claim, + :name => "test_claim" + ) + + group = FactoryGirl.create( + :container_group, + :name => "group", + ) + + ems = FactoryGirl.create( + :ems_kubernetes, + :id => group.id, + :name => "ems" + ) + + FactoryGirl.create( + :container_volume, + :name => "container_volume", + :type => 'ContainerVolume', + :parent => group, + :persistent_volume_claim => pvc + ) + + FactoryGirl.create( + :persistent_volume, + :name => "persistent_volume0", + :parent => ems, + :persistent_volume_claim => pvc + ) + + FactoryGirl.create( + :persistent_volume, + :name => "persistent_volume1", + :parent => ems, + :persistent_volume_claim => pvc + ) + + assert_pod_to_pv_relationships(group) + end + + def assert_pod_to_pv_relationships(group) + expect(group.persistent_volume_claim.first.name).to eq("test_claim") + expect(group.persistent_volume_claim.count).to eq(1) + expect(group.persistent_volumes.first.name).to eq("persistent_volume0") + expect(group.persistent_volumes.second.name).to eq("persistent_volume1") + expect(group.persistent_volumes.count).to eq(2) + end +end