Project

General

Profile

« Previous | Next » 

Revision 9883149a

Added by Amir Fefer over 7 years ago

Fixes #6952 - Set hostgroup after provisioning from pxe

After hostgroup provisioning, when the machine has registered
with foreman, it should be in the same hostgroup.
to achieve this behavier, the fact foreman_hostgroup should be
added to hostgroup provisioning template

View differences:

test/controllers/api/v2/hosts_controller_test.rb
assert_response :unprocessable_entity
end
test 'set hostgroup when foreman_hostgroup present in facts' do
Setting[:create_new_host_when_facts_are_uploaded] = true
hostgroup = FactoryGirl.create(:hostgroup)
hostname = fact_json['name']
facts = fact_json['facts']
facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}
assert_response :success
assert_equal hostgroup, Host.find_by(:name => hostname).hostgroup
end
test 'assign hostgroup attributes when foreman_hostgroup present in facts' do
Setting[:create_new_host_when_facts_are_uploaded] = true
hostgroup = FactoryGirl.create(:hostgroup, :with_rootpass)
hostname = fact_json['name']
facts = fact_json['facts']
facts['foreman_hostgroup'] = hostgroup.title
post :facts, {:name => hostname, :facts => facts}
assert_response :success
assert_equal hostgroup.root_pass, Host.find_by(:name => hostname).root_pass
end
test 'when ":restrict_registered_smart_proxies" is false, HTTP requests should be able to import facts' do
User.current = users(:one) #use an unprivileged user, not apiadmin
Setting[:restrict_registered_smart_proxies] = false

Also available in: Unified diff