Commit 06d25a4e authored by Tim Smith's avatar Tim Smith
Browse files

fix custom resource, remove of the service helpers, add serverspecs

parent 1701e373
......@@ -2,6 +2,11 @@ rsyslog Cookbook CHANGELOG
==========================
This file is used to list changes made in each version of the rsyslog cookbook.
UNRELEASED
--------------------
- Breaking change: The file_input LWRP has been updated to be a Chef 12.5 custom_resource, with backwards compatibility to all Chef 12.x released provided by compat_resource. Additionally the 'source' and 'cookbook' attributes in the file_input resource have been renamed to 'template_source' and 'cookbook_source' to prevent failures.
- Helpers for determining the service provider on Ubuntu have been removed since Chef 12 does the right thing with Init, Upstart, and systemd.
v.2.2.0 (2015-10-05)
----------
- Add why-run support to the file_input LWRP
......
......@@ -140,9 +140,9 @@ file_input
Configures a [text file input
monitor](http://www.rsyslog.com/doc/imfile.html) to push a log file into
rsyslog.
rsyslog. Rsyslog must be installed to use this custom resource either using your own wrapper cookbook or the rsyslog::default recipe
Attributes:
Properties:
* `name`: name of the resource, also used for the syslog tag. Required.
* `file`: file path for input file to monitor. Required.
* `priority`: config order priority. Defaults to `99`.
......@@ -153,8 +153,8 @@ undefined, rsyslog interprets this as `notice`.
`daemon`, `cron`, `ftp`, `lpr`, `kern`, `mail`, `news`, `syslog`,
`user`, `uucp`, `local0`, ... , `local7`. If undefined, rsyslog
interprets this as `local0`.
* `cookbook`: cookbook containing the template. Defaults to `rsyslog`.
* `source`: template file source. Defaults to `file-input.conf.erb`
* `cookbook_source`: cookbook containing the template. Defaults to `rsyslog`.
* `template_source`: template file source. Defaults to `file-input.conf.erb`
Usage
......@@ -222,42 +222,11 @@ default_attributes(
)
```
Development
-----------
This section details "quick development" steps. For a detailed explanation, see [[Contributing.md]].
1. Clone this repository from GitHub:
$ git clone git@github.com:chef-cookbooks/rsyslog.git
2. Create a git branch
$ git checkout -b my_bug_fix
3. Install dependencies:
$ bundle install
4. Make your changes/patches/fixes, committing appropriately
5. **Write tests**
6. Run the tests:
- bundle exec foodcritic -f any .
- bundle exec rspec
- bundle exec rubocop
- bundle exec kitchen test
In detail:
- Foodcritic will catch any Chef-specific style errors
- RSpec will run the unit tests
- Rubocop will check for Ruby-specific style errors
- Test Kitchen will run and converge the recipes
License & Authors
-----------------
- Author:: Joshua Timberman (<joshua@chef.io>)
- Author:: Denis Barishev (<denz@twiket.com>)
- Author:: Tim Smith (<tsmith84@gmail.com>)
- Author:: Tim Smith (<tsmith@chef.io>)
```text
Copyright:: 2009-2015, Chef Software, Inc
......
module RsyslogCookbook
# helpers for the various service providers on Ubuntu systems
module Helpers
# use the correct provider based on the Ubuntu release
def find_service_provider
if Chef::VersionConstraint.new('>= 15.04').include?(node['platform_version'])
service_provider = Chef::Provider::Service::Systemd
elsif Chef::VersionConstraint.new('>= 12.04').include?(node['platform_version'])
service_provider = Chef::Provider::Service::Upstart
else
service_provider = nil
end
service_provider
end
# declare the service with the appropriate provider if on Ubuntu
def declare_rsyslog_service
service_provider = 'ubuntu' == node['platform'] ? find_service_provider : nil
service node['rsyslog']['service_name'] do
supports restart: true, status: true
action [:enable, :start]
provider service_provider
end
end
# determine if chef solo search is available
def chef_solo_search_installed?
klass = ::Search.const_get('Helper')
......@@ -31,6 +8,5 @@ module RsyslogCookbook
rescue NameError
return false
end
end
end
......@@ -17,8 +17,6 @@
# limitations under the License.
#
extend RsyslogCookbook::Helpers
package 'rsyslog'
package 'rsyslog-relp' if node['rsyslog']['use_relp']
......@@ -86,4 +84,7 @@ if platform_family?('omnios')
end
end
declare_rsyslog_service
service node['rsyslog']['service_name'] do
supports restart: true, status: true
action [:enable, :start]
end
......@@ -18,30 +18,31 @@
actions :create
property :name, kind_of: String, name_attribute: true, required: true
property :file, kind_of: String, required: true
property :priority, kind_of: Integer, default: 99
property :severity, kind_of: String
property :facility, kind_of: String
property :cookbook, kind_of: String, default: 'rsyslog'
property :source, kind_of: String, default: 'file-input.conf.erb'
include RsyslogCookbook::Helpers
property :name, String, name_attribute: true, required: true
property :file, String, required: true
property :priority, Integer, default: 99
property :severity, String
property :facility, String
property :cookbook_source, String, default: 'rsyslog'
property :template_source, String, default: 'file-input.conf.erb'
action :create do
declare_rsyslog_service
template "/etc/rsyslog.d/#{new_resource.priority}-#{new_resource.name}.conf" do
template "/etc/rsyslog.d/#{priority}-#{name}.conf" do
mode '0664'
owner node['rsyslog']['user']
group node['rsyslog']['group']
source new_resource.source
cookbook new_resource.cookbook
variables 'file_name' => new_resource.file,
'tag' => new_resource.name,
'state_file' => new_resource.name,
'severity' => new_resource.severity,
'facility' => new_resource.facility
notifies :restart, resources('service[rsyslog]')
source template_source
cookbook cookbook_source
variables 'file_name' => file,
'tag' => name,
'state_file' => name,
'severity' => severity,
'facility' => facility
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
service node['rsyslog']['service_name'] do
supports restart: true, status: true
action [:enable, :start]
end
end
include_recipe 'rsyslog::default'
rsyslog_file_input 'test-file' do
file '/var/log/boot'
end
require 'serverspec'
set :backend, :exec
@test "the input_file is created" {
test /etc/rsyslog.d/99-test-file.conf
}
@test "the input_file contains given file" {
grep "InputFileName /var/log/boot" /etc/rsyslog.d/99-test-file.conf
}
require_relative './spec_helper'
describe service('rsyslog') do
it { should be_running }
end
describe file('/etc/rsyslog.d/99-test-file.conf') do
it { should exist }
end
describe file('/etc/rsyslog.d/99-test-file.conf') do
its(:content) { should match /InputFileName \/var\/log\/boot/ }
end
require_relative './spec_helper'
describe service('rsyslogd') do
it { should be_running }
end
describe package('rsyslog-relp') do
it { should be_installed }
end
@test "the server is configured" {
test /etc/rsyslog.d/35-server-per-host.conf
}
@test "the remote.conf does not exist" {
test ! -f /etc/rsyslog.d/remote.conf
}
require_relative './spec_helper'
describe service('rsyslogd') do
it { should be_running }
end
describe file('/etc/rsyslog.d/35-server-per-host.conf') do
it { should be_file }
end
describe file('/etc/rsyslog.d/remote.conf') do
it { should_not be_file }
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment