diff --git a/app/models/host/managed.rb b/app/models/host/managed.rb index 41a485ce437..9b5d059d229 100644 --- a/app/models/host/managed.rb +++ b/app/models/host/managed.rb @@ -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 diff --git a/app/models/setting/provisioning.rb b/app/models/setting/provisioning.rb index 33f1a604df7..29af67f1736 100644 --- a/app/models/setting/provisioning.rb +++ b/app/models/setting/provisioning.rb @@ -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')), diff --git a/test/models/host_test.rb b/test/models/host_test.rb index 41bd5135a3e..c920cc80f37 100644 --- a/test/models/host_test.rb +++ b/test/models/host_test.rb @@ -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),