summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2016-04-01 11:58:47 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2016-04-01 11:58:47 -0700
commit996b50bf99ecf2d9489c39baedf5e92ce0db2ecd (patch)
treeee1822317f725f24a9cf62445d06c971c695e647
parent8f48805e75e5e6be27da414d00fb8c7f8bbc9378 (diff)
parentf81c4518ff4ab37e8f5ccade4e395b8552c9480b (diff)
downloadohai-996b50bf99ecf2d9489c39baedf5e92ce0db2ecd.tar.gz
Merge pull request #788 from chef/shellout-log-and-timeout
Ohai shell_out logging, timeouts, and error handling
-rw-r--r--lib/ohai/mixin/command.rb21
-rw-r--r--lib/ohai/plugins/c.rb114
-rw-r--r--lib/ohai/plugins/rackspace.rb8
-rw-r--r--spec/unit/mixin/command_spec.rb118
-rw-r--r--spec/unit/plugins/c_spec.rb287
-rw-r--r--spec/unit/plugins/rackspace_spec.rb337
6 files changed, 561 insertions, 324 deletions
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb
index 6e090db3..6823ccf2 100644
--- a/lib/ohai/mixin/command.rb
+++ b/lib/ohai/mixin/command.rb
@@ -28,10 +28,23 @@ require "mixlib/shellout"
module Ohai
module Mixin
module Command
- def shell_out(cmd)
- m = Mixlib::ShellOut.new(cmd)
- m.run_command
- m
+ # DISCLAIMER: Logging only works in the context of a plugin!!
+ # accept a command and any of the mixlib-shellout options
+ def shell_out(cmd, **options)
+ # unless specified by the caller timeout after 30 seconds
+ options[:timeout] ||= 30
+ so = Mixlib::ShellOut.new(cmd, options)
+ begin
+ so.run_command
+ Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and returned #{so.exitstatus}")
+ so
+ rescue Errno::ENOENT => e
+ Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and failed #{e.inspect}")
+ raise Ohai::Exceptions::Exec, e
+ rescue Mixlib::ShellOut::CommandTimeout => e
+ Ohai::Log.debug("Plugin #{self.name} ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
+ raise Ohai::Exceptions::Exec, e
+ end
end
module_function :shell_out
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index 4dd5b2e7..7817fc86 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -23,68 +23,58 @@ Ohai.plugin(:C) do
depends "languages"
+ def collect(cmd, &block)
+ so = shell_out(cmd)
+ yield(so) if so.exitstatus == 0
+ rescue Ohai::Exceptions::Exec
+ # ignore
+ end
+
collect_data do
c = Mash.new
#gcc
- begin
- so = shell_out("gcc -v")
- if so.exitstatus == 0
- description = so.stderr.split($/).last
- output = description.split
- if output.length >= 3
- c[:gcc] = Mash.new
- c[:gcc][:version] = output[2]
- c[:gcc][:description] = description
- end
+ collect("gcc -v") do |so|
+ description = so.stderr.split($/).last
+ output = description.split
+ if output.length >= 3
+ c[:gcc] = Mash.new
+ c[:gcc][:version] = output[2]
+ c[:gcc][:description] = description
end
- rescue Errno::ENOENT
end
#glibc
["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc|
- begin
- so = shell_out( Ohai.abs_path( glibc ))
- if so.exitstatus == 0
- description = so.stdout.split($/).first
- if description =~ /(\d+\.\d+\.?\d*)/
- c[:glibc] = Mash.new
- c[:glibc][:version] = $1
- c[:glibc][:description] = description
- end
- break
+ collect( Ohai.abs_path( glibc )) do |so|
+ description = so.stdout.split($/).first
+ if description =~ /(\d+\.\d+\.?\d*)/
+ c[:glibc] = Mash.new
+ c[:glibc][:version] = $1
+ c[:glibc][:description] = description
end
- rescue Errno::ENOENT
- end
+ end unless c[:glibc]
end
#ms cl
- begin
- so = shell_out("cl /?")
- if so.exitstatus == 0
- description = so.stderr.lines.first.chomp
- if description =~ /Compiler Version ([\d\.]+)/
- c[:cl] = Mash.new
- c[:cl][:version] = $1
- c[:cl][:description] = description
- end
+ collect("cl /?") do |so|
+ description = so.stderr.lines.first.chomp
+ if description =~ /Compiler Version ([\d\.]+)/
+ c[:cl] = Mash.new
+ c[:cl][:version] = $1
+ c[:cl][:description] = description
end
- rescue Errno::ENOENT
end
#ms vs
- begin
- so = shell_out("devenv.com /?")
- if so.exitstatus == 0
- lines = so.stdout.split($/)
- description = lines[0].length == 0 ? lines[1] : lines[0]
- if description =~ /Visual Studio Version ([\d\.]+)/
- c[:vs] = Mash.new
- c[:vs][:version] = $1.chop
- c[:vs][:description] = description
- end
+ collect("devenv.com /?") do |so|
+ lines = so.stdout.split($/)
+ description = lines[0].length == 0 ? lines[1] : lines[0]
+ if description =~ /Visual Studio Version ([\d\.]+)/
+ c[:vs] = Mash.new
+ c[:vs][:version] = $1.chop
+ c[:vs][:description] = description
end
- rescue Errno::ENOENT
end
#ibm xlc
@@ -98,36 +88,28 @@ Ohai.plugin(:C) do
c[:xlc][:description] = description.strip
end
end
- rescue Errno::ENOENT
+ rescue Ohai::Exceptions::Exec
end
#sun pro
- begin
- so = shell_out("cc -V -flags")
- if so.exitstatus == 0
- output = so.stderr.split
- if so.stderr =~ /^cc: Sun C/ && output.size >= 4
- c[:sunpro] = Mash.new
- c[:sunpro][:version] = output[3]
- c[:sunpro][:description] = so.stderr.chomp
- end
+ collect("cc -V -flags") do |so|
+ output = so.stderr.split
+ if so.stderr =~ /^cc: Sun C/ && output.size >= 4
+ c[:sunpro] = Mash.new
+ c[:sunpro][:version] = output[3]
+ c[:sunpro][:description] = so.stderr.chomp
end
- rescue Errno::ENOENT
end
#hpux cc
- begin
- so = shell_out("what /opt/ansic/bin/cc")
- if so.exitstatus == 0
- description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first
- if description
- output = description.split
- c[:hpcc] = Mash.new
- c[:hpcc][:version] = output[1] if output.size >= 1
- c[:hpcc][:description] = description.strip
- end
+ collect("what /opt/ansic/bin/cc") do |so|
+ description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first
+ if description
+ output = description.split
+ c[:hpcc] = Mash.new
+ c[:hpcc][:version] = output[1] if output.size >= 1
+ c[:hpcc][:description] = description.strip
end
- rescue Errno::ENOENT
end
languages[:c] = c if c.keys.length > 0
diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb
index 18a6216e..52612120 100644
--- a/lib/ohai/plugins/rackspace.rb
+++ b/lib/ohai/plugins/rackspace.rb
@@ -40,7 +40,7 @@ Ohai.plugin(:Rackspace) do
if so.exitstatus == 0
so.stdout.strip.downcase == "rackspace"
end
- rescue Errno::ENOENT
+ rescue Ohai::Exceptions::Exec
false
end
@@ -91,7 +91,7 @@ Ohai.plugin(:Rackspace) do
rackspace[:region] = line.split[2].delete('\"') if line =~ /^region/
end
end
- rescue Errno::ENOENT
+ rescue Ohai::Exceptions::Exec
Ohai::Log.debug("rackspace plugin: Unable to find xenstore-ls, cannot capture region information for Rackspace cloud")
nil
end
@@ -103,7 +103,7 @@ Ohai.plugin(:Rackspace) do
if so.exitstatus == 0
rackspace[:instance_id] = so.stdout.gsub(/instance-/, "")
end
- rescue Errno::ENOENT
+ rescue Ohai::Exceptions::Exec
Ohai::Log.debug("rackspace plugin: Unable to find xenstore-read, cannot capture instance ID information for Rackspace cloud")
nil
end
@@ -127,7 +127,7 @@ Ohai.plugin(:Rackspace) do
networks.delete_if { |hash| hash["label"] == "private" }
networks.delete_if { |hash| hash["label"] == "public" }
end
- rescue Errno::ENOENT
+ rescue Ohai::Exceptions::Exec
Ohai::Log.debug("rackspace plugin: Unable to capture custom private networking information for Rackspace cloud")
nil
end
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb
index 97180d06..14a91405 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/command_spec.rb
@@ -85,5 +85,123 @@ describe Ohai::Mixin::Command, "popen4" do
end
expect(reaped_procs).to eq(0)
end
+end
+
+describe Ohai::Mixin::Command, "shell_out" do
+ let(:cmd) { "sparkle-dream --version" }
+
+ let(:shell_out) { double("Mixlib::ShellOut") }
+
+ let(:plugin_name) { :OSSparkleDream }
+
+ before(:each) do
+ allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name)
+ end
+
+ describe "when the command runs" do
+ it "logs the command and exitstatus" do
+ expect(Mixlib::ShellOut).
+ to receive(:new).
+ with(cmd, { timeout: 30 }).
+ and_return(shell_out)
+
+ expect(shell_out).
+ to receive(:run_command)
+
+ expect(shell_out).
+ to receive(:exitstatus).
+ and_return(256)
+
+ expect(Ohai::Log).to receive(:debug).
+ with("Plugin OSSparkleDream ran 'sparkle-dream --version' and returned 256")
+
+ Ohai::Mixin::Command.shell_out(cmd)
+ end
+ end
+
+ describe "when the command does not exist" do
+ it "logs the command and error message" do
+ expect(Mixlib::ShellOut).
+ to receive(:new).
+ with(cmd, { timeout: 30 }).
+ and_return(shell_out)
+
+ expect(shell_out).
+ to receive(:run_command).
+ and_raise(Errno::ENOENT, "sparkle-dream")
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("Plugin OSSparkleDream ran 'sparkle-dream --version' and failed " \
+ "#<Errno::ENOENT: No such file or directory - sparkle-dream>")
+
+ expect { Ohai::Mixin::Command.shell_out(cmd) }.
+ to raise_error(Ohai::Exceptions::Exec)
+ end
+ end
+ describe "when the command times out" do
+ it "logs the command an timeout error message" do
+ expect(Mixlib::ShellOut).
+ to receive(:new).
+ with(cmd, { timeout: 30 }).
+ and_return(shell_out)
+
+ expect(shell_out).
+ to receive(:run_command).
+ and_raise(Mixlib::ShellOut::CommandTimeout)
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("Plugin OSSparkleDream ran 'sparkle-dream --version' and timed " \
+ "out after 30 seconds")
+
+ expect { Ohai::Mixin::Command.shell_out(cmd) }.
+ to raise_error(Ohai::Exceptions::Exec)
+ end
+ end
+
+ describe "when a timeout option is provided" do
+ let(:options) { { timeout: 10 } }
+
+ it "runs the command with the provided timeout" do
+ expect(Mixlib::ShellOut).
+ to receive(:new).
+ with(cmd, options).
+ and_return(shell_out)
+
+ expect(shell_out).
+ to receive(:run_command)
+
+ expect(shell_out).
+ to receive(:exitstatus).
+ and_return(256)
+
+ expect(Ohai::Log).to receive(:debug).
+ with("Plugin OSSparkleDream ran 'sparkle-dream --version' and returned 256")
+
+ Ohai::Mixin::Command.shell_out(cmd, options)
+ end
+
+ describe "when the command times out" do
+ it "logs the command an timeout error message" do
+ expect(Mixlib::ShellOut).
+ to receive(:new).
+ with(cmd, options).
+ and_return(shell_out)
+
+ expect(shell_out).
+ to receive(:run_command).
+ and_raise(Mixlib::ShellOut::CommandTimeout)
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("Plugin OSSparkleDream ran 'sparkle-dream --version' and timed " \
+ "out after 10 seconds")
+
+ expect { Ohai::Mixin::Command.shell_out(cmd, options) }.
+ to raise_error(Ohai::Exceptions::Exec)
+ end
+ end
+ end
end
diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb
index 78372132..5b542f4e 100644
--- a/spec/unit/plugins/c_spec.rb
+++ b/spec/unit/plugins/c_spec.rb
@@ -102,207 +102,258 @@ EOF
describe Ohai::System, "plugin c" do
+ let(:plugin) { get_plugin("c") }
+
before(:each) do
- @plugin = get_plugin("c")
- @plugin[:languages] = Mash.new
+ plugin[:languages] = Mash.new
#gcc
- allow(@plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
+ allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
#glibc
- allow(@plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
#ms cl
- allow(@plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
#ms vs
- allow(@plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
#ibm xlc
- allow(@plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
#sun pro
- allow(@plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
#hpux cc
- allow(@plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
end
#gcc
- it "should get the gcc version from running gcc -v" do
- expect(@plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
- @plugin.run
+ it "gets the gcc version from running gcc -v" do
+ expect(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC))
+ plugin.run
+ end
+
+ it "sets languages[:c][:gcc][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:gcc][:version]).to eql("3.4.6")
end
- it "should set languages[:c][:gcc][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:gcc][:version]).to eql("3.4.6")
+ it "sets languages[:c][:gcc][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:gcc][:description]).to eql(C_GCC.split($/).last)
end
- it "should set languages[:c][:gcc][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:gcc][:description]).to eql(C_GCC.split($/).last)
+ it "does not set the languages[:c][:gcc] tree up if gcc command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:gcc)
end
- it "should not set the languages[:c][:gcc] tree up if gcc command fails" do
- allow(@plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:gcc) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:gcc] tree up if gcc command fails" do
+ allow(plugin).to receive(:shell_out).with("gcc -v").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:gcc)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
#glibc
- it "should get the glibc x.x.x version from running /lib/libc.so.6" do
- expect(@plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
- @plugin.run
+ it "gets the glibc x.x.x version from running /lib/libc.so.6" do
+ expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_3_4, ""))
+ plugin.run
+ end
+
+ it "sets languages[:c][:glibc][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:glibc][:version]).to eql("2.3.4")
end
- it "should set languages[:c][:glibc][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:glibc][:version]).to eql("2.3.4")
+ it "sets languages[:c][:glibc][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:glibc][:description]).to eql(C_GLIBC_2_3_4.split($/).first)
end
- it "should set languages[:c][:glibc][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:glibc][:description]).to eql(C_GLIBC_2_3_4.split($/).first)
+ it "does not set the languages[:c][:glibc] tree up if glibc exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(1, "", ""))
+ allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:glibc)
end
- it "should not set the languages[:c][:glibc] tree up if glibc command fails" do
- allow(@plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(1, "", ""))
- allow(@plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:glibc) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:glibc] tree up if glibc fails" do
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_raise(Ohai::Exceptions::Exec)
+ allow(plugin).to receive(:shell_out).with("/lib64/libc.so.6").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:glibc)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
- it "should get the glibc x.x version from running /lib/libc.so.6" do
- allow(@plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
- expect(@plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
- @plugin.run
- expect(@plugin.languages[:c][:glibc][:version]).to eql("2.5")
+ it "gets the glibc x.x version from running /lib/libc.so.6" do
+ allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
+ expect(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC_2_5, ""))
+ plugin.run
+ expect(plugin.languages[:c][:glibc][:version]).to eql("2.5")
end
#ms cl
- it "should get the cl version from running cl /?" do
- expect(@plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
- @plugin.run
+ it "gets the cl version from running cl /?" do
+ expect(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL))
+ plugin.run
+ end
+
+ it "sets languages[:c][:cl][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:cl][:version]).to eql("14.00.50727.762")
end
- it "should set languages[:c][:cl][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:cl][:version]).to eql("14.00.50727.762")
+ it "sets languages[:c][:cl][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:cl][:description]).to eql(C_CL.split($/).first)
end
- it "should set languages[:c][:cl][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:cl][:description]).to eql(C_CL.split($/).first)
+ it "does not set the languages[:c][:cl] tree up if cl command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:cl)
end
- it "should not set the languages[:c][:cl] tree up if cl command fails" do
- allow(@plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:cl) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:cl] tree up if cl command fails" do
+ allow(plugin).to receive(:shell_out).with("cl /\?").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:cl)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
#ms vs
- it "should get the vs version from running devenv.com /?" do
- expect(@plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
- @plugin.run
+ it "gets the vs version from running devenv.com /?" do
+ expect(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, ""))
+ plugin.run
end
- it "should set languages[:c][:vs][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:vs][:version]).to eql("8.0.50727.762")
+ it "sets languages[:c][:vs][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:vs][:version]).to eql("8.0.50727.762")
end
- it "should set languages[:c][:vs][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:vs][:description]).to eql(C_VS.split($/)[1])
+ it "sets languages[:c][:vs][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:vs][:description]).to eql(C_VS.split($/)[1])
end
- it "should not set the languages[:c][:vs] tree up if devenv command fails" do
- allow(@plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:vs) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:vs] tree up if devenv command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:vs)
+ end
+
+ it "does not set the languages[:c][:vs] tree up if devenv command fails" do
+ allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:vs)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
#ibm xlc
- it "should get the xlc version from running xlc -qversion" do
- expect(@plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
- @plugin.run
+ it "gets the xlc version from running xlc -qversion" do
+ expect(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, ""))
+ plugin.run
+ end
+
+ it "sets languages[:c][:xlc][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:xlc][:version]).to eql("9.0")
end
- it "should set languages[:c][:xlc][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:xlc][:version]).to eql("9.0")
+ it "sets languages[:c][:xlc][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:xlc][:description]).to eql(C_XLC.split($/).first)
end
- it "should set languages[:c][:xlc][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:xlc][:description]).to eql(C_XLC.split($/).first)
+ it "does not set the languages[:c][:xlc] tree up if xlc command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
end
- it "should not set the languages[:c][:xlc] tree up if xlc command fails" do
- allow(@plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:xlc) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:xlc] tree up if xlc command fails" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
- it "should set the languages[:c][:xlc] tree up if xlc exit status is 249" do
- allow(@plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:xlc) if @plugin[:languages][:c]
+ it "sets the languages[:c][:xlc] tree up if xlc exit status is 249" do
+ allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(63744, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:xlc)
end
#sun pro
- it "should get the cc version from running cc -V -flags" do
- expect(@plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
- @plugin.run
+ it "gets the cc version from running cc -V -flags" do
+ expect(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", C_SUN))
+ plugin.run
end
- it "should set languages[:c][:sunpro][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:sunpro][:version]).to eql("5.8")
+ it "sets languages[:c][:sunpro][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:sunpro][:version]).to eql("5.8")
end
- it "should set languages[:c][:sunpro][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:sunpro][:description]).to eql(C_SUN.chomp)
+ it "sets languages[:c][:sunpro][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:sunpro][:description]).to eql(C_SUN.chomp)
end
- it "should not set the languages[:c][:sunpro] tree up if cc command fails" do
- allow(@plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:sunpro) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:sunpro] tree up if cc command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
end
- it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
+ it "does not set the languages[:c][:sunpro] tree up if cc command fails" do
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
+ end
+
+ it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory"
- allow(@plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", fedora_error_message))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:sunpro) if @plugin[:languages][:c]
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", fedora_error_message))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
end
- it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
+ it "does not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]"
- allow(@plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", hpux_error_message))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:sunpro) if @plugin[:languages][:c]
+ allow(plugin).to receive(:shell_out).with("cc -V -flags").and_return(mock_shell_out(0, "", hpux_error_message))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:sunpro)
end
#hpux cc
- it "should get the cc version from running what cc" do
- expect(@plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
- @plugin.run
+ it "gets the cc version from running what cc" do
+ expect(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, ""))
+ plugin.run
+ end
+
+ it "sets languages[:c][:hpcc][:version]" do
+ plugin.run
+ expect(plugin.languages[:c][:hpcc][:version]).to eql("B.11.11.16")
end
- it "should set languages[:c][:hpcc][:version]" do
- @plugin.run
- expect(@plugin.languages[:c][:hpcc][:version]).to eql("B.11.11.16")
+ it "sets languages[:c][:hpcc][:description]" do
+ plugin.run
+ expect(plugin.languages[:c][:hpcc][:description]).to eql(C_HPUX.split($/)[3].strip)
end
- it "should set languages[:c][:hpcc][:description]" do
- @plugin.run
- expect(@plugin.languages[:c][:hpcc][:description]).to eql(C_HPUX.split($/)[3].strip)
+ it "does not set the languages[:c][:hpcc] tree up if cc command exits nonzero" do
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(1, "", ""))
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:hpcc)
end
- it "should not set the languages[:c][:hpcc] tree up if cc command fails" do
- allow(@plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(1, "", ""))
- @plugin.run
- expect(@plugin[:languages][:c]).not_to have_key(:hpcc) if @plugin[:languages][:c]
+ it "does not set the languages[:c][:hpcc] tree up if cc command fails" do
+ allow(plugin).to receive(:shell_out).with("what /opt/ansic/bin/cc").and_raise(Ohai::Exceptions::Exec)
+ plugin.run
+ expect(plugin[:languages][:c]).not_to have_key(:hpcc)
+ expect(plugin[:languages][:c]).not_to be_empty # expect other attributes
end
end
diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb
index 8fb42167..5678dccb 100644
--- a/spec/unit/plugins/rackspace_spec.rb
+++ b/spec/unit/plugins/rackspace_spec.rb
@@ -20,110 +20,118 @@ require "resolv"
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
describe Ohai::System, "plugin rackspace" do
+ let(:plugin) { get_plugin("rackspace") }
+
before(:each) do
allow(Resolv).to receive(:getname).and_return("1.2.3.4")
- @plugin = get_plugin("rackspace")
- @plugin[:hostname] = "katie"
- @plugin[:network] = { :interfaces => { :eth0 => { "addresses" => {
- "1.2.3.4" => {
- "broadcast" => "67.23.20.255",
- "netmask" => "255.255.255.0",
- "family" => "inet",
- },
- "2a00:1a48:7805:111:e875:efaf:ff08:75" => {
- "family" => "inet6",
- "prefixlen" => "64",
- "scope" => "Global",
- },
- "fe80::4240:95ff:fe47:6eed" => {
- "scope" => "Link",
- "prefixlen" => "64",
- "family" => "inet6",
- },
- "40:40:95:47:6E:ED" => {
- "family" => "lladdr",
- },
- } },
- },
- }
-
- @plugin[:network][:interfaces][:eth1] = { :addresses => {
- "fe80::4240:f5ff:feab:2836" => {
- "scope" => "Link",
- "prefixlen" => "64",
- "family" => "inet6",
- },
- "5.6.7.8" => {
- "broadcast" => "10.176.191.255",
- "netmask" => "255.255.224.0",
- "family" => "inet",
+
+ plugin[:hostname] = "katie"
+
+ plugin[:network] = {
+ :interfaces => {
+ :eth0 => {
+ "addresses" => {
+ "1.2.3.4" => {
+ "broadcast" => "67.23.20.255",
+ "netmask" => "255.255.255.0",
+ "family" => "inet",
+ },
+ "2a00:1a48:7805:111:e875:efaf:ff08:75" => {
+ "family" => "inet6",
+ "prefixlen" => "64",
+ "scope" => "Global",
+ },
+ "fe80::4240:95ff:fe47:6eed" => {
+ "scope" => "Link",
+ "prefixlen" => "64",
+ "family" => "inet6",
+ },
+ "40:40:95:47:6E:ED" => {
+ "family" => "lladdr",
+ },
+ },
+ },
},
- "40:40:F5:AB:28:36" => {
- "family" => "lladdr",
+ }
+
+ plugin[:network][:interfaces][:eth1] = {
+ :addresses => {
+ "fe80::4240:f5ff:feab:2836" => {
+ "scope" => "Link",
+ "prefixlen" => "64",
+ "family" => "inet6",
+ },
+ "5.6.7.8" => {
+ "broadcast" => "10.176.191.255",
+ "netmask" => "255.255.224.0",
+ "family" => "inet",
+ },
+ "40:40:F5:AB:28:36" => {
+ "family" => "lladdr",
+ },
},
- } }
+ }
# In olden days we could detect rackspace by a -rscloud suffix on the kernel
# This is here to make #has_rackspace_kernel? fail until we remove that check
- @plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
+ plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
# We need a generic stub here for the later stubs with arguments to work
# Because, magic.
- allow(@plugin).to receive(:shell_out).and_return(mock_shell_out(1, "", ""))
+ allow(plugin).to receive(:shell_out).and_return(mock_shell_out(1, "", ""))
end
shared_examples_for "!rackspace" do
- it "should NOT create rackspace" do
- @plugin.run
- expect(@plugin[:rackspace]).to be_nil
+ it "does not create rackspace" do
+ plugin.run
+ expect(plugin[:rackspace]).to be_nil
end
end
shared_examples_for "rackspace" do
-
- it "should create rackspace" do
- @plugin.run
- expect(@plugin[:rackspace]).not_to be_nil
+ it "creates rackspace" do
+ plugin.run
+ expect(plugin[:rackspace]).not_to be_nil
end
- it "should have all required attributes" do
- @plugin.run
- expect(@plugin[:rackspace][:public_ip]).not_to be_nil
- expect(@plugin[:rackspace][:private_ip]).not_to be_nil
- expect(@plugin[:rackspace][:public_ipv4]).not_to be_nil
- expect(@plugin[:rackspace][:local_ipv4]).not_to be_nil
- expect(@plugin[:rackspace][:public_ipv6]).not_to be_nil
- expect(@plugin[:rackspace][:local_ipv6]).to be_nil
- expect(@plugin[:rackspace][:local_hostname]).not_to be_nil
- expect(@plugin[:rackspace][:public_hostname]).not_to be_nil
+ it "has all required attributes" do
+ plugin.run
+ expect(plugin[:rackspace][:public_ip]).not_to be_nil
+ expect(plugin[:rackspace][:private_ip]).not_to be_nil
+ expect(plugin[:rackspace][:public_ipv4]).not_to be_nil
+ expect(plugin[:rackspace][:local_ipv4]).not_to be_nil
+ expect(plugin[:rackspace][:public_ipv6]).not_to be_nil
+ expect(plugin[:rackspace][:local_ipv6]).to be_nil
+ expect(plugin[:rackspace][:local_hostname]).not_to be_nil
+ expect(plugin[:rackspace][:public_hostname]).not_to be_nil
end
- it "should resolve hostname if reverse dns is set" do
+ it "resolves hostname if reverse dns is set" do
allow(Resolv).to receive(:getname).and_return("1234.resolved.com")
- @plugin.run
- expect(@plugin[:rackspace][:public_hostname]).to eq("1234.resolved.com")
+ plugin.run
+ expect(plugin[:rackspace][:public_hostname]).to eq("1234.resolved.com")
end
[Resolv::ResolvError, Resolv::ResolvTimeout].each do |exception|
- it "should return ip address when reverse dns returns exception: #{exception}" do
+ it "returns ip address when reverse dns returns exception: #{exception}" do
allow(Resolv).to receive(:getname).and_raise(exception)
- @plugin.run
- expect(@plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
+ plugin.run
+ expect(plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
end
end
- it "should have correct values for all attributes" do
- @plugin.run
- expect(@plugin[:rackspace][:public_ip]).to eq("1.2.3.4")
- expect(@plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
- expect(@plugin[:rackspace][:public_ipv4]).to eq("1.2.3.4")
- expect(@plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
- expect(@plugin[:rackspace][:public_ipv6]).to eq("2a00:1a48:7805:111:e875:efaf:ff08:75")
- expect(@plugin[:rackspace][:local_hostname]).to eq("katie")
- expect(@plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
+ it "has correct values for all attributes" do
+ plugin.run
+ expect(plugin[:rackspace][:public_ip]).to eq("1.2.3.4")
+ expect(plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
+ expect(plugin[:rackspace][:public_ipv4]).to eq("1.2.3.4")
+ expect(plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
+ expect(plugin[:rackspace][:public_ipv6]).to eq("2a00:1a48:7805:111:e875:efaf:ff08:75")
+ expect(plugin[:rackspace][:local_hostname]).to eq("katie")
+ expect(plugin[:rackspace][:public_hostname]).to eq("1.2.3.4")
end
- it "should capture region information" do
+ it "captures region information" do
provider_data = <<-OUT
provider = "Rackspace"
service_type = "cloudServers"
@@ -131,21 +139,53 @@ server_id = "21301000"
created_at = "2012-12-06T22:08:16Z"
region = "dfw"
OUT
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/provider_data").and_return(mock_shell_out(0, provider_data, ""))
- @plugin.run
- expect(@plugin[:rackspace][:region]).to eq("dfw")
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/provider_data").and_return(mock_shell_out(0, provider_data, ""))
+ plugin.run
+ expect(plugin[:rackspace][:region]).to eq("dfw")
+ end
+
+ it "logs a debug message when region info cannot be collected" do
+ expect(plugin).
+ to receive(:shell_out).
+ with("xenstore-ls vm-data/provider_data").
+ and_raise(Ohai::Exceptions::Exec)
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("rackspace plugin: Unable to find xenstore-ls, cannot capture " \
+ "region information for Rackspace cloud")
+
+ plugin.run
+
+ expect(plugin[:rackspace]).not_to have_key(:region)
end
- it "should capture instance ID information" do
+ it "captures instance ID information" do
provider_data = "instance-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- allow(@plugin).to receive(:shell_out).with("xenstore-read name").and_return(mock_shell_out(0, provider_data, ""))
- @plugin.run
- expect(@plugin[:rackspace][:instance_id]).to eq("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
+ allow(plugin).to receive(:shell_out).with("xenstore-read name").and_return(mock_shell_out(0, provider_data, ""))
+ plugin.run
+ expect(plugin[:rackspace][:instance_id]).to eq("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
+ end
+
+ it "logs error if instance id cannot be found" do
+ expect(plugin).
+ to receive(:shell_out).
+ with("xenstore-read name").
+ and_raise(Ohai::Exceptions::Exec)
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("rackspace plugin: Unable to find xenstore-read, cannot capture " \
+ "instance ID information for Rackspace cloud")
+
+ plugin.run
+
+ expect(plugin[:rackspace]).not_to have_key(:instance_id)
end
end
describe "with rackspace cloud file" do
- it_should_behave_like "rackspace"
+ it_behaves_like "rackspace"
before(:each) do
allow(Resolv).to receive(:getname).and_raise(Resolv::ResolvError)
@@ -160,34 +200,34 @@ OUT
describe "with no public interfaces (empty eth0)" do
before do
# unset public (eth0) addresses
- @plugin[:network][:interfaces][:eth0]["addresses"] = {}
+ plugin[:network][:interfaces][:eth0]["addresses"] = {}
end
- it "should have all required attributes" do
- @plugin.run
+ it "has all required attributes" do
+ plugin.run
# expliticly nil
- expect(@plugin[:rackspace][:public_ip]).to be_nil
- expect(@plugin[:rackspace][:public_ipv4]).to be_nil
- expect(@plugin[:rackspace][:public_ipv6]).to be_nil
- expect(@plugin[:rackspace][:public_hostname]).to be_nil
+ expect(plugin[:rackspace][:public_ip]).to be_nil
+ expect(plugin[:rackspace][:public_ipv4]).to be_nil
+ expect(plugin[:rackspace][:public_ipv6]).to be_nil
+ expect(plugin[:rackspace][:public_hostname]).to be_nil
# per normal
- expect(@plugin[:rackspace][:private_ip]).not_to be_nil
- expect(@plugin[:rackspace][:local_ipv4]).not_to be_nil
- expect(@plugin[:rackspace][:local_ipv6]).to be_nil
- expect(@plugin[:rackspace][:local_hostname]).not_to be_nil
+ expect(plugin[:rackspace][:private_ip]).not_to be_nil
+ expect(plugin[:rackspace][:local_ipv4]).not_to be_nil
+ expect(plugin[:rackspace][:local_ipv6]).to be_nil
+ expect(plugin[:rackspace][:local_hostname]).not_to be_nil
end
- it "should have correct values for all attributes" do
- @plugin.run
- expect(@plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
- expect(@plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
- expect(@plugin[:rackspace][:local_hostname]).to eq("katie")
+ it "has correct values for all attributes" do
+ plugin.run
+ expect(plugin[:rackspace][:private_ip]).to eq("5.6.7.8")
+ expect(plugin[:rackspace][:local_ipv4]).to eq("5.6.7.8")
+ expect(plugin[:rackspace][:local_hostname]).to eq("katie")
end
end
end
describe "without cloud file" do
- it_should_behave_like "!rackspace"
+ it_behaves_like "!rackspace"
before(:each) do
allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(false)
@@ -196,7 +236,7 @@ OUT
end
describe "with ec2 cloud file" do
- it_should_behave_like "!rackspace"
+ it_behaves_like "!rackspace"
before(:each) do
allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/ec2.json").and_return(true)
@@ -210,29 +250,60 @@ OUT
end
describe "xenstore provider returns rackspace" do
- it_should_behave_like "rackspace"
+ it_behaves_like "rackspace"
before(:each) do
stdout = "Rackspace\n"
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
end
end
describe "xenstore provider does not return rackspace" do
- it_should_behave_like "!rackspace"
+ it_behaves_like "!rackspace"
before(:each) do
stdout = "cumulonimbus\n"
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" ))
+ end
+ end
+
+ describe "xenstore provider does not exist" do
+ it_behaves_like "!rackspace"
+
+ before(:each) do
+ allow(plugin).
+ to receive(:shell_out).
+ with("xenstore-read vm-data/provider_data/provider").
+ and_raise(Ohai::Exceptions::Exec)
+ end
+ end
+
+ describe "when private networks shell out fails" do
+ it "logs an error and does not collect private_networks" do
+ allow(plugin).to receive(:hint?).with("rackspace").and_return(true)
+
+ expect(plugin).
+ to receive(:shell_out).
+ with("xenstore-ls vm-data/networking").
+ and_raise(Ohai::Exceptions::Exec)
+
+ expect(Ohai::Log).
+ to receive(:debug).
+ with("rackspace plugin: Unable to capture custom private networking " \
+ "information for Rackspace cloud")
+
+ plugin.run
+
+ expect(plugin[:rackspace]).not_to have_key(:private_networks)
end
end
describe "does not have private networks" do
before do
stdout = 'BC764E20422B = "{"label": "public"}"\n'
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
stdout = '{"label": "public", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(true)
allow(File).to receive(:read).with("/etc/chef/ohai/hints/rackspace.json").and_return("")
@@ -240,33 +311,35 @@ OUT
allow(File).to receive(:read).with('C:\chef\ohai\hints/rackspace.json').and_return("")
end
- it "should not have private_networks object" do
- @plugin.run
- expect(@plugin[:rackspace][:private_networks]).to eq([])
+ it "does not have private_networks object" do
+ plugin.run
+ expect(plugin[:rackspace][:private_networks]).to eq([])
end
end
describe "has private networks" do
before do
- @plugin[:network][:interfaces][:eth2] = { :addresses => {
- "fe80::be76:4eff:fe20:422b" => {
- "scope" => "Link",
- "prefixlen" => "64",
- "family" => "inet6",
- },
- "9.10.11.12" => {
- "broadcast" => "9.10.11.255",
- "netmask" => "255.255.255.0",
- "family" => "inet",
- },
- "BC:76:4E:20:42:2B" => {
- "family" => "lladdr",
+ plugin[:network][:interfaces][:eth2] = {
+ :addresses => {
+ "fe80::be76:4eff:fe20:422b" => {
+ "scope" => "Link",
+ "prefixlen" => "64",
+ "family" => "inet6",
+ },
+ "9.10.11.12" => {
+ "broadcast" => "9.10.11.255",
+ "netmask" => "255.255.255.0",
+ "family" => "inet",
+ },
+ "BC:76:4E:20:42:2B" => {
+ "family" => "lladdr",
+ },
},
- } }
+ }
stdout = 'BC764E20422B = "{"label": "private-network"}"\n'
- allow(@plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-ls vm-data/networking").and_return(mock_shell_out(0, stdout, "" ))
stdout = '{"label": "private-network", "broadcast": "9.10.11.255", "ips": [{"ip": "9.10.11.12", "netmask": "255.255.255.0", "enabled": "1", "gateway": null}], "mac": "BC:76:4E:20:42:2B", "dns": ["69.20.0.164", "69.20.0.196"], "gateway": null}'
- allow(@plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
+ allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/networking/BC764E20422B").and_return(mock_shell_out(0, stdout, "" ))
allow(File).to receive(:exist?).with("/etc/chef/ohai/hints/rackspace.json").and_return(true)
allow(File).to receive(:read).with("/etc/chef/ohai/hints/rackspace.json").and_return("")
@@ -274,16 +347,16 @@ OUT
allow(File).to receive(:read).with('C:\chef\ohai\hints/rackspace.json').and_return("")
end
- it "should private_networks object" do
- @plugin.run
- expect(@plugin[:rackspace][:private_networks]).not_to be_nil
+ it "has private_networks object" do
+ plugin.run
+ expect(plugin[:rackspace][:private_networks]).not_to be_nil
end
- it "should have correct values for all attributes" do
- @plugin.run
- expect(@plugin[:rackspace][:private_networks][0][:label]).to eq("private-network")
- expect(@plugin[:rackspace][:private_networks][0][:broadcast]).to eq("9.10.11.255")
- expect(@plugin[:rackspace][:private_networks][0][:mac]).to eq("BC:76:4E:20:42:2B")
+ it "has correct values for all attributes" do
+ plugin.run
+ expect(plugin[:rackspace][:private_networks][0][:label]).to eq("private-network")
+ expect(plugin[:rackspace][:private_networks][0][:broadcast]).to eq("9.10.11.255")
+ expect(plugin[:rackspace][:private_networks][0][:mac]).to eq("BC:76:4E:20:42:2B")
end
end