diff --git a/examples/cmdline_parameter.pp b/examples/cmdline_parameter.pp index d68a52d..b24cfe3 100644 --- a/examples/cmdline_parameter.pp +++ b/examples/cmdline_parameter.pp @@ -1,3 +1,7 @@ +class { 'pi::cmdline': + reboot => false, # reboots are problematic for acceptance testing +} + pi::cmdline::parameter { '8250.nr_uarts=0': } pi::cmdline::parameter { 'coherent_pool=1M': } pi::cmdline::parameter { 'snd_bcm2835.enable_headphones=0': } diff --git a/examples/parameters.pp b/examples/parameters.pp new file mode 100644 index 0000000..6732e93 --- /dev/null +++ b/examples/parameters.pp @@ -0,0 +1,8 @@ +class { 'pi::cmdline': + reboot => false, # reboots are problematic for acceptance testing + parameters => { + 'coherent_pool=1M' => {}, + 'bcm2708_fb.fbwidth=0' => {}, + 'bcm2708_fb.fbswap=1' => {}, + }, +} diff --git a/manifests/cmdline.pp b/manifests/cmdline.pp index 318bdbb..df787c8 100644 --- a/manifests/cmdline.pp +++ b/manifests/cmdline.pp @@ -1,8 +1,31 @@ # # @summary Manages /boot/cmdline.txt parameters. # -class pi::cmdline { +# @param parameters +# A hash of pi::cmdline::parameter resources to create. +# +# @param reboot +# Whether or not to force a reboot when `/boot/cmdline.txt` parameters change. +# +class pi::cmdline ( + Hash[String[1], Hash] $parameters = {}, + Boolean $reboot = true, +) { augeas::lens { 'boot_cmdline': lens_content => file("${module_name}/boot_cmdline.aug"), } + + $parameters.each | String $name, Hash $conf | { + pi::cmdline::parameter { $name: + * => $conf, + } + } + + if ($reboot) { + reboot { '/boot/cmdline.txt': + apply => finished, + message => 'Rebooting to apply /boot/config.txt changes', + when => refreshed, + } + } } diff --git a/manifests/cmdline/parameter.pp b/manifests/cmdline/parameter.pp index f0ebf14..098a463 100644 --- a/manifests/cmdline/parameter.pp +++ b/manifests/cmdline/parameter.pp @@ -27,4 +27,8 @@ ], require => Augeas::Lens['boot_cmdline'], } + + if Class['pi::cmdline']['reboot'] { + Augeas[$name] ~> Reboot['/boot/cmdline.txt'] + } } diff --git a/metadata.json b/metadata.json index 49b8079..a61eebe 100644 --- a/metadata.json +++ b/metadata.json @@ -9,6 +9,10 @@ { "name": "camptocamp/augeas", "version_requirement": ">= 1.0.0 < 2.0.0" + }, + { + "name": "puppetlabs/reboot", + "version_requirement": ">= 5.0.0 < 6.0.0" } ], "operatingsystem_support": [ diff --git a/spec/acceptance/cmdline/parameter_spec.rb b/spec/acceptance/cmdline/parameter_spec.rb index b10642d..40979a0 100644 --- a/spec/acceptance/cmdline/parameter_spec.rb +++ b/spec/acceptance/cmdline/parameter_spec.rb @@ -4,15 +4,18 @@ describe 'pi::cmdline::parameter define' do context 'without any parameters' do - before(:context) do - shell('mkdir -p /boot') - create_remote_file('default', '/boot/cmdline.txt', 'console=serial0,115200 console=tty1 root=PARTUUID=4a435670-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles') - end - - include_examples 'the example', 'cmdline.pp' + include_context 'cmdline.txt test setup' + include_examples 'the example', 'cmdline_parameter.pp' describe file('/boot/cmdline.txt') do it { is_expected.to be_file } + %w[ + 8250.nr_uarts=0 + coherent_pool=1M + snd_bcm2835.enable_headphones=0 + ].each do |param| + its(:content) { is_expected.to match param } + end end end end diff --git a/spec/acceptance/cmdline_spec.rb b/spec/acceptance/cmdline_spec.rb index 7b1d4ff..36b667c 100644 --- a/spec/acceptance/cmdline_spec.rb +++ b/spec/acceptance/cmdline_spec.rb @@ -10,4 +10,24 @@ it { is_expected.to be_file } end end + + context 'with parameters =>' do + include_context 'cmdline.txt test setup' + include_examples 'the example', 'parameters.pp' + + describe file('/opt/puppetlabs/puppet/share/augeas/lenses/boot_cmdline.aug') do + it { is_expected.to be_file } + end + + describe file('/boot/cmdline.txt') do + it { is_expected.to be_file } + %w[ + coherent_pool=1M + bcm2708_fb.fbwidth=0 + bcm2708_fb.fbswap=1 + ].each do |param| + its(:content) { is_expected.to match param } + end + end + end end diff --git a/spec/support/acceptance/cmdline.rb b/spec/support/acceptance/cmdline.rb new file mode 100644 index 0000000..4fae8fd --- /dev/null +++ b/spec/support/acceptance/cmdline.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +shared_context 'cmdline.txt test setup' do + before(:context) do + shell('mkdir -p /boot') + + create_remote_file('default', '/boot/cmdline.txt', 'console=serial0,115200 console=tty1 root=PARTUUID=4a435670-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles') + end + + after(:context) do + shell('rm -rf /boot/cmdline.txt') + end +end