Skip to content

Commit

Permalink
OHAI-529 Remove ipaddr_extension from Gemfile
Browse files Browse the repository at this point in the history
Specs for the ip_scopes plugin can be run in two ways:
* Run rspec in the context of `bundle exec`
* Install ipaddr_extensions, then run rspec outside of
  `bundle exec`
  • Loading branch information
sax authored and btm committed Nov 26, 2013
1 parent 5e6e083 commit 669cd21
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ group :development do

gem "sigar", :platform => "ruby"
gem 'plist'
gem 'ipaddr_extensions'
#gem 'pry'
#gem 'pry-debugger'
# gem 'pry-stack_explorer'
Expand Down
103 changes: 56 additions & 47 deletions spec/unit/plugins/ip_scopes_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')

begin
require 'ipaddr_extensions'
rescue LoadError
end

describe Ohai::System, "plugin ip_scopes" do
let(:plugin) { get_plugin('ip_scopes') }
let(:network) { Mash.new(:interfaces => interfaces) }
Expand All @@ -15,72 +20,76 @@

before { plugin[:network] = network }

context 'with ipaddr_extensions gem' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '1.2.3.4' }
let(:ip3) { 'fe80::8638:35ff:fe4e:dc74' }
if defined?(IPAddrExtensions)
context 'with ipaddr_extensions gem' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '1.2.3.4' }
let(:ip3) { 'fe80::8638:35ff:fe4e:dc74' }

let(:addresses1) { Hash[ip1, {}] }
let(:addresses2) { Hash[ip2, {}, ip3, {}] }
let(:addresses1) { Hash[ip1, {}] }
let(:addresses2) { Hash[ip2, {}, ip3, {}] }

it 'adds ip_scope to each address' do
plugin.run
expect(plugin[:network][:interfaces][:eth0][:addresses]['10.0.0.1'][:ip_scope]).to eq('RFC1918 PRIVATE')
expect(plugin[:network][:interfaces][:eth1][:addresses]['1.2.3.4'][:ip_scope]).to eq('GLOBAL UNICAST')
expect(plugin[:network][:interfaces][:eth1][:addresses]['fe80::8638:35ff:fe4e:dc74'][:ip_scope]).to eq('LINK LOCAL UNICAST')
end
it 'adds ip_scope to each address' do
plugin.run
expect(plugin[:network][:interfaces][:eth0][:addresses]['10.0.0.1'][:ip_scope]).to eq('RFC1918 PRIVATE')
expect(plugin[:network][:interfaces][:eth1][:addresses]['1.2.3.4'][:ip_scope]).to eq('GLOBAL UNICAST')
expect(plugin[:network][:interfaces][:eth1][:addresses]['fe80::8638:35ff:fe4e:dc74'][:ip_scope]).to eq('LINK LOCAL UNICAST')
end

describe 'privateaddress' do
before { plugin.run }
describe 'privateaddress' do
before { plugin.run }

context 'host has multiple RFC1918 ethernet addresses' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '192.168.1.1' }
let(:interface1_type) { 'eth' }
let(:interface2_type) { 'eth' }
context 'host has multiple RFC1918 ethernet addresses' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '192.168.1.1' }
let(:interface1_type) { 'eth' }
let(:interface2_type) { 'eth' }

it 'picks the last address' do
expect(plugin[:privateaddress]).to eq('192.168.1.1')
it 'picks the last address' do
expect(plugin[:privateaddress]).to eq('192.168.1.1')
end
end
end

context 'host has PPP and ethernet RFC1918 addresses' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '192.168.1.1' }
let(:interface1_type) { 'eth' }
let(:interface2_type) { 'ppp' }
context 'host has PPP and ethernet RFC1918 addresses' do
let(:ip1) { '10.0.0.1' }
let(:ip2) { '192.168.1.1' }
let(:interface1_type) { 'eth' }
let(:interface2_type) { 'ppp' }

it 'prefers the eth address' do
expect(plugin[:privateaddress]).to eq('10.0.0.1')
it 'prefers the eth address' do
expect(plugin[:privateaddress]).to eq('10.0.0.1')
end
end
end

context 'host only has ppp RFC1918 address' do
let(:ip1) { '10.0.0.1' }
let(:interface1_type) { 'ppp' }
context 'host only has ppp RFC1918 address' do
let(:ip1) { '10.0.0.1' }
let(:interface1_type) { 'ppp' }

it 'uses it' do
expect(plugin[:privateaddress]).to eq('10.0.0.1')
it 'uses it' do
expect(plugin[:privateaddress]).to eq('10.0.0.1')
end
end
end
end
end

context 'without the ipaddr_extensions gem' do
let(:addresses1) { Hash['10.0.0.1', {}] }
unless defined?(IPAddrExtensions)
context 'without the ipaddr_extensions gem' do
let(:addresses1) { Hash['10.0.0.1', {}] }

before do
# standin for raising on `require 'ipaddr_extensions'`
plugin[:network][:interfaces].stub(:keys).and_raise(LoadError)
plugin.run
end
before do
# standin for raising on `require 'ipaddr_extensions'`
plugin[:network][:interfaces].stub(:keys).and_raise(LoadError)
plugin.run
end

it 'does not add ip_scope to address' do
expect(plugin[:network][:interfaces][:eth0][:addresses]['10.0.0.1'][:ip_scope]).to be nil
end
it 'does not add ip_scope to address' do
expect(plugin[:network][:interfaces][:eth0][:addresses]['10.0.0.1'][:ip_scope]).to be nil
end

it 'does not add a privateaddress key' do
expect(plugin[:privateaddress]).to be nil
it 'does not add a privateaddress key' do
expect(plugin[:privateaddress]).to be nil
end
end
end
end

0 comments on commit 669cd21

Please sign in to comment.