Project

General

Profile

Bug #8769

Unable to build new VM in openstack with API

Added by Brian Lee almost 8 years ago. Updated almost 8 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
API
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

I am using json to create a new VM in a openstack Icehouse environment. I get this error as a response from the json request:

{
"host": {
"id": null,
"errors": {
"base": [
"Failed to create a compute Openstack-Quicksand-SE (OpenStack) instance se-test-api.vm.<domain>.com: undefined method `delete_if' for nil:NilClass\n "
]
},
"full_messages": [
"Failed to create a compute Openstack-Quicksand-SE (OpenStack) instance se-test-api.vm.<domain>.com: undefined method `delete_if' for nil:NilClass\n "
]
}
}

Paste bin of the error in the production.log: http://pastebin.com/8F0a8AkR


Related issues

Related to Foreman - Bug #12320: Hammer CLI : Failed to create a new VM on OpenStack - undefined method `delete_if' for nil:NilClassRejected

History

#1 Updated by Dominic Cleal almost 8 years ago

Try passing an empty array in for compute_attributes[nics] so it can iterate over something at least, though you probably need to add some info about network interfaces.

#2 Updated by Brian Lee almost 8 years ago

I am back to working on this. How do I add a empty array to it? This is my current json:

{"host":{"name":"se-test-api",
         "environment_id":"1",
         "hostgroup_id":"6",
         "architecture_id":1,
         "operatingsystem_id":"1",
         "provision_method":"image",
         "compute_resource_id":1,
         "compute_attributes":{"flavor_ref":3,
                               "image_ref":"0937879c-c44a-42b9-b3f5-f03c1928bf39",
                               "tenant_id":"b9241c2ab4884ef7911b13e4cd26aa44",
                               "security_groups":"default",
                               "network":"nova"}
        }
}

I have tried adding "nics": , "nics":{}, "nics":[] to the compute_attrubutes section and it does not seem to help.
When I do "nics":{}, I am getting this error: undefined method `map!' for {}:ActiveSupport::HashWithIndifferentAccess

What else can I try?

#3 Updated by Dominic Cleal almost 8 years ago

I'd try:

{"host":{"name":"se-test-api",
         "environment_id":"1",
         "hostgroup_id":"6",
         "architecture_id":1,
         "operatingsystem_id":"1",
         "provision_method":"image",
         "compute_resource_id":1,
         "compute_attributes":{"flavor_ref":3,
                               "image_ref":"0937879c-c44a-42b9-b3f5-f03c1928bf39",
                               "tenant_id":"b9241c2ab4884ef7911b13e4cd26aa44",
                               "security_groups":"default",
                               "network":"nova",
                               "nics":[]}
        }
}

Can you check the exact error when you try it?

#4 Updated by Brian Lee almost 8 years ago

It throws the same error as above. From the log:

Processing by Api::V1::HostsController#create as JSON
Parameters: {"host"=>{"name"=>"se-test-api", "environment_id"=>"1", "hostgroup_id"=>"6", "architecture_id"=>1, "operatingsystem_id"=>"1", "provision_method"=>"image", "compute_resource_id"=>1, "compute_attributes"=>{"flavor_ref"=>3, "image_ref"=>"0937879c-c44a-42b9-b3f5-f03c1928bf39", "tenant_id"=>"b9241c2ab4884ef7911b13e4cd26aa44", "security_groups"=>"default", "network"=>"nova", "nics"=>nil}}, "apiv"=>"v1"}
Authorized user blee(Brian Lee)
Adding Compute instance for se-test-api.<domain>.com
failed to create vm: undefined method `delete_if' for nil:NilClass

#5 Updated by Dominic Cleal almost 8 years ago

"nics"=>nil looks odd, it's not an empty array as I'd expect if you're doing "nics": [].

#6 Updated by Brian Lee almost 8 years ago

Looking at the log its erroring in the /usr/share/foreman/app/models/compute_resources/foreman/model/openstack.rb. This is the section:
def create_vm(args = {})
network = args.delete(:network) # fix internal network format for fog.
args[:nics].delete_if(&:blank?)
args[:nics].map! {|nic| { 'net_id' => nic } }
vm = super(args)
if network.present?
address = allocate_address(network)
assign_floating_ip(address, vm)
end
vm
rescue => e
message = JSON.parse(e.response.body)['badRequest']['message'] rescue (e.to_s)
logger.warn "failed to create vm: #{message}"
destroy_vm vm.id if vm
raise message
end

Its complaining about the delete_if function. Is there a missing class for it? I don't know Ruby very well so I am just guessing.

#7 Updated by Dominic Cleal almost 8 years ago

args[:nic] inside compute_attributes is nil (aka null), when it expects an array of NICs. "delete_if" is only valid on arrays, not nil. I thought "nics": [] should pass in an empty array, but the params log you pasted shows it's nil still.

#8 Updated by Brian Lee almost 8 years ago

So what else can I do? This is a major blocker on my project. Is there some sort of a a hack workaround I can put in until it is resolved?

#9 Updated by Brian Lee almost 8 years ago

I did a little hacking on that part of the code and I am now able to spin up a openstack VM with the API call:

 def create_vm(args = {})
      network = args.delete(:network)
      # fix internal network format for fog.
      #args[:nics].delete_if(&:blank?)
      args.delete(:nics)
      #args[:nics].map! {|nic| { 'net_id' => nic } }
      vm      = super(args)
      if network.present?
        address = allocate_address(network)
        assign_floating_ip(address, vm)
      end
      vm
    rescue => e
      message = JSON.parse(e.response.body)['badRequest']['message'] rescue (e.to_s)
      logger.warn "failed to create vm: #{message}" 
      destroy_vm vm.id if vm
      raise message
    end

I am sure this is not ideal, but it is working for me.

#10 Updated by Brian Lee almost 8 years ago

I upgraded to foreman 1.7.2 and now when you pass "nics":[""] into the JSON request you do not get the error. I would say it is fixed in 1.7.2 now.

#11 Updated by Dominic Cleal almost 8 years ago

  • Status changed from New to Resolved

That's good news, thanks for confirming Brian.

#12 Updated by The Foreman Bot almost 8 years ago

  • Pull request https://github.com/Katello/katello-installer/pull/176 added
  • Pull request deleted ()

#13 Updated by Stephen Benjamin almost 8 years ago

  • Pull request added
  • Pull request deleted (https://github.com/Katello/katello-installer/pull/176)

#14 Updated by Dominic Cleal about 7 years ago

  • Related to Bug #12320: Hammer CLI : Failed to create a new VM on OpenStack - undefined method `delete_if' for nil:NilClass added

Also available in: Atom PDF