Last active
August 29, 2015 14:14
-
-
Save skamithi/925daed0265413020b0b to your computer and use it in GitHub Desktop.
serverspec/specinfra for bonding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cumulus@leaf1$ netshow bond | |
Name Speed Mtu Mode Summary | |
-- ------ ------- ----- ------- ------------------------------- | |
UP bond0 20G 1500 Bond/L3 BondMems: swp1s0(UP) swp1s1(UP) | |
IP: 10.1.2.1/30 | |
cumulus@leaf1$ | |
cumulus@leaf1$ bundle exec rspec | |
Interface "br0" | |
should have ipv4 address "10.100.200.1" | |
Interface "swp1s0" | |
speed | |
should eq 10000 | |
Bridge "br0" | |
should exist | |
should have ipv4 address "10.100.200.1" | |
should have interface "swp10" | |
speed | |
should not eq 1000 | |
Bond "bond0" | |
should exist | |
should have interface "swp1s0" | |
speed | |
should eq 20000 | |
Finished in 0.95497 seconds (files took 2.39 seconds to load) | |
9 examples, 0 failures | |
cumulus@leaf1$ cat spec/localhost/sample_spec.rb | |
require 'spec_helper' | |
describe interface('br0') do | |
it { should have_ipv4_address('10.100.200.1') } | |
end | |
describe interface('swp1s0') do | |
its(:speed) { should eq 10000 } | |
end | |
describe bridge('br0') do | |
it { should exist } | |
it { should have_ipv4_address('10.100.200.1') } | |
it { should have_interface('swp10') } | |
its(:speed) { should_not eq 1000 } | |
end | |
describe bond('bond0') do | |
it { should exist } | |
it { should have_interface('swp1s0') } | |
its(:speed) { should eq 20000 } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/lib/serverspec/helper/type.rb | |
+++ b/lib/serverspec/helper/type.rb | |
@@ -3,7 +3,7 @@ module Serverspec | |
module Type | |
types = %w( | |
base cgroup command cron default_gateway file fstab group host | |
- iis_website iis_app_pool interface bridge ipfilter ipnat iptables | |
+ iis_website iis_app_pool interface bridge bond ipfilter ipnat iptables | |
ip6tables kernel_module linux_kernel_parameter lxc mail_alias | |
package php_config port ppa process routing_table selinux | |
selinux_module service user yumrepo windows_feature | |
diff --git a/lib/serverspec/type/bond.rb b/lib/serverspec/type/bond.rb | |
new file mode 100644 | |
index 0000000..d06283b | |
--- /dev/null | |
+++ b/lib/serverspec/type/bond.rb | |
@@ -0,0 +1,7 @@ | |
+module Serverspec::Type | |
+ class Bond < Interface | |
+ def has_interface?(interface) | |
+ @runner.check_bond_has_interface(@name, interface) | |
+ end | |
+ end | |
+end | |
diff --git a/spec/type/linux/bond_spec.rb b/spec/type/linux/bond_spec.rb | |
new file mode 100644 | |
index 0000000..d8cf17f | |
--- /dev/null | |
+++ b/spec/type/linux/bond_spec.rb | |
@@ -0,0 +1,8 @@ | |
+require 'spec_helper' | |
+ | |
+set :os, :family => 'linux' | |
+ | |
+describe bond('bond0') do | |
+ let (:stdout) { 'eth0' } | |
+ it { should have_interface 'eth0' } | |
+end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/specinfra/command.rb b/lib/specinfra/command.rb | |
index ee37603..a6a9a19 100644 | |
--- a/lib/specinfra/command.rb | |
+++ b/lib/specinfra/command.rb | |
@@ -12,8 +12,6 @@ require 'specinfra/command/base/file' | |
require 'specinfra/command/base/fstab' | |
require 'specinfra/command/base/group' | |
require 'specinfra/command/base/host' | |
-require 'specinfra/command/base/interface' | |
-require 'specinfra/command/base/bridge' | |
require 'specinfra/command/base/inventory' | |
require 'specinfra/command/base/ipfilter' | |
require 'specinfra/command/base/ipnat' | |
@@ -35,13 +33,16 @@ require 'specinfra/command/base/user' | |
require 'specinfra/command/base/yumrepo' | |
require 'specinfra/command/base/zfs' | |
+# Base::Interface (inherits Base) | |
+require 'specinfra/command/base/interface' | |
+require 'specinfra/command/base/bridge' | |
+require 'specinfra/command/base/bond' | |
+ | |
# Linux (inhefit Base) | |
require 'specinfra/command/linux' | |
require 'specinfra/command/linux/base' | |
-require 'specinfra/command/linux/base/bridge' | |
require 'specinfra/command/linux/base/file' | |
require 'specinfra/command/linux/base/fstab' | |
-require 'specinfra/command/linux/base/interface' | |
require 'specinfra/command/linux/base/inventory' | |
require 'specinfra/command/linux/base/iptables' | |
require 'specinfra/command/linux/base/ip6tables' | |
@@ -55,6 +56,11 @@ require 'specinfra/command/linux/base/service' | |
require 'specinfra/command/linux/base/yumrepo' | |
require 'specinfra/command/linux/base/zfs' | |
+# Linux::Interfaces (inherits Base) | |
+require 'specinfra/command/linux/base/interface' | |
+require 'specinfra/command/linux/base/bridge' | |
+require 'specinfra/command/linux/base/bond' | |
+ | |
# RedHat (inherit Linux) | |
require 'specinfra/command/redhat' | |
require 'specinfra/command/redhat/base' | |
diff --git a/lib/specinfra/command/base/bond.rb b/lib/specinfra/command/base/bond.rb | |
new file mode 100644 | |
index 0000000..f606f8a | |
--- /dev/null | |
+++ b/lib/specinfra/command/base/bond.rb | |
@@ -0,0 +1,3 @@ | |
+class Specinfra::Command::Base::Bond < Specinfra::Command::Base::Interface | |
+end | |
+ | |
diff --git a/lib/specinfra/command/linux/base/bond.rb b/lib/specinfra/command/linux/base/bond.rb | |
new file mode 100644 | |
index 0000000..afdc364 | |
--- /dev/null | |
+++ b/lib/specinfra/command/linux/base/bond.rb | |
@@ -0,0 +1,8 @@ | |
+class Specinfra::Command::Linux::Base::Bond < Specinfra::Command::Linux::Base::Interface | |
+ class << self | |
+ def check_has_interface(name, interface) | |
+ "awk '/Slave Interface: #{interface}/' /proc/net/bonding/#{name}" | |
+ end | |
+ end | |
+end | |
+ | |
diff --git a/spec/command/linux/bond_spec.rb b/spec/command/linux/bond_spec.rb | |
new file mode 100644 | |
index 0000000..dc528c2 | |
--- /dev/null | |
+++ b/spec/command/linux/bond_spec.rb | |
@@ -0,0 +1,9 @@ | |
+require 'spec_helper' | |
+ | |
+property[:os] = nil | |
+set :os, :family => 'linux' | |
+ | |
+describe get_command(:check_bond_has_interface, 'bond0', 'eth0') do | |
+ it { should eq "awk '/Slave Interface: eth0/' /proc/net/bonding/bond0" } | |
+end | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment