Skip to content

Commit

Permalink
Merge pull request #19 from traylenator/hiera
Browse files Browse the repository at this point in the history
Support of hash of zram_generator::zram instances
  • Loading branch information
traylenator authored Jun 21, 2024
2 parents b5b31eb + a987d76 commit 30775ef
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ zram_generator::zram{'zram1':

This will create a `/dev/zram1` device half the size of available RAM and activate it.

## Hiera Example

A set of `zram_generator::zram` can be loaded from hiera:

```yaml
zram_generator::zrams:
zram0:
fs_type: 'ext4'
mount_point: '/run/mount'
zram1:
zram_size: 1024
```
## Reference
Expand Down
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following parameters are available in the `zram_generator` class:

* [`install_defaults`](#-zram_generator--install_defaults)
* [`manage_defaults_package`](#-zram_generator--manage_defaults_package)
* [`zrams`](#-zram_generator--zrams)

##### <a name="-zram_generator--install_defaults"></a>`install_defaults`

Expand All @@ -52,6 +53,14 @@ whether the zram-generator-defaults package should be managed

Default value: `$facts['os']['name'] != 'Archlinux'`

##### <a name="-zram_generator--zrams"></a>`zrams`

Data type: `Stdlib::CreateResources`

Hash of zram_generator::zram instances to expand from hiera.

Default value: `{}`

## Defined types

### <a name="zram_generator--zram"></a>`zram_generator::zram`
Expand Down
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# @see https://github.com/systemd/zram-generator
# @param install_defaults Controls if the package 'zram-generator-defaults' be installed.
# @param manage_defaults_package whether the zram-generator-defaults package should be managed
# @param zrams Hash of zram_generator::zram instances to expand from hiera.
#
class zram_generator (
Enum['installed', 'absent'] $install_defaults = 'absent',
Boolean $manage_defaults_package = $facts['os']['name'] != 'Archlinux',
Stdlib::CreateResources $zrams = {},
) {
contain zram_generator::install
contain zram_generator::config
Expand All @@ -14,4 +16,10 @@
Class['zram_generator::install']
-> Class['zram_generator::config']
-> Class['zram_generator::service']

$zrams.each |$name, $resource| {
zram_generator::zram { $name:
* => $resource,
}
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 4.18.0 < 10.0.0"
"version_requirement": ">= 8.5.0 < 10.0.0"
}
],
"tags": [
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
it { is_expected.to contain_exec('generate_zram_units').with_refreshonly(true) }
it { is_expected.to contain_file('/usr/lib/systemd/zram-generator.conf.d').with_ensure('directory') }
it { is_expected.to contain_package('zram-generator').with_ensure('installed') }
it { is_expected.to have_zram_generator__zram_resource_count(0) }

if facts[:os]['name'] == 'Archlinux'
it { is_expected.not_to contain_package('zram-generator-defaults') }
Expand Down Expand Up @@ -54,6 +55,35 @@

it { is_expected.not_to contain_package('zram-generator-defaults') }
end

context 'with a hash of zrams specified' do
let :params do
{
zrams: {
'zram0' => {
'fs_type' => 'ext4',
'mount_point' => '/run/mount',
},
'zram1' => {
'zram_size' => 1024,
},
},
}
end

it {
is_expected.to contain_zram_generator__zram('zram0').
with_fs_type('ext4').
with_mount_point('/run/mount')
}

it {
is_expected.to contain_zram_generator__zram('zram1').
with_zram_size('1024')
}

it { is_expected.to have_zram_generator__zram_resource_count(2) }
end
end
end
end
Expand Down

0 comments on commit 30775ef

Please sign in to comment.