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

Manage more parameters extension #141

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
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/camptocamp/puppet-systemd'
8 changes: 4 additions & 4 deletions data/Amazon.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tftp::package: tftp-server
tftp::root: "/var/lib/tftpboot"
tftp::service: tftp.socket
tftp::syslinux_package: syslinux
tftp::package: 'tftp-server'
tftp::root: '/var/lib/tftpboot'
tftp::service: 'tftp.socket'
tftp::syslinux_package: 'syslinux'
10 changes: 6 additions & 4 deletions data/Archlinux.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
tftp::package: tftp-hpa
tftp::root: "/srv/tftp"
tftp::service: tftpd.socket
tftp::syslinux_package: syslinux
tftp::package: 'tftp-hpa'
tftp::root: '/srv/tftp'
tftp::service: 'tftpd.service'
tftp::syslinux_package: 'syslinux'
tftp::username: 'nobody'
tftp::options: '--secure'
12 changes: 7 additions & 5 deletions data/Debian.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
tftp::package: tftpd-hpa
tftp::root: "/srv/tftp"
tftp::service: tftpd-hpa
tftp::package: 'tftpd-hpa'
tftp::root: '/srv/tftp'
tftp::service: 'tftpd-hpa'
tftp::syslinux_package:
- syslinux-common
- pxelinux
- 'syslinux-common'
- 'pxelinux'
tftp::username: 'tftp'
tftp::options: '--secure'
8 changes: 4 additions & 4 deletions data/DragonFly.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tftp::package: tftp-hpa
tftp::root: "/tftpboot"
tftp::service: tftpd
tftp::syslinux_package: syslinux
tftp::package: 'tftp-hpa'
tftp::root: '/tftpboot'
tftp::service: 'tftpd'
tftp::syslinux_package: 'syslinux'
8 changes: 4 additions & 4 deletions data/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
tftp::package: tftp-hpa
tftp::root: "/tftpboot"
tftp::service: tftpd
tftp::syslinux_package: syslinux
tftp::package: 'tftp-hpa'
tftp::root: '/tftpboot'
tftp::service: 'tftpd'
tftp::syslinux_package: 'syslinux'
11 changes: 7 additions & 4 deletions data/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
tftp::service: tftp.socket
tftp::package: tftp-server
tftp::root: "/var/lib/tftpboot"
tftp::syslinux_package: syslinux
tftp::service:
- 'tftp.socket'
- 'tftp.service'
tftp::package: 'tftp-server'
tftp::root: '/var/lib/tftpboot'
tftp::syslinux_package: 'syslinux'
tftp::options: '--secure'
44 changes: 40 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,46 @@
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 => template('tftp/tftpd-hpa.erb'),
notify => Service[$tftp::service],
}
}
'Archlinux': {
file { '/etc/conf.d/tftpd':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => template('tftp/tftpd.erb'),
notify => Service[$tftp::service],
}
}
'RedHat': {
systemd::dropin_file { 'tftp-socket-override.conf':
unit => 'tftp.socket',
content => epp('tftp/tftp.socket-override.epp'),
}
systemd::dropin_file { 'tftp-service-override.conf':
unit => 'tftp.service',
content => epp('tftp/tftp.service-override.epp'),
require => Systemd::Dropin_file['tftp-socket-override.conf'],
}
}
default: {
notify { "Unsupported platform: ${facts['os']['family']}, the tftp service will run with with default parameters": }
}
}
}
15 changes: 12 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@
# @param syslinux_package Name of the syslinux package, essential for pxe boot
# @param manage_syslinux_package manages the syslinux package, defaults to true
# @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 service Name of the TFTP service
# @param service_provider Override TFTP service provider
# @param username Configures the service 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 service options

class tftp (
Stdlib::Absolutepath $root,
String $package,
Variant[String, Array[String]] $syslinux_package,
Boolean $manage_syslinux_package,
Boolean $manage_root_dir,
Optional[String] $service = undef,
Variant[String, Array[String]] $service,
Optional[String] $service_provider = undef,
String $username = 'root',
Stdlib::Port $port = 69,
Optional[Stdlib::IP::Address] $address = undef,
Optional[String] $options = undef,
) {
contain tftp::install
contain tftp::config
Expand Down
1 change: 0 additions & 1 deletion manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
service { $tftp::service:
ensure => running,
enable => true,
alias => 'tftpd',
provider => $tftp::service_provider,
}
}
49 changes: 49 additions & 0 deletions spec/acceptance/tftp_port_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.service'
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) do
it { is_expected.not_to be_listening }
end

describe port(1234) do
it { is_expected.to be_listening.with('udp').or be_listening.with('udp6') }
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
6 changes: 3 additions & 3 deletions spec/acceptance/tftp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class { 'tftp': }

service_name = case fact('osfamily')
when 'Archlinux'
'tftpd.socket'
'tftpd.service'
when 'RedHat'
'tftp.socket'
when 'Debian'
Expand All @@ -28,8 +28,8 @@ class { 'tftp': }
it { is_expected.to be_running }
end

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

describe command("echo get /test /tmp/downloaded_file | tftp #{fact('fqdn')}") do
Expand Down
17 changes: 11 additions & 6 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,37 @@
should contain_service('tftp.socket')
.with_ensure('running')
.with_enable('true')
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end

it 'should contain the service override' do
should contain_systemd__dropin_file('tftp-service-override.conf')
.with_content("[Service]\nExecStart=\nExecStart=/usr/sbin/in.tftpd --secure /var/lib/tftpboot\n")
end

it 'should contain the socket override' do
should contain_systemd__dropin_file('tftp-socket-override.conf')
.with_content("[Socket]\nListenDatagram=\nListenDatagram=69\n")
end
when 'FreeBSD'
it 'should contain the service' do
should contain_service('tftpd')
.with_ensure('running')
.with_enable('true')
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end
when 'Archlinux'
it 'should contain the service' do
should contain_service('tftpd.socket')
should contain_service('tftpd.service')
.with_ensure('running')
.with_enable('true')
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end
else
it 'should contain the service' do
should contain_service('tftpd-hpa')
.with_ensure('running')
.with_enable('true')
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end
end
Expand Down Expand Up @@ -141,7 +147,6 @@
should contain_service('tftp.socket')
.with_ensure('running')
.with_enable('true')
.with_alias('tftpd')
.that_subscribes_to('Class[Tftp::Config]')
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/setup_acceptance_node.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
ensure => installed,
}
}

# without it "ss" command is not found and "port listening" tests fail
if $facts['os']['name'] == 'Fedora' {
package { 'iproute':
ensure => installed,
}
}
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.tftpd <%= $tftp::options %> <%= $tftp::root %>
3 changes: 3 additions & 0 deletions templates/tftp.socket-override.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Socket]
ListenDatagram=
ListenDatagram=<%= $tftp::port %>
6 changes: 6 additions & 0 deletions templates/tftpd-hpa.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# /etc/default/tftpd-hpa

TFTP_USERNAME="<%= scope['tftp::username'] %>"
TFTP_DIRECTORY="<%= scope['tftp::root'] %>"
TFTP_ADDRESS="<%= scope['tftp::address'] %>:<%= scope['tftp::port'] %>"
TFTP_OPTIONS="<%= scope['tftp::options'] %>"
3 changes: 3 additions & 0 deletions templates/tftpd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# /etc/conf.d/tftpd

TFTPD_ARGS="<%= scope['tftp::options'] %> <%= scope['tftp::root'] %> --address <%= scope['tftp::address'] %>:<%= scope['tftp::port'] %> --user <%= scope['tftp::username'] %>"