Actions
Bug #16578
closedResolve templates button throws undefined method `[]' for nil:NilClass on image hosts
Description
- Go to New Host, choose a compute resource with image support
- Fill in OS details, select Image Based provisioning method
- Click Resolve (templates) button
This results in a server error and "Sorry but no templates were configured":
2016-09-16T11:09:44 4ccec210 [app] [I] Started POST "/hosts/template_used?provisioning=image" for 127.0.0.1 at 2016-09-16 11:09:44 +0100 2016-09-16T11:09:46 4ccec210 [app] [I] Processing by HostsController#template_used as */* 2016-09-16T11:09:46 4ccec210 [app] [I] Parameters: {"utf8"=>"✓", "authenticity_token"=>"[..]=", "host"=>{"name"=>"jose-schleppy", "hostgroup_id"=>"6", "compute_resource_id"=>"1", "config_group_ids"=>[""], "puppetclass_ids"=>[""], "managed"=>"true", "progress_report_id"=>"[FILTERED]", "type"=>"Host::Managed", "interfaces_attributes"=>{"0"=>{"_destroy"=>"0", "type"=>"Nic::Managed", "mac"=>"", "identifier"=>"", "name"=>"jose-schleppy", "domain_id"=>"6", "subnet_id"=>"4", "subnet6_id"=>"", "ip"=>"", "ip6"=>"", "managed"=>"1", "primary"=>"1", "provision"=>"1", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>{"type"=>"network", "network"=>"default", "bridge"=>"", "model"=>"virtio"}}, "new_interfaces"=>{"_destroy"=>"1", "type"=>"Nic::Managed", "mac"=>"", "identifier"=>"", "name"=>"", "domain_id"=>"", "subnet_id"=>"", "subnet6_id"=>"", "ip"=>"", "ip6"=>"", "managed"=>"1", "primary"=>"0", "provision"=>"0", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>{"type"=>"bridge", "bridge"=>"", "model"=>"virtio"}}}, "compute_attributes"=>{"cpus"=>"3", "memory"=>"1073741824", "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"=>"qcow2"}}, "image_id"=>"/home/libvirt/foreman_template.img"}, "architecture_id"=>"1", "operatingsystem_id"=>"6", "provision_method"=>"image", "build"=>"1", "medium_id"=>"1", "ptable_id"=>"86", "pxe_loader"=>"PXELinux BIOS", "disk"=>"", "root_pass"=>"[FILTERED]", "is_owned_by"=>"24-Users", "enabled"=>"1", "model_id"=>"", "comment"=>"", "overwrite"=>"false"}, "capabilities"=>"build image", "provider"=>"Libvirt", "fakepassword"=>"[FILTERED]", "bare_metal_capabilities"=>"build", "provisioning"=>"image"} 2016-09-16T11:09:46 4ccec210 [sql] [D] ActiveRecord::SessionStore::Session Load (0.2ms) SELECT "sessions".* FROM "sessions" WHERE "sessions"."session_id" = ? ORDER BY "sessions"."id" ASC LIMIT 1 [["session_id", "[..]"]] 2016-09-16T11:09:46 4ccec210 [sql] [D] ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations" 2016-09-16T11:09:46 4ccec210 [sql] [D] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 24]] 2016-09-16T11:09:46 4ccec210 [app] [D] Setting current user thread-local variable to admin 2016-09-16T11:09:46 4ccec210 [sql] [D] AuthSource Load (0.3ms) SELECT "auth_sources".* FROM "auth_sources" WHERE "auth_sources"."id" = ? LIMIT 1 [["id", 1]] 2016-09-16T11:09:46 4ccec210 [sql] [D] User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY firstname LIMIT 1 [["id", 24]] 2016-09-16T11:09:46 4ccec210 [sql] [D] ComputeResource Load (0.2ms) SELECT "compute_resources".* FROM "compute_resources" WHERE "compute_resources"."id" = ? ORDER BY compute_resources.name LIMIT 1 [["id", 1]] 2016-09-16T11:09:46 4ccec210 [sql] [D] Image Load (0.2ms) SELECT "images".* FROM "images" WHERE "images"."compute_resource_id" = ? [["compute_resource_id", 1]] 2016-09-16T11:09:46 4ccec210 [app] [I] Completed 500 Internal Server Error in 411ms (ActiveRecord: 5.5ms) 2016-09-16T11:09:46 4ccec210 [app] [F] | NoMethodError (undefined method `[]' for nil:NilClass): | app/models/host/managed.rb:793:in `available_template_kinds' | app/controllers/hosts_controller.rb:687:in `template_used' | app/controllers/concerns/application_shared.rb:14:in `set_timezone' | app/models/concerns/foreman/thread_session.rb:32:in `clear_thread' | lib/middleware/catch_json_parse_errors.rb:8:in `call' | lib/middleware/tagged_logging.rb:18:in `call'
It appears that host_params
is called multiple times in the controller's template_used method, and only includes compute_attributes
on the first call (keep_param deletes it from the source params hash).
Actions