Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint and rubocop (autofixes only) #289

Merged
merged 41 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
77b5cae
Fix puppet-lint warning
alexjfisher Mar 8, 2019
c73bfe6
Add `.rubocop.yml` file
alexjfisher Mar 8, 2019
e565c3c
Rubocop Autofix: Style/WordArray
alexjfisher Mar 8, 2019
6e3dbcd
Rubocop Autofix: Style/HashSyntax
alexjfisher Mar 8, 2019
5e6573f
Rubocop Autofix: Style/TrailingCommaInArguments
alexjfisher Mar 8, 2019
d043506
Rubocop Autofix: Style/NumericLiterals
alexjfisher Mar 8, 2019
0ec1170
Rubocop Autofix: Style/MethodDefParentheses
alexjfisher Mar 8, 2019
385ede1
Rubocop Autofix: Style/MethodCallWithoutArgsParentheses
alexjfisher Mar 8, 2019
3a40893
Rubocop Autofix: Style/ConditionalAssignment
alexjfisher Mar 8, 2019
d8bf16c
Rubocop Autofix: Style/AndOr
alexjfisher Mar 8, 2019
46100f0
Rubocop Autofix: Style/Alias
alexjfisher Mar 8, 2019
12466da
Rubocop Autofix: RSpec/HookArgument
alexjfisher Mar 8, 2019
52f30e3
Rubocop Autofix: Layout/TrailingBlankLines
alexjfisher Mar 8, 2019
643e35e
Rubocop Autofix: Layout/SpaceAfterComma
alexjfisher Mar 8, 2019
f4345b9
Rubocop Autofix: Layout/IndentationConsistency
alexjfisher Mar 8, 2019
203a70d
Rubocop Autofix: Layout/EmptyLinesAroundMethodBody
alexjfisher Mar 8, 2019
9b8fc51
Rubocop Autofix: Layout/CaseIndentation
alexjfisher Mar 8, 2019
220e3a5
Rubocop Autofix: Layout/BlockEndNewline
alexjfisher Mar 8, 2019
18cfd1c
Rubocop Autofix: Lint/DeprecatedClassMethods
alexjfisher Mar 8, 2019
4b800a2
Rubocop Autofix: Layout/IndentationWidth
alexjfisher Mar 8, 2019
51f4e36
Rubocop Autofix: Layout/IndentArray
alexjfisher Mar 8, 2019
9c8633f
Rubocop Autofix: Layout/EmptyLines
alexjfisher Mar 8, 2019
e69cf52
Rubocop Autofix: Style/MutableConstant
alexjfisher Mar 8, 2019
47a834a
Rubocop Autofix: Lint/BlockAlignment
alexjfisher Mar 8, 2019
94b6e11
Rubocop Autofix: Layout/SpaceInsideHashLiteralBraces
alexjfisher Mar 8, 2019
dbd210a
Rubocop Autofix: Layout/SpaceInsideBlockBraces
alexjfisher Mar 8, 2019
47b166c
Rubocop Autofix: RSpec/EmptyLineAfterFinalLet
alexjfisher Mar 8, 2019
743d979
Rubocop Autofix: Layout/SpaceAroundOperators
alexjfisher Mar 8, 2019
2348bb1
Rubocop Autofix: RSpec/ExampleWording
alexjfisher Mar 8, 2019
482651d
Rubocop Autofix: Style/BracesAroundHashParameters
alexjfisher Mar 8, 2019
44047f5
Rubocop Autofix: Style/TrailingCommaInLiteral
alexjfisher Mar 8, 2019
9e58510
Rubocop Autofix: Layout/IndentHash
alexjfisher Mar 8, 2019
e631704
Rubocop Autofix: Style/StringLiterals
alexjfisher Mar 8, 2019
e124bcd
Rubocop Autofix: Layout/FirstParameterIndentation
alexjfisher Mar 8, 2019
a552472
Rubocop Autofix: Layout/ClosingParenthesisIndentation
alexjfisher Mar 8, 2019
1b6699a
Rubocop Autofix: Layout/EmptyLinesAroundBlockBody
alexjfisher Mar 8, 2019
b136945
Rubocop Autofix: Layout/MultilineBlockLayout
alexjfisher Mar 8, 2019
047436c
Rubocop Autofix: Style/BlockDelimiters
alexjfisher Mar 8, 2019
b0a3642
Rubocop Autofix: RSpec/ImplicitExpect
alexjfisher Mar 8, 2019
deef109
Rubocop Autofix: Style/RegexpLiteral
alexjfisher Mar 8, 2019
93676ed
Rubocop Autofix: Lint/UnneededDisable
alexjfisher Mar 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
545 changes: 545 additions & 0 deletions .rubocop.yml

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions lib/facter/redis_server_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
# Purpose: Retrieve redis-server version if installed
#
Facter.add(:redis_server_version) do

