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 7aa796f commit 978c926
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 7 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
fixtures:
forge_modules:
stdlib: "camptocamp/augeas"
stdlib: "puppetlabs/reboot"
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 }

Check failure on line 11 in spec/acceptance/cmdline/parameter_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterExample: Add an empty line after `it`. (https://rspec.rubystyle.guide/#empty-lines-around-examples, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample)
%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 }

describe file('/boot/cmdline.txt') do
it { is_expected.to be_file }

Check failure on line 22 in spec/acceptance/cmdline_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterExample: Add an empty line after `it`. (https://rspec.rubystyle.guide/#empty-lines-around-examples, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample)
%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
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

Check failure on line 4 in spec/support/acceptance/cmdline.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/BeforeAfterAll: Beware of using `before(:context)` as it may cause state to leak between tests. If you are using `rspec-rails`, and `use_transactional_fixtures` is enabled, then records created in `before(:context)` are not automatically rolled back. (https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll)
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

Check failure on line 10 in spec/support/acceptance/cmdline.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/BeforeAfterAll: Beware of using `after(:context)` as it may cause state to leak between tests. If you are using `rspec-rails`, and `use_transactional_fixtures` is enabled, then records created in `after(:context)` are not automatically rolled back. (https://rspec.rubystyle.guide/#avoid-hooks-with-context-scope, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeforeAfterAll)
shell('rm -rf /boot/cmdline.txt')
end
end

0 comments on commit 978c926

Please sign in to comment.