Skip to content

Commit

Permalink
Fixes #21565 - Orchestration on fact import
Browse files Browse the repository at this point in the history
This adds the enable_orchestration_on_fact_import setting, which allows
a user to make Foreman perform host orchestration operations when a
host is updated from puppet fact upload
  • Loading branch information
fabianvf committed Nov 13, 2017
1 parent 5dcb9bc commit d254e22
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/host/managed.rb
Expand Up @@ -294,10 +294,10 @@ def handle_ca
def import_facts(facts, source_proxy = nil)
# Facts come from 'existing' attributes/infrastructure. We skip triggering
# the orchestration of this infrastructure when we create a host this way.
skip_orchestration! if SETTINGS[:unattended]
skip_orchestration! if SETTINGS[:unattended] && !SETTINGS[:enable_orchestration_on_fact_import]
super
ensure
enable_orchestration! if SETTINGS[:unattended]
enable_orchestration! if SETTINGS[:unattended] && !SETTINGS[:enable_orchestration_on_fact_import]
end

# Request a new OTP for a host
Expand Down
1 change: 1 addition & 0 deletions app/models/setting/provisioning.rb
Expand Up @@ -46,6 +46,7 @@ def self.default_settings
self.set('access_unattended_without_build', N_("Allow access to unattended URLs without build mode being used"), false, N_('Access unattended without build')),
self.set('manage_puppetca', N_("Foreman will automate certificate signing upon provision of new host"), true, N_('Manage PuppetCA')),
self.set('ignore_puppet_facts_for_provisioning', N_("Stop updating IP address and MAC values from Puppet facts (affects all interfaces)"), false, N_('Ignore Puppet facts for provisioning')),
self.set('enable_orchestration_on_fact_import', N_("Enable host orchestration on puppet fact import. This could cause serious performance issues as the number of hosts increase"), false, N_('Enable orchestration on puppet fact import')),
self.set('ignored_interface_identifiers', N_("Ignore interfaces that match these values during facts importing, you can use * wildcard to match names with indexes e.g. macvtap*"), IGNORED_INTERFACES, N_('Ignore interfaces with matching identifier')),
self.set('ignore_facts_for_operatingsystem', N_("Stop updating Operating System from facts"), false, N_('Ignore facts for operating system')),
self.set('ignore_facts_for_domain', N_("Stop updating domain values from facts"), false, N_('Ignore facts for domain')),
Expand Down
37 changes: 37 additions & 0 deletions test/models/host_test.rb
Expand Up @@ -163,6 +163,43 @@ def teardown
end
end

context "when enable_orchestration_on_fact_import is true" do
def setup
SETTINGS[:enable_orchestration_on_fact_import] = true
end

def teardown
SETTINGS[:enable_orchestration_on_fact_import] = false
end

test "should trigger orchestration when importing facts if enable_orchestration_on_fact_import is true" do
refute Host.find_by_name('sinn1636.lan')
raw = read_json_fixture('facts/facts_with_certname.json')
host = Host.import_host(raw['name'], 'puppet')
host.stubs(:skip_orchestration_for_testing?).returns(false) # Explicitly enable orchestration

host.expects(:skip_orchestration!).never
host.expects(:skip_orchestration?).at_least_once.returns(false)
host.expects(:queue).at_least_once

assert host.import_facts(raw['facts'])
end
end

test "should not trigger orchestration when importing facts if enable_orchestration_on_fact_import is false" do
refute Host.find_by_name('sinn1636.lan')
raw = read_json_fixture('facts/facts_with_certname.json')
host = Host.import_host(raw['name'], 'puppet')
host.stubs(:skip_orchestration_for_testing?).returns(false) # Explicitly enable orchestration

host.expects(:skip_orchestration!).at_least_once
host.expects(:skip_orchestration?).at_least_once.returns(true)
host.expects(:enable_orchestration!).at_least_once
host.expects(:queue).never

assert host.import_facts(raw['facts'])
end

test "should be able to save host" do
host = Host.create :name => "myfullhost", :mac => "aabbecddeeff", :ip => "3.3.4.3",
:domain => domains(:mydomain), :operatingsystem => operatingsystems(:redhat), :medium => media(:one),
Expand Down

0 comments on commit d254e22

Please sign in to comment.