Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #30552 - Fix vmware vm cloning when volumes are not present #7942

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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],
Comment on lines +551 to +552
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it's specific to hammer, would a clearer commit message be something like "fix vmware vm cloning when volumes are not present"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree I will change the commit message.

"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" => "",
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.

"0" => {
"type" => "VirtualVmxnet3",
"network" => "network-17",
"_delete" => "",
},
}
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/ClosingParenthesisIndentation: Indent ) to column 6 (not 4)

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"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/ClosingParenthesisIndentation: Indent ) to column 6 (not 4)


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