Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Bumping papertrail cookbook to reflect PR to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
fh committed Mar 22, 2016
1 parent 753b84d commit 581c1ff
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 58 deletions.
2 changes: 1 addition & 1 deletion VERSIONS.md
Expand Up @@ -14,7 +14,7 @@ nodejs | [2.4.0](https://github.com/redguide/nodejs/releases/tag/v2.4.0) | disab
ohai| [2.0.4](https://github.com/chef-cookbooks/ohai/commit/bc6b53ff9807cd02d5cea86f18470a81e7678771) |
rabbitmq | [3.4.0](https://github.com/jjasghar/rabbitmq/commit/b71c0a068419ad10324e8d13b517fafbf373c0c3) | removed yum, ignored in our cs/test setup
xml| [1.2.4](https://github.com/opscode-cookbooks/xml/tree/v1.2.4) |
papertrail | [0.0.7](https://github.com/librato/papertrail-cookbook/releases/tag/0.0.7) |
papertrail | [#21](https://github.com/librato/papertrail-cookbook/pull/21) | PR 21 is 0.0.7 + priority fix
python | [master](https://github.com/poise/python/commit/56424ab64b06f584c13dba2dbb1cc5369faf20f4) |
rsyslog | [2.2.0](https://github.com/chef-cookbooks/rsyslog/releases/tag/v2.2.0) | 2.2.0 because 3.0.0+ is Chef 12+ only
sinopia | [0.3.0](https://github.com/BarthV/sinopia-cookbook/releases/tag/0.3.0) | removed dependency `user` cookbook, fix: use user resource
Expand Down
1 change: 1 addition & 0 deletions papertrail/.rubocop.yml
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
110 changes: 110 additions & 0 deletions papertrail/.rubocop_todo.yml
@@ -0,0 +1,110 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-21 16:30:19 +0100 using RuboCop version 0.38.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods:
Exclude:
- 'recipes/default.rb'

# Offense count: 10
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 132

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
Exclude:
- 'recipes/default.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerBackticks.
# SupportedStyles: backticks, percent_x, mixed
Style/CommandLiteral:
Exclude:
- 'recipes/default.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: SingleLineConditionsOnly.
Style/ConditionalAssignment:
Exclude:
- 'recipes/default.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
Exclude:
- 'metadata.rb'
- 'recipes/default.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
Style/HashSyntax:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 7

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'metadata.rb'
- 'recipes/default.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceAfterComma:
Exclude:
- 'recipes/default.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceBeforeFirstArg:
Exclude:
- 'metadata.rb'
- 'recipes/default.rb'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
Style/SpaceInsideBlockBraces:
Enabled: false

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceInsideHashLiteralBraces:
Enabled: false

# Offense count: 39
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 1
Style/ZeroLengthPredicate:
Exclude:
- 'recipes/default.rb'
5 changes: 5 additions & 0 deletions papertrail/.travis.yml
@@ -0,0 +1,5 @@
language: ruby
rvm:
- 2.2.4
script:
- bundle exec rake --trace
8 changes: 8 additions & 0 deletions papertrail/Berksfile
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# ^syntax detection

source "https://supermarket.chef.io"

metadata

cookbook 'rsyslog'
12 changes: 12 additions & 0 deletions papertrail/Berksfile.lock
@@ -0,0 +1,12 @@
DEPENDENCIES
papertrail
path: .
metadata: true
rsyslog

GRAPH
compat_resource (12.9.0)
papertrail (0.0.7)
rsyslog (>= 0.0.0)
rsyslog (4.0.0)
compat_resource (>= 0.0.0)
6 changes: 0 additions & 6 deletions papertrail/Cheffile

This file was deleted.

8 changes: 0 additions & 8 deletions papertrail/Cheffile.lock

This file was deleted.

12 changes: 10 additions & 2 deletions papertrail/Gemfile
@@ -1,4 +1,12 @@
source "http://rubygems.org"

gem 'chefspec', git: 'git://github.com/acrmp/chefspec.git'
gem 'librarian-chef'
group :style do
gem 'foodcritic'
gem 'rubocop'
gem 'rubocop-rspec'
end

group :unit do
gem 'chefspec', '~> 4'
gem 'berkshelf'
end
25 changes: 25 additions & 0 deletions papertrail/Rakefile
@@ -0,0 +1,25 @@
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'foodcritic'

namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)

desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
tags: ['~FC064', '~FC065'] # FC064 and FC065 breakcookbooks with chef11
}
end
end

desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']

# Rspec and ChefSpec
desc "Run ChefSpec examples"
RSpec::Core::RakeTask.new(:spec)

task default: %w(style spec)
1 change: 1 addition & 0 deletions papertrail/attributes/papertrail.rb
Expand Up @@ -61,3 +61,4 @@
# node['papertrail']['watch_files'] =
# [{:filename => "/var/log/myapp.log", :tag => "myapp:"}]
#
default['papertrail']['watch_files'] = {}
10 changes: 6 additions & 4 deletions papertrail/recipes/default.rb
Expand Up @@ -69,7 +69,7 @@
group "root"
mode "0644"
variables(:watch_files => watch_file_array)
notifies :restart, resources(:service => syslogger)
notifies :restart, "service[#{syslogger}]"
end
end

Expand All @@ -82,7 +82,9 @@
if !hostname_name.empty?
name = hostname_name
else
name = %x{#{hostname_cmd}}.chomp
cmd = Mixlib::ShellOut.new(hostname_cmd)
cmd.run_command
name = cmd.stdout.chomp
end

template "#{syslogdir}/61-fixhostnames.conf" do
Expand All @@ -91,7 +93,7 @@
group "root"
mode "0644"
variables({:name => name})
notifies :restart, resources(:service => syslogger)
notifies :restart, "service[#{syslogger}]"
end
end

Expand All @@ -105,5 +107,5 @@
:port => node['papertrail']['remote_port'],
:fixhostname => node['papertrail']['fixhostname']
})
notifies :restart, resources(:service => syslogger)
notifies :restart, "service[#{syslogger}]"
end
81 changes: 61 additions & 20 deletions papertrail/spec/default_spec.rb
@@ -1,29 +1,70 @@
require 'spec_helper'

describe 'papertrail-cookbook::default' do
describe 'papertrail::default' do
let(:runner) { ChefSpec::SoloRunner.new }
let(:chef_run) { runner.converge(described_recipe) }
let(:node) { runner.node }
let(:default_configfile) { '/etc/rsyslog.d/65-papertrail.conf' }
let(:watchfiles_configfile) { '/etc/rsyslog.d/60-watch-files.conf' }
let(:fixhost_configfile) { '/etc/rsyslog.d/61-fixhostnames.conf' }

it 'require rsyslog' do
expect(runner.converge('papertrail-cookbook::default')).to include_recipe 'rsyslog'
expect(chef_run).to include_recipe 'rsyslog'
end

it 'uses the basename of the filename as the suffix for state file name' do
chef_run = runner('test', {
papertrail: {
watch_files: {
'test/file/name.jpg' => 'test_file'
}
}
}).converge('papertrail-cookbook::default')

expect(chef_run).to create_file_with_content '/etc/rsyslog.d/60-watch-files.conf', '$InputFileName test/file/name.jpg'
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/60-watch-files.conf', '$InputFileTag test_file'
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/60-watch-files.conf', '$InputFileStateFile state_file_name_test_file'
it 'uses attributes to generate configuration' do
expect(chef_run).to render_file(default_configfile)
.with_content('$ActionResumeRetryCount -1')
expect(chef_run).to render_file(default_configfile)
.with_content('$ActionQueueMaxDiskSpace 100M')
expect(chef_run).to render_file(default_configfile)
.with_content('$ActionQueueSize 100000')
expect(chef_run).to render_file(default_configfile)
.with_content('$ActionQueueFileName papertrailqueue')
end

it 'uses attributes to generate configuration' do
chef_run = runner.converge('papertrail-cookbook::default')
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/65-papertrail.conf', '$ActionResumeRetryCount -1'
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/65-papertrail.conf', '$ActionQueueMaxDiskSpace 100M'
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/65-papertrail.conf', '$ActionQueueSize 100000'
expect(chef_run).to create_file_with_content '/etc/rsyslog.d/65-papertrail.conf', '$ActionQueueFileName /var/log/rsyslog_queue_main'
it 'does not create watch files conf' do
expect(chef_run).not_to render_file(watchfiles_configfile)
end

it 'does not create fix hostnames conf' do
expect(chef_run).not_to render_file(fixhost_configfile)
end

it 'does not add the fixhostname cmd to the log target' do
expect(chef_run).not_to render_file(default_configfile)
.with_content(';FixHostname')
end

describe 'with watchfiles added' do
before do
node.set['papertrail']['watch_files'] = { 'test/file/name.jpg' => 'test_file' }
end

it 'uses the basename of the filename as the suffix for state file name' do
expect(chef_run).to render_file(watchfiles_configfile)
.with_content('$InputFileName test/file/name.jpg')
expect(chef_run).to render_file(watchfiles_configfile)
.with_content('$InputFileTag test_file')
expect(chef_run).to render_file(watchfiles_configfile)
.with_content('$InputFileStateFile state_file_name_test_file')
end
end

describe 'with hostname set' do
before do
# no good idea how to mock something to test hostname_cmd.. :/
node.set['papertrail']['hostname_name'] = 'some.host.tld'
end

it 'creates the fix host template' do
expect(chef_run).to render_file(fixhost_configfile)
.with_content('FixHostname,"<%pri%>%timestamp% some.host.tld %syslogtag%')
end

it 'sets the fix host template in papertrail conf' do
expect(chef_run).to render_file(default_configfile)
.with_content(';FixHostname')
end
end
end
21 changes: 5 additions & 16 deletions papertrail/spec/spec_helper.rb
@@ -1,19 +1,8 @@
require 'chefspec'
require 'chefspec/berkshelf'

Dir['./spec/support/**/*.rb'].sort.each {|f| require f}

def runner(environment = 'test', attributes = {})
cookbook_paths = %W(#{File.expand_path('..', Dir.pwd)} #{File.expand_path(Dir.pwd)}/cookbooks)

# A workaround so that ChefSpec can work with Chef environments (from https://github.com/acrmp/chefspec/issues/54)
@runner ||= ChefSpec::ChefRunner.new(cookbook_path: cookbook_paths, platform: 'ubuntu', version: '10.04') do |node|
env = Chef::Environment.new
env.name environment
node.stub(:chef_environment).and_return env.name
Chef::Environment.stub!(:load).and_return env

attributes.each_pair do |key, val|
node.set[key] = val
end
end
RSpec.configure do |c|
c.platform = 'ubuntu'
c.version = '12.04'
# c.log_level = :debug
end
2 changes: 1 addition & 1 deletion papertrail/templates/default/fixhostnames.conf.erb
@@ -1,3 +1,3 @@
# A template that renames our hostname
# See http://www.rsyslog.com/doc/v8-stable/configuration/property_replacer.html for the msg replace templates
$template FixHostname,"<%pri%> %timestamp% <%= @name %> %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$template FixHostname,"<%%pri%>%timestamp% <%= @name %> %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"

0 comments on commit 581c1ff

Please sign in to comment.