Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fwv #3

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
---
fixtures:
forge_modules:
stdlib: "camptocamp/augeas"
stdlib: puppetlabs/stdlib # dep of puppetlabs/concat
augeas: camptocamp/augeas
reboot: puppetlabs/reboot
concat: puppetlabs/concat
3 changes: 2 additions & 1 deletion .mdl_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
rule "MD013", :code_blocks => false
exclude_rule "MD003"
exclude_rule "MD013"
exclude_rule "MD036"
exclude_rule "MD024"
exclude_rule "MD034"
exclude_rule "MD036"
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

inherit_gem:
voxpupuli-test: rubocop.yml
RSpec/BeforeAfterAll:
Enabled: false
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,96 @@

Manages features specific to [raspberrypi](https://www.raspberrypi.org/) and
related fruit flavored hardware.

## /boot/cmdline.txt

### puppet

```puppet
class { 'pi::cmdline':
reboot => false, # reboots are problematic for acceptance testing
parameters => {
'coherent_pool=1M' => {},
'bcm2708_fb.fbwidth=0' => {},
'bcm2708_fb.fbswap=1' => {},
},
}

pi::cmdline::parameter { '8250.nr_uarts=0': }
pi::cmdline::parameter { 'coherent_pool=1M': }
pi::cmdline::parameter { 'snd_bcm2835.enable_headphones=0': }
```

### hiera

```yaml
pi::cmdline::reboot: false
pi::cmdline::parameters:
coherent_pool=1M: {}
bcm2708_fb.fbwidth=0: {}
bcm2708_fb.fbswap=1: {}
8250.nr_uarts=0: {}
coherent_pool=1M: {}
snd_bcm2835.enable_headphones=0: {}
```

## /boot/config.txt

### puppet

```puppet
class { 'pi::config':
reboot => false, # reboots are problematic for acceptance testing
fragments => {
'dtoverlay=pps-gpio,gpiopin=4' => {
'order' => 99,
},
'dtparam=i2c_arm=on' => {
'order' => 1,
},
'dtparam=spi=on' => {},
'serial port' => {
# lint:ignore:strict_indent
'content' => @("CONTENT"),
enable_uart=1
init_uart_baud=9600
| CONTENT
# lint:endignore
},
},
}

pi::config::fragment { 'disable_overscan=1': }
pi::config::fragment { 'dtparam=audio=on':
order => 1,
}
pi::config::fragment { 'hdmi_mode=1':
order => 99,
}
pi::config::fragment { 'foo':
content => "hdmi_safe=1\n",
}
```

### hiera

```yaml
pi::config::reboot: false
pi::config::fragments:
dtoverlay=pps-gpio,gpiopin=4':
order: 99
dtparam=i2c_arm=on:
order: 1
dtparam=spi=on: {}
'serial port':
content: |
enable_uart=1
init_uart_baud=9600
disable_overscan=1: {}
dtparam=audio=on:
order: 1
hdmi_mode=1:
order: 99
foo:
content: "hdmi_safe=1\n"
```
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
7 changes: 7 additions & 0 deletions examples/cmdline_parameter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +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': }
1 change: 1 addition & 0 deletions examples/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include pi::config
14 changes: 14 additions & 0 deletions examples/config_fragment.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class { 'pi::config':
reboot => false, # reboots are problematic for acceptance testing
}

pi::config::fragment { 'disable_overscan=1': }
pi::config::fragment { 'dtparam=audio=on':
order => 1,
}
pi::config::fragment { 'hdmi_mode=1':
order => 99,
}
pi::config::fragment { 'foo':
content => "hdmi_safe=1\n",
}
20 changes: 20 additions & 0 deletions examples/fragments.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class { 'pi::config':
reboot => false, # reboots are problematic for acceptance testing
fragments => {
'dtoverlay=pps-gpio,gpiopin=4' => {
'order' => 99,
},
'dtparam=i2c_arm=on' => {
'order' => 1,
},
'dtparam=spi=on' => {},
'serial port' => {
# lint:ignore:strict_indent
'content' => @("CONTENT"),
enable_uart=1
init_uart_baud=9600
| CONTENT
# lint:endignore
},
},
}
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' => {},
},
}
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")
31 changes: 31 additions & 0 deletions manifests/cmdline.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# @summary Manages /boot/cmdline.txt parameters.
#
# @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,
}
}
}
34 changes: 34 additions & 0 deletions manifests/cmdline/parameter.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @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'],
}

if Class['pi::cmdline']['reboot'] {
Augeas[$name] ~> Reboot['/boot/cmdline.txt']
}
}
33 changes: 33 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# @summary
# Manages `/boot/config.txt`
#
# @param fragments
# A hash of profile::pi::config::fragments to be concatenated into
# `/boot/config.txt`.
#
# @param reboot
# Whether or not to force a reboot when `/boot/config.txt` changes.
#
class pi::config (
Hash[String[1], Hash] $fragments = {},
Boolean $reboot = true,
) {
concat { '/boot/config.txt':
ensure => present,
mode => '0755', # this is the default, +x seems odd
}

$fragments.each | String $name, Hash $conf | {
pi::config::fragment { $name:
* => $conf,
}
}

if ($reboot) {
reboot { '/boot/config.txt':
apply => finished,
message => 'Rebooting to apply /boot/config.txt changes',
when => refreshed,
}
}
}
30 changes: 30 additions & 0 deletions manifests/config/fragment.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @summary
# Create a /boot/config.txt fragment
#
# @param content
# /boot/config.txt configuration fragment
#
# @param order
# Order of the fragment within /boot/config.txt
#
define pi::config::fragment (
Optional[String[1]] $content = undef,
Integer[1] $order = 50,
) {
include pi::config

$_real_content = $content ? {
undef => "${name}\n",
default => $content,
}

concat::fragment { $name:
target => '/boot/config.txt',
content => $_real_content,
order => $order,
}

if Class['pi::config']['reboot'] {
Concat::Fragment[$name] ~> Reboot['/boot/config.txt']
}
}
6 changes: 0 additions & 6 deletions manifests/init.pp

This file was deleted.

21 changes: 21 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
{
"name": "camptocamp/augeas",
"version_requirement": ">= 1.0.0 < 2.0.0"
},
{
"name": "puppetlabs/reboot",
"version_requirement": ">= 5.0.0 < 6.0.0"
},
{
"name": "puppetlabs/concat",
"version_requirement": ">= 9.0.0 < 10.0.0"
}
],
"operatingsystem_support": [
Expand All @@ -31,5 +39,18 @@
"name": "puppet",
"version_requirement": ">= 7.0.0 < 9.0.0"
}
],
"tags": [
"pi",
"rpi",
"raspberry",
"raspberry pi",
"banana pi",
"orange pi",
"/boot/config.txt",
"config.txt",
"/boot/cmdline.txt",
"cmdline.txt",
"raspbian"
]
}
22 changes: 22 additions & 0 deletions spec/acceptance/cmdline/parameter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'pi::cmdline::parameter define' do
context 'without any parameters' do
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
Loading
Loading