Skip to content

Commit

Permalink
Merge branch 'bonding'
Browse files Browse the repository at this point in the history
This partially addresses GH-17.
  • Loading branch information
adrienthebo committed Mar 12, 2013
2 parents 139f274 + 1a2dad5 commit 01c52ba
Show file tree
Hide file tree
Showing 23 changed files with 634 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixtures:
repositories:
kmod: 'https://github.com/camptocamp/puppet-kmod'
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
boolean: 'https://github.com/adrienthebo/puppet-boolean'
filemapper: 'https://github.com/adrienthebo/puppet-filemapper'
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
language: ruby
before_script:
- "bundle exec puppet module install adrien/boolean"
- "bundle exec puppet module install adrien/filemapper"
script: "spec/travis_rspec.rb --color --format documentation"
before_script: 'bundle exec rake fixture:prepare'
script: 'SPEC_OPTS="--format documentation" bundle exec rake spec'
notifications:
email: false
rvm:
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source :rubygems
source 'https://rubygems.org'

gem 'puppet', '>= 2.7.0'
gem 'facter', '>= 1.6.2'
Expand All @@ -7,6 +7,7 @@ group :test, :development do
gem 'rspec', '~> 2.10.0'
gem 'mocha', '~> 0.10.5'
gem 'rspec-puppet', '>= 0.1.5'
gem 'puppetlabs_spec_helper'
end

if File.exists? "#{__FILE__}.local"
Expand Down
4 changes: 3 additions & 1 deletion Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ description 'Manage persistent network interface configuration'
source 'https://github.com/adrienthebo/puppet-network'
project_page 'https://github.com/adrienthebo/puppet-network'

dependency 'puppetlabs/stdlib', '>= 2.3.0'
dependency 'adrien/filemapper', '>= 1.0.0'
dependency 'adrien/boolean', '0.9.x'
dependency 'adrien/boolean', '0.9.x'
dependency 'camptocamp/kmod', '0.0.x'
48 changes: 48 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'rake'
require 'yaml'
require 'rspec/core/rake_task'

def fixtures(category)
root = File.dirname(__FILE__)
yaml = YAML.load_file(File.expand_path('.fixtures.yml', root))

fixtures = yaml["fixtures"]

if fixtures.nil?
raise ".fixtures.yml contained no top level 'fixtures' key"
end

fixtures[category] || {}
rescue => e
raise e, "Could not load fixture data: #{e}"
end

namespace :fixture do

desc "Prepare all fixture repositories"
task :prepare do
fixtures("repositories").each_pair do |name, remote|
fixture_target = "spec/fixtures/modules/#{name}"
sh "git clone '#{remote}' '#{fixture_target}'" unless File.exist? fixture_target
end
end

desc "Remove all fixture repositories"
task :remove do
fixtures["repositories"].each_pair do |name, remote|
fixture_target = "spec/fixtures/modules/#{name}"
FileUtils.rm_rf fixture_target if File.exist? fixture_target
end
end
end

desc "Run spec tests on an existing fixtures directory"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--color']
t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
end

desc "Display the list of available rake tasks"
task :help do
system("rake -T")
end
27 changes: 27 additions & 0 deletions lib/puppet/parser/functions/compact_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Puppet::Parser::Functions.newfunction(:compact_hash,
:type => :rvalue,
:arity => 1,
:doc => <<-EOD) do |args|
compact_hash
============
Compresses a hash to remove all elements whose values are nil or undef.
Examples
--------
$example = {
'one' => 'two',
'red' => undef,
'blue' => nil,
}
compact_hash($example)
# => { 'one => 'two' }
EOD

hash = args[0]

hash.reject { |_, val| val.nil? or val == :undef }
end
96 changes: 96 additions & 0 deletions manifests/bond.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# = Define: network::bond
#
# Instantiate cross-platform bonded interfaces
#
# == Parameters
#
#
# == Examples
#
# network::bond { 'bond0':
# ipaddress => '172.16.1.2',
# netmask => '255.255.128.0',
# ensure => present,
# slaves => ['eth0', 'eth1'],
# }
#
# == See also
#
# * Linux Ethernet Bonding Driver HOWTO, Section 2 "Bonding Driver Options" http://www.kernel.org/doc/Documentation/networking/bonding.txt
#
define network::bond(
$slaves,
$ensure = present,
$ipaddress = undef,
$netmask = undef,
$method = undef,
$family = undef,
$onboot = undef,

$mode = "active-backup",
$miimon = "100",
$downdelay = "200",
$updelay = "200",
$lacp_rate = "slow",
$primary = $slaves[0],
$primary_reselect = "always",
$xmit_hash_policy = "layer2",
) {

require network::bond::setup

kmod::alias { $name:
source => 'bonding',
ensure => $ensure,
}

case $osfamily {
Debian: {
network::bond::debian { $name:
slaves => $slaves,
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
method => $method,
family => $family,
onboot => $onboot,

mode => $mode,
miimon => $miimon,
downdelay => $downdelay,
updelay => $updelay,
lacp_rate => $lacp_rate,
primary => $primary,
primary_reselect => $primary_reselect,
xmit_hash_policy => $xmit_hash_policy,

require => Kmod::Alias[$name],
}
}
RedHat: {
network::bond::redhat { $name:
slaves => $slaves,
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
family => $family,
method => $method,
onboot => $onboot,

mode => $mode,
miimon => $miimon,
downdelay => $downdelay,
updelay => $updelay,
lacp_rate => $lacp_rate,
primary => $primary,
primary_reselect => $primary_reselect,
xmit_hash_policy => $xmit_hash_policy,

require => Kmod::Alias[$name],
}
}
default: {
fail("network::bond does not support osfamily '${osfamily}'")
}
}
}
56 changes: 56 additions & 0 deletions manifests/bond/debian.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# = Define: network::bond::debian
#
# Instantiate bonded interfaces on Debian based systems.
#
# == See also
#
# * Debian Network Bonding http://wiki.debian.org/Bonding
define network::bond::debian(
$slaves,
$ensure = present,
$ipaddress = undef,
$netmask = undef,
$method = undef,
$family = undef,
$onboot = undef,

$mode = undef,
$miimon = undef,
$downdelay = undef,
$updelay = undef,
$lacp_rate = undef,
$primary = undef,
$primary_reselect = undef,
$xmit_hash_policy = undef,
) {

$raw = {
'bond-slaves' => join($slaves, ' '),
'bond-mode' => $mode,
'bond-miimon' => $miimon,
'bond-downdelay' => $downdelay,
'bond-updelay' => $updelay,
'bond-lacp-rate' => $lacp_rate,
'bond-primary' => $primary,
'bond-primary-reselect' => $primary_reselect,
'bond-xmit-hash-policy' => $xmit_hash_policy,
}

$opts = compact_hash($raw)

network_config { $name:
ensure => $ensure,
ipaddress => $ipaddress,
netmask => $netmask,
family => $family,
method => $method,
onboot => $onboot,
options => $opts,
}

network_config { $slaves:
ensure => absent,
reconfigure => true,
before => Network_config[$name],
}
}
52 changes: 52 additions & 0 deletions manifests/bond/redhat.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# = Define: network::bond::redhat
#
# Instantiate bonded interfaces on Redhat based systems.
#
# == See also
#
# * Red Hat Deployment Guide 25.7.2 "Using Channel Bonding" https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Using_Channel_Bonding.html
#
define network::bond::redhat(
$slaves,
$ensure = present,
$ipaddress = undef,
$netmask = undef,
$method = undef,
$family = undef,
$onboot = undef,

$mode = undef,
$miimon = undef,
$downdelay = undef,
$updelay = undef,
$lacp_rate = undef,
$primary = undef,
$primary_reselect = undef,
$xmit_hash_policy = undef,
) {

$bonding_opts = template("network/bond/opts-redhat.erb")

network_config { $name:
ensure => $ensure,
method => $method,
ipaddress => $ipaddress,
netmask => $netmask,
family => $family,
onboot => $onboot,
options => {
'BONDING_OPTS' => $bonding_opts,
}
}

network_config { $slaves:
ensure => $ensure,
method => static,
onboot => true,
options => {
'MASTER' => $name,
'SLAVE' => 'yes',
}
}
}

14 changes: 14 additions & 0 deletions manifests/bond/setup.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class network::bond::setup {

case $osfamily {
RedHat: {
# Redhat installs the ifenslave command with the iputils package which
# is available by default
}
Debian: {
package { 'ifenslave':
ensure => present,
}
}
}
}
9 changes: 9 additions & 0 deletions spec/classes/bond/setup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'network::bond::setup', :type => :class do
describe 'on Debian' do
let(:facts) {{:osfamily => 'Debian'}}

it { should contain_package('ifenslave') }
end
end
Loading

0 comments on commit 01c52ba

Please sign in to comment.