setcode do
if Facter::Util::Resolution.which('redis-server')
redis_server_version_output = Facter::Util::Resolution.exec('redis-server -v')
if redis_server_version_output =~ /v=([\w\.]+)/
if redis_server_version_output =~ %r{v=([\w\.]+)}
# Redis server v=2.8.17 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=4c1d5710660b9479
redis_server_version_output.match(/Redis server v=([\w\.]+).+/)[1]
elsif redis_server_version_output =~ /version ([\w\.]+)/
redis_server_version_output.match(%r{Redis server v=([\w\.]+).+})[1]
elsif redis_server_version_output =~ %r{version ([\w\.]+)}
# Redis server version 2.4.10 (00000000:0)
redis_server_version_output.match(/Redis server version ([\w\.]+).+/)[1]
redis_server_version_output.match(%r{Redis server version ([\w\.]+).+})[1]
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/puppet/parser/functions/redisget.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'redis'

module Puppet::Parser::Functions
newfunction(:redisget, :type => :rvalue, :doc => <<-DOC
newfunction(:redisget, type: :rvalue, doc: <<-DOC
Returns the value of the key being looked up or nil if the key does not
exist. Takes two arguments with an optional third. The first being a string
value of the key to be looked up, the second is the URL to the Redis service
Expand All @@ -18,9 +18,9 @@ module Puppet::Parser::Functions
@example Calling the function with a default if failure occurs
$version = redisget('version.myapp', 'redis://redis.example.com:6379', $::myapp_version)
DOC
) do |args|
) do |args|

raise(Puppet::ParseError, "redisget(): Wrong number of arguments given (#{args.size} for 2 or 3)") if args.size != 2 and args.size != 3
raise(Puppet::ParseError, "redisget(): Wrong number of arguments given (#{args.size} for 2 or 3)") if args.size != 2 && args.size != 3

key = args[0]
url = args[1]
Expand All @@ -34,12 +34,11 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "redisget(): Wrong argument type given (#{url.class} for String) for arg2 (url)") if url.is_a?(String) == false

begin
Redis.new(:url => url).get(key) || default
Redis.new(url: url).get(key) || default
rescue Redis::CannotConnectError, SocketError => e
raise Puppet::Error, "connection to redis server failed - #{e}" unless default
debug "Connection to redis failed with #{e} - Returning default value of #{default}"
default
end

end
end
4 changes: 2 additions & 2 deletions manifests/ulimit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
lens => 'Systemd.lns',
changes => [
"defnode nofile Service/LimitNOFILE \"\"",
"set \$nofile/value \"${::redis::ulimit}\""
],
"set \$nofile/value \"${::redis::ulimit}\"",
],
notify => [
Exec['systemd-reload-redis'],
],
Expand Down
3 changes: 1 addition & 2 deletions spec/acceptance/redis_cli_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'spec_helper_acceptance'

describe 'redis-cli task' do

it 'install redis-cli with the class' do
pp = <<-EOS
Exec {
Expand All @@ -15,7 +14,7 @@ class { '::redis':
EOS

# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, catch_failures: true)
end

describe 'ping' do
Expand Down
26 changes: 13 additions & 13 deletions spec/acceptance/suites/default/redis_adminstration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
require 'spec_helper_acceptance'

# systcl settings are untestable in docker
unless default['hypervisor'] =~ /docker/
unless default['hypervisor'] =~ %r{docker}
describe 'redis::administration' do
it 'should run successfully' do
it 'runs successfully' do
pp = <<-EOS
include redis
include redis::administration
EOS

# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
it 'should set overcommit_memory to 1 in a seperate sysctl file' do
it 'sets overcommit_memory to 1 in a seperate sysctl file' do
shell('/bin/cat /proc/sys/vm/overcommit_memory') do |result|
expect(result.stdout).to match(/^1$/)
expect(result.stdout).to match(%r{^1$})
end
end
it 'should disable thp' do
it 'disables thp' do
shell('/bin/cat /sys/kernel/mm/transparent_hugepage/enabled') do |result|
expect(result.stdout).to match(/^always madvise \[never\]$/)
expect(result.stdout).to match(%r{^always madvise \[never\]$})
end
end
it 'should set somaxconn to 65535' do
it 'sets somaxconn to 65535' do
shell('/bin/cat /proc/sys/net/core/somaxconn') do |result|
expect(result.stdout).to match(/^65535$/)
expect(result.stdout).to match(%r{^65535$})
end
end
it 'should show no warnings about kernel settings in logs' do
shell('timeout 1s redis-server --port 7777 --loglevel verbose', { :acceptable_exit_codes => [0,124] }) do |result|
expect(result.stdout).not_to match(/WARNING/)
it 'shows no warnings about kernel settings in logs' do
shell('timeout 1s redis-server --port 7777 --loglevel verbose', acceptable_exit_codes: [0, 124]) do |result|
expect(result.stdout).not_to match(%r{WARNING})
expect(result.exit_code).to match(124)
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/suites/default/redis_debian_run_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# since this test polutes others, we'll only run it if specifically asked
if ENV['RUN_BACKPORT_TEST'] == 'yes'
describe 'redis', :if => (fact('operatingsystem') == 'Debian') do
it 'should run with newer Debian package' do
describe 'redis', if: (fact('operatingsystem') == 'Debian') do
it 'runs with newer Debian package' do
pp = <<-EOS

include ::apt
Expand All @@ -28,27 +28,27 @@ class { 'redis':
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_change => true)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_change: true)
end

describe package('redis-server') do
it { should be_installed }
it { is_expected.to be_installed }
end

describe service('redis-server') do
it { should be_running }
it { is_expected.to be_running }
end

context 'redis should respond to ping command' do
describe command('redis-cli ping') do
its(:stdout) { should match /PONG/ }
its(:stdout) { is_expected.to match %r{PONG} }
end
end

context 'redis log should be clean' do
describe command('journalctl --no-pager') do
its(:stdout) { should_not match /Failed at step RUNTIME_DIRECTORY/ }
its(:stdout) { is_expected.not_to match %r{Failed at step RUNTIME_DIRECTORY} }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper_acceptance'

# Cant get this to work on Debian, add exception for now
describe 'redis::instance', :unless => (fact('operatingsystem') == 'Debian') do
describe 'redis::instance', unless: (fact('operatingsystem') == 'Debian') do
case fact('osfamily')
when 'Debian'
config_path = '/etc/redis'
Expand All @@ -13,7 +13,7 @@
manage_repo = true
end

it 'should run successfully' do
it 'runs successfully' do
pp = <<-EOS
Exec {
path => [ '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', ]
Expand All @@ -35,37 +35,37 @@ class { '::redis':
EOS

# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe package(redis_name) do
it { should be_installed }
it { is_expected.to be_installed }
end

describe service('redis-server-redis1') do
it { should be_running }
it { is_expected.to be_running }
end

describe service('redis-server-redis2') do
it { should be_running }
it { is_expected.to be_running }
end

describe file("#{config_path}/redis-server-redis1.conf") do
its(:content) { should match /port 7777/ }
its(:content) { is_expected.to match %r{port 7777} }
end

describe file("#{config_path}/redis-server-redis2.conf") do
its(:content) { should match /port 8888/ }
its(:content) { is_expected.to match %r{port 8888} }
end

context 'redis should respond to ping command' do
describe command('redis-cli -h 127.0.0.1 -p 7777 ping') do
its(:stdout) { should match /PONG/ }
its(:stdout) { is_expected.to match %r{PONG} }
end

describe command('redis-cli -h 127.0.0.1 -p 8888 ping') do
its(:stdout) { should match /PONG/ }
its(:stdout) { is_expected.to match %r{PONG} }
end
end
end
23 changes: 9 additions & 14 deletions spec/acceptance/suites/default/redis_multi_node_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'spec_helper_acceptance'

if hosts.length >= 3
describe "configuring master and slave redis hosts" do

describe 'configuring master and slave redis hosts' do
let(:master_ip_address) do
# hosts_as('master').inject({}) do |memo,host|
# memo[host] = fact_on host, "ipaddress_enp0s8"
Expand All @@ -12,7 +11,7 @@

hosts_as('master').each do |host|
context "should be able to configure a host as master on #{host}" do
it 'should work idempotently with no errors' do
it 'works idempotently with no errors' do
pp = <<-EOS
# Stop firewall so we can easily connect
service {'firewalld':
Expand All @@ -25,21 +24,20 @@ class { 'redis':
requirepass => 'foobared',
}
EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, catch_failures: true)

command_to_check = "redis-cli -h #{master_ip_address} -a foobared info replication"

on host, command_to_check do
expect(stdout).to match(/^role:master/)
expect(stdout).to match(%r{^role:master})
end

end
end
end

hosts_as('slave').each do |host|
context "should be able to configure a host as master on #{host}" do
it 'should work idempotently with no errors' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'redis':
manage_repo => true,
Expand All @@ -49,30 +47,27 @@ class { 'redis':
}

EOS
apply_manifest_on(host, pp, :catch_failures => true)
apply_manifest_on(host, pp, catch_failures: true)

on host, 'redis-cli -h $(facter ipaddress_enp0s8) info replication' do
expect(stdout).to match(/^role:slave/)
expect(stdout).to match(%r{^role:slave})
end

end
end
end

hosts_as('master').each do |host|
context "should be able to configure a host as master on #{host}" do
it 'should work idempotently with no errors' do
it 'works idempotently with no errors' do
command_to_check = "redis-cli -h #{master_ip_address} -a foobared info replication"

sleep(5)

on host, command_to_check do
expect(stdout).to match(/^connected_slaves:2/)
expect(stdout).to match(%r{^connected_slaves:2})
end

end
end
end

end
end
33 changes: 16 additions & 17 deletions spec/acceptance/suites/default/redis_sentinel_one_node_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require 'spec_helper_acceptance'

# CentOS 6 Redis package is too old for Sentinel (2.4.10, needs 2.8+)
describe 'redis::sentinel', :unless => (fact('osfamily') == 'RedHat' && (fact('operatingsystemmajrelease') == '6')) do
case fact('osfamily')
when 'Debian'
redis_name = 'redis-server'
else
redis_name = 'redis'
end

it 'should run successfully' do
describe 'redis::sentinel', unless: (fact('osfamily') == 'RedHat' && (fact('operatingsystemmajrelease') == '6')) do
redis_name = case fact('osfamily')
when 'Debian'
'redis-server'
else
'redis'
end

it 'runs successfully' do
pp = <<-EOS

$master_name = 'mymaster'
Expand All @@ -27,38 +27,37 @@ class { 'redis::sentinel':
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, catch_failures: true)
end

describe package(redis_name) do
it { should be_installed }
it { is_expected.to be_installed }
end

describe service(redis_name) do
it { should be_running }
it { is_expected.to be_running }
end

describe service('redis-sentinel') do
it { should be_running }
it { is_expected.to be_running }
end

case fact('osfamily')
when 'Debian'
describe package('redis-sentinel') do
it { should be_installed }
it { is_expected.to be_installed }
end
end

context 'redis should respond to ping command' do
describe command('redis-cli ping') do
its(:stdout) { should match /PONG/ }
its(:stdout) { is_expected.to match %r{PONG} }
end
end

context 'redis-sentinel should return correct sentinel master' do
describe command('redis-cli -p 26379 SENTINEL masters') do
its(:stdout) { should match /^mymaster/ }
its(:stdout) { is_expected.to match %r{^mymaster} }
end
end

end
Loading