Skip to content

Commit

Permalink
(WIP) cmdline.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Nov 21, 2023
1 parent f4f126d commit 9d8654c
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/cmdline.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pi::cmdline { '8250.nr_uarts=0': }
pi::cmdline { 'coherent_pool=1M': }
pi::cmdline { 'snd_bcm2835.enable_headphones=0': }
1 change: 1 addition & 0 deletions examples/pi.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include pi
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")
30 changes: 30 additions & 0 deletions manifests/cmdline.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @summary
# Manage /boot/cmdline.txt kernel parameters.
#
# @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 (
Optional[String[1]] $parameter = undef,
) {
include pi

$_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'],
}
}
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# @summary Manages Fruit Pi specific features.
#
class pi {
include augeas
augeas::lens { 'boot_cmdline':
lens_content => file("${module_name}/boot_cmdline.aug"),
}
}
18 changes: 18 additions & 0 deletions spec/acceptance/cmdline_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 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/pi_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 class' do
context 'without any parameters' do
include_examples 'the example', 'pi.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/pi_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' 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 9d8654c

Please sign in to comment.