Commit 35e052d7 authored by Seth Vargo's avatar Seth Vargo
Browse files

[COOK-3573] Add Test Kitchen, Specs, and Travis CI


Signed-off-by: default avatarSeth Vargo <sethvargo@gmail.com>
parent 0f3457d9
.bundle
.cache
.kitchen
bin
Berksfile.lock
Gemfile.lock
vendor/
driver_plugin: 'vagrant'
driver_config:
require_chef_omnibus: true
platforms:
- name: ubuntu-12.04
run_list:
- recipe[apt]
- name: ubuntu-10.04
run_list:
- recipe[apt]
- name: centos-6.4
- name: centos-5.9
suites:
- name: default
run_list:
- recipe[rsyslog::default]
- name: client
run_list:
- recipe[rsyslog::client]
attributes:
rsyslog:
server_ip: 10.0.0.50
- name: server
run_list:
- recipe[rsyslog::server]
AllCops:
Excludes:
- vendor/**
AlignParameters:
Enabled: false
Encoding:
Enabled: false
HashSyntax:
Enabled: false
LineLength:
Enabled: false
MethodLength:
Max: 30
rvm:
- 1.9.3
- 2.0.0
before_script:
- bundle exec berks install
script:
- bundle exec foodcritic -f any --tags ~FC023 .
- bundle exec rspec --color --format progress
- bundle exec rubocop
site :opscode
metadata
group :integration do
cookbook 'apt', '~> 2.0'
end
source :rubygems
source 'http://rubygems.org'
gem 'test-kitchen', '< 1.0'
gem 'berkshelf', '~> 2.0'
gem 'chefspec', '~> 2.0'
gem 'foodcritic', '~> 2.2'
gem 'rubocop', '~> 0.12'
group :integration do
gem 'test-kitchen', '~> 1.0.0.beta'
gem 'kitchen-vagrant', '~> 0.11'
end
rsyslog Cookbook CHANGELOG
==========================
Installs and configures rsyslog to replace sysklogd for client and/or server use. By default, the service will be configured to log to files on local disk. See the __Recipes__ and __Examples__ sections for other uses.
**Major Changes in 1.2.0**: See CHANGELOG.md
**Important Changes in 1.1.0**: See the CHANGELOG.md file for important changes to this cookbook. There are some incompatibilities with existing installations. Use version 1.0.0 if you're not ready for these changes.
rsyslog Cookbook
================
Installs and configures rsyslog to replace sysklogd for client and/or server use. By default, the service will be configured to log to files on local disk. See the Recipes and Examples sections for other uses.
Requirements
------------
### Platforms
Tested on Ubuntu 9.10, 10.04 and Red Hat 6.3
Ubuntu 8.04, 8.10, and 9.04 are no longer supported releases and have not been tested with this cookbook.
Tested on:
- Ubuntu 9.10
- Ubuntu 10.04
- RedHat 6.3
### Other
To use the `recipe[rsyslog::client]` recipe, you'll need to set up the `rsyslog.server_search` or `rsyslog.server_ip` attributes. See the __Recipes__ and __Examples__ sections below.
......@@ -131,6 +128,40 @@ 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:opscode-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 appropiately
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@opscode.com>)
......@@ -138,7 +169,7 @@ License & Authors
- Author:: Tim Smith (<tsmith@limelight.com>)
```text
Copyright:: 2009-2012, Opscode, Inc
Copyright:: 2009-2013, Opscode, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
This cookbook uses a variety of testing components:
- Unit tests: [ChefSpec](https://github.com/acrmp/chefspec)
- Integration tests: [Test Kitchen](https://github.com/opscode/test-kitchen)
- Chef Style lints: [Foodcritic](https://github.com/acrmp/foodcritic)
- Ruby Style lints: [Rubocop](https://github.com/bbatsov/rubocop)
Prerequisites
-------------
To develop on this cookbook, you must have a sane Ruby 1.9+ environment. Given the nature of this installation process (and it's variance across multiple operating systems), we will leave this installation process to the user.
You must also have `bundler` installed:
$ gem install bundler
You must also have Vagrant and VirtualBox installed:
- [Vagrant](https://vagrantup.com)
- [VirtualBox](https://virtualbox.org)
Once installed, you must install the `vagrant-berkshelf` plugin:
$ vagrant plugin install vagrant-berkshelf
Development
-----------
1. Clone the git repository from GitHub:
$ git clone git@github.com:opscode-cookbooks/COOKBOOK.git
2. Install the dependencies using bundler:
$ bundle install
3. Create a branch for your changes:
$ git checkout -b my_bug_fix
4. Make any changes
5. Write tests to support those changes. It is highly recommended you write both unit and integration tests.
6. Run the tests:
- `bundle exec rspec`
- `bundle exec foodcritic .`
- `bundle exec rubocop`
- `bundle exec kitchen test`
7. Assuming the tests pass, open a Pull Request on GitHub
8. Open a JIRA ticket for this compontent, linking the JIRA ticket to the Pull Request and visa versa.
9. Mark the JIRA ticket as "Fix Provided"
For more information, see [Opscode's Contribution Guidelines](https://wiki.opscode.com/display/chef/How+to+Contribute).
......@@ -2,7 +2,7 @@
# Cookbook Name:: rsyslog
# Attributes:: default
#
# Copyright 2009, Opscode, Inc.
# Copyright 2009-2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -17,34 +17,34 @@
# limitations under the License.
#
default["rsyslog"]["log_dir"] = "/srv/rsyslog"
default["rsyslog"]["server"] = false
default["rsyslog"]["protocol"] = "tcp"
default["rsyslog"]["port"] = 514
default["rsyslog"]["server_ip"] = nil
default["rsyslog"]["server_search"] = "role:loghost"
default["rsyslog"]["remote_logs"] = true
default["rsyslog"]["per_host_dir"] = "%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%"
default["rsyslog"]["max_message_size"] = "2k"
default["rsyslog"]["preserve_fqdn"] = "off"
default["rsyslog"]["high_precision_timestamps"] = false
default["rsyslog"]["repeated_msg_reduction"] = "on"
default["rsyslog"]["logs_to_forward"] = "*.*"
default['rsyslog']['log_dir'] = '/srv/rsyslog'
default['rsyslog']['server'] = false
default['rsyslog']['protocol'] = 'tcp'
default['rsyslog']['port'] = 514
default['rsyslog']['server_ip'] = nil
default['rsyslog']['server_search'] = 'role:loghost'
default['rsyslog']['remote_logs'] = true
default['rsyslog']['per_host_dir'] = '%$YEAR%/%$MONTH%/%$DAY%/%HOSTNAME%'
default['rsyslog']['max_message_size'] = '2k'
default['rsyslog']['preserve_fqdn'] = 'off'
default['rsyslog']['high_precision_timestamps'] = false
default['rsyslog']['repeated_msg_reduction'] = 'on'
default['rsyslog']['logs_to_forward'] = '*.*'
# The most likely platform-specific attributes
default["rsyslog"]["service_name"] = "rsyslog"
default["rsyslog"]["user"] = "root"
default["rsyslog"]["group"] = "adm"
default["rsyslog"]["priv_seperation"] = false
default['rsyslog']['service_name'] = 'rsyslog'
default['rsyslog']['user'] = 'root'
default['rsyslog']['group'] = 'adm'
default['rsyslog']['priv_seperation'] = false
case node["platform"]
when "ubuntu"
case node['platform']
when 'ubuntu'
# syslog user introduced with natty package
if node['platform_version'].to_f < 10.10 then
default["rsyslog"]["user"] = "syslog"
default["rsyslog"]["group"] = "adm"
default["rsyslog"]["priv_seperation"] = true
if node['platform_version'].to_f < 10.10
default['rsyslog']['user'] = 'syslog'
default['rsyslog']['group'] = 'adm'
default['rsyslog']['priv_seperation'] = true
end
when "arch"
default["rsyslog"]["service_name"] = "rsyslogd"
when 'arch'
default['rsyslog']['service_name'] = 'rsyslogd'
end
name "rsyslog"
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs and configures rsyslog"
name 'rsyslog'
maintainer 'Opscode, Inc.'
maintainer_email 'cookbooks@opscode.com'
license 'Apache 2.0'
description 'Installs and configures rsyslog'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.7.1"
recipe "rsyslog", "Installs rsyslog"
recipe "rsyslog::client", "Sets up a client to log to a remote rsyslog server"
recipe "rsyslog::server", "Sets up an rsyslog server"
supports "ubuntu"
supports "debian", ">= 5.0"
supports "redhat", ">= 6.0"
attribute "rsyslog",
:display_name => "Rsyslog",
:description => "Hash of Rsyslog attributes",
:type => "hash"
attribute "rsyslog/log_dir",
:display_name => "Rsyslog Log Directory",
:description => "Filesystem location of logs from clients",
:default => "/srv/rsyslog"
attribute "rsyslog/server",
:display_name => "Rsyslog Server?",
:description => "Is this node an rsyslog server?",
:default => "false"
attribute "rsyslog/server_ip",
:display_name => "Rsyslog Server IP Address",
:description => "Set rsyslog server ip address explicitly"
attribute "rsyslog/server_search",
:display_name => "Rsyslog Server Search Criteria",
:description => "Set the search criteria for rsyslog server resolving",
:default => "role:loghost"
attribute "rsyslog/protocol",
:display_name => "Rsyslog Protocol",
:description => "Set which network protocol to use for rsyslog",
:default => "tcp"
attribute "rsyslog/port",
:display_name => "Rsyslog Port",
:description => "Port that Rsyslog listens for incoming connections",
:default => "514"
attribute "rsyslog/remote_logs",
:display_name => "Remote Logs",
:description => "Specifies whether redirect all log from client to server",
:default => "true"
attribute "rsyslog/user",
:display_name => "User",
:description => "The owner of Rsyslog config files and directories",
:default => "root"
attribute "rsyslog/group",
:display_name => "Group",
:description => "The group-owner of Rsyslog config files and directories",
:default => "adm"
attribute "rsyslog/service_name",
:display_name => "Service name",
:description => "The name of the service for the platform",
:default => "rsyslog"
attribute "rsyslog/max_message_size",
:display_name => "Maximum Rsyslog message size",
:description => "Specifies the maximum size of allowable Rsyslog messages",
:default => "2k"
attribute "rsyslog/preserve_fqdn",
:display_name => "Preserve FQDN",
:description => "Specifies if the short or full host name will be used. The default off setting is more compatible.",
:default => "off"
attribute "rsyslog/repeated_msg_reduction",
:display_name => "Filter duplicated messages",
:description => "Specifies whether or not repeated messages should be reduced.",
:default => "on"
attribute "rsyslog/priv_seperation",
:display_name => "Privilege separation",
:description => "Whether or not to make use of Rsyslog privilege separation",
:default => "false"
version '1.7.1'
recipe 'rsyslog', 'Installs rsyslog'
recipe 'rsyslog::client', 'Sets up a client to log to a remote rsyslog server'
recipe 'rsyslog::server', 'Sets up an rsyslog server'
supports 'ubuntu'
supports 'debian', '>= 5.0'
supports 'redhat', '>= 6.0'
attribute 'rsyslog',
:display_name => 'Rsyslog',
:description => 'Hash of Rsyslog attributes',
:type => 'hash'
attribute 'rsyslog/log_dir',
:display_name => 'Rsyslog Log Directory',
:description => 'Filesystem location of logs from clients',
:default => '/srv/rsyslog'
attribute 'rsyslog/server',
:display_name => 'Rsyslog Server?',
:description => 'Is this node an rsyslog server?',
:default => 'false'
attribute 'rsyslog/server_ip',
:display_name => 'Rsyslog Server IP Address',
:description => 'Set rsyslog server ip address explicitly'
attribute 'rsyslog/server_search',
:display_name => 'Rsyslog Server Search Criteria',
:description => 'Set the search criteria for rsyslog server resolving',
:default => 'role:loghost'
attribute 'rsyslog/protocol',
:display_name => 'Rsyslog Protocol',
:description => 'Set which network protocol to use for rsyslog',
:default => 'tcp'
attribute 'rsyslog/port',
:display_name => 'Rsyslog Port',
:description => 'Port that Rsyslog listens for incoming connections',
:default => '514'
attribute 'rsyslog/remote_logs',
:display_name => 'Remote Logs',
:description => 'Specifies whether redirect all log from client to server',
:default => 'true'
attribute 'rsyslog/user',
:display_name => 'User',
:description => 'The owner of Rsyslog config files and directories',
:default => 'root'
attribute 'rsyslog/group',
:display_name => 'Group',
:description => 'The group-owner of Rsyslog config files and directories',
:default => 'adm'
attribute 'rsyslog/service_name',
:display_name => 'Service name',
:description => 'The name of the service for the platform',
:default => 'rsyslog'
attribute 'rsyslog/max_message_size',
:display_name => 'Maximum Rsyslog message size',
:description => 'Specifies the maximum size of allowable Rsyslog messages',
:default => '2k'
attribute 'rsyslog/preserve_fqdn',
:display_name => 'Preserve FQDN',
:description => 'Specifies if the short or full host name will be used. The default off setting is more compatible.',
:default => 'off'
attribute 'rsyslog/repeated_msg_reduction',
:display_name => 'Filter duplicated messages',
:description => 'Specifies whether or not repeated messages should be reduced.',
:default => 'on'
attribute 'rsyslog/priv_seperation',
:display_name => 'Privilege separation',
:description => 'Whether or not to make use of Rsyslog privilege separation',
:default => 'false'
......@@ -17,42 +17,39 @@
# limitations under the License.
#
include_recipe "rsyslog"
# Do not run this recipe if the server attribute is set
return if node['rsyslog']['server']
rsyslog_servers = []
include_recipe 'rsyslog::default'
if !node['rsyslog']['server'] and node['rsyslog']['server_ip'].nil? and Chef::Config[:solo]
Chef::Log.fatal("Chef Solo does not support search, therefore it is a requirement of the rsyslog::client recipe that the attribute 'server_ip' is set when using Chef Solo. 'server_ip' is not set.")
elsif !node['rsyslog']['server']
# On Chef Solo, we use the node['rsyslog']['server_ip'] attribute, and on
# normal Chef, we leverage the search query.
if Chef::Config[:solo]
if node['rsyslog']['server_ip']
# handle node['rsyslog']['server_ip'] being a string or an array
rsyslog_servers = Array(node['rsyslog']['server_ip'])
else
Chef::Application.fatal!("Chef Solo does not support search. You must set node['rsyslog']['server_ip']!")
end
else
results = search(:node, node['rsyslog']['server_search']).map { |n| n['ipaddress'] }
rsyslog_servers = Array(node['rsyslog']['server_ip']) + Array(results)
end
# add all syslog servers to the syslog_servers array
search(:node, node["rsyslog"]["server_search"]) do |result|
syslog_servers << result['ipaddress']
end
if rsyslog_servers.empty?
Chef::Application.fatal!("The rsyslog::client recipe was unable to determine the remote syslog server. Checked both the server_ip attribute and search()")
end
if rsyslog_servers.empty?
Chef::Application.fatal!('The rsyslog::client recipe was unable to determine the remote syslog server. Checked both the server_ip attribute and search!')
end
template "/etc/rsyslog.d/49-remote.conf" do
only_if { node['rsyslog']['remote_logs'] && !rsyslog_servers.empty? }
source "49-remote.conf.erb"
backup false
variables(
:servers => rsyslog_servers,
:protocol => node['rsyslog']['protocol'],
:port => node['rsyslog']['port']
)
mode 0644
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
template '/etc/rsyslog.d/49-remote.conf' do
source '49-remote.conf.erb'
owner 'root'
group 'root'
mode '0644'
variables :servers => rsyslog_servers
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
only_if { node['rsyslog']['remote_logs'] }
end
file "/etc/rsyslog.d/server.conf" do
action :delete
notifies :reload, "service[#{node['rsyslog']['service_name']}]"
end
file '/etc/rsyslog.d/server.conf' do
action :delete
notifies :reload, "service[#{node['rsyslog']['service_name']}]"
end
......@@ -17,42 +17,46 @@
# limitations under the License.
#
package "rsyslog" do
action :install
end
package 'rsyslog'
directory "/etc/rsyslog.d" do
mode 0755
directory '/etc/rsyslog.d' do
owner 'root'
group 'root'
mode '0755'
end
directory "/var/spool/rsyslog" do
mode 0755
directory '/var/spool/rsyslog' do
owner 'root'
group 'root'
mode '0755'
end
# Our main stub which then does its own rsyslog-specific
# include of things in /etc/rsyslog.d/*
template "/etc/rsyslog.conf" do
source 'rsyslog.conf.erb'
mode 0644
variables(:protocol => node['rsyslog']['protocol'])
template '/etc/rsyslog.conf' do
source 'rsyslog.conf.erb'
owner 'root'
group 'root'
mode '0644'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
template "/etc/rsyslog.d/50-default.conf" do
source "50-default.conf.erb"
backup false
mode 0644
template '/etc/rsyslog.d/50-default.conf' do
source '50-default.conf.erb'
owner 'root'
group 'root'
mode '0644'
notifies :restart, "service[#{node['rsyslog']['service_name']}]"
end
# syslog needs to be stopped before rsyslog can be started on RHEL versions before 6.0
if platform_family?('rhel') && node['platform_version'].to_i < 6
service "syslog" do
service 'syslog' do
action [:stop, :disable]
end
end
service node['rsyslog']['service_name'] do
supports :restart => true, :reload => true, :status => true
action [:enable, :start]
action [:enable, :start]
end
......@@ -2,7 +2,7 @@
# Cookbook Name:: rsyslog
# Recipe:: server
#
# Copyright 2009-2011, Opscode, Inc.
# Copyright 2009-2013, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -17,29 +17,28 @@
# limitations under the License.
#
# Manually set this attribute
node.set['rsyslog']['server'] = true
include_recipe "rsyslog"
include_recipe 'rsyslog::default'
directory node['rsyslog']['log_dir'] do
owner 'root'
group 'root'
mode '0755'
recursive true
mode 0755
end
template "/etc/rsyslog.d/35-server-per-host.conf" do
source "35-server-per-host.conf.erb"