summaryrefslogtreecommitdiffstats
path: root/spec/unit/util
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-04-21 14:37:50 -0700
commit01f610bb223b435dc52f491260af3ea002930102 (patch)
tree93565136d5ef2b4156fdd64476792e441bcfbb4e /spec/unit/util
parentac428b9557e2da251e4b51e48de844833ca0aa2a (diff)
parentfc66e98b84b9a16728af054485883334a5887cca (diff)
Merge branch 'next'
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-xspec/unit/util/network_device/cisco/device_spec.rb137
-rw-r--r--spec/unit/util/network_device/cisco/facts_spec.rb63
-rw-r--r--spec/unit/util/network_device/config_spec.rb102
-rwxr-xr-xspec/unit/util/network_device/transport/ssh_spec.rb8
-rw-r--r--spec/unit/util/network_device_spec.rb50
-rwxr-xr-xspec/unit/util/queue/stomp_spec.rb20
6 files changed, 245 insertions, 135 deletions
diff --git a/spec/unit/util/network_device/cisco/device_spec.rb b/spec/unit/util/network_device/cisco/device_spec.rb
index 82b0666e6..33242a1ab 100755
--- a/spec/unit/util/network_device/cisco/device_spec.rb
+++ b/spec/unit/util/network_device/cisco/device_spec.rb
@@ -392,130 +392,17 @@ eos
@cisco.parse_interface_config("Gi0/17").should == {:etherchannel=>"1"}
end
end
+
+ describe "when finding device facts" do
+ it "should delegate to the cisco facts entity" do
+ facts = stub 'facts'
+ Puppet::Util::NetworkDevice::Cisco::Facts.expects(:new).returns(facts)
+
+ facts.expects(:retrieve).returns(:facts)
+
+ @cisco.facts.should == :facts
+ end
+ end
+
end
-# static access
-# Switch#sh interfaces FastEthernet 0/1 switchport
-# Name: Fa0/1
-# Switchport: Enabled
-# Administrative mode: static access
-# Operational Mode: static access
-# Administrative Trunking Encapsulation: isl
-# Operational Trunking Encapsulation: isl
-# Negotiation of Trunking: Disabled
-# Access Mode VLAN: 100 (SHDSL)
-# Trunking Native Mode VLAN: 1 (default)
-# Trunking VLANs Enabled: NONE
-# Pruning VLANs Enabled: NONE
-#
-# Priority for untagged frames: 0
-# Override vlan tag priority: FALSE
-# Voice VLAN: none
-# Appliance trust: none
-# Self Loopback: No
-# Switch#
-
-# c2960#sh interfaces GigabitEthernet 0/1 switchport
-# Name: Gi0/1
-# Switchport: Enabled
-# Administrative Mode: trunk
-# Operational Mode: trunk
-# Administrative Trunking Encapsulation: dot1q
-# Operational Trunking Encapsulation: dot1q
-# Negotiation of Trunking: On
-# Access Mode VLAN: 1 (default)
-# Trunking Native Mode VLAN: 1 (default)
-# Administrative Native VLAN tagging: enabled
-# Voice VLAN: none
-# Administrative private-vlan host-association: none
-# Administrative private-vlan mapping: none
-# Administrative private-vlan trunk native VLAN: none
-# Administrative private-vlan trunk Native VLAN tagging: enabled
-# Administrative private-vlan trunk encapsulation: dot1q
-# Administrative private-vlan trunk normal VLANs: none
-# Administrative private-vlan trunk associations: none
-# Administrative private-vlan trunk mappings: none
-# Operational private-vlan: none
-# Trunking VLANs Enabled: 1,99
-# Pruning VLANs Enabled: 2-1001
-# Capture Mode Disabled
-# Capture VLANs Allowed: ALL
-#
-# Protected: false
-# Unknown unicast blocked: disabled
-# Unknown multicast blocked: disabled
-# Appliance trust: none
-# c2960#
-
-# c2960#sh interfaces GigabitEthernet 0/2 switchport
-# Name: Gi0/2
-# Switchport: Enabled
-# Administrative Mode: static access
-# Operational Mode: static access
-# Administrative Trunking Encapsulation: dot1q
-# Operational Trunking Encapsulation: native
-# Negotiation of Trunking: Off
-# Access Mode VLAN: 99 (MGMT)
-# Trunking Native Mode VLAN: 1 (default)
-# Administrative Native VLAN tagging: enabled
-# Voice VLAN: none
-# Administrative private-vlan host-association: none
-# Administrative private-vlan mapping: none
-# Administrative private-vlan trunk native VLAN: none
-# Administrative private-vlan trunk Native VLAN tagging: enabled
-# Administrative private-vlan trunk encapsulation: dot1q
-# Administrative private-vlan trunk normal VLANs: none
-# Administrative private-vlan trunk associations: none
-# Administrative private-vlan trunk mappings: none
-# Operational private-vlan: none
-# Trunking VLANs Enabled: ALL
-# Pruning VLANs Enabled: 2-1001
-# Capture Mode Disabled
-# Capture VLANs Allowed: ALL
-#
-# Protected: false
-# Unknown unicast blocked: disabled
-# Unknown multicast blocked: disabled
-# Appliance trust: none
-# c2960#
-
-# c877#sh interfaces FastEthernet 1 switchport
-# Name: Fa1
-# Switchport: Enabled
-# Administrative Mode: trunk
-# Operational Mode: trunk
-# Administrative Trunking Encapsulation: dot1q
-# Operational Trunking Encapsulation: dot1q
-# Negotiation of Trunking: Disabled
-# Access Mode VLAN: 0 ((Inactive))
-# Trunking Native Mode VLAN: 1 (default)
-# Trunking VLANs Enabled: ALL
-# Trunking VLANs Active: 1
-# Protected: false
-# Priority for untagged frames: 0
-# Override vlan tag priority: FALSE
-# Voice VLAN: none
-# Appliance trust: none
-
-
-# c2960#sh etherchannel summary
-# Flags: D - down P - bundled in port-channel
-# I - stand-alone s - suspended
-# H - Hot-standby (LACP only)
-# R - Layer3 S - Layer2
-# U - in use f - failed to allocate aggregator
-#
-# M - not in use, minimum links not met
-# u - unsuitable for bundling
-# w - waiting to be aggregated
-# d - default port
-#
-#
-# Number of channel-groups in use: 1
-# Number of aggregators: 1
-#
-# Group Port-channel Protocol Ports
-# ------+-------------+-----------+-----------------------------------------------
-# 1 Po1(SU) LACP Gi0/17(P) Gi0/18(P)
-#
-# c2960#
diff --git a/spec/unit/util/network_device/cisco/facts_spec.rb b/spec/unit/util/network_device/cisco/facts_spec.rb
new file mode 100644
index 000000000..bb29ac292
--- /dev/null
+++ b/spec/unit/util/network_device/cisco/facts_spec.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device'
+require 'puppet/util/network_device/cisco/facts'
+
+describe Puppet::Util::NetworkDevice::Cisco::Facts do
+ before(:each) do
+ @transport = stub_everything 'transport'
+ @facts = Puppet::Util::NetworkDevice::Cisco::Facts.new(@transport)
+ end
+
+ {
+ "cisco WS-C2924C-XL (PowerPC403GA) processor (revision 0x11) with 8192K/1024K bytes of memory." => {:hardwaremodel => "WS-C2924C-XL", :memorysize => "8192K", :processor => "PowerPC403GA", :hardwarerevision => "0x11" },
+ "Cisco 1841 (revision 5.0) with 355328K/37888K bytes of memory." => {:hardwaremodel=>"1841", :memorysize => "355328K", :hardwarerevision => "5.0" },
+ "Cisco 877 (MPC8272) processor (revision 0x200) with 118784K/12288K bytes of memory." => {:hardwaremodel=>"877", :memorysize => "118784K", :processor => "MPC8272", :hardwarerevision => "0x200" },
+ "cisco WS-C2960G-48TC-L (PowerPC405) processor (revision C0) with 61440K/4088K bytes of memory." => {:hardwaremodel=>"WS-C2960G-48TC-L", :memorysize => "61440K", :processor => "PowerPC405", :hardwarerevision => "C0" },
+ "cisco WS-C2950T-24 (RC32300) processor (revision R0) with 19959K bytes of memory." => {:hardwaremodel=>"WS-C2950T-24", :memorysize => "19959K", :processor => "RC32300", :hardwarerevision => "R0" }
+ }.each do |ver, expected|
+ it "should parse show ver output for hardware device facts" do
+ @transport.stubs(:command).with("sh ver").returns(<<eos)
+Switch>sh ver
+#{ver}
+Switch>
+eos
+ @facts.parse_show_ver.should == expected
+ end
+ end
+
+ {
+"Switch uptime is 1 year, 12 weeks, 6 days, 22 hours, 32 minutes" => { :hostname => "Switch", :uptime => "1 year, 12 weeks, 6 days, 22 hours, 32 minutes", :uptime_seconds => 39393120, :uptime_days => 455 },
+"c2950 uptime is 3 weeks, 1 day, 23 hours, 36 minutes" => { :hostname => "c2950", :uptime => "3 weeks, 1 day, 23 hours, 36 minutes", :uptime_days => 22, :uptime_seconds => 1985760},
+"router uptime is 5 weeks, 1 day, 3 hours, 30 minutes" => { :hostname => "router", :uptime => "5 weeks, 1 day, 3 hours, 30 minutes", :uptime_days => 36, :uptime_seconds => 3123000 },
+"c2950 uptime is 1 minute" => { :hostname => "c2950", :uptime => "1 minute", :uptime_days => 0, :uptime_seconds => 60 }
+ }.each do |ver, expected|
+ it "should parse show ver output for device uptime facts" do
+ @transport.stubs(:command).with("sh ver").returns(<<eos)
+Switch>sh ver
+#{ver}
+Switch>
+eos
+ @facts.parse_show_ver.should == expected
+ end
+ end
+
+ {
+"IOS (tm) C2900XL Software (C2900XL-C3H2S-M), Version 12.0(5)WC10, RELEASE SOFTWARE (fc1)"=> { :operatingsystem => "IOS", :operatingsystemrelease => "12.0(5)WC10", :operatingsystemmajrelease => "12.0WC", :operatingsystemfeature => "C3H2S"},
+"IOS (tm) C2950 Software (C2950-I6K2L2Q4-M), Version 12.1(22)EA8a, RELEASE SOFTWARE (fc1)"=> { :operatingsystem => "IOS", :operatingsystemrelease => "12.1(22)EA8a", :operatingsystemmajrelease => "12.1EA", :operatingsystemfeature => "I6K2L2Q4"},
+"Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(44)SE, RELEASE SOFTWARE (fc1)"=>{ :operatingsystem => "IOS", :operatingsystemrelease => "12.2(44)SE", :operatingsystemmajrelease => "12.2SE", :operatingsystemfeature => "LANBASEK9"},
+"Cisco IOS Software, C870 Software (C870-ADVIPSERVICESK9-M), Version 12.4(11)XJ4, RELEASE SOFTWARE (fc2)"=>{ :operatingsystem => "IOS", :operatingsystemrelease => "12.4(11)XJ4", :operatingsystemmajrelease => "12.4XJ", :operatingsystemfeature => "ADVIPSERVICESK9"},
+"Cisco IOS Software, 1841 Software (C1841-ADVSECURITYK9-M), Version 12.4(24)T4, RELEASE SOFTWARE (fc2)" =>{ :operatingsystem => "IOS", :operatingsystemrelease => "12.4(24)T4", :operatingsystemmajrelease => "12.4T", :operatingsystemfeature => "ADVSECURITYK9"},
+ }.each do |ver, expected|
+ it "should parse show ver output for device software version facts" do
+ @transport.stubs(:command).with("sh ver").returns(<<eos)
+Switch>sh ver
+#{ver}
+Switch>
+eos
+ @facts.parse_show_ver.should == expected
+ end
+ end
+end
diff --git a/spec/unit/util/network_device/config_spec.rb b/spec/unit/util/network_device/config_spec.rb
new file mode 100644
index 000000000..52796f30b
--- /dev/null
+++ b/spec/unit/util/network_device/config_spec.rb
@@ -0,0 +1,102 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/util/network_device/config'
+
+describe Puppet::Util::NetworkDevice::Config do
+ before(:each) do
+ Puppet[:deviceconfig] = "/dummy"
+ FileTest.stubs(:exists?).with("/dummy").returns(true)
+ end
+
+ describe "when initializing" do
+ before :each do
+ Puppet::Util::NetworkDevice::Config.any_instance.stubs(:read)
+ end
+
+ it "should use the deviceconfig setting as pathname" do
+ Puppet.expects(:[]).with(:deviceconfig).returns("/dummy")
+
+ Puppet::Util::NetworkDevice::Config.new
+ end
+
+ it "should raise an error if no file is defined finally" do
+ Puppet.expects(:[]).with(:deviceconfig).returns(nil)
+
+ lambda { Puppet::Util::NetworkDevice::Config.new }.should raise_error(Puppet::DevError)
+ end
+
+ it "should read and parse the file" do
+ Puppet::Util::NetworkDevice::Config.any_instance.expects(:read)
+
+ Puppet::Util::NetworkDevice::Config.new
+ end
+ end
+
+ describe "when parsing device" do
+ before :each do
+ @config = Puppet::Util::NetworkDevice::Config.new
+ @config.stubs(:changed?).returns(true)
+ @fd = stub 'fd'
+ File.stubs(:open).yields(@fd)
+ end
+
+ it "should skip comments" do
+ @fd.stubs(:each).yields(' # comment')
+
+ OpenStruct.expects(:new).never
+
+ @config.read
+ end
+
+ it "should increment line number even on commented lines" do
+ @fd.stubs(:each).multiple_yields(' # comment','[router.puppetlabs.com]')
+
+ @config.read
+ @config.devices.should be_include('router.puppetlabs.com')
+ end
+
+ it "should skip blank lines" do
+ @fd.stubs(:each).yields(' ')
+
+ @config.read
+ @config.devices.should be_empty
+ end
+
+ it "should produce the correct line number" do
+ @fd.stubs(:each).multiple_yields(' ', '[router.puppetlabs.com]')
+
+ @config.read
+ @config.devices['router.puppetlabs.com'].line.should == 2
+ end
+
+ it "should throw an error if the current device already exists" do
+ @fd.stubs(:each).multiple_yields('[router.puppetlabs.com]', '[router.puppetlabs.com]')
+
+ lambda { @config.read }.should raise_error
+ end
+
+ it "should create a new device for each found device line" do
+ @fd.stubs(:each).multiple_yields('[router.puppetlabs.com]', '[swith.puppetlabs.com]')
+
+ @config.read
+ @config.devices.size.should == 2
+ end
+
+ it "should parse the device type" do
+ @fd.stubs(:each).multiple_yields('[router.puppetlabs.com]', 'type cisco')
+
+ @config.read
+ @config.devices['router.puppetlabs.com'].provider.should == 'cisco'
+ end
+
+ it "should parse the device url" do
+ @fd.stubs(:each).multiple_yields('[router.puppetlabs.com]', 'type cisco', 'url ssh://test/')
+
+ @config.read
+ @config.devices['router.puppetlabs.com'].url.should == 'ssh://test/'
+ end
+ end
+
+end \ No newline at end of file
diff --git a/spec/unit/util/network_device/transport/ssh_spec.rb b/spec/unit/util/network_device/transport/ssh_spec.rb
index 0e91ed9f9..18d22a953 100755
--- a/spec/unit/util/network_device/transport/ssh_spec.rb
+++ b/spec/unit/util/network_device/transport/ssh_spec.rb
@@ -30,6 +30,14 @@ describe Puppet::Util::NetworkDevice::Transport::Ssh, :if => Puppet.features.ssh
@transport.connect
end
+ it "should raise a Puppet::Error when encountering an authentication failure" do
+ Net::SSH.expects(:start).raises Net::SSH::AuthenticationFailed
+ @transport.host = "localhost"
+ @transport.user = "user"
+
+ lambda { @transport.connect }.should raise_error Puppet::Error
+ end
+
describe "when connected" do
before(:each) do
@ssh = stub_everything 'ssh'
diff --git a/spec/unit/util/network_device_spec.rb b/spec/unit/util/network_device_spec.rb
new file mode 100644
index 000000000..0f7c6036b
--- /dev/null
+++ b/spec/unit/util/network_device_spec.rb
@@ -0,0 +1,50 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+require 'ostruct'
+require 'puppet/util/network_device'
+
+describe Puppet::Util::NetworkDevice do
+
+ before(:each) do
+ @device = OpenStruct.new(:name => "name", :provider => "test")
+ end
+
+ after(:each) do
+ Puppet::Util::NetworkDevice.teardown
+ end
+
+ class Puppet::Util::NetworkDevice::Test
+ class Device
+ def initialize(device)
+ end
+ end
+ end
+
+ describe "when initializing the remote network device singleton" do
+ it "should load the network device code" do
+ Puppet::Util::NetworkDevice.expects(:require)
+ Puppet::Util::NetworkDevice.init(@device)
+ end
+
+ it "should create a network device instance" do
+ Puppet::Util::NetworkDevice.stubs(:require)
+ Puppet::Util::NetworkDevice::Test::Device.expects(:new)
+ Puppet::Util::NetworkDevice.init(@device)
+ end
+
+ it "should raise an error if the remote device instance can't be created" do
+ Puppet::Util::NetworkDevice.stubs(:require).raises("error")
+ lambda { Puppet::Util::NetworkDevice.init(@device) }.should raise_error
+ end
+
+ it "should let caller to access the singleton device" do
+ device = stub 'device'
+ Puppet::Util::NetworkDevice.stubs(:require)
+ Puppet::Util::NetworkDevice::Test::Device.expects(:new).returns(device)
+ Puppet::Util::NetworkDevice.init(@device)
+
+ Puppet::Util::NetworkDevice.current.should == device
+ end
+ end
+end
diff --git a/spec/unit/util/queue/stomp_spec.rb b/spec/unit/util/queue/stomp_spec.rb
index f67189cf5..99c77d0b4 100755
--- a/spec/unit/util/queue/stomp_spec.rb
+++ b/spec/unit/util/queue/stomp_spec.rb
@@ -63,26 +63,26 @@ describe 'Puppet::Util::Queue::Stomp', :if => Puppet.features.stomp? do
end
end
- describe "when sending a message" do
+ describe "when publishing a message" do
before do
@client = stub 'client'
Stomp::Client.stubs(:new).returns @client
@queue = Puppet::Util::Queue::Stomp.new
end
- it "should send it to the queue client instance" do
- @client.expects(:send).with { |queue, msg, options| msg == "Smite!" }
- @queue.send_message('fooqueue', 'Smite!')
+ it "should publish it to the queue client instance" do
+ @client.expects(:publish).with { |queue, msg, options| msg == "Smite!" }
+ @queue.publish_message('fooqueue', 'Smite!')
end
- it "should send it to the transformed queue name" do
- @client.expects(:send).with { |queue, msg, options| queue == "/queue/fooqueue" }
- @queue.send_message('fooqueue', 'Smite!')
+ it "should publish it to the transformed queue name" do
+ @client.expects(:publish).with { |queue, msg, options| queue == "/queue/fooqueue" }
+ @queue.publish_message('fooqueue', 'Smite!')
end
- it "should send it as a persistent message" do
- @client.expects(:send).with { |queue, msg, options| options[:persistent] == true }
- @queue.send_message('fooqueue', 'Smite!')
+ it "should publish it as a persistent message" do
+ @client.expects(:publish).with { |queue, msg, options| options[:persistent] == true }
+ @queue.publish_message('fooqueue', 'Smite!')
end
end