summaryrefslogtreecommitdiffstats
path: root/spec/unit/util
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
committerMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
commit3dde838ac992571e13262ea29ba3a0eb8152e753 (patch)
tree90520cf62bfa2f1bb9c992bbfe1bc47ae10471f2 /spec/unit/util
parentfe45c2417af580597cd39adec96a30a05a7cd66a (diff)
parent3ab44c7ce01ab86a995deb66228f5be95239c92a (diff)
Merge branch 'next'
* next: (204 commits) Revert "(#6928) Removed --ignoreimport" Updated CHANGELOG for 2.6.8rc1 (#6928) Removed --ignoreimport (#6928) Remove --parseonly (#6928) Add a Parser face with Validate action (#6830) Fix sha1 to digest/sha1 require issue for Ruby 1.9 (#6830) Fix UTF-8 encoding issue for Ruby 1.9 (#6830) Fix string method sub call on a symbol for Ruby 1.9 (#2331) Remove darwinports pkg provider, replace with rewritten macports provider (#7059) handle inherited action binding scope maint: ensure we handle '-foo=' options correctly in faces. (#2150) Fix File const lookup when configuring routes Fixed #7082 - Added system support for groups maint: install erb templates under lib/ maint: clean up the spec test headers in bulk. (#7056) Use 'face' rather than 'faces' in the production code. maint: eliminate deprecated since 2008 code from Puppet. (#6117) Add POST support to indirector requests (#6962) Move option handling into #parse_options, not #preinit. maint: whitespace cleanup for puppet/util/command_line. ...
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-xspec/unit/util/autoload/file_cache_spec.rb5
-rwxr-xr-xspec/unit/util/autoload_spec.rb5
-rwxr-xr-xspec/unit/util/backups_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/cache_accumulator_spec.rb5
-rwxr-xr-xspec/unit/util/cacher_spec.rb5
-rwxr-xr-xspec/unit/util/checksums_spec.rb4
-rwxr-xr-xspec/unit/util/command_line_spec.rb17
-rwxr-xr-xspec/unit/util/constant_inflector_spec.rb4
-rwxr-xr-xspec/unit/util/errors_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/execution_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/execution_stub_spec.rb5
-rwxr-xr-xspec/unit/util/feature_spec.rb5
-rwxr-xr-xspec/unit/util/file_locking_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/filetype_spec.rb5
-rwxr-xr-xspec/unit/util/inline_docs_spec.rb5
-rwxr-xr-xspec/unit/util/ldap/connection_spec.rb4
-rwxr-xr-xspec/unit/util/ldap/generator_spec.rb4
-rwxr-xr-xspec/unit/util/ldap/manager_spec.rb4
-rwxr-xr-xspec/unit/util/loadedfile_spec.rb5
-rwxr-xr-xspec/unit/util/log/destinations_spec.rb5
-rwxr-xr-xspec/unit/util/log_spec.rb5
-rwxr-xr-xspec/unit/util/logging_spec.rb30
-rwxr-xr-xspec/unit/util/metric_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/monkey_patches_spec.rb28
-rwxr-xr-xspec/unit/util/nagios_maker_spec.rb4
-rwxr-xr-xspec/unit/util/network_device/cisco/device_spec.rb521
-rwxr-xr-xspec/unit/util/network_device/cisco/interface_spec.rb89
-rwxr-xr-xspec/unit/util/network_device/ipcalc_spec.rb63
-rwxr-xr-xspec/unit/util/network_device/transport/base_spec.rb42
-rwxr-xr-xspec/unit/util/network_device/transport/ssh_spec.rb211
-rwxr-xr-xspec/unit/util/network_device/transport/telnet_spec.rb76
-rwxr-xr-x[-rw-r--r--]spec/unit/util/package_spec.rb5
-rwxr-xr-xspec/unit/util/posix_spec.rb5
-rwxr-xr-xspec/unit/util/pson_spec.rb5
-rwxr-xr-xspec/unit/util/queue/stomp_spec.rb5
-rwxr-xr-xspec/unit/util/queue_spec.rb5
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb5
-rwxr-xr-xspec/unit/util/rdoc_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/reference_serializer_spec.rb5
-rwxr-xr-xspec/unit/util/resource_template_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/util/run_mode_spec.rb5
-rwxr-xr-xspec/unit/util/selinux_spec.rb5
-rwxr-xr-xspec/unit/util/settings/file_setting_spec.rb5
-rwxr-xr-xspec/unit/util/settings_spec.rb5
-rwxr-xr-xspec/unit/util/storage_spec.rb5
-rwxr-xr-xspec/unit/util/tagging_spec.rb4
-rwxr-xr-x[-rw-r--r--]spec/unit/util/user_attr_spec.rb5
-rwxr-xr-xspec/unit/util/warnings_spec.rb5
-rwxr-xr-xspec/unit/util/zaml_spec.rb5
49 files changed, 1145 insertions, 125 deletions
diff --git a/spec/unit/util/autoload/file_cache_spec.rb b/spec/unit/util/autoload/file_cache_spec.rb
index 5ad820e4c..cdde9bb48 100755
--- a/spec/unit/util/autoload/file_cache_spec.rb
+++ b/spec/unit/util/autoload/file_cache_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/autoload/file_cache'
class FileCacheTester
diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb
index 808885dd7..6d49b57dc 100755
--- a/spec/unit/util/autoload_spec.rb
+++ b/spec/unit/util/autoload_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/autoload'
diff --git a/spec/unit/util/backups_spec.rb b/spec/unit/util/backups_spec.rb
index 3d707a58c..611c19304 100755
--- a/spec/unit/util/backups_spec.rb
+++ b/spec/unit/util/backups_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/backups'
diff --git a/spec/unit/util/cache_accumulator_spec.rb b/spec/unit/util/cache_accumulator_spec.rb
index 4ed9abf5c..9c35cc353 100644..100755
--- a/spec/unit/util/cache_accumulator_spec.rb
+++ b/spec/unit/util/cache_accumulator_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/rails/cache_accumulator'
describe Puppet::Util::CacheAccumulator do
diff --git a/spec/unit/util/cacher_spec.rb b/spec/unit/util/cacher_spec.rb
index 125382e84..2e43b4e20 100755
--- a/spec/unit/util/cacher_spec.rb
+++ b/spec/unit/util/cacher_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/cacher'
diff --git a/spec/unit/util/checksums_spec.rb b/spec/unit/util/checksums_spec.rb
index 954dc650b..146544201 100755
--- a/spec/unit/util/checksums_spec.rb
+++ b/spec/unit/util/checksums_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2007-9-22.
# Copyright (c) 2007. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'puppet/util/checksums'
diff --git a/spec/unit/util/command_line_spec.rb b/spec/unit/util/command_line_spec.rb
index a7d261dcf..81612ee5c 100755
--- a/spec/unit/util/command_line_spec.rb
+++ b/spec/unit/util/command_line_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/command_line'
@@ -99,10 +98,11 @@ describe Puppet::Util::CommandLine do
Puppet::Util.expects(:which).with('puppet-whatever').returns(nil)
commandline.expects(:system).never
- commandline.expects(:usage_message).returns("the usage message")
- commandline.expects(:abort).with{|x| x =~ /the usage message/}.raises("stubbed abort")
+ text = Puppet::Face[:help, :current].help
+ commandline.expects(:puts).with { |x| x =~ /Unknown Puppet subcommand/ }
+ commandline.expects(:puts).with text
- lambda{ commandline.execute }.should raise_error('stubbed abort')
+ commandline.execute
end
end
end
@@ -111,6 +111,11 @@ describe Puppet::Util::CommandLine do
@core_apps = %w{describe filebucket kick queue resource agent cert apply doc master}
@command_line = Puppet::Util::CommandLine.new("foo", %w{ client --help whatever.pp }, @tty )
end
+ it "should expose available_subcommands as a class method" do
+ @core_apps.each do |command|
+ @command_line.available_subcommands.should include command
+ end
+ end
it 'should be able to find all existing commands' do
@core_apps.each do |command|
@command_line.available_subcommands.should include command
diff --git a/spec/unit/util/constant_inflector_spec.rb b/spec/unit/util/constant_inflector_spec.rb
index 29574fd5b..cf2e8f892 100755
--- a/spec/unit/util/constant_inflector_spec.rb
+++ b/spec/unit/util/constant_inflector_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2008-02-12.
# Copyright (c) 2007. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'puppet/util/constant_inflector'
diff --git a/spec/unit/util/errors_spec.rb b/spec/unit/util/errors_spec.rb
index da1b8b0bd..d51a15ef4 100755
--- a/spec/unit/util/errors_spec.rb
+++ b/spec/unit/util/errors_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/errors'
diff --git a/spec/unit/util/execution_spec.rb b/spec/unit/util/execution_spec.rb
index 312dd3b8e..5b8b8a527 100644..100755
--- a/spec/unit/util/execution_spec.rb
+++ b/spec/unit/util/execution_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
+#!/usr/bin/env rspec
+require 'spec_helper'
describe Puppet::Util::Execution do
include Puppet::Util::Execution
diff --git a/spec/unit/util/execution_stub_spec.rb b/spec/unit/util/execution_stub_spec.rb
index 14cf9c67a..34987689c 100644..100755
--- a/spec/unit/util/execution_stub_spec.rb
+++ b/spec/unit/util/execution_stub_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
+#!/usr/bin/env rspec
+require 'spec_helper'
describe Puppet::Util::ExecutionStub do
it "should use the provided stub code when 'set' is called" do
diff --git a/spec/unit/util/feature_spec.rb b/spec/unit/util/feature_spec.rb
index 365428752..15375e0b1 100755
--- a/spec/unit/util/feature_spec.rb
+++ b/spec/unit/util/feature_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/feature'
diff --git a/spec/unit/util/file_locking_spec.rb b/spec/unit/util/file_locking_spec.rb
index e9dbe9d7b..261474263 100755
--- a/spec/unit/util/file_locking_spec.rb
+++ b/spec/unit/util/file_locking_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/file_locking'
diff --git a/spec/unit/util/filetype_spec.rb b/spec/unit/util/filetype_spec.rb
index 012631b91..a2c0da660 100644..100755
--- a/spec/unit/util/filetype_spec.rb
+++ b/spec/unit/util/filetype_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/filetype'
diff --git a/spec/unit/util/inline_docs_spec.rb b/spec/unit/util/inline_docs_spec.rb
index 75afb57cb..1d88180b3 100755
--- a/spec/unit/util/inline_docs_spec.rb
+++ b/spec/unit/util/inline_docs_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/inline_docs'
diff --git a/spec/unit/util/ldap/connection_spec.rb b/spec/unit/util/ldap/connection_spec.rb
index 91f008a2e..f97c72d77 100755
--- a/spec/unit/util/ldap/connection_spec.rb
+++ b/spec/unit/util/ldap/connection_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2008-3-19.
# Copyright (c) 2006. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+require 'spec_helper'
require 'puppet/util/ldap/connection'
diff --git a/spec/unit/util/ldap/generator_spec.rb b/spec/unit/util/ldap/generator_spec.rb
index 59c05b7c7..b3e664d6b 100755
--- a/spec/unit/util/ldap/generator_spec.rb
+++ b/spec/unit/util/ldap/generator_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2008-3-28.
# Copyright (c) 2008. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+require 'spec_helper'
require 'puppet/util/ldap/generator'
diff --git a/spec/unit/util/ldap/manager_spec.rb b/spec/unit/util/ldap/manager_spec.rb
index e91582c8d..5cce626b5 100755
--- a/spec/unit/util/ldap/manager_spec.rb
+++ b/spec/unit/util/ldap/manager_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2008-3-19.
# Copyright (c) 2006. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+require 'spec_helper'
require 'puppet/util/ldap/manager'
diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb
index 92daeb953..dcea53e45 100755
--- a/spec/unit/util/loadedfile_spec.rb
+++ b/spec/unit/util/loadedfile_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'tempfile'
require 'puppet/util/loadedfile'
diff --git a/spec/unit/util/log/destinations_spec.rb b/spec/unit/util/log/destinations_spec.rb
index b84c2ab44..873c5f0c7 100755
--- a/spec/unit/util/log/destinations_spec.rb
+++ b/spec/unit/util/log/destinations_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/log'
diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb
index 3c8577493..78411d187 100755
--- a/spec/unit/util/log_spec.rb
+++ b/spec/unit/util/log_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/log'
diff --git a/spec/unit/util/logging_spec.rb b/spec/unit/util/logging_spec.rb
index 97ffc0b25..6a77e70ef 100755
--- a/spec/unit/util/logging_spec.rb
+++ b/spec/unit/util/logging_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/logging'
@@ -92,4 +91,29 @@ describe Puppet::Util::Logging do
end
end
end
+
+ describe "when sending a deprecation warning" do
+ before do
+ @logger.clear_deprecation_warnings
+ end
+
+ it "should the message with warn" do
+ @logger.expects(:warning).with('foo')
+ @logger.deprecation_warning 'foo'
+ end
+
+ it "should only log each unique message once" do
+ @logger.expects(:warning).with('foo').once
+ 5.times { @logger.deprecation_warning 'foo' }
+ end
+
+ it "should only log the first 100 messages" do
+ (1..100).each { |i|
+ @logger.expects(:warning).with(i).once
+ @logger.deprecation_warning i
+ }
+ @logger.expects(:warning).with(101).never
+ @logger.deprecation_warning 101
+ end
+ end
end
diff --git a/spec/unit/util/metric_spec.rb b/spec/unit/util/metric_spec.rb
index 425812297..07a9e4945 100755
--- a/spec/unit/util/metric_spec.rb
+++ b/spec/unit/util/metric_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/metric'
diff --git a/spec/unit/util/monkey_patches_spec.rb b/spec/unit/util/monkey_patches_spec.rb
index 8bfcd900e..4b609ad09 100644..100755
--- a/spec/unit/util/monkey_patches_spec.rb
+++ b/spec/unit/util/monkey_patches_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/monkey_patches'
@@ -31,3 +30,26 @@ describe "yaml deserialization" do
obj.foo.should == 100
end
end
+
+# In Ruby > 1.8.7 this is a builtin, otherwise we monkey patch the method in
+describe "Array#combination" do
+ it "should fail if wrong number of arguments given" do
+ lambda { [1,2,3].combination() }.should raise_error(ArgumentError, /wrong number/)
+ lambda { [1,2,3].combination(1,2) }.should raise_error(ArgumentError, /wrong number/)
+ end
+
+ it "should return an empty array if combo size than array size or negative" do
+ [1,2,3].combination(4).to_a.should == []
+ [1,2,3].combination(-1).to_a.should == []
+ end
+
+ it "should return an empty array with an empty array if combo size == 0" do
+ [1,2,3].combination(0).to_a.should == [[]]
+ end
+
+ it "should all provide all combinations of size passed in" do
+ [1,2,3,4].combination(1).to_a.should == [[1], [2], [3], [4]]
+ [1,2,3,4].combination(2).to_a.should == [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
+ [1,2,3,4].combination(3).to_a.should == [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]
+ end
+end
diff --git a/spec/unit/util/nagios_maker_spec.rb b/spec/unit/util/nagios_maker_spec.rb
index 20582525d..b61f4fe9d 100755
--- a/spec/unit/util/nagios_maker_spec.rb
+++ b/spec/unit/util/nagios_maker_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2007-11-18.
# Copyright (c) 2007. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'puppet/util/nagios_maker'
diff --git a/spec/unit/util/network_device/cisco/device_spec.rb b/spec/unit/util/network_device/cisco/device_spec.rb
new file mode 100755
index 000000000..82b0666e6
--- /dev/null
+++ b/spec/unit/util/network_device/cisco/device_spec.rb
@@ -0,0 +1,521 @@
+#!/usr/bin/env rspec
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device/cisco/device'
+
+describe Puppet::Util::NetworkDevice::Cisco::Device do
+ before(:each) do
+ @transport = stub_everything 'transport', :is_a? => true, :command => ""
+ @cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/")
+ @cisco.transport = @transport
+ end
+
+ describe "when creating the device" do
+ it "should find the enable password from the url" do
+ cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/?enable=enable_password")
+ cisco.enable_password.should == "enable_password"
+ end
+
+ it "should find the enable password from the options" do
+ cisco = Puppet::Util::NetworkDevice::Cisco::Device.new("telnet://user:password@localhost:23/?enable=enable_password", :enable_password => "mypass")
+ cisco.enable_password.should == "mypass"
+ end
+ end
+
+ describe "when connecting to the physical device" do
+ it "should connect to the transport" do
+ @transport.expects(:connect)
+ @cisco.command
+ end
+
+ it "should attempt to login" do
+ @cisco.expects(:login)
+ @cisco.command
+ end
+
+ it "should tell the device to not page" do
+ @transport.expects(:command).with("terminal length 0")
+ @cisco.command
+ end
+
+ it "should enter the enable password if returned prompt is not privileged" do
+ @transport.stubs(:command).yields("Switch>").returns("")
+ @cisco.expects(:enable)
+ @cisco.command
+ end
+
+ it "should find device capabilities" do
+ @cisco.expects(:find_capabilities)
+ @cisco.command
+ end
+
+ it "should execute given command" do
+ @transport.expects(:command).with("mycommand")
+ @cisco.command("mycommand")
+ end
+
+ it "should yield to the command block if one is provided" do
+ @transport.expects(:command).with("mycommand")
+ @cisco.command do |c|
+ c.command("mycommand")
+ end
+ end
+
+ it "should close the device transport" do
+ @transport.expects(:close)
+ @cisco.command
+ end
+
+ describe "when login in" do
+ it "should not login if transport handles login" do
+ @transport.expects(:handles_login?).returns(true)
+ @transport.expects(:command).never
+ @transport.expects(:expect).never
+ @cisco.login
+ end
+
+ it "should send username if one has been provided" do
+ @transport.expects(:command).with("user", :prompt => /^Password:/)
+ @cisco.login
+ end
+
+ it "should send password after the username" do
+ @transport.expects(:command).with("user", :prompt => /^Password:/)
+ @transport.expects(:command).with("password")
+ @cisco.login
+ end
+
+ it "should expect the Password: prompt if no user was sent" do
+ @cisco.url.user = ''
+ @transport.expects(:expect).with(/^Password:/)
+ @transport.expects(:command).with("password")
+ @cisco.login
+ end
+ end
+
+ describe "when entering enable password" do
+ it "should raise an error if no enable password has been set" do
+ @cisco.enable_password = nil
+ lambda{ @cisco.enable }.should raise_error
+ end
+
+ it "should send the enable command and expect an enable prompt" do
+ @cisco.enable_password = 'mypass'
+ @transport.expects(:command).with("enable", :prompt => /^Password:/)
+ @cisco.enable
+ end
+
+ it "should send the enable password" do
+ @cisco.enable_password = 'mypass'
+ @transport.stubs(:command).with("enable", :prompt => /^Password:/)
+ @transport.expects(:command).with("mypass")
+ @cisco.enable
+ end
+ end
+ end
+
+ describe "when finding network device capabilities" do
+ it "should try to execute sh vlan brief" do
+ @transport.expects(:command).with("sh vlan brief").returns("")
+ @cisco.find_capabilities
+ end
+
+ it "should detect errors" do
+ @transport.stubs(:command).with("sh vlan brief").returns(<<eos)
+Switch#sh vlan brief
+% Ambiguous command: "sh vlan brief"
+Switch#
+eos
+
+ @cisco.find_capabilities
+ @cisco.should_not be_support_vlan_brief
+ end
+ end
+
+
+ {
+ "Fa 0/1" => "FastEthernet0/1",
+ "Fa0/1" => "FastEthernet0/1",
+ "FastEth 0/1" => "FastEthernet0/1",
+ "Gi1" => "GigEthernet1",
+ "Di9" => "Dialer9",
+ "Ethernet 0/0/1" => "Ethernet0/0/1",
+ "E0" => "Ethernet0",
+ "ATM 0/1.1" => "ATM0/1.1",
+ "VLAN99" => "VLAN99"
+ }.each do |input,expected|
+ it "should canonicalize #{input} to #{expected}" do
+ @cisco.canonalize_ifname(input).should == expected
+ 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
+
+ it "should parse interface output" do
+ @cisco.expects(:parse_interface).returns({ :ensure => :present })
+
+ @cisco.interface("FastEthernet0/1").should == { :ensure => :present }
+ end
+
+ it "should parse trunking and merge results" do
+ @cisco.stubs(:parse_interface).returns({ :ensure => :present })
+ @cisco.expects(:parse_trunking).returns({ :native_vlan => "100" })
+
+ @cisco.interface("FastEthernet0/1").should == { :ensure => :present, :native_vlan => "100" }
+ end
+
+ it "should return an absent interface if parse_interface returns nothing" do
+ @cisco.stubs(:parse_interface).returns({})
+
+ @cisco.interface("FastEthernet0/1").should == { :ensure => :absent }
+ end
+
+ it "should parse ip address information and merge results" do
+ @cisco.stubs(:parse_interface).returns({ :ensure => :present })
+ @cisco.expects(:parse_interface_config).returns({ :ipaddress => [24,IPAddr.new('192.168.0.24'), nil] })
+
+ @cisco.interface("FastEthernet0/1").should == { :ensure => :present, :ipaddress => [24,IPAddr.new('192.168.0.24'), nil] }
+ end
+
+ it "should parse the sh interface command" do
+ @transport.stubs(:command).with("sh interface FastEthernet0/1").returns(<<eos)
+Switch#sh interfaces FastEthernet 0/1
+FastEthernet0/1 is down, line protocol is down
+ Hardware is Fast Ethernet, address is 00d0.bbe2.19c1 (bia 00d0.bbe2.19c1)
+ MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
+ reliability 255/255, txload 1/255, rxload 1/255
+ Encapsulation ARPA, loopback not set
+ Keepalive not set
+ Auto-duplex , Auto Speed , 100BaseTX/FX
+ ARP type: ARPA, ARP Timeout 04:00:00
+ Last input never, output 5d04h, output hang never
+ Last clearing of "show interface" counters never
+ Queueing strategy: fifo
+ Output queue 0/40, 0 drops; input queue 0/75, 0 drops
+ 5 minute input rate 0 bits/sec, 0 packets/sec
+ 5 minute output rate 0 bits/sec, 0 packets/sec
+ 580 packets input, 54861 bytes
+ Received 6 broadcasts, 0 runts, 0 giants, 0 throttles
+ 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
+ 0 watchdog, 1 multicast
+ 0 input packets with dribble condition detected
+ 845 packets output, 80359 bytes, 0 underruns
+ 0 output errors, 0 collisions, 1 interface resets
+ 0 babbles, 0 late collision, 0 deferred
+ 0 lost carrier, 0 no carrier
+ 0 output buffer failures, 0 output buffers swapped out
+Switch#
+eos
+
+ @cisco.parse_interface("FastEthernet0/1").should == { :ensure => :absent, :duplex => :auto, :speed => :auto }
+ end
+
+ it "should be able to parse the sh vlan brief command output" do
+ @cisco.stubs(:support_vlan_brief?).returns(true)
+ @transport.stubs(:command).with("sh vlan brief").returns(<<eos)
+Switch#sh vlan brief
+VLAN Name Status Ports
+---- -------------------------------- --------- -------------------------------
+1 default active Fa0/3, Fa0/4, Fa0/5, Fa0/6,
+ Fa0/7, Fa0/8, Fa0/9, Fa0/10,
+ Fa0/11, Fa0/12, Fa0/13, Fa0/14,
+ Fa0/15, Fa0/16, Fa0/17, Fa0/18,
+ Fa0/23, Fa0/24
+10 VLAN0010 active
+100 management active Fa0/1, Fa0/2
+Switch#
+eos
+
+ @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
+ @transport.stubs(:command).with("sh interface FastEthernet0/21 switchport").returns(<<eos)
+Switch#sh interfaces FastEthernet 0/21 switchport
+Name: Fa0/21
+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,10,100
+Pruning VLANs Enabled: 2-1001
+
+Priority for untagged frames: 0
+Override vlan tag priority: FALSE
+Voice VLAN: none
+Appliance trust: none
+Self Loopback: No
+Switch#
+eos
+
+ @cisco.parse_trunking("FastEthernet0/21").should == { :mode => :trunk, :encapsulation => :dot1q, :allowed_trunk_vlans=>:all, }
+ end
+
+ it "should parse trunk switchport information with allowed vlans" do
+ @transport.stubs(:command).with("sh interface GigabitEthernet 0/1 switchport").returns(<<eos)
+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#
+eos
+
+ @cisco.parse_trunking("GigabitEthernet 0/1").should == { :mode => :trunk, :encapsulation => :dot1q, :allowed_trunk_vlans=>"1,99", }
+ end
+
+ it "should parse access switchport information" do
+ @transport.stubs(:command).with("sh interface FastEthernet0/1 switchport").returns(<<eos)
+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#
+eos
+
+ @cisco.parse_trunking("FastEthernet0/1").should == { :mode => :access, :native_vlan => "100" }
+ end
+
+ it "should parse ip addresses" do
+ @transport.stubs(:command).with("sh running-config interface Vlan 1 | begin interface").returns(<<eos)
+router#sh running-config interface Vlan 1 | begin interface
+interface Vlan1
+ description $ETH-SW-LAUNCH$$INTF-INFO-HWIC 4ESW$$FW_INSIDE$
+ ip address 192.168.0.24 255.255.255.0 secondary
+ ip address 192.168.0.1 255.255.255.0
+ ip access-group 100 in
+ no ip redirects
+ no ip proxy-arp
+ ip nbar protocol-discovery
+ ip dns view-group dow
+ ip nat inside
+ ip virtual-reassembly
+ ip route-cache flow
+ ipv6 address 2001:7A8:71C1::/64 eui-64
+ ipv6 enable
+ ipv6 traffic-filter DENY-ACL6 out
+ ipv6 mtu 1280
+ ipv6 nd prefix 2001:7A8:71C1::/64
+ ipv6 nd ra interval 60
+ ipv6 nd ra lifetime 180
+ ipv6 verify unicast reverse-path
+ ipv6 inspect STD6 out
+end
+
+router#
+eos
+ @cisco.parse_interface_config("Vlan 1").should == {:ipaddress=>[[24, IPAddr.new('192.168.0.24'), 'secondary'],
+ [24, IPAddr.new('192.168.0.1'), nil],
+ [64, IPAddr.new('2001:07a8:71c1::'), "eui-64"]]}
+ end
+
+ it "should parse etherchannel membership" do
+ @transport.stubs(:command).with("sh running-config interface Gi0/17 | begin interface").returns(<<eos)
+c2960#sh running-config interface Gi0/17 | begin interface
+interface GigabitEthernet0/17
+ description member of Po1
+ switchport mode access
+ channel-protocol lacp
+ channel-group 1 mode passive
+ spanning-tree portfast
+ spanning-tree bpduguard enable
+end
+
+c2960#
+eos
+ @cisco.parse_interface_config("Gi0/17").should == {:etherchannel=>"1"}
+ 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/interface_spec.rb b/spec/unit/util/network_device/cisco/interface_spec.rb
new file mode 100755
index 000000000..24217750c
--- /dev/null
+++ b/spec/unit/util/network_device/cisco/interface_spec.rb
@@ -0,0 +1,89 @@
+#!/usr/bin/env rspec
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device'
+require 'puppet/util/network_device/cisco/interface'
+
+describe Puppet::Util::NetworkDevice::Cisco::Interface do
+ before(:each) do
+ @transport = stub_everything 'transport'
+ @interface = Puppet::Util::NetworkDevice::Cisco::Interface.new("FastEthernet0/1",@transport)
+ end
+
+ it "should include IPCalc" do
+ @interface.class.include?(Puppet::Util::NetworkDevice::IPCalc)
+ end
+
+ describe "when updating the physical device" do
+ it "should enter global configuration mode" do
+ @transport.expects(:command).with("conf t")
+ @interface.update
+ end
+
+ it "should enter interface configuration mode" do
+ @transport.expects(:command).with("interface FastEthernet0/1")
+ @interface.update
+ end
+
+ it "should 'execute' all differing properties" do
+ @interface.expects(:execute).with(:description, "b")
+ @interface.expects(:execute).with(:mode, :access).never
+ @interface.update({ :description => "a", :mode => :access }, { :description => "b", :mode => :access })
+ end
+
+ it "should execute in cisco ios defined order" do
+ speed = states('speed').starts_as('notset')
+ @interface.expects(:execute).with(:speed, :auto).then(speed.is('set'))
+ @interface.expects(:execute).with(:duplex, :auto).when(speed.is('set'))
+ @interface.update({ :duplex => :half, :speed => "10" }, { :duplex => :auto, :speed => :auto })
+ end
+
+ it "should execute absent properties with a no prefix" do
+ @interface.expects(:execute).with(:description, "a", "no ")
+ @interface.update({ :description => "a"}, { })
+ end
+
+ it "should exit twice" do
+ @transport.expects(:command).with("exit").twice
+ @interface.update
+ end
+ end
+
+ describe "when executing commands" do
+ it "should execute string commands directly" do
+ @transport.expects(:command).with("speed auto")
+ @interface.execute(:speed, :auto)
+ end
+
+ it "should execute string commands with the given prefix" do
+ @transport.expects(:command).with("no speed auto")
+ @interface.execute(:speed, :auto, "no ")
+ end
+
+ it "should stop at executing the first command that works for array" do
+ @transport.expects(:command).with("channel-group 1").yields("% Invalid command")
+ @transport.expects(:command).with("port group 1")
+ @interface.execute(:etherchannel, "1")
+ end
+
+ it "should execute the block for block commands" do
+ @transport.expects(:command).with("ip address 192.168.0.1 255.255.255.0")
+ @interface.execute(:ipaddress, [[24, IPAddr.new('192.168.0.1'), nil]])
+ end
+
+ it "should execute the block for block commands" do
+ @transport.expects(:command).with("ipv6 address fe08::/76 link-local")
+ @interface.execute(:ipaddress, [[76, IPAddr.new('fe08::'), 'link-local']])
+ end
+
+ end
+
+ describe "when sending commands to the device" do
+ it "should detect errors" do
+ Puppet.expects(:err)
+ @transport.stubs(:command).yields("% Invalid Command")
+ @interface.command("sh ver")
+ end
+ end
+end
diff --git a/spec/unit/util/network_device/ipcalc_spec.rb b/spec/unit/util/network_device/ipcalc_spec.rb
new file mode 100755
index 000000000..0418c6a84
--- /dev/null
+++ b/spec/unit/util/network_device/ipcalc_spec.rb
@@ -0,0 +1,63 @@
+#!/usr/bin/env rspec
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/util/network_device/ipcalc'
+
+describe Puppet::Util::NetworkDevice::IPCalc do
+ class TestIPCalc
+ include Puppet::Util::NetworkDevice::IPCalc
+ end
+
+ before(:each) do
+ @ipcalc = TestIPCalc.new
+ end
+
+ describe "when parsing ip/prefix" do
+ it "should parse ipv4 without prefixes" do
+ @ipcalc.parse('127.0.0.1').should == [32,IPAddr.new('127.0.0.1')]
+ end
+
+ it "should parse ipv4 with prefixes" do
+ @ipcalc.parse('127.0.1.2/8').should == [8,IPAddr.new('127.0.1.2')]
+ end
+
+ it "should parse ipv6 without prefixes" do
+ @ipcalc.parse('FE80::21A:2FFF:FE30:ECF0').should == [128,IPAddr.new('FE80::21A:2FFF:FE30:ECF0')]
+ end
+
+ it "should parse ipv6 with prefixes" do
+ @ipcalc.parse('FE80::21A:2FFF:FE30:ECF0/56').should == [56,IPAddr.new('FE80::21A:2FFF:FE30:ECF0')]
+ end
+ end
+
+ describe "when building netmask" do
+ it "should produce the correct ipv4 netmask from prefix length" do
+ @ipcalc.netmask(Socket::AF_INET, 27).should == IPAddr.new('255.255.255.224')
+ end
+
+ it "should produce the correct ipv6 netmask from prefix length" do
+ @ipcalc.netmask(Socket::AF_INET6, 56).should == IPAddr.new('ffff:ffff:ffff:ff00::0')
+ end
+ end
+
+ describe "when building wildmask" do
+ it "should produce the correct ipv4 wildmask from prefix length" do
+ @ipcalc.wildmask(Socket::AF_INET, 27).should == IPAddr.new('0.0.0.31')
+ end
+
+ it "should produce the correct ipv6 wildmask from prefix length" do
+ @ipcalc.wildmask(Socket::AF_INET6, 126).should == IPAddr.new('::3')
+ end
+ end
+
+ describe "when computing prefix length from netmask" do
+ it "should produce the correct ipv4 prefix length" do
+ @ipcalc.prefix_length(IPAddr.new('255.255.255.224')).should == 27
+ end
+
+ it "should produce the correct ipv6 prefix length" do
+ @ipcalc.prefix_length(IPAddr.new('fffe::0')).should == 15
+ end
+ end
+end
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 100755
index 000000000..c186d72e5
--- /dev/null
+++ b/spec/unit/util/network_device/transport/base_spec.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env rspec
+
+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
diff --git a/spec/unit/util/network_device/transport/ssh_spec.rb b/spec/unit/util/network_device/transport/ssh_spec.rb
new file mode 100755
index 000000000..0e91ed9f9
--- /dev/null
+++ b/spec/unit/util/network_device/transport/ssh_spec.rb
@@ -0,0 +1,211 @@
+#!/usr/bin/env rspec
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device/transport/ssh'
+
+describe Puppet::Util::NetworkDevice::Transport::Ssh, :if => Puppet.features.ssh? do
+
+ before(:each) do
+ @transport = Puppet::Util::NetworkDevice::Transport::Ssh.new()
+ end
+
+ it "should handle login through the transport" do
+ @transport.should be_handles_login
+ end
+
+ it "should connect to the given host and port" do
+ Net::SSH.expects(:start).with { |host, user, args| host == "localhost" && args[:port] == 22 }.returns stub_everything
+ @transport.host = "localhost"
+ @transport.port = 22
+
+ @transport.connect
+ end
+
+ it "should connect using the given username and password" do
+ Net::SSH.expects(:start).with { |host, user, args| user == "user" && args[:password] == "pass" }.returns stub_everything
+ @transport.user = "user"
+ @transport.password = "pass"
+
+ @transport.connect
+ end
+
+ describe "when connected" do
+ before(:each) do
+ @ssh = stub_everything 'ssh'
+ @channel = stub_everything 'channel'
+ Net::SSH.stubs(:start).returns @ssh
+ @ssh.stubs(:open_channel).yields(@channel)
+ @transport.stubs(:expect)
+ end
+
+ it "should open a channel" do
+ @ssh.expects(:open_channel)
+
+ @transport.connect
+ end
+
+ it "should request a pty" do
+ @channel.expects(:request_pty)
+
+ @transport.connect
+ end
+
+ it "should create a shell channel" do
+ @channel.expects(:send_channel_request).with("shell")
+ @transport.connect
+ end
+
+ it "should raise an error if shell channel creation fails" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, false)
+ lambda { @transport.connect }.should raise_error
+ end
+
+ it "should register an on_data and on_extended_data callback" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, true)
+ @channel.expects(:on_data)
+ @channel.expects(:on_extended_data)
+ @transport.connect
+ end
+
+ it "should accumulate data to the buffer on data" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, true)
+ @channel.expects(:on_data).yields(@channel, "data")
+
+ @transport.connect
+ @transport.buf.should == "data"
+ end
+
+ it "should accumulate data to the buffer on extended data" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, true)
+ @channel.expects(:on_extended_data).yields(@channel, 1, "data")
+
+ @transport.connect
+ @transport.buf.should == "data"
+ end
+
+ it "should mark eof on close" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, true)
+ @channel.expects(:on_close).yields(@channel)
+
+ @transport.connect
+ @transport.should be_eof
+ end
+
+ it "should expect output to conform to the default prompt" do
+ @channel.expects(:send_channel_request).with("shell").yields(@channel, true)
+ @transport.expects(:default_prompt).returns("prompt")
+ @transport.expects(:expect).with("prompt")
+ @transport.connect
+ end
+
+ it "should start the ssh loop" do
+ @ssh.expects(:loop)
+ @transport.connect
+ end
+ end
+
+ describe "when closing" do
+ before(:each) do
+ @ssh = stub_everything 'ssh'
+ @channel = stub_everything 'channel'
+ Net::SSH.stubs(:start).returns @ssh
+ @ssh.stubs(:open_channel).yields(@channel)
+ @channel.stubs(:send_channel_request).with("shell").yields(@channel, true)
+ @transport.stubs(:expect)
+ @transport.connect
+ end
+
+ it "should close the channel" do
+ @channel.expects(:close)
+ @transport.close
+ end
+
+ it "should close the ssh session" do
+ @ssh.expects(:close)
+ @transport.close
+ end
+ end
+
+ describe "when sending commands" do
+ before(:each) do
+ @ssh = stub_everything 'ssh'
+ @channel = stub_everything 'channel'
+ Net::SSH.stubs(:start).returns @ssh
+ @ssh.stubs(:open_channel).yields(@channel)
+ @channel.stubs(:send_channel_request).with("shell").yields(@channel, true)
+ @transport.stubs(:expect)
+ @transport.connect
+ end
+
+ it "should send data to the ssh channel" do
+ @channel.expects(:send_data).with("data\n")
+ @transport.command("data")
+ end
+
+ it "should expect the default prompt afterward" do
+ @transport.expects(:default_prompt).returns("prompt")
+ @transport.expects(:expect).with("prompt")
+ @transport.command("data")
+ end
+
+ it "should expect the given prompt" do
+ @transport.expects(:expect).with("myprompt")
+ @transport.command("data", :prompt => "myprompt")
+ end
+
+ it "should yield the buffer output to given block" do
+ @transport.expects(:expect).yields("output")
+ @transport.command("data") do |out|
+ out.should == "output"
+ end
+ end
+
+ it "should return buffer output" do
+ @transport.expects(:expect).returns("output")
+ @transport.command("data").should == "output"
+ end
+ end
+
+ describe "when expecting output" do
+ before(:each) do
+ @connection = stub_everything 'connection'
+ @socket = stub_everything 'socket'
+ transport = stub 'transport', :socket => @socket
+ @ssh = stub_everything 'ssh', :transport => transport
+ @channel = stub_everything 'channel', :connection => @connection
+ @transport.ssh = @ssh
+ @transport.channel = @channel
+ end
+
+ it "should process the ssh event loop" do
+ IO.stubs(:select)
+ @transport.buf = "output"
+ @transport.expects(:process_ssh)
+ @transport.expect(/output/)
+ end
+
+ it "should return the output" do
+ IO.stubs(:select)
+ @transport.buf = "output"
+ @transport.stubs(:process_ssh)
+ @transport.expect(/output/).should == "output"
+ end
+
+ it "should return the output" do
+ IO.stubs(:select)
+ @transport.buf = "output"
+ @transport.stubs(:process_ssh)
+ @transport.expect(/output/).should == "output"
+ end
+
+ describe "when processing the ssh loop" do
+ it "should advance one tick in the ssh event loop and exit on eof" do
+ @transport.buf = ''
+ @connection.expects(:process).then.raises(EOFError)
+ @transport.process_ssh
+ end
+ end
+ end
+
+end
diff --git a/spec/unit/util/network_device/transport/telnet_spec.rb b/spec/unit/util/network_device/transport/telnet_spec.rb
new file mode 100755
index 000000000..7528e0740
--- /dev/null
+++ b/spec/unit/util/network_device/transport/telnet_spec.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env rspec
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+
+require 'puppet/util/network_device/transport/telnet'
+
+describe Puppet::Util::NetworkDevice::Transport::Telnet do
+
+ before(:each) do
+ @transport = Puppet::Util::NetworkDevice::Transport::Telnet.new()
+ end
+
+ it "should not handle login through the transport" do
+ @transport.should_not be_handles_login
+ end
+
+ it "should connect to the given host and port" do
+ Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything
+ @transport.host = "localhost"
+ @transport.port = 23
+
+ @transport.connect
+ end
+
+ it "should connect and specify the default prompt" do
+ @transport.default_prompt = "prompt"
+ Net::Telnet.expects(:new).with { |args| args["Prompt"] == "prompt" }.returns stub_everything
+ @transport.host = "localhost"
+ @transport.port = 23
+
+ @transport.connect
+ end
+
+ describe "when connected" do
+ before(:each) do
+ @telnet = stub_everything 'telnet'
+ Net::Telnet.stubs(:new).returns(@telnet)
+ @transport.connect
+ end
+
+ it "should send line to the telnet session" do
+ @telnet.expects(:puts).with("line")
+ @transport.send("line")
+ end
+
+ describe "when expecting output" do
+ it "should waitfor output on the telnet session" do
+ @telnet.expects(:waitfor).with(/regex/)
+ @transport.expect(/regex/)
+ end
+
+ it "should return telnet session output" do
+ @telnet.expects(:waitfor).returns("output")
+ @transport.expect(/regex/).should == "output"
+ end
+
+ it "should yield telnet session output to the given block" do
+ @telnet.expects(:waitfor).yields("output")
+ @transport.expect(/regex/) { |out| out.should == "output" }
+ end
+ end
+ end
+
+ describe "when closing" do
+ before(:each) do
+ @telnet = stub_everything 'telnet'
+ Net::Telnet.stubs(:new).returns(@telnet)
+ @transport.connect
+ end
+
+ it "should close the telnet session" do
+ @telnet.expects(:close)
+ @transport.close
+ end
+ end
+end
diff --git a/spec/unit/util/package_spec.rb b/spec/unit/util/package_spec.rb
index e72a7ae91..78c114afc 100644..100755
--- a/spec/unit/util/package_spec.rb
+++ b/spec/unit/util/package_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/package'
diff --git a/spec/unit/util/posix_spec.rb b/spec/unit/util/posix_spec.rb
index 6d7351220..db7c5c3a7 100755
--- a/spec/unit/util/posix_spec.rb
+++ b/spec/unit/util/posix_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/posix'
diff --git a/spec/unit/util/pson_spec.rb b/spec/unit/util/pson_spec.rb
index 08758ee38..63d085a66 100755
--- a/spec/unit/util/pson_spec.rb
+++ b/spec/unit/util/pson_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/pson'
diff --git a/spec/unit/util/queue/stomp_spec.rb b/spec/unit/util/queue/stomp_spec.rb
index a11d5324e..f67189cf5 100755
--- a/spec/unit/util/queue/stomp_spec.rb
+++ b/spec/unit/util/queue/stomp_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/queue'
describe Puppet::Util::Queue, :if => Puppet.features.stomp? do
diff --git a/spec/unit/util/queue_spec.rb b/spec/unit/util/queue_spec.rb
index d356fd7bb..59ea57d9b 100755
--- a/spec/unit/util/queue_spec.rb
+++ b/spec/unit/util/queue_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/queue'
require 'spec/mocks'
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index f118dc99b..c7f99051f 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/resource/type_collection'
require 'puppet/util/rdoc/parser'
diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb
index 3b5248528..067b5b8a7 100755
--- a/spec/unit/util/rdoc_spec.rb
+++ b/spec/unit/util/rdoc_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/rdoc'
require 'rdoc/rdoc'
diff --git a/spec/unit/util/reference_serializer_spec.rb b/spec/unit/util/reference_serializer_spec.rb
index f72715ed6..de53ab9bb 100644..100755
--- a/spec/unit/util/reference_serializer_spec.rb
+++ b/spec/unit/util/reference_serializer_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/rails/reference_serializer'
class SerializeTester
diff --git a/spec/unit/util/resource_template_spec.rb b/spec/unit/util/resource_template_spec.rb
index e823a9ff4..4f7cafdb7 100755
--- a/spec/unit/util/resource_template_spec.rb
+++ b/spec/unit/util/resource_template_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/resource_template'
diff --git a/spec/unit/util/run_mode_spec.rb b/spec/unit/util/run_mode_spec.rb
index 1956973ea..c8d2b31f6 100644..100755
--- a/spec/unit/util/run_mode_spec.rb
+++ b/spec/unit/util/run_mode_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
describe Puppet::Util::RunMode do
before do
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index c18be0c2f..0eaf43cbb 100755
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/selinux'
include Puppet::Util::SELinux
diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb
index a2049e2ad..734b41f3a 100755
--- a/spec/unit/util/settings/file_setting_spec.rb
+++ b/spec/unit/util/settings/file_setting_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/settings'
require 'puppet/util/settings/file_setting'
diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb
index 2ab31c294..aa50c8f3a 100755
--- a/spec/unit/util/settings_spec.rb
+++ b/spec/unit/util/settings_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
describe Puppet::Util::Settings do
describe "when specifying defaults" do
diff --git a/spec/unit/util/storage_spec.rb b/spec/unit/util/storage_spec.rb
index 5359f746f..90c11aa69 100755
--- a/spec/unit/util/storage_spec.rb
+++ b/spec/unit/util/storage_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'yaml'
require 'puppet/util/storage'
diff --git a/spec/unit/util/tagging_spec.rb b/spec/unit/util/tagging_spec.rb
index 5231be2eb..018871bef 100755
--- a/spec/unit/util/tagging_spec.rb
+++ b/spec/unit/util/tagging_spec.rb
@@ -1,9 +1,9 @@
-#!/usr/bin/env ruby
+#!/usr/bin/env rspec
#
# Created by Luke Kanies on 2008-01-19.
# Copyright (c) 2007. All rights reserved.
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'puppet/util/tagging'
diff --git a/spec/unit/util/user_attr_spec.rb b/spec/unit/util/user_attr_spec.rb
index 5acdaee58..2d6ba8b5a 100644..100755
--- a/spec/unit/util/user_attr_spec.rb
+++ b/spec/unit/util/user_attr_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/user_attr'
diff --git a/spec/unit/util/warnings_spec.rb b/spec/unit/util/warnings_spec.rb
index a3460bccf..cc2c44711 100755
--- a/spec/unit/util/warnings_spec.rb
+++ b/spec/unit/util/warnings_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
describe Puppet::Util::Warnings do
before(:all) do
diff --git a/spec/unit/util/zaml_spec.rb b/spec/unit/util/zaml_spec.rb
index 804aa8e58..d77cf99d2 100755
--- a/spec/unit/util/zaml_spec.rb
+++ b/spec/unit/util/zaml_spec.rb
@@ -1,6 +1,5 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+#!/usr/bin/env rspec
+require 'spec_helper'
require 'puppet/util/monkey_patches'