Please review pull request #450: (#12396) DRY up self.timeout opened by (jeffweiss)
Description:
Move duplicate definitions of self.timeout into newly created module.
- Opened: Thu Feb 02 23:58:58 UTC 2012
- Based on: puppetlabs:master (ca50b7cd625d654265138ca07106317180ec4c04)
- Requested merge: jeffweiss:ticket/master/12396_dry_up_self.timeout (84884a8f7941f24abd7a7daac1e78d9aa059ba8d)
Diff follows:
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index f314fa3..a2d6c8f 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -7,10 +7,15 @@
class Puppet::Configurer
require 'puppet/configurer/fact_handler'
require 'puppet/configurer/plugin_handler'
+ require 'puppet/util/config_timeout'
include Puppet::Configurer::FactHandler
include Puppet::Configurer::PluginHandler
+ class <<self
+ include Puppet::Util::ConfigTimeout
+ end
+
# For benchmarking
include Puppet::Util
@@ -198,23 +203,6 @@ def save_last_run_summary(report)
private
- def self.timeout
- timeout = Puppet[:configtimeout]
- case timeout
- when String
- if timeout =~ /^\d+$/
- timeout = Integer(timeout)
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
- when Integer # nothing
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
-
- timeout
- end
-
def execute_from_setting(setting)
return true if (command = Puppet[setting]) == ""
diff --git a/lib/puppet/configurer/downloader.rb b/lib/puppet/configurer/downloader.rb
index 54075ee..89e07d6 100644
--- a/lib/puppet/configurer/downloader.rb
+++ b/lib/puppet/configurer/downloader.rb
@@ -2,25 +2,12 @@
require 'puppet/resource/catalog'
class Puppet::Configurer::Downloader
- attr_reader :name, :path, :source, :ignore
-
- # Determine the timeout value to use.
- def self.timeout
- timeout = Puppet[:configtimeout]
- case timeout
- when String
- if timeout =~ /^\d+$/
- timeout = Integer(timeout)
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
- when Integer # nothing
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
-
- timeout
+ require 'puppet/util/config_timeout'
+ class <<self
+ include Puppet::Util::ConfigTimeout
end
+
+ attr_reader :name, :path, :source, :ignore
# Evaluate our download, returning the list of changed values.
def evaluate
@@ -28,7 +15,7 @@ def evaluate
files = []
begin
- Timeout.timeout(self.class.timeout) do
+ ::Timeout.timeout(self.class.timeout) do
catalog.apply do |trans|
trans.changed?.find_all do |resource|
yield resource if block_given?
diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb
index e41ef02..407d2a0 100644
--- a/lib/puppet/indirector/facts/facter.rb
+++ b/lib/puppet/indirector/facts/facter.rb
@@ -2,6 +2,10 @@
require 'puppet/indirector/code'
class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
+ require 'puppet/util/config_timeout'
+ class <<self
+ include Puppet::Util::ConfigTimeout
+ end
desc "Retrieve facts from Facter. This provides a somewhat abstract interface
between Puppet and Facter. It's only `somewhat` abstract because it always
returns the local host's facts, regardless of what you attempt to find."
@@ -44,7 +48,7 @@ def self.load_facts_in_dir(dir)
fqfile = ::File.join(dir, file)
begin
Puppet.info "Loading facts in #{fqfile}"
- Timeout::timeout(self.timeout) do
+ ::Timeout::timeout(self.timeout) do
load file
end
rescue SystemExit,NoMemoryError
@@ -56,23 +60,6 @@ def self.load_facts_in_dir(dir)
end
end
- def self.timeout
- timeout = Puppet[:configtimeout]
- case timeout
- when String
- if timeout =~ /^\d+$/
- timeout = Integer(timeout)
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
- when Integer # nothing
- else
- raise ArgumentError, "Configuration timeout must be an integer"
- end
-
- timeout
- end
-
def destroy(facts)
raise Puppet::DevError, "You cannot destroy facts in the code store; it is only used for getting facts from Facter"
end
diff --git a/lib/puppet/util/config_timeout.rb b/lib/puppet/util/config_timeout.rb
new file mode 100644
index 0000000..6e05ea2
--- /dev/null
+++ b/lib/puppet/util/config_timeout.rb
@@ -0,0 +1,18 @@
+module Puppet::Util::ConfigTimeout
+ def timeout
+ timeout = Puppet[:configtimeout]
+ case timeout
+ when String
+ if timeout =~ /^\d+$/
+ timeout = Integer(timeout)
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+ when Integer # nothing
+ else
+ raise ArgumentError, "Configuration timeout must be an integer"
+ end
+
+ timeout
+ end
+end
\ No newline at end of file
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
