Skip to content

Commit

Permalink
add syslog verbosity management
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed Sep 20, 2013
1 parent db481ed commit fedd155
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ Usage

### Basic Example

This class does not need to be declared in the manfiest when using the
This class does not need to be manually included in the manifest when using the
`udev::rule` defined type.

```puppet
include udev
```

### Managing a `udev` rules
### Managing `udev` syslog verbosity

```puppet
class { 'udev': udev_log => 'debug' }
```

### Managing `udev` rules

Note that either the `content` or `source` parameter must be specified unless
`ensure` is `absent`and that these parameters are mutually exclusive; you can
Expand Down
24 changes: 23 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@
# This class does not need to be declared in the manfiest when using the
# udev::rule defined type.
#
#
# === Parameters
#
# [*udev_log*]
#
# String. Possible values: 'err, 'info', 'debug'
#
# Default: 'err'
#
#
# === Examples
#
# include udev
#
class udev inherits udev::params {
class udev(
$udev_log = 'err',
) inherits udev::params {
validate_re($udev_log, '^err$|^info$|^debug$')

package{ $udev::params::udev_package:
ensure => present,
} ->
file { '/etc/udev/udev.conf':
ensure => file,
content => template("${module_name}/udev.conf.erb"),
owner => 'root',
group => 'root',
mode => '0644',
notify => Class['udev::udevadm::logpriority'],
}

class { 'udev::udevadm': } ->
class { 'udev::udevadm::logpriority': udev_log => $udev_log } ->
Class['udev']
}
30 changes: 30 additions & 0 deletions manifests/udevadm/logpriority.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# == Class: udev::udevadm::logpriority
#
# Set the udev daemon runtime log level.
#
# This class does nothing unless it receives a *notify* message.
#
# === Parameters
#
# [*udev_log*]
#
# String. Possible values: 'err, 'info', 'debug'
#
# Default: 'err'
#
#
# === Examples
#
# class { 'udev::udevadm::logpriority': udev_log => 'debug' }
#
#
class udev::udevadm::logpriority(
$udev_log = 'err',
) inherits udev::params {
validate_re($udev_log, '^err$|^info$|^debug$')

exec { "udevadm control --log-priority=${udev_log}":
refreshonly => true,
path => [$udev::params::udevadm_path],
}
}
49 changes: 46 additions & 3 deletions spec/classes/udev_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,55 @@

describe 'udev', :type => :class do

shared_examples 'udev_log_param' do |udev_log, params|
let(:params) { params }

it do
should include_class('udev')
should contain_package('udev').with_ensure('present')
should contain_file('/etc/udev/udev.conf').
with({
:ensure => 'file',
:owner => 'root',
:group => 'root',
:mode => '0644',
}).
with_content(/udev_log="#{udev_log}"/)
should contain_class('udev::udevadm')
should contain_class('udev::udevadm::logpriority').
with_udev_log(udev_log)
end
end

describe 'for osfamily RedHat' do
let(:facts) {{ :osfamily => 'RedHat' }}

it { should include_class('udev') }
it { should contain_package('udev').with_ensure(:present) }
it { should contain_class('udev::udevadm') }
describe 'no params' do
it_behaves_like('udev_log_param', 'err', {})
end

describe 'udev_log => err' do
it_behaves_like('udev_log_param', 'err', { :udev_log => 'err' })
end

describe 'udev_log => info' do
it_behaves_like('udev_log_param', 'info', { :udev_log => 'info' })
end

describe 'udev_log => debug' do
it_behaves_like('udev_log_param', 'debug', { :udev_log => 'debug' })
end

describe 'udev_log => invalid' do
let(:params) {{ :udev_log => 'invalid' }}

it 'should fail' do
expect {
should include_class('udev')
}.to raise_error(Puppet::Error, /does not match/)
end
end

end

end
49 changes: 49 additions & 0 deletions spec/classes/udevadm/logpriority_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'spec_helper'

describe 'udev::udevadm::logpriority', :type => :class do

shared_examples 'udev_log_param' do |udev_log, params|
let(:params) { params }

it do
should contain_class('udev::udevadm::logpriority').
with_udev_log(udev_log)
should contain_exec("udevadm control --log-priority=#{udev_log}").with({
:refreshonly => true,
:path => '/sbin',
})
end
end

describe 'for osfamily RedHat' do
let(:facts) {{ :osfamily => 'RedHat' }}

describe 'no params' do
it_behaves_like('udev_log_param', 'err', {})
end

describe 'udev_log => err' do
it_behaves_like('udev_log_param', 'err', { :udev_log => 'err' })
end

describe 'udev_log => info' do
it_behaves_like('udev_log_param', 'info', { :udev_log => 'info' })
end

describe 'udev_log => debug' do
it_behaves_like('udev_log_param', 'debug', { :udev_log => 'debug' })
end

describe 'udev_log => invalid' do
let(:params) {{ :udev_log => 'invalid' }}

it 'should fail' do
expect {
should include_class('udev::udevadm::logpriority')
}.to raise_error(Puppet::Error, /does not match/)
end
end

end

end
4 changes: 4 additions & 0 deletions templates/udev.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The initial syslog(3) priority: "err", "info", "debug" or its
# numerical equivalent. For runtime debugging, the daemons internal
# state can be changed with: "udevadm control --log-priority=<value>".
udev_log="<%= udev_log %>"

0 comments on commit fedd155

Please sign in to comment.