Bug #20374
closedImage templates don't resolve any more during host creation
Description
Foreman version 1.15-2 with a Vmware compute resource that used to work with 1.14.2/3
To reproduce:
Create a template in Vmware, windows2012R2 in my case. Add the image to compute resource/images
Create a host based on the image and on the tab Operating System tick the radio button Image Based, make sure that the required fields are filled with info and hit the Provisioning templates Resolve button --> Sorry but no templates were configured. despite the fact that all was working well with 1.14.2/3
The following stacktrace is found in production.log:
2017-07-21 10:36:19 ac197707 [app] [W] Action failed | NoMethodError: undefined method `[]' for nil:NilClass | /usr/share/foreman/app/models/concerns/hostext/operating_system.rb:47:in `template_kinds' | /usr/share/foreman/app/models/concerns/hostext/operating_system.rb:26:in `available_template_kinds' | /usr/share/foreman/app/controllers/hosts_controller.rb:649:in `template_used' | /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/implicit_render.rb:4:in `send_action' | /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/abstract_controller/base.rb:198:in `process_action' | /opt/rh/sclo-ror42/root/usr/share/gems/gems/actionpack-4.2.5.1/lib/action_controller/metal/rendering.rb:10:in `process_action'
And if I modify the following file (/usr/share/foreman/app/models/concerns/hostext/operating_system.rb) to use some logging.info lines then I get the following:
2017-07-21 10:48:37 54f7774f [app] [I] In Available_template_kinds 2017-07-21 10:48:37 54f7774f [app] [I] Template_kinds start parameter= image. 2017-07-21 10:48:37 54f7774f [app] [I] Computeresource is: VMWare (VMware). 2017-07-21 10:48:37 54f7774f [app] [I] Images: #<Image::ActiveRecord_Associations_CollectionProxy:0x0000000d34dd68>. 2017-07-21 10:48:37 54f7774f [app] [I] Before UUID. 2017-07-21 10:48:37 54f7774f [app] [W] Action failed | NoMethodError: undefined method `[]' for nil:NilClass | /usr/share/foreman/app/models/concerns/hostext/operating_system.rb:48:in `template_kinds' | /usr/share/foreman/app/models/concerns/hostext/operating_system.rb:27:in `available_template_kinds'
def template_kinds(provisioning = nil)
logger.info "Template_kinds start parameter= #{provisioning}."
return TemplateKind.all unless provisioning == 'image'
cr = ComputeResource.find_by_id(self.compute_resource_id)
logger.info "Computeresource is: #{cr}."
images = cr.try(:images)
logger.info "Images: #{images}."
if images.blank?
[TemplateKind.friendly.find('finish')]
else
logger.info "Before UUID."
uuid = self.compute_attributes[cr.image_param_name]
logger.info "After UUID, uuid=: #{uuid}."
image_kind = images.find_by_uuid(uuid).try(:user_data) ? 'user_data' : 'finish'
logger.info "Imagekind: #{image_kind} (finish omdat uuid =nil)."
[TemplateKind.friendly.find(image_kind)]
end
end
Looks like the uuid can't be filled but if I use foreman-rake console then I can see that images does have an uuid for this compute resource.
Updated by Joop van de Wege over 7 years ago
Ignoring the Red message and hitting Submit will roll out a new Window VM on our Vmware platform with use of the template.
Updated by Marek Hulán over 7 years ago
Are you provisioning the host under admin user? Do you use some organizations/locations?
Updated by Greg Sutcliffe over 7 years ago
Marek, I've seen this with image-based provisioning on Libvirt - my hunch is that the UUID doesn't exist when you click Resolve (since the VM doesn't exist yet, the request hasn't been submitted to Fog)
Updated by Greg Sutcliffe over 7 years ago
Oops, forgot to mention - this is with an admin user, no taxonomies.
Updated by Greg Sutcliffe over 7 years ago
Looks like this line didn't survive the refactoring:
I'm not sure what `uuid` is set to in the current code, which is why I suspect it's wrong ... ;)
EDIT: misread, sorry. Still looking.
Updated by Greg Sutcliffe over 7 years ago
OK, out of time to debug this just now - but `self.compute_attributes` is definitely `nil`. The code finds the right CR and it's image list, but then bombs out after that. I see the attrs in the request though:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", ...,
"compute_attributes"=>{
"cpus"=>"1",
"memory"=>"805306368",
"start"=>"1",
"volumes_attributes"=>{
"new_volumes"=>{"_delete"=>"", "pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"raw"},
"0"=>{"_delete"=>"", "pool_name"=>"default", "capacity"=>"10G", "allocation"=>"0G", "format_type"=>"raw"}}, "image_id"=>"/var/lib/libvirt/images/packer-jessie-shrunk.qcow2"},
"capabilities"=>"build image",
"provider"=>"Libvirt",
"fakepassword"=>"[FILTERED]",
"bare_metal_capabilities"=>"build",
"provisioning"=>"image"
}
}
Updated by Nora Vord over 7 years ago
- Priority changed from Normal to High
I can confirm this issue. It happens (after upgrade and also new installation) on Debian and CentOS.
I think changing the priority to high is appropriate because vmware provisioning is not possible anymore
Updated by Anonymous over 7 years ago
- Related to Bug #20098: Cannot resolve user_data template with all kind of compute-resource added
Updated by Anonymous over 7 years ago
- Related to Bug #18557: Image based provisioning broken added
Updated by Tomer Brisker about 7 years ago
- Status changed from New to Need more information
Is this still present after 1.15.4 or is it a duplicate of #20098?
Updated by Joop van de Wege about 7 years ago
I don't have access to a VMWare environment anymore but a quick test on my own oVirt cluster didn't show any problems with using an image, atleast with version 1.16.
Regards,
Joop
Updated by Daniel Lobato Garcia about 7 years ago
- Status changed from Need more information to Closed
Closing as duplicate of #20098 - https://github.com/theforeman/foreman/pull/4808 fixes the error mentioned in the logs here by Greg.
Updated by Daniel Lobato Garcia about 7 years ago
- Related to deleted (Bug #20098: Cannot resolve user_data template with all kind of compute-resource)
Updated by Daniel Lobato Garcia about 7 years ago
- Is duplicate of Bug #20098: Cannot resolve user_data template with all kind of compute-resource added
Updated by Tomer Brisker about 7 years ago
- Status changed from Closed to Duplicate