Skip to content

Commit

Permalink
add pi::cmdline & pi::cmdline::parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Nov 21, 2023
1 parent f4f126d commit 84495b3
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
---
fixtures:
forge_modules:
stdlib: "camptocamp/augeas"
augeas: camptocamp/augeas
reboot: puppetlabs/reboot
1 change: 1 addition & 0 deletions examples/cmdline.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include pi::cmdline
3 changes: 3 additions & 0 deletions examples/cmdline_parameter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pi::cmdline::parameter { '8250.nr_uarts=0': }
pi::cmdline::parameter { 'coherent_pool=1M': }
pi::cmdline::parameter { 'snd_bcm2835.enable_headphones=0': }
14 changes: 14 additions & 0 deletions files/boot_cmdline.aug
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* /boot/cmdline.txt module for Augeas *)

module Boot_Cmdline =
autoload xfm

let word = /[^ \n\t]+/
let cmdline = [ seq "cmdline" . Util.indent .
[ label "parameter" . store word ] .
[ label "parameter" . Sep.space . store word ]*
. Util.eol ]

let lns = cmdline

let xfm = transform lns (incl "/boot/cmdline.txt")
8 changes: 8 additions & 0 deletions manifests/cmdline.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# @summary Manages /boot/cmdline.txt parameters.
#
class pi::cmdline {
augeas::lens { 'boot_cmdline':
lens_content => file("${module_name}/boot_cmdline.aug"),
}
}
30 changes: 30 additions & 0 deletions manifests/cmdline/parameter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @summary
# Manage a single /boot/cmdline.txt kernel parameter
#
# @param parameter
# The kernel parameter to manage. E.g. 8250.nr_uarts=1
#
# Note that the management of parameters is not very intelligent.
# 8250.nr_uarts=1 and 8250.nr_uarts=2 would be treated as two different
# parameters.
#
define pi::cmdline::parameter (
Optional[String[1]] $parameter = undef,
) {
include pi::cmdline

$_real_parameter = $parameter ? {
undef => $name,
default => $parameter,
}

augeas { $name:
context => '/files/boot/cmdline.txt/1',
lens => 'Boot_Cmdline.lns',
incl => '/boot/cmdline.txt',
changes => [
"set parameter[. = '${_real_parameter}'] '${_real_parameter}'",
],
require => Augeas::Lens['boot_cmdline'],
}
}
6 changes: 0 additions & 6 deletions manifests/init.pp

This file was deleted.

18 changes: 18 additions & 0 deletions spec/acceptance/cmdline/parameter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

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'

describe file('/boot/cmdline.txt') do
it { is_expected.to be_file }
end
end
end
13 changes: 13 additions & 0 deletions spec/acceptance/cmdline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'pi::cmdline class' do
context 'without any parameters' do
include_examples 'the example', 'cmdline.pp'

describe file('/opt/puppetlabs/puppet/share/augeas/lenses/boot_cmdline.aug') do
it { is_expected.to be_file }
end
end
end
14 changes: 14 additions & 0 deletions spec/classes/cmdline_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'pi::cmdline' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
# camptocamp/augeas 1.9.0 is using legacy facts
let(:facts) { override_facts(os_facts, osfamily: os_facts[:os]['family']) }

it { is_expected.to compile.with_all_deps }
end
end
end

0 comments on commit 84495b3

Please sign in to comment.