Last active
August 29, 2015 14:14
-
-
Save skamithi/bd42fbddd38d651aedf2 to your computer and use it in GitHub Desktop.
serverspec patches to make bridge class inherit from interface class
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/serverspec/helper/type.rb b/lib/serverspec/helper/type.rb | |
| index 5fcfaae..23d81a0 100644 | |
| --- a/lib/serverspec/helper/type.rb | |
| +++ b/lib/serverspec/helper/type.rb | |
| @@ -2,8 +2,8 @@ module Serverspec | |
| module Helper | |
| module Type | |
| types = %w( | |
| - base bridge cgroup command cron default_gateway file fstab group host | |
| - iis_website iis_app_pool interface ipfilter ipnat iptables | |
| + base cgroup command cron default_gateway file fstab group host | |
| + iis_website iis_app_pool interface bridge 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/bridge.rb b/lib/serverspec/type/bridge.rb | |
| index 0309b6a..2647a81 100644 | |
| --- a/lib/serverspec/type/bridge.rb | |
| +++ b/lib/serverspec/type/bridge.rb | |
| @@ -1,11 +1,7 @@ | |
| module Serverspec::Type | |
| - class Bridge < Base | |
| - def exists? | |
| - @runner.check_bridge_exists(@name) | |
| - end | |
| - | |
| + class Bridge < Interface | |
| def has_interface?(interface) | |
| @runner.check_bridge_has_interface(@name, interface) | |
| end | |
| end | |
| -end | |
| +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
| 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" | |
| speed | |
| should not eq 1000 | |
| Finished in 0.66042 seconds (files took 2.39 seconds to load) | |
| 5 examples, 0 failures | |
| cumulus@leaf1$ netshow phy ; netshow bridge all | |
| Name Speed Mtu Mode Summary | |
| -- ------- --------- ----- --------- ----------------- | |
| UP swp1s0 10G(4x10) 1500 BondMem Master: bond0(UP) | |
| UP swp1s1 10G(4x10) 1500 BondMem Master: bond0(UP) | |
| UP swp32s0 10G(4x10) 1500 Access/L3 IP: 10.20.1.1/24 | |
| Name Speed Mtu Mode Summary | |
| ---- ------ ------- ----- --------- ------------------- | |
| DOWN br0 N/A 1500 Bridge/L3 IP: 10.100.200.1/24 | |
| Untagged: swp10-12 | |
| VlanID: Untagged | |
| 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') } | |
| its(:speed) { should_not eq 1000 } | |
| 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
| ➜ specinfra git:(master) ✗ cat 1.patch | |
| diff --git a/lib/specinfra/command.rb b/lib/specinfra/command.rb | |
| index a494d6b..ee37603 100644 | |
| --- a/lib/specinfra/command.rb | |
| +++ b/lib/specinfra/command.rb | |
| @@ -7,13 +7,13 @@ require 'specinfra/command/module/zfs' | |
| # Base | |
| require 'specinfra/command/base' | |
| -require 'specinfra/command/base/bridge' | |
| require 'specinfra/command/base/cron' | |
| 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' | |
| diff --git a/lib/specinfra/command/base/bridge.rb b/lib/specinfra/command/base/bridge.rb | |
| index 21af11c..6f6859b 100644 | |
| --- a/lib/specinfra/command/base/bridge.rb | |
| +++ b/lib/specinfra/command/base/bridge.rb | |
| @@ -1,2 +1,2 @@ | |
| -class Specinfra::Command::Base::Bridge < Specinfra::Command::Base | |
| +class Specinfra::Command::Base::Bridge < Specinfra::Command::Base::Interface | |
| end | |
| diff --git a/lib/specinfra/command/linux/base/bridge.rb b/lib/specinfra/command/linux/base/bridge.rb | |
| index 89ad60f..842dabf 100644 | |
| --- a/lib/specinfra/command/linux/base/bridge.rb | |
| +++ b/lib/specinfra/command/linux/base/bridge.rb | |
| @@ -1,9 +1,5 @@ | |
| -class Specinfra::Command::Linux::Base::Bridge < Specinfra::Command::Base::Bridge | |
| +class Specinfra::Command::Linux::Base::Bridge < Specinfra::Command::Linux::Base::Interface | |
| class << self | |
| - def check_exists(name) | |
| - "ip link show #{name}" | |
| - end | |
| - | |
| def check_has_interface(name, interface) | |
| "brctl show #{name} | grep -o #{interface}" | |
| end | |
| diff --git a/lib/specinfra/command/linux/base/interface.rb b/lib/specinfra/command/linux/base/interface.rb | |
| index 2bb5bec..0ba7efc 100644 | |
| --- a/lib/specinfra/command/linux/base/interface.rb | |
| +++ b/lib/specinfra/command/linux/base/interface.rb | |
| @@ -5,7 +5,7 @@ class Specinfra::Command::Linux::Base::Interface < Specinfra::Command::Base::Int | |
| end | |
| def get_speed_of(name) | |
| - "ethtool #{name} | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\\/s/,\"\\\\1\",\"\")}'" | |
| + "cat /sys/class/net/#{name}/speed" | |
| end | |
| def check_has_ipv4_address(interface, ip_address) | |
| diff --git a/spec/command/linux/bridge_spec.rb b/spec/command/linux/bridge_spec.rb | |
| index c8353e4..cf762b4 100644 | |
| --- a/spec/command/linux/bridge_spec.rb | |
| +++ b/spec/command/linux/bridge_spec.rb | |
| @@ -3,10 +3,6 @@ require 'spec_helper' | |
| property[:os] = nil | |
| set :os, :family => 'linux' | |
| -describe get_command(:check_bridge_exists, 'br0') do | |
| - it { should eq "ip link show br0" } | |
| -end | |
| - | |
| describe get_command(:check_bridge_has_interface, 'br0', 'eth0') do | |
| it { should eq "brctl show br0 | grep -o eth0" } | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
by making bridge class inherit from interface class you can also run ip checks and any other interface test on a bridge or bond or any other virtual interface.
then for speed check use sys/class/net listing of the speed instead of ethtool.. easier solution to me.