Pulled some puppetrun logic into another class

Not totally happy, but baby step towards putting everything into testable 
classes

Signed-off-by: Andrew Shafer <[EMAIL PROTECTED]>
---
 bin/puppetrun                        |   16 ++++++----------
 lib/puppet/executables/ldap_hosts.rb |   21 +++++++++++++++++++++
 spec/unit/executables/ldap_hosts.rb  |   26 ++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 10 deletions(-)
 create mode 100644 lib/puppet/executables/ldap_hosts.rb
 create mode 100644 spec/unit/executables/ldap_hosts.rb

diff --git a/bin/puppetrun b/bin/puppetrun
index 28f72d9..f101ec5 100755
--- a/bin/puppetrun
+++ b/bin/puppetrun
@@ -245,18 +245,14 @@ end
 # Now parse the config
 Puppet.parse_config
 
-if Puppet[:node_terminus] == "ldap" and (options[:all] or classes)
+if Puppet[:node_terminus] == "ldap"
+    require 'puppet/executables/ldap_nodes'
     if options[:all]
-        hosts = Puppet::Node.search("whatever").collect { |node| node.name }
-        puts "all: %s" % hosts.join(", ")
+        hosts = Puppet::Executables::LDAPNodes.get_all_hosts 
+    elsif ! classes.empty?
+        hosts = Puppet::Executables::LDAPNodes.get_hosts_for_classes(classes)
     else
-        hosts = []
-        classes.each do |klass|
-            list = Puppet::Node.search("whatever", :class => klass).collect { 
|node| node.name }
-            puts "%s: %s" % [klass, list.join(", ")]
-
-            hosts += list
-        end
+        $stderr.puts "puppetrun with ldap nodes without all or classes"
     end
 elsif ! classes.empty?
     $stderr.puts "You must be using LDAP to specify host classes"
diff --git a/lib/puppet/executables/ldap_hosts.rb 
b/lib/puppet/executables/ldap_hosts.rb
new file mode 100644
index 0000000..6389c06
--- /dev/null
+++ b/lib/puppet/executables/ldap_hosts.rb
@@ -0,0 +1,21 @@
+module Puppet
+    module Executables
+        class LDAPHosts 
+            def self.get_all_hosts
+                hosts = Puppet::Node.search("whatever").collect { |node| 
node.name }
+                puts "all: %s" % hosts.join(", ")
+                hosts
+            end
+            
+            def self.get_hosts_for_classes(classes)
+                hosts = []
+                classes.each do |klass|
+                    list = Puppet::Node.search("whatever", :class => 
klass).collect { |node| node.name }
+                    puts "%s: %s" % [klass, list.join(", ")]
+                    hosts += list
+                end
+                hosts
+            end
+        end
+    end
+end
diff --git a/spec/unit/executables/ldap_hosts.rb 
b/spec/unit/executables/ldap_hosts.rb
new file mode 100644
index 0000000..e125b12
--- /dev/null
+++ b/spec/unit/executables/ldap_hosts.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? 
require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/executables/ldap_hosts'
+
+
+ldap_hosts = Puppet::Executables::LDAPHosts
+
+classes = ["a", "b", "c"]
+
+describe ldap_hosts do
+    describe "when gettin hosts using LDAP" do
+            it "get_all_hosts should call Puppet.Node.search(whatever)" do
+                Puppet::Node.expects(:search).with("whatever").returns([])
+                ldap_hosts.get_all_hosts
+            end
+
+            it "get_hosts_for_classes should call Puppet::Node.search with a 
hash for each class" do
+                classes.each do |klass|
+                   Puppet::Node.expects(:search).with("whatever", :class => 
klass).returns([])
+                end
+                ldap_hosts.get_hosts_for_classes(classes)
+            end
+    end
+end
-- 
1.5.3.7


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to