summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/interface/cisco_spec.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2011-01-03 19:47:03 +0100
committerJames Turnbull <james@lovedthanlost.net>2011-04-08 18:19:54 +1000
commit1cb18410732a4b51efa0a106d4a1437daef08fc5 (patch)
treef1a66bfa5abfe1631211d51ffdec00038cc93054 /spec/unit/provider/interface/cisco_spec.rb
parent596571fd2b03957e7ed185856ee649c1e610716c (diff)
downloadpuppet-1cb18410732a4b51efa0a106d4a1437daef08fc5.tar.gz
puppet-1cb18410732a4b51efa0a106d4a1437daef08fc5.tar.xz
puppet-1cb18410732a4b51efa0a106d4a1437daef08fc5.zip
Cisco Switch/Router Interface management
This patch introduces managing remotely cisco IOS network devices through ssh or telnet with a puppet type/provider. This patch allows to manage router/switch interface with the interface type: interface { "FastEthernet 0/1": device_url => "ssh://user:pass@cisco2960.domain.com/", mode => trunk, encapsulation => dot1q, trunk_allowed_vlans => "1-99,200,253", description => "to back bone router" } It is possible with this patch to set interface: * mode (access or trunk) * native vlan (only for access mode) * speed (auto or a given speed) * duplex (auto, half or full) * trunk encapsulation * allowed trunk vlan * ipv4 addresses * ipv6 addresses * etherchannel membership The interface name (at least for the cisco provider) can be any shorthand interface name a switch or router can use. The device url should conform to: * scheme: either telnet or ssh * user: can be absent depending on switch/router line config * pass: must be present * port: optional * an optional enable password can be mentioned in the url query string Ex: To connect to a switch with a line password and an enable password: "telnet://:letmein@cisco29224XL.domain.com/?enable=letmeinagain" To connect to a switch/router through ssh and a privileged user: "ssh://brice:letmein@cisco1841L.domain.com/" Note: This patch only includes a Cisco IOS provider. Also terminology adopted in the various types are mostly the ones used in Cisco devices. This patch was tested against: * (really old) Cisco switch 2924XL with ios 12.0(5)WC10 * Cisco router 1841 with ios 12.4(15)T8 * Cisco router 877 with ios 12.4(11)XJ4 * Cisco switch 2960G with ios 12.2(44)SE Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit/provider/interface/cisco_spec.rb')
-rw-r--r--spec/unit/provider/interface/cisco_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/unit/provider/interface/cisco_spec.rb b/spec/unit/provider/interface/cisco_spec.rb
new file mode 100644
index 000000000..7904711f5
--- /dev/null
+++ b/spec/unit/provider/interface/cisco_spec.rb
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/provider/interface/cisco'
+
+provider_class = Puppet::Type.type(:interface).provider(:cisco)
+
+describe provider_class do
+ before do
+ @resource = stub("resource", :name => "Fa0/1")
+ @provider = provider_class.new(@resource)
+ end
+
+ it "should have a parent of Puppet::Provider::NetworkDevice" do
+ provider_class.should < Puppet::Provider::NetworkDevice
+ end
+
+ it "should have an instances method" do
+ provider_class.should respond_to(:instances)
+ end
+
+ describe "when looking up instances at prefetch" do
+ before do
+ @device = stub_everything 'device'
+ Puppet::Util::NetworkDevice::Cisco::Device.stubs(:new).returns(@device)
+ @device.stubs(:command).yields(@device)
+ end
+
+ it "should initialize the network device with the given url" do
+ Puppet::Util::NetworkDevice::Cisco::Device.expects(:new).with(:url).returns(@device)
+ provider_class.lookup(:url, "Fa0/1")
+ end
+
+ it "should delegate to the device interface fetcher" do
+ @device.expects(:interface)
+ provider_class.lookup("", "Fa0/1")
+ end
+
+ it "should return the given interface data" do
+ @device.expects(:interface).returns({ :description => "thisone", :mode => :access})
+ provider_class.lookup("", "Fa0").should == {:description => "thisone", :mode => :access }
+ end
+
+ end
+
+ describe "when an instance is being flushed" do
+ it "should call the device interface update method with current and past properties" do
+ @instance = provider_class.new(:ensure => :present, :name => "Fa0/1", :description => "myinterface")
+ @instance.description = "newdesc"
+ @instance.resource = @resource
+ @resource.stubs(:[]).with(:name).returns("Fa0/1")
+ device = stub_everything 'device'
+ @instance.stubs(:device).returns(device)
+ device.expects(:command).yields(device)
+ interface = stub 'interface'
+ device.expects(:new_interface).with("Fa0/1").returns(interface)
+ interface.expects(:update).with( {:ensure => :present, :name => "Fa0/1", :description => "myinterface"},
+ {:ensure => :present, :name => "Fa0/1", :description => "newdesc"})
+
+ @instance.flush
+ end
+ end
+end