[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
James Turnbull
james at lovedthanlost.net
Tue May 10 08:11:40 UTC 2011
The following commit has been merged in the experimental branch:
commit c947a6dee2134964e04146d6da7b1d1c4f814169
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date: Mon Jan 3 19:48:18 2011 +0100
Remote Network Device transport system
This is the base for upcoming telnet and ssh transport mechanism
to send commands to network devices.
Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>
diff --git a/lib/puppet/util/network_device/transport.rb b/lib/puppet/util/network_device/transport.rb
new file mode 100644
index 0000000..e64fe9b
--- /dev/null
+++ b/lib/puppet/util/network_device/transport.rb
@@ -0,0 +1,5 @@
+# stub
+module Puppet::Util::NetworkDevice
+ module Transport
+ end
+end
\ No newline at end of file
diff --git a/lib/puppet/util/network_device/transport/base.rb b/lib/puppet/util/network_device/transport/base.rb
new file mode 100644
index 0000000..1d62209
--- /dev/null
+++ b/lib/puppet/util/network_device/transport/base.rb
@@ -0,0 +1,26 @@
+
+require 'puppet/util/network_device'
+require 'puppet/util/network_device/transport'
+
+class Puppet::Util::NetworkDevice::Transport::Base
+ attr_accessor :user, :password, :host, :port
+ attr_accessor :default_prompt, :timeout
+
+ def initialize
+ @timeout = 10
+ end
+
+ def send(cmd)
+ end
+
+ def expect(prompt)
+ end
+
+ def command(cmd, options = {})
+ send(cmd)
+ expect(options[:prompt] || default_prompt) do |output|
+ yield output if block_given?
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/spec/unit/util/network_device/transport/base_spec.rb b/spec/unit/util/network_device/transport/base_spec.rb
new file mode 100644
index 0000000..5d52574
--- /dev/null
+++ b/spec/unit/util/network_device/transport/base_spec.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device/transport/base'
+
+describe Puppet::Util::NetworkDevice::Transport::Base do
+ class TestTransport < Puppet::Util::NetworkDevice::Transport::Base
+ end
+
+ before(:each) do
+ @transport = TestTransport.new
+ end
+
+ describe "when sending commands" do
+ it "should send the command to the telnet session" do
+ @transport.expects(:send).with("line")
+ @transport.command("line")
+ end
+
+ it "should expect an output matching the given prompt" do
+ @transport.expects(:expect).with(/prompt/)
+ @transport.command("line", :prompt => /prompt/)
+ end
+
+ it "should expect an output matching the default prompt" do
+ @transport.default_prompt = /defprompt/
+ @transport.expects(:expect).with(/defprompt/)
+ @transport.command("line")
+ end
+
+ it "should yield telnet output to the given block" do
+ @transport.expects(:expect).yields("output")
+ @transport.command("line") { |out| out.should == "output" }
+ end
+
+ it "should return telnet output to the caller" do
+ @transport.expects(:expect).returns("output")
+ @transport.command("line").should == "output"
+ end
+ end
+end
\ No newline at end of file
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list