Skip to content
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
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ fixtures:
repositories:
augeas_core: 'https://github.com/puppetlabs/puppetlabs-augeas_core'
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
systemd: 'https://github.com/voxpupuli/puppet-systemd'
2 changes: 2 additions & 0 deletions data/Debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ tftp::service: tftpd-hpa
tftp::syslinux_package:
- syslinux-common
- pxelinux
tftp::username: 'tftp'
tftp::options: '--secure'
1 change: 1 addition & 0 deletions data/RedHat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ tftp::service: tftp.socket
tftp::package: tftp-server
tftp::root: "/var/lib/tftpboot"
tftp::syslinux_package: syslinux
tftp::options: '--secure'
26 changes: 22 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@
ensure_resource('file', $tftp::root, { 'ensure' => 'directory' })
}

if $facts['os']['family'] =~ /^(FreeBSD|DragonFly)$/ {
augeas { 'set root directory':
context => '/files/etc/rc.conf',
changes => "set tftpd_flags '\"-s ${tftp::root}\"'",
case $facts['os']['family'] {
'FreeBSD', 'DragonFly': {
augeas { 'set root directory':
context => '/files/etc/rc.conf',
changes => "set tftpd_flags '\"-s ${tftp::root}\"'",
}
}
'Debian': {
file { '/etc/default/tftpd-hpa':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp("${module_name}/tftpd-hpa.epp"),
}
}
'RedHat': {
systemd::dropin_file { 'tftp.conf':
unit => 'tftp.service',
content => epp("${module_name}/tftp.service-override.epp"),
}
}
default: {}
}
}
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# @param manage_root_dir manages the root dir, which tftpd will serve, defaults to true
# @param service Name of the TFTP service, when daemon is true
# @param service_provider Override TFTP service provider, when daemon is true
# @param username Configures the daemon user
# @param port Configures the Listen Port
# @param address Configures the Listen Address, if empty it will listen on IPv4 and IPv6 (only on tftpd-hpa)
# @param options Configures daemon options
class tftp (
Stdlib::Absolutepath $root,
String $package,
Expand All @@ -28,6 +32,10 @@
Boolean $manage_root_dir,
Optional[String] $service = undef,
Optional[String] $service_provider = undef,
String[1] $username = 'root',
Stdlib::Port $port = 69,
Optional[Stdlib::IP::Address] $address = undef,
Optional[String[1]] $options = undef,
) {
contain tftp::install
contain tftp::config
Expand Down
53 changes: 53 additions & 0 deletions spec/acceptance/tftp_port_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'spec_helper_acceptance'

describe 'tftp with default parameters' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-EOS
class { 'tftp':
port => 1234,
}

file { "${tftp::root}/test":
ensure => file,
content => 'running on a different port',
}
EOS
end
end

service_name = case fact('osfamily')
when 'Archlinux'
'tftpd.socket'
when 'RedHat'
'tftp.socket'
when 'Debian'
'tftpd-hpa'
end

describe service(service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe port(69), unless: service_name.end_with?('.socket') do
it { is_expected.not_to be_listening }
end

describe port(1234), unless: service_name.end_with?('.socket') do
it { is_expected.to be_listening.with('udp') }
end

describe 'ensure tftp client is installed' do
on hosts, puppet('resource', 'package', 'tftp', 'ensure=installed')
end

describe command("echo get /test /tmp/downloaded_file | tftp #{fact('fqdn')} 1234") do
its(:exit_status) { should eq 0 }
end

describe file('/tmp/downloaded_file') do
it { should be_file }
its(:content) { should eq 'running on a different port' }
end
end
26 changes: 26 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end

it 'should contain the service override' do
should contain_systemd__dropin_file('tftp.conf')
.with_content(%r{^ExecStart=/usr/sbin/in\.tftp --secure /var/lib/tftpboot$})
end
when 'FreeBSD'
it 'should contain the service' do
should contain_service('tftpd')
Expand All @@ -75,6 +80,27 @@
end
end

context 'with custom options' do
let :params do
{
options: '--secure --verbose'
}
end

case facts[:os]['family']
when 'Debian'
it 'should configure tftpd-hpa with custom options' do
should contain_file('/etc/default/tftpd-hpa')
.with_content(%r{^TFTP_OPTIONS="--secure --verbose"$})
end
when 'RedHat'
it 'should contain the service override with custom options' do
should contain_systemd__dropin_file('tftp.conf')
.with_content(%r{^ExecStart=/usr/sbin/in\.tftp --secure --verbose /var/lib/tftpboot$})
end
end
end

context 'with custom tftp package set to tftp-hpa-destruct' do
let :params do
{
Expand Down
3 changes: 3 additions & 0 deletions templates/tftp.service-override.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
ExecStart=
ExecStart=/usr/sbin/in.tftp <%= $tftp::options %> <%= $tftp::root %>
7 changes: 7 additions & 0 deletions templates/tftpd-hpa.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# /etc/default/tftpd-hpa
# This file is managed by Puppet.

TFTP_USERNAME="<%= $tftp::username %>"
TFTP_DIRECTORY="<%= $tftp::root %>"
TFTP_ADDRESS="<%= $tftp::address %>:<%= $tftp::port %>"
TFTP_OPTIONS="<%= $tftp::options %>"
Loading