Correctly set hostgroup after provisioning from PXE menu
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1127164
Description of problem:
When we provision from the standard PXE menu, we can choose which hostgroup template to install the new server from.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Create some hostgroups with associated content views and lifecycle environments
2. Build the PXE default menu from the Provisioning Templates screen
3. PXE boot a new server
4. From the boot menu, select a hostgroup boot option
Machine boots and installs, however once it has registered with foreman, it is not in a hostgroup
The newly installed machine should be in the same hostgroup that we selected in the PXE menu.
p0 -l -f << EOF /usr/share/foreman/app/models/host/managed.rb 2014-08-06 08:24:18.912311511 + /usr/share/foreman/app/models/host/managed.rb 2014-08-06 09:06:02.716311124 +0000
@ -404,6 +404,14 @
host ||= Host.new(:name => hostname, :certname => certname) if Setting[:create_new_host_when_facts_are_uploaded]
# set hostgroup defaults if provided by a fact
+ if facts.keys.include?(hostgroup_fact)
+ host.hostgroup = Hostgroup.find_by_title(facts[hostgroup_fact])
- if we were given a certname but found the Host by hostname we should update the certname
host.certname = certname if certname.present?