Skip to content

Commit

Permalink
add pi::cmdline::parameters param
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Nov 21, 2023
1 parent 84495b3 commit 4372992
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
4 changes: 4 additions & 0 deletions examples/cmdline_parameter.pp
Original file line number Diff line number Diff line change
@@ -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': }
8 changes: 8 additions & 0 deletions examples/parameters.pp
Original file line number Diff line number Diff line change
@@ -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' => {},
},
}
25 changes: 24 additions & 1 deletion manifests/cmdline.pp
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
4 changes: 4 additions & 0 deletions manifests/cmdline/parameter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
],
require => Augeas::Lens['boot_cmdline'],
}

if Class['pi::cmdline']['reboot'] {
Augeas[$name] ~> Reboot['/boot/cmdline.txt']
}
}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
15 changes: 9 additions & 6 deletions spec/acceptance/cmdline/parameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions spec/acceptance/cmdline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions spec/support/acceptance/cmdline.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4372992

Please sign in to comment.