Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #135 and #134 (UNTESTED!) #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions manifests/route.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
# gateway => [ '192.168.1.1', '10.0.0.1', ],
# }
#
# network::route { 'ens192':
# ipaddress => [
# '192.168.2.0/24 via 192.168.1.1',
# '10.0.0.0/8 via 10.0.0.1'
# ]
# }
#
# === Authors:
#
# Mike Arnold <[email protected]>
Expand All @@ -41,29 +48,37 @@
# Copyright (C) 2011 Mike Arnold, unless otherwise noted.
#
define network::route (
$ipaddress,
$netmask,
$gateway,
$restart = true,
Array[String] $ipaddress,
Optional[Array[String]] $netmask = undef,
Optional[Array[String]] $gateway = undef,
Boolean $restart = true,
) {
# Validate our arrays
validate_array($ipaddress)
validate_array($netmask)
validate_array($gateway)
# Validate our booleans
validate_bool($restart)

include '::network'

$interface = $name

if $ipaddress != undef and $netmask != undef and $gateway != undef {
if length($ipaddress) == length($netmask) and length($netmask) == length($gateway) {
$template = 'network/route-eth.erb';
else {
fail { 'All arrays must be the same length': }
}
}
elsif $netmask == undef and $gateway == undef {
$template = 'network/route-eth-ip.erb';
}
else {
fail { 'Either use just ipaddress, or use all three array parameters': }
}

file { "route-${interface}":
ensure => 'present',
mode => '0644',
owner => 'root',
group => 'root',
path => "/etc/sysconfig/network-scripts/route-${interface}",
content => template('network/route-eth.erb'),
content => template($template),
before => File["ifcfg-${interface}"],
}

Expand Down
28 changes: 28 additions & 0 deletions spec/defines/network_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@

describe 'network::route', :type => 'define' do

context 'array parameters, ip command format' do
let(:title) { 'ens192' }
let :params do
{
:ipaddress => [
'192.168.2.0/24 via 192.168.1.2',
'10.0.0.0/8 via 10.1.1.1',
],
}
end
let(:facts) {{ :osfamily => 'RedHat' }}
it { should contain_file('route-ens192').with(
:ensure => 'present',
:mode => '0644',
:owner => 'root',
:group => 'root',
:path => '/etc/sysconfig/network-scripts/route-ens192'
)}
it 'should contain File[route-ens192 with contents "192.168.2.0/24 via 192.168.1.2\n10.0.0.0/8 via 10.1.1.1"' do
verify_contents(catalogue, 'route-ens192', [
'192.168.2.0/24 via 192.168.1.2',
'10.0.0.0/8 via 10.1.1.1',
])
end
it { should contain_service('network') }
it { is_expected.to contain_file('route-ens192').that_notifies('Service[network]') }
end

context 'singular parameters' do
let(:title) { 'eth1' }
let :params do {
Expand Down
6 changes: 6 additions & 0 deletions templates/route-eth-ip.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###
### File managed by Puppet
###
<% @ipaddress.each do |addr| -%>
<%= addr %>
<% end -%>