Skip to content

Commit

Permalink
Merge pull request #18537 from fdupont-redhat/v2v_generate_ansible_ex…
Browse files Browse the repository at this point in the history
…tra_vars

[V2V] Generate extra vars for conversion host playbooks
  • Loading branch information
agrare committed Mar 13, 2019
2 parents c323d0e + b47b4dc commit 6e9428f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
26 changes: 10 additions & 16 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,29 @@ def get_conversion_log(path)
end

def check_conversion_host_role
install_conversion_host_module
playbook = "/usr/share/ovirt-ansible-v2v-conversion-host/playbooks/conversion_host_check.yml"
extra_vars = { :v2v_manageiq_conversion_host_check => true }
ansible_playbook(playbook, extra_vars)
ansible_playbook(playbook)
tag_resource_as('enabled')
rescue
tag_resource_as('disabled')
end

def enable_conversion_host_role(v2v_vddk_package_url = nil)
install_conversion_host_module
v2v_vddk_package_url ||= "http://#{resource.ext_management_system.hostname}/vddk/VMware-vix-disklib-stable.tar.gz"
def enable_conversion_host_role(vmware_vddk_package_url = nil, vmware_ssh_private_key = nil)
raise "vddk_package_url is mandatory if transformation method is vddk" if vddk_transport_supported && vmware_vddk_package_url.nil?
raise "ssh_private_key is mandatory if transformation_method is ssh" if ssh_transport_supported && vmware_ssh_private_key.nil?
playbook = "/usr/share/ovirt-ansible-v2v-conversion-host/playbooks/conversion_host_enable.yml"
extra_vars = {
:v2v_vddk_package_name => "VMware-vix-disklib-stable.tar.gz",
:v2v_vddk_package_url => v2v_vddk_package_url
}
:v2v_transport_method => vddk_transport_supported ? 'vddk' : 'ssh',
:v2v_vddk_package_url => vmware_vddk_package_url,
:v2v_ssh_private_key => vmware_ssh_private_key,
:v2v_ca_bundle => resource.ext_management_system.connection_configurations['default'].certificate_authority
}.compact
ansible_playbook(playbook, extra_vars)
ensure
check_conversion_host_role
end

def disable_conversion_host_role
install_conversion_host_module
playbook = "/usr/share/ovirt-ansible-v2v-conversion-host/playbooks/conversion_host_disable.yml"
ansible_playbook(playbook)
ensure
Expand Down Expand Up @@ -180,6 +179,7 @@ def miq_ssh_util_args_manageiq_providers_openstack_cloudmanager_vm
def ansible_playbook(playbook, extra_vars = {})
command = "ansible-playbook #{playbook} -i #{ipaddress}"

extra_vars[:v2v_host_type] = resource.ext_management_system.emstype
extra_vars.each { |k, v| command += " -e '#{k}=#{v}'" }

connect_ssh { |ssu| ssu.shell_exec(command) }
Expand All @@ -188,12 +188,6 @@ def ansible_playbook(playbook, extra_vars = {})
raise e
end

def install_conversion_host_module
connect_ssh { |ssu| ssu.shell_exec("yum install -y ovirt-ansible-v2v-conversion-host") }
rescue => e
_log.error("Ansible module installation failed for '#{resource.name}'}with [#{e.class}: #{e.message}]")
end

# Wrapper method for the various tag_resource_as_xxx methods.
#--
# TODO: Do we need this?
Expand Down
7 changes: 5 additions & 2 deletions app/models/conversion_host/configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ def enable(params)
params.delete(:task_id) # In case this is being called through *_queue which will stick in a :task_id
params.delete(:miq_task_id) # The miq_queue.activate_miq_task will stick in a :miq_task_id

vddk_url = params.delete(:param_v2v_vddk_package_url)
vmware_vddk_package_url = params.delete(:vmware_vddk_package_url)
params[:vddk_transport_supported] = !vmware_vddk_package_url.nil?
vmware_ssh_private_key = params.delete(:vmware_ssh_private_key)
params[:ssh_transport_supported] = !vmware_ssh_private_key.nil?

conversion_host = new(params)
conversion_host.enable_conversion_host_role(vddk_url)
conversion_host.enable_conversion_host_role(vmware_vddk_package_url, vmware_ssh_private_key)
conversion_host.save!
conversion_host
rescue StandardError => error
Expand Down
39 changes: 30 additions & 9 deletions spec/models/conversion_host/configurations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
describe ConversionHost do
let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => vm, :ssh_transport_supported => true) }
let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => vm) }
let(:conversion_host_ssh) { FactoryBot.create(:conversion_host, :resource => vm, :ssh_transport_supported => true) }
let(:conversion_host_vddk) { FactoryBot.create(:conversion_host, :resource => vm, :vddk_transport_supported => true) }
let(:params) do
{
:name => 'transformer',
Expand Down Expand Up @@ -40,15 +42,34 @@
expect { described_class.enable(params) }.to raise_error(StandardError)
end

it "tags the associated resource as expected" do
allow(conversion_host).to receive(:enable_conversion_host_role)
taggings = conversion_host.resource.taggings
tag_names = taggings.map { |tagging| tagging.tag.name }
context "transport method is SSH" do
let(:conversion_host) { conversion_host_ssh }

expect(tag_names).to contain_exactly(
'/user/v2v_transformation_host/true',
'/user/v2v_transformation_method/ssh'
)
it "tags the associated resource as expected" do
allow(conversion_host).to receive(:enable_conversion_host_role)
taggings = conversion_host.resource.taggings
tag_names = taggings.map { |tagging| tagging.tag.name }

expect(tag_names).to contain_exactly(
'/user/v2v_transformation_host/true',
'/user/v2v_transformation_method/ssh'
)
end
end

context "transport method is VDDK" do
let(:conversion_host) { conversion_host_vddk }

it "tags the associated resource as expected" do
allow(conversion_host).to receive(:enable_conversion_host_role)
taggings = conversion_host.resource.taggings
tag_names = taggings.map { |tagging| tagging.tag.name }

expect(tag_names).to contain_exactly(
'/user/v2v_transformation_host/true',
'/user/v2v_transformation_method/vddk'
)
end
end
end

Expand Down

0 comments on commit 6e9428f

Please sign in to comment.