summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2011-01-02 19:26:19 +0100
committerJames Turnbull <james@lovedthanlost.net>2011-04-08 18:19:54 +1000
commit28e3db87a105eba5eddbb11167d0a6c33b18f8ce (patch)
tree528522c0f8f73fdd88facbc4dfe27cc05444554d /spec
parent1cb18410732a4b51efa0a106d4a1437daef08fc5 (diff)
downloadpuppet-28e3db87a105eba5eddbb11167d0a6c33b18f8ce.tar.gz
puppet-28e3db87a105eba5eddbb11167d0a6c33b18f8ce.tar.xz
puppet-28e3db87a105eba5eddbb11167d0a6c33b18f8ce.zip
Add management of router/switchs global vlans
This allows to manage the global device list of vlans. Currently supports only cisco IOS devices. This is as easy as: Vlan { device_url => "ssh://user:pass@switch.domain.com/" } vlan { "200": description => "R&D"; "99": description => "Management"; } The device_url conforms to the same specs as for the interface type. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/vlan/cisco_spec.rb62
-rw-r--r--spec/unit/type/vlan_spec.rb40
-rw-r--r--spec/unit/util/network_device/cisco/device_spec.rb22
3 files changed, 123 insertions, 1 deletions
diff --git a/spec/unit/provider/vlan/cisco_spec.rb b/spec/unit/provider/vlan/cisco_spec.rb
new file mode 100644
index 000000000..0951367e6
--- /dev/null
+++ b/spec/unit/provider/vlan/cisco_spec.rb
@@ -0,0 +1,62 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/provider/vlan/cisco'
+
+provider_class = Puppet::Type.type(:vlan).provider(:cisco)
+
+describe provider_class do
+ before do
+ @resource = stub("resource", :name => "200")
+ @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, "200")
+ end
+
+ it "should delegate to the device vlans" do
+ @device.expects(:parse_vlans)
+ provider_class.lookup("", "200")
+ end
+
+ it "should return only the given vlan" do
+ @device.expects(:parse_vlans).returns({"200" => { :description => "thisone" }, "1" => { :description => "nothisone" }})
+ provider_class.lookup("", "200").should == {:description => "thisone" }
+ end
+
+ end
+
+ describe "when an instance is being flushed" do
+ it "should call the device update_vlan method with its vlan id, current attributes, and desired attributes" do
+ @instance = provider_class.new(:ensure => :present, :name => "200", :description => "myvlan")
+ @instance.description = "myvlan2"
+ @instance.resource = @resource
+ @resource.stubs(:[]).with(:name).returns("200")
+ device = stub_everything 'device'
+ @instance.stubs(:device).returns(device)
+ device.expects(:command).yields(device)
+ device.expects(:update_vlan).with(@instance.name, {:ensure => :present, :name => "200", :description => "myvlan"},
+ {:ensure => :present, :name => "200", :description => "myvlan2"})
+
+ @instance.flush
+ end
+ end
+end
diff --git a/spec/unit/type/vlan_spec.rb b/spec/unit/type/vlan_spec.rb
new file mode 100644
index 000000000..607d7116d
--- /dev/null
+++ b/spec/unit/type/vlan_spec.rb
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Type.type(:vlan) do
+ it "should have a 'name' parameter'" do
+ Puppet::Type.type(:vlan).new(:name => "200")[:name].should == "200"
+ end
+
+ it "should have a 'device_url' parameter'" do
+ Puppet::Type.type(:vlan).new(:name => "200", :device_url => :device)[:device_url].should == :device
+ end
+
+ it "should have an ensure property" do
+ Puppet::Type.type(:vlan).attrtype(:ensure).should == :property
+ end
+
+ it "should have a description property" do
+ Puppet::Type.type(:vlan).attrtype(:description).should == :property
+ end
+
+ describe "when validating attribute values" do
+ before do
+ @provider = stub 'provider', :class => Puppet::Type.type(:vlan).defaultprovider, :clear => nil
+ Puppet::Type.type(:vlan).defaultprovider.stubs(:new).returns(@provider)
+ end
+
+ it "should support :present as a value to :ensure" do
+ Puppet::Type.type(:vlan).new(:name => "200", :ensure => :present)
+ end
+
+ it "should support :absent as a value to :ensure" do
+ Puppet::Type.type(:vlan).new(:name => "200", :ensure => :absent)
+ end
+
+ it "should fail if vlan name is not a number" do
+ lambda { Puppet::Type.type(:vlan).new(:name => "notanumber", :ensure => :present) }.should raise_error
+ end
+ end
+end
diff --git a/spec/unit/util/network_device/cisco/device_spec.rb b/spec/unit/util/network_device/cisco/device_spec.rb
index 9021bbd2c..31aec920e 100644
--- a/spec/unit/util/network_device/cisco/device_spec.rb
+++ b/spec/unit/util/network_device/cisco/device_spec.rb
@@ -150,6 +150,26 @@ eos
end
end
+ describe "when updating device vlans" do
+ describe "when removing a vlan" do
+ it "should issue the no vlan command" do
+ @transport.expects(:command).with("no vlan 200")
+ @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :absent})
+ end
+ end
+
+ describe "when updating a vlan" do
+ it "should issue the vlan command to enter global vlan modifications" do
+ @transport.expects(:command).with("vlan 200")
+ @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :present, :name => "200"})
+ end
+
+ it "should issue the name command to modify the vlan description" do
+ @transport.expects(:command).with("name myvlan")
+ @cisco.update_vlan("200", {:ensure => :present, :name => "200"}, { :ensure=> :present, :name => "200", :description => "myvlan"})
+ end
+ end
+ end
describe "when parsing interface" do
@@ -228,7 +248,7 @@ VLAN Name Status Ports
Switch#
eos
- @cisco.parse_vlans.should == {"100"=>{:status=>"active", :interfaces=>["FastEthernet0/1", "FastEthernet0/2"], :name=>"management", :id=>"100"}, "1"=>{:status=>"active", :interfaces=>["FastEthernet0/3", "FastEthernet0/4", "FastEthernet0/5", "FastEthernet0/6", "FastEthernet0/7", "FastEthernet0/8", "FastEthernet0/9", "FastEthernet0/10", "FastEthernet0/11", "FastEthernet0/12", "FastEthernet0/13", "FastEthernet0/14", "FastEthernet0/15", "FastEthernet0/16", "FastEthernet0/17", "FastEthernet0/18", "FastEthernet0/23", "FastEthernet0/24"], :name=>"default", :id=>"1"}, "10"=>{:status=>"active", :interfaces=>[], :name=>"VLAN0010", :id=>"10"}}
+ @cisco.parse_vlans.should == {"100"=>{:status=>"active", :interfaces=>["FastEthernet0/1", "FastEthernet0/2"], :description=>"management", :name=>"100"}, "1"=>{:status=>"active", :interfaces=>["FastEthernet0/3", "FastEthernet0/4", "FastEthernet0/5", "FastEthernet0/6", "FastEthernet0/7", "FastEthernet0/8", "FastEthernet0/9", "FastEthernet0/10", "FastEthernet0/11", "FastEthernet0/12", "FastEthernet0/13", "FastEthernet0/14", "FastEthernet0/15", "FastEthernet0/16", "FastEthernet0/17", "FastEthernet0/18", "FastEthernet0/23", "FastEthernet0/24"], :description=>"default", :name=>"1"}, "10"=>{:status=>"active", :interfaces=>[], :description=>"VLAN0010", :name=>"10"}}
end
it "should parse trunk switchport information" do