From 57f3551b404e4507e10512b2f854897688b12ca6 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Wed, 4 Mar 2020 10:45:41 -0500 Subject: [PATCH 1/2] Configuration of conversion host without IP should fail early --- app/models/conversion_host.rb | 1 + spec/models/conversion_host_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index 2095a472ecc..ecfc86b2f47 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -428,6 +428,7 @@ def ansible_playbook(playbook, extra_vars = {}, miq_task_id = nil, auth_type = ' task = MiqTask.find(miq_task_id) if miq_task_id.present? host = hostname || ipaddress + raise "#{resource.class.name.demodulize} '#{resource.name}' doesn't have a hostname or IP address in inventory" if host.nil? params = [ playbook, diff --git a/spec/models/conversion_host_spec.rb b/spec/models/conversion_host_spec.rb index d325f56c783..1ec632a3c9f 100644 --- a/spec/models/conversion_host_spec.rb +++ b/spec/models/conversion_host_spec.rb @@ -212,6 +212,22 @@ expect { conversion_host.enable_conversion_host_role }.to raise_error("vmware_vddk_package_url is mandatory if transformation method is vddk") end + it "enable_conversion_host_role raises if resource has no hostname nor IP address" do + check_playbook = '/usr/share/v2v-conversion-host-ansible/playbooks/conversion_host_check.yml' + enable_extra_vars = { + :v2v_host_type => 'rhevm', + :v2v_transport_method => 'vddk', + :v2v_vddk_package_url => package_url + } + check_extra_vars = { + :v2v_host_type => 'rhevm', + :v2v_transport_method => 'vddk' + } + allow(host).to receive(:hostname).and_return(nil) + allow(host).to receive(:ipaddresses).and_return([]) + expect { conversion_host.enable_conversion_host_role('http://file.example.com/vddk-stable.tar.gz', nil) }.to raise_error("Host '#{host.name}' doesn't have a hostname or IP address in inventory") + end + it "enable_conversion_host_role calls ansible_playbook with extra_vars" do check_playbook = '/usr/share/v2v-conversion-host-ansible/playbooks/conversion_host_check.yml' enable_extra_vars = { From b336a196a366b8edbe89aa8bd406e7468140bc5f Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Wed, 4 Mar 2020 12:29:39 -0500 Subject: [PATCH 2/2] Remove unneeded variables from spec --- spec/models/conversion_host_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/models/conversion_host_spec.rb b/spec/models/conversion_host_spec.rb index 1ec632a3c9f..8bfbf8fb8b6 100644 --- a/spec/models/conversion_host_spec.rb +++ b/spec/models/conversion_host_spec.rb @@ -213,16 +213,6 @@ end it "enable_conversion_host_role raises if resource has no hostname nor IP address" do - check_playbook = '/usr/share/v2v-conversion-host-ansible/playbooks/conversion_host_check.yml' - enable_extra_vars = { - :v2v_host_type => 'rhevm', - :v2v_transport_method => 'vddk', - :v2v_vddk_package_url => package_url - } - check_extra_vars = { - :v2v_host_type => 'rhevm', - :v2v_transport_method => 'vddk' - } allow(host).to receive(:hostname).and_return(nil) allow(host).to receive(:ipaddresses).and_return([]) expect { conversion_host.enable_conversion_host_role('http://file.example.com/vddk-stable.tar.gz', nil) }.to raise_error("Host '#{host.name}' doesn't have a hostname or IP address in inventory")