Creating VMware host over API with compute profile doesn't perform image provisioning
Scenario: Clone a VMware image via API using compute_profiles Given that a VMware vSphere cluster is a compute resource, And given that a compute profile exists on that resource, And given that the compute profile has a valid VMware image associated with it, And given that a hostgroup associated is with that compute profile, When I POST to /api/v2/hosts with the hostgroup_id and compute_resource_id, Then I should create a new VMware guest as a clone from the specified image.
This scenario fails in the following conditional expression:
if args[:image_id].present? clone_vm(args) else vm = new_vm(args) vm.save end
The test "#create_vm calls clone_vm when image provisioning" currently succeeds because it is incorrectly instantiating the input hash with indifferent access. Updating the test to use an unmodified "image_id" key will show the test correctly failing, exposing this bug.
A suggestion to fix this is:
Modified app/models/compute_resources/foreman/model/vmware.rb diff --git a/app/models/compute_resources/foreman/model/vmware.rb b/app/models/compute_resources/foreman/model/vmware.rb index 9c4d471..9871d8b 100644 --- a/app/models/compute_resources/foreman/model/vmware.rb +++ b/app/models/compute_resources/foreman/model/vmware.rb @@ -313,7 +313,7 @@ module Foreman::Model test_connection return unless errors.empty? - args = parse_networks(args) + args = parse_networks(args.with_indifferent_access) if args[:image_id].present? clone_vm(args) else @@ -470,4 +470,3 @@ module Foreman::Model end end end -
Fixes #10093 - VMware#create_vm calls clone_vm
Apply '.with_indifferent_access' to the args passed in to create_vm,
ensuring symbol test for args[:image_id] succeeds when args["image_id"]