Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiendupont committed Sep 28, 2018
1 parent 7a6eb40 commit febf6b3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 57 deletions.
11 changes: 3 additions & 8 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,15 @@ def conversion_options_source_provider_vmwarews_vddk(vm, _storage)

def conversion_options_source_provider_vmwarews_ssh(vm, storage)
{
:vm_name => URI::Generic.build(
:scheme => 'ssh',
:userinfo => 'root',
:host => vm.host.ipaddress,
:path => "/vmfs/volumes"
).to_s + "/#{storage.name}/#{vm.location}",
:vm_name => URI::Generic.build(:scheme => 'ssh', :userinfo => 'root', :host => vm.host.ipaddress, :path => "/vmfs/volumes").to_s + "/#{storage.name}/#{vm.location}",
:transport_method => 'ssh'
}
end

def conversion_options_destination_provider_rhevm(_task, ems, cluster, storage)
{
:rhv_url => URI::Generic.build(:scheme => 'https', :host => ems.hostname, :path => '/ovirt-engine/api').to_s,
:rhv_cluster => cluster.name,
:rhv_url => URI::Generic.build(:scheme => 'https', :host => ems.hostname, :path => '/ovirt-engine/api').to_s,
:rhv_cluster => cluster.name,
:rhv_storage => storage.name,
:rhv_password => ems.authentication_password,
:install_drivers => true,
Expand Down
37 changes: 15 additions & 22 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
class ServiceTemplateTransformationPlanTask < ServiceTemplateProvisionTask

SUPPORTED_SOURCE_EMS_TYPES = %w(vmwarews).freeze
SUPPORTED_DESTINATION_EMS_TYPES = %w(openstack rhevm).freeze
SUPPORTED_SOURCE_TRANSPORT_METHOD = {
'vmwarews': ['vddk', 'ssh'],
}.freeze

def self.base_model
ServiceTemplateTransformationPlanTask
end
Expand Down Expand Up @@ -60,55 +53,55 @@ def conversion_host
def source_ems
options[:source_ems_id] ||= source.ext_management_system.id
source.ext_management_system
end
end

def destination_ems
options[:destination_ems_id] ||= transformation_destination(source.ems_cluster).ext_management_system.id
transformation_destination(source.ems_cluster).ext_management_system
end
end

def source_disks
options[:source_disks] ||= source.hardware.disks.select { |d| d.device_type == 'disk' }.collect do |disk|
source_storage = disk.storage
destination_storage = transformation_destination(disk.storage)
raise "[#{source.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil?
{
{
:path => disk.filename,
:size => disk.size,
:percent => 0,
:weight => disk.size.to_f / source.allocated_disk_storage.to_f * 100
}
end
end
:weight => disk.size.to_f / source.allocated_disk_storage.to_f * 100
}
end
end

def network_mappings
options[:network_mappings] ||= source.hardware.nics.select { |n| n.device_type == 'ethernet' }.collect do |nic|
source_network = nic.lan
destination_network = transformation_destination(source_network)
raise "[#{source.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping. Aborting." if destination_network.nil?
{
{
:source => source_network.name,
:destination => destination_network_ref(destination_network),
:mac_address => nic.address
}
end
end
}
end
end

def destination_network_ref(network)
send("destination_network_ref_#{destination_ems.emstype}", network)
end
end

def destination_network_ref_rhevm(network)
network.name
end
end

def destination_network_ref_openstack(network)
network.ems_ref
end
end

def destination_flavor
Flavor.find_by(:id => miq_request.source.options[:config_info][:osp_flavor])
end
end

def destination_security_group
SecurityGroup.find_by(:id => miq_request.source.options[:config_info][:osp_security_group])
Expand Down
34 changes: 17 additions & 17 deletions spec/models/conversion_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
let(:src_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => src_ems) }
let(:src_host) { FactoryGirl.create(:host, :ext_management_system => src_ems, :ipaddress => '10.0.0.1') }
let(:src_storage) { FactoryGirl.create(:storage, :ext_management_system => src_ems) }

let(:src_lan_1) { FactoryGirl.create(:lan) }
let(:src_lan_2) { FactoryGirl.create(:lan) }
let(:src_nic_1) { FactoryGirl.create(:guest_device_nic, :lan => src_lan_1) }
let(:src_nic_2) { FactoryGirl.create(:guest_device_nic, :lan => src_lan_2) }

let(:src_disk_1) { instance_double("disk", :device_name => "Hard disk 1", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm.vmdk", :size => 17_179_869_184) }
let(:src_disk_2) { instance_double("disk", :device_name => "Hard disk 2", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm-2.vmdk", :size => 17_179_869_184) }

let(:src_hardware) { FactoryGirl.create(:hardware, :nics => [src_nic_1, src_nic_2]) }

let(:src_vm) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) }
Expand All @@ -70,22 +70,22 @@
{:path => src_disk_2.filename, :size => src_disk_2.size, :percent => 0, :weight => 50.0 }
]
end

before do
allow(src_hardware).to receive(:disks).and_return([src_disk_1, src_disk_2])
allow(src_disk_1).to receive(:storage).and_return(src_storage)
allow(src_host).to receive(:fingerprint).and_return('01:23:45:67:89:ab:cd:ef:01:23:45:67:89:ab:cd:ef:01:23:45:67')
allow(src_host).to receive(:authentication_userid).and_return('esx_user')
allow(src_host).to receive(:authentication_password).and_return('esx_passwd')
end

context "destination is rhevm" do
let(:dst_ems) { FactoryGirl.create(:ems_redhat, :zone => FactoryGirl.create(:zone)) }
let(:dst_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => dst_ems) }
let(:dst_storage) { FactoryGirl.create(:storage) }
let(:dst_lan_1) { FactoryGirl.create(:lan) }
let(:dst_lan_2) { FactoryGirl.create(:lan) }

let(:mapping) do
FactoryGirl.create(
:transformation_mapping,
Expand Down Expand Up @@ -121,12 +121,12 @@
task.options[:transformation_host_id] = conversion_host.id
allow(task).to receive(:source_disks).and_return(source_disks)
end

context "transport method is vddk" do
before do
conversion_host.vddk_transport_supported = true
end

it "#conversion_options" do
expect(conversion_host.conversion_options(task)).to eq(
:vm_name => src_vm.name,
Expand All @@ -145,13 +145,13 @@
)
end
end

context "transport method is ssh" do
before do
conversion_host.vddk_transport_supported = false
conversion_host.ssh_transport_supported = true
end

it "#conversion_options" do
expect(conversion_host.conversion_options(task)).to eq(
:vm_name => "ssh://[email protected]/vmfs/volumes/#{src_storage.name}/#{src_vm.location}",
Expand All @@ -168,7 +168,7 @@
end
end
end

context "destination is openstack" do
let(:dst_ems) { FactoryGirl.create(:ems_openstack, :zone => FactoryGirl.create(:zone)) }
let(:dst_cloud_tenant) { FactoryGirl.create(:cloud_tenant, :ext_management_system => dst_ems) }
Expand All @@ -177,7 +177,7 @@
let(:dst_cloud_network_2) { FactoryGirl.create(:cloud_network) }
let(:dst_flavor) { FactoryGirl.create(:flavor) }
let(:dst_security_group) { FactoryGirl.create(:security_group) }

let(:mapping) do
FactoryGirl.create(
:transformation_mapping,
Expand Down Expand Up @@ -215,12 +215,12 @@
task.options[:transformation_host_id] = conversion_host.id
allow(task).to receive(:source_disks).and_return(source_disks)
end

context "transport method is vddk" do
before do
conversion_host.vddk_transport_supported = true
end

it "#conversion_options" do
expect(conversion_host.conversion_options(task)).to eq(
:vm_name => src_vm.name,
Expand Down Expand Up @@ -250,7 +250,7 @@
)
end
end

context "transport method is ssh" do
before do
conversion_host.vddk_transport_supported = false
Expand All @@ -259,8 +259,8 @@

it "#conversion_options" do
expect(conversion_host.conversion_options(task)).to eq(
:vm_name => "ssh://[email protected]/vmfs/volumes/#{src_storage.name}/#{src_vm.location}",
:transport_method => 'ssh',
:vm_name => "ssh://[email protected]/vmfs/volumes/#{src_storage.name}/#{src_vm.location}",
:transport_method => 'ssh',
:osp_environment => {
:os_no_cache => true,
:os_auth_url => URI::Generic.build(
Expand Down
23 changes: 13 additions & 10 deletions spec/models/service_template_transformation_plan_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@

context 'when conversion host exists' do
before do
# FactoryGirl.create(:conversion_host, :id => host_id, :ext_management_system => FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone)))
FactoryGirl.create(:conversion_host, :id => conversion_host_id, :resource => host)

allow(described_class).to receive(:find).and_return(task)
Expand Down Expand Up @@ -273,7 +272,7 @@
let(:src_disk_1) { instance_double("disk", :device_name => "Hard disk 1", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm.vmdk", :size => 17_179_869_184) }
let(:src_disk_2) { instance_double("disk", :device_name => "Hard disk 2", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm-2.vmdk", :size => 17_179_869_184) }

let(:src_hardware) { FactoryGirl.create(:hardware, :nics => [src_nic_1, src_nic_2 ]) }
let(:src_hardware) { FactoryGirl.create(:hardware, :nics => [src_nic_1, src_nic_2]) }

let(:src_vm_1) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) }
let(:src_vm_2) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) }
Expand Down Expand Up @@ -318,17 +317,21 @@
end

it "has source_disks" do
expect(task_1.source_disks).to eq([
{ :path => src_disk_1.filename, :size => src_disk_1.size, :percent => 0, :weight => 50.0 },
{ :path => src_disk_2.filename, :size => src_disk_2.size, :percent => 0, :weight => 50.0 }
])
expect(task_1.source_disks).to eq(
[
{ :path => src_disk_1.filename, :size => src_disk_1.size, :percent => 0, :weight => 50.0 },
{ :path => src_disk_2.filename, :size => src_disk_2.size, :percent => 0, :weight => 50.0 }
]
)
end

it "has network_mappings" do
expect(task_1.network_mappings).to eq([
{ :source => src_lan_1.name, :destination => dst_lan_1.name, :mac_address => src_nic_1.address },
{ :source => src_lan_2.name, :destination => dst_lan_2.name, :mac_address => src_nic_2.address }
])
expect(task_1.network_mappings).to eq(
[
{ :source => src_lan_1.name, :destination => dst_lan_1.name, :mac_address => src_nic_1.address },
{ :source => src_lan_2.name, :destination => dst_lan_2.name, :mac_address => src_nic_2.address }
]
)
end
end
end
Expand Down

0 comments on commit febf6b3

Please sign in to comment.