The EC2 fact is completely broken at the moment:

* Timeout::Error isn't caught by rescue (due to how it inherits)
* The issue of wrong open semantics outlined here, this is causing hidden 
immediate failure
* The fact is going to cause a 2 second wait to every facter run

Whilst the following patch fixes the first two, I'm not sure we want to take
the timeout hit, we also want to add tests as even simple ruby code can get
logic errors such as the open().

Signed-off-by: Paul Nasrat <pnas...@googlemail.com>
---
 lib/facter/ec2.rb |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/facter/ec2.rb b/lib/facter/ec2.rb
index ef84757..447a4d8 100644
--- a/lib/facter/ec2.rb
+++ b/lib/facter/ec2.rb
@@ -6,8 +6,11 @@ require 'open-uri'
 require 'timeout'
 
 def can_connect?(ip,port,wait_sec=2)
- Timeout::timeout(wait_sec) {open(ip, port)}
+ url = "http://#{ip}:#{port}/";
+ Timeout::timeout(wait_sec) {open(url)}
  return true
+rescue Timeout::Error
+  return false
 rescue
   return false
 end
-- 
1.6.4.2

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to