Skip to content

Commit

Permalink
Fixes #30552 - Fix vmware vm cloning when volumes are not present
Browse files Browse the repository at this point in the history
(cherry picked from commit 62ac9fe)
  • Loading branch information
yifatmakias authored and tbrisker committed Nov 17, 2020
1 parent 4b1bc78 commit fbbc297
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def clone_vm(raw_args)
"numCPUs" => args[:cpus],
"numCoresPerSocket" => args[:corespersocket],
"memoryMB" => args[:memory_mb],
"datastore" => args[:volumes].first[:datastore],
"storage_pod" => args[:volumes].first[:storage_pod],
"datastore" => args[:volumes].empty? ? nil : args[:volumes].first[:datastore],
"storage_pod" => args[:volumes].empty? ? nil : args[:volumes].first[:storage_pod],
"resource_pool" => [args[:cluster], args[:resource_pool]],
"boot_order" => [:disk],
"annotation" => args[:annotation],
Expand Down
43 changes: 43 additions & 0 deletions test/models/compute_resources/vmware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,49 @@ class Foreman::Model::VmwareTest < ActiveSupport::TestCase
assert_equal mock_vm, cr.create_vm(attrs_in)
end

test "#clone_vm works with no volume attributes" do
attrs_in = HashWithIndifferentAccess.new(
"image_id" => "2",
"cpus" => "1",
"interfaces_attributes" => {
"new_interfaces" => {
"type" => "VirtualE1000",
"network" => "network-17",
"_delete" => "",
},
"0" => {
"type" => "VirtualVmxnet3",
"network" => "network-17",
"_delete" => "",
},
}
)
attrs_parsed = HashWithIndifferentAccess.new(
"image_id" => "2",
"cpus" => "1",
"interfaces_attributes" => {
"new_interfaces" => {
"type" => "VirtualE1000",
"network" => "Test network",
"_delete" => "",
},
"0" => {
"type" => "VirtualVmxnet3",
"network" => "Test network",
"_delete" => "",
},
},
"provision_method" => "image"
)

mock_vm = mock('vm')
cr = FactoryBot.build_stubbed(:vmware_cr)
cr.expects(:parse_networks).with(attrs_in).returns(attrs_parsed)
cr.expects(:clone_vm).with(attrs_parsed).returns(mock_vm)
cr.expects(:test_connection)
assert_equal mock_vm, cr.create_vm(attrs_in)
end

describe "#parse_args" do
setup do
@cr = FactoryBot.build_stubbed(:vmware_cr)
Expand Down

0 comments on commit fbbc297

Please sign in to comment.