From 7646495cbda53add7ed707fe3ed530549d733136 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 15 Oct 2018 12:18:14 -0400 Subject: [PATCH 1/3] Add ext_management_system method to conversion host --- app/models/conversion_host.rb | 4 ++++ spec/models/conversion_host_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index 202ae1eb06d..fae12e2d4e7 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -7,6 +7,10 @@ class ConversionHost < ApplicationRecord has_many :service_template_transformation_plan_tasks, :dependent => :nullify has_many :active_tasks, -> { where(:state => 'active') }, :class_name => ServiceTemplateTransformationPlanTask, :inverse_of => :conversion_host + def ext_management_system + resource.ext_management_system + end + # To be eligible, a conversion host must have the following properties # - A transport mechanism is configured for source (set by 3rd party) # - Credentials are set on the resource and SSH connection works diff --git a/spec/models/conversion_host_spec.rb b/spec/models/conversion_host_spec.rb index a5e98a95042..931168b671e 100644 --- a/spec/models/conversion_host_spec.rb +++ b/spec/models/conversion_host_spec.rb @@ -127,6 +127,12 @@ end end + shared_examples_for "#ext_management_system" do + it "returns the EMS of resource" do + expect(conversion_host.ext_management_system).to eq(ems) + end + end + shared_examples_for "#check_ssh_connection" do it "fails when SSH send an error" do allow(conversion_host).to receive(:connect).and_raise('Unexpected failure') @@ -144,6 +150,8 @@ let(:host) { FactoryGirl.create(:host_redhat, :ext_management_system => ems) } let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host, :vddk_transport_supported => true) } + it_behaves_like "#ext_management_system" + context "host userid is nil" do before { allow(host).to receive(:authentication_userid).and_return(nil) } it { expect(conversion_host.check_ssh_connection).to eq(false) } @@ -169,6 +177,8 @@ let(:vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems) } let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => vm, :vddk_transport_supported => true) } + it_behaves_like "#ext_management_system" + context "ems authentications is empty" do it { expect(conversion_host.check_ssh_connection).to be(false) } end From ea6261c68f3d58c19489e723e4f027b1a053d0c4 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 15 Oct 2018 12:50:19 -0400 Subject: [PATCH 2/3] Use delegate --- app/models/conversion_host.rb | 5 +---- spec/models/conversion_host_spec.rb | 10 ---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index fae12e2d4e7..eb2ac709a1b 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -6,10 +6,7 @@ class ConversionHost < ApplicationRecord belongs_to :resource, :polymorphic => true has_many :service_template_transformation_plan_tasks, :dependent => :nullify has_many :active_tasks, -> { where(:state => 'active') }, :class_name => ServiceTemplateTransformationPlanTask, :inverse_of => :conversion_host - - def ext_management_system - resource.ext_management_system - end + delegate :ext_management_system, :to => :resource # To be eligible, a conversion host must have the following properties # - A transport mechanism is configured for source (set by 3rd party) diff --git a/spec/models/conversion_host_spec.rb b/spec/models/conversion_host_spec.rb index 931168b671e..a5e98a95042 100644 --- a/spec/models/conversion_host_spec.rb +++ b/spec/models/conversion_host_spec.rb @@ -127,12 +127,6 @@ end end - shared_examples_for "#ext_management_system" do - it "returns the EMS of resource" do - expect(conversion_host.ext_management_system).to eq(ems) - end - end - shared_examples_for "#check_ssh_connection" do it "fails when SSH send an error" do allow(conversion_host).to receive(:connect).and_raise('Unexpected failure') @@ -150,8 +144,6 @@ let(:host) { FactoryGirl.create(:host_redhat, :ext_management_system => ems) } let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host, :vddk_transport_supported => true) } - it_behaves_like "#ext_management_system" - context "host userid is nil" do before { allow(host).to receive(:authentication_userid).and_return(nil) } it { expect(conversion_host.check_ssh_connection).to eq(false) } @@ -177,8 +169,6 @@ let(:vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems) } let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => vm, :vddk_transport_supported => true) } - it_behaves_like "#ext_management_system" - context "ems authentications is empty" do it { expect(conversion_host.check_ssh_connection).to be(false) } end From 90da9fa8124dcfef7ffe6473b7571f82f4ff34e8 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Mon, 15 Oct 2018 15:13:02 -0400 Subject: [PATCH 3/3] Add allow_nil to delegate --- app/models/conversion_host.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index eb2ac709a1b..1c1cb4fdd88 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -6,7 +6,7 @@ class ConversionHost < ApplicationRecord belongs_to :resource, :polymorphic => true has_many :service_template_transformation_plan_tasks, :dependent => :nullify has_many :active_tasks, -> { where(:state => 'active') }, :class_name => ServiceTemplateTransformationPlanTask, :inverse_of => :conversion_host - delegate :ext_management_system, :to => :resource + delegate :ext_management_system, :to => :resource, :allow_nil => true # To be eligible, a conversion host must have the following properties # - A transport mechanism is configured for source (set by 3rd party)