Project

General

Profile

Bug #10093

Creating VMware host over API with compute profile doesn't perform image provisioning

Added by Chad Walstrom over 6 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Compute resources - VMware
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

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
-

Associated revisions

Revision 140cfe26 (diff)
Added by Chad Walstrom over 6 years ago

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"]
is present.

Revision 3aec1326 (diff)
Added by Chad Walstrom over 6 years ago

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"]
is present.

(cherry picked from commit 140cfe262eac838e76eb27517bd0271beab9be15)

History

#1 Updated by Dominic Cleal over 6 years ago

  • Subject changed from VMware#create_vm calls clone_vm when image provisioning to Creating VMware host over API with compute profile doesn't perform image provisioning
  • Category set to Compute resources - VMware

#2 Updated by The Foreman Bot over 6 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2294 added
  • Pull request deleted ()

#3 Updated by Anonymous over 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by Dominic Cleal over 6 years ago

  • Assignee set to Chad Walstrom
  • Legacy Backlogs Release (now unused) set to 28

Also available in: Atom PDF