Skip to content

Commit 7a451f3

Browse files
committed
Style fixes for rubocop
1 parent 0455335 commit 7a451f3

22 files changed

Lines changed: 1202 additions & 1010 deletions

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
2424
minor_version = ruby_version_segments[0..1].join('.')
2525

2626
group :development do
27+
gem "pry-byebug"
2728
gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
2829
gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
2930
gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')

lib/puppet/parser/functions/puppetdb_create_subsetting_resource_hash.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module Puppet::Parser::Functions
2-
newfunction(:puppetdb_create_subsetting_resource_hash, :type => :rvalue) do |args|
2+
newfunction(:puppetdb_create_subsetting_resource_hash, type: :rvalue) do |args|
33
java_args = args[0]
44
params = args[1]
55
resource_hash = {}
66

7-
java_args.each { |k,v|
7+
java_args.each do |k, v|
88
item_params = { 'subsetting' => k, 'value' => (v || '') }
99
item_params.merge!(params)
10-
resource_hash.merge!({ "'#{k}'" => item_params })
11-
}
10+
resource_hash.merge!("'#{k}'" => item_params)
11+
end
1212

1313
resource_hash
1414
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Puppet::Parser::Functions
2-
newfunction(:puppetdb_flatten_java_args, :type => :rvalue) do |args|
2+
newfunction(:puppetdb_flatten_java_args, type: :rvalue) do |args|
33
java_args = args[0] || {}
4-
args = ""
5-
java_args.each {|k,v| args += "#{k}#{v} "}
4+
args = ''
5+
java_args.each { |k, v| args += "#{k}#{v} " }
66
"\"#{args.chomp(' ')}\""
77
end
88
end

lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# In this case I'm trying the relative path first, then falling back to normal
77
# mechanisms. This should be fixed in future versions of puppet but it looks
88
# like we'll need to maintain this for some time perhaps.
9-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","..",".."))
9+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
1010
require 'puppet/util/puppetdb_validator'
1111

1212
# This file contains a provider for the resource type `puppetdb_conn_validator`,
@@ -38,7 +38,7 @@ def exists?
3838
# especially on the first install. Therefore, our first connection attempt
3939
# may fail. Here we have somewhat arbitrarily chosen to retry every 2
4040
# seconds until the configurable timeout has expired.
41-
Puppet.notice("Failed to connect to puppetdb; sleeping 2 seconds before retry")
41+
Puppet.notice('Failed to connect to puppetdb; sleeping 2 seconds before retry')
4242
sleep 2
4343
success = validator.attempt_connection
4444
end
@@ -67,6 +67,4 @@ def create
6767
def validator
6868
@validator ||= Puppet::Util::PuppetdbValidator.new(resource[:puppetdb_server], resource[:puppetdb_port], resource[:use_ssl], resource[:test_url])
6969
end
70-
7170
end
72-

lib/puppet/type/puppetdb_conn_validator.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Puppet::Type.newtype(:puppetdb_conn_validator) do
2-
32
@doc = "Verify that a connection can be successfully established between a node
43
and the puppetdb server. Its primary use is as a precondition to
54
prevent configuration changes from being applied if the puppetdb
@@ -11,7 +10,7 @@
1110
defaultto :present
1211
end
1312

14-
newparam(:name, :namevar => true) do
13+
newparam(:name, namevar: true) do
1514
desc 'An arbitrary name used as the identity of the resource.'
1615
end
1716

@@ -45,5 +44,4 @@
4544
Integer(value)
4645
end
4746
end
48-
4947
end
Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11
require 'puppet/network/http_pool'
22

3-
module Puppet
4-
module Util
5-
# Validator class, for testing that PuppetDB is alive
6-
class PuppetdbValidator
7-
attr_reader :puppetdb_server
8-
attr_reader :puppetdb_port
9-
attr_reader :use_ssl
10-
attr_reader :test_path
11-
attr_reader :test_headers
3+
# Validator class, for testing that PuppetDB is alive
4+
class Puppet::Util::PuppetdbValidator
5+
attr_reader :puppetdb_server
6+
attr_reader :puppetdb_port
7+
attr_reader :use_ssl
8+
attr_reader :test_path
9+
attr_reader :test_headers
1210

13-
def initialize(puppetdb_server, puppetdb_port, use_ssl=true, test_path = "/pdb/meta/v1/version")
14-
@puppetdb_server = puppetdb_server
15-
@puppetdb_port = puppetdb_port
16-
@use_ssl = use_ssl
17-
@test_path = test_path
18-
@test_headers = { "Accept" => "application/json" }
19-
end
11+
def initialize(puppetdb_server, puppetdb_port, use_ssl = true, test_path = '/pdb/meta/v1/version')
12+
@puppetdb_server = puppetdb_server
13+
@puppetdb_port = puppetdb_port
14+
@use_ssl = use_ssl
15+
@test_path = test_path
16+
@test_headers = { 'Accept' => 'application/json' }
17+
end
2018

21-
# Utility method; attempts to make an http/https connection to the puppetdb server.
22-
# This is abstracted out into a method so that it can be called multiple times
23-
# for retry attempts.
24-
#
25-
# @return true if the connection is successful, false otherwise.
26-
def attempt_connection
27-
# All that we care about is that we are able to connect successfully via
28-
# http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL
29-
# on the puppetdb server.
30-
conn = Puppet::Network::HttpPool.http_instance(puppetdb_server, puppetdb_port, use_ssl)
19+
# Utility method; attempts to make an http/https connection to the puppetdb server.
20+
# This is abstracted out into a method so that it can be called multiple times
21+
# for retry attempts.
22+
#
23+
# @return true if the connection is successful, false otherwise.
24+
def attempt_connection
25+
# All that we care about is that we are able to connect successfully via
26+
# http(s), so here we're simpling hitting a somewhat arbitrary low-impact URL
27+
# on the puppetdb server.
28+
conn = Puppet::Network::HttpPool.http_instance(puppetdb_server, puppetdb_port, use_ssl)
3129

32-
response = conn.get(test_path, test_headers)
33-
unless response.kind_of?(Net::HTTPSuccess)
34-
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? "s" : ""}://#{puppetdb_server}:#{puppetdb_port}): [#{response.code}] #{response.msg}"
35-
return false
36-
end
37-
return true
38-
rescue Exception => e
39-
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? "s" : ""}://#{puppetdb_server}:#{puppetdb_port}): #{e.message}"
40-
return false
41-
end
30+
response = conn.get(test_path, test_headers)
31+
unless response.is_a?(Net::HTTPSuccess)
32+
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? 's' : ''}://#{puppetdb_server}:#{puppetdb_port}): [#{response.code}] #{response.msg}"
33+
return false
4234
end
35+
return true
36+
rescue StandardError => e
37+
Puppet.notice "Unable to connect to puppetdb server (http#{use_ssl ? 's' : ''}://#{puppetdb_server}:#{puppetdb_port}): #{e.message}"
38+
return false
4339
end
4440
end
45-

spec/acceptance/basic_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
describe 'basic tests:' do
44
it 'make sure we have copied the module across' do
55
# No point diagnosing any more if the module wasn't copied properly
6-
shell("ls /etc/puppetlabs/code/modules/puppetdb") do |r|
7-
r.exit_code.should == 0
8-
r.stdout.should =~ /metadata\.json/
6+
shell('ls /etc/puppetlabs/code/modules/puppetdb') do |r|
7+
r.exit_code.should be_zero
8+
r.stdout.should =~ %r{metadata\.json}
99
r.stderr.should == ''
1010
end
1111
end
@@ -18,8 +18,8 @@ class { 'puppetdb::master::config': puppetdb_port => '8080', puppetdb_server =>
1818
EOS
1919

2020
it 'make sure it runs without error' do
21-
apply_manifest(pp, :catch_errors => true)
22-
apply_manifest(pp, :catch_changes => true)
21+
apply_manifest(pp, catch_errors: true)
22+
apply_manifest(pp, catch_changes: true)
2323
end
2424
end
2525

@@ -34,12 +34,12 @@ class { 'puppetdb::master::config':
3434
}
3535
EOS
3636

37-
it 'should add the puppetdb report processor to puppet.conf' do
38-
apply_manifest(pp, :catch_errors => true)
39-
apply_manifest(pp, :catch_changes => true)
37+
it 'adds the puppetdb report processor to puppet.conf' do
38+
apply_manifest(pp, catch_errors: true)
39+
apply_manifest(pp, catch_changes: true)
4040

4141
shell('cat /etc/puppetlabs/puppet/puppet.conf') do |r|
42-
expect(r.stdout).to match(/^reports\s*=\s*([^,]+,)*puppetdb(,[^,]+)*$/)
42+
expect(r.stdout).to match(%r{^reports\s*=\s*([^,]+,)*puppetdb(,[^,]+)*$})
4343
end
4444
end
4545
end

spec/spec_helper_acceptance.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
require 'beaker/module_install_helper'
44

55
hosts.each do |host|
6-
if host['platform'] =~ /debian/
6+
if host['platform'] =~ %r{debian}
77
on host, 'echo \'export PATH=/var/lib/gems/1.8/bin/:${PATH}\' >> ~/.bashrc'
88
end
9-
#install_puppet
10-
if host['platform'] =~ /el-(5|6|7)/
11-
relver = $1
9+
# install_puppet
10+
if host['platform'] =~ %r{el-(5|6|7)}
11+
relver = Regexp.last_match(1)
1212
on host, "rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-pc1-el-#{relver}.noarch.rpm"
1313
on host, 'yum install -y puppetserver'
14-
elsif host['platform'] =~ /fedora-(\d+)/
15-
relver = $1
14+
elsif host['platform'] =~ %r{fedora-(\d+)}
15+
relver = Regexp.last_match(1)
1616
on host, "rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-pc1-fedora-#{relver}.noarch.rpm"
1717
on host, 'yum install -y puppetserver'
18-
elsif host['platform'] =~ /(ubuntu|debian)/
19-
if ! host.check_for_package 'curl'
18+
elsif host['platform'] =~ %r{(ubuntu|debian)}
19+
unless host.check_for_package 'curl'
2020
on host, 'apt-get install -y curl'
2121
end
2222
on host, 'apt-get install apt-transport-https --assume-yes'

spec/unit/classes/init_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
require 'spec_helper'
22

3-
describe 'puppetdb', :type => :class do
4-
ttl_args = ['node_ttl','node_purge_ttl','report_ttl']
3+
describe 'puppetdb', type: :class do
4+
ttl_args = ['node_ttl', 'node_purge_ttl', 'report_ttl']
55

66
on_supported_os.each do |os, facts|
77
context "on #{os}" do
88
let(:facts) do
9-
facts.merge({
10-
:selinux => false
11-
})
9+
facts.merge(selinux: false)
1210
end
1311

1412
describe 'when using default values for puppetdb class' do
15-
it { should contain_class('puppetdb') }
16-
it { should contain_class('puppetdb::server') }
17-
it { should contain_class('puppetdb::database::postgresql') }
13+
it { is_expected.to contain_class('puppetdb') }
14+
it { is_expected.to contain_class('puppetdb::server') }
15+
it { is_expected.to contain_class('puppetdb::database::postgresql') }
1816
end
1917
end
2018
end
2119

2220
context 'with invalid arguments on a supported platform' do
2321
let(:facts) do
2422
{
25-
:osfamily => 'RedHat',
26-
:operatingsystem => 'Debian',
27-
:puppetversion => Puppet.version,
28-
:operatingsystemrelease => '6.0',
29-
:kernel => 'Linux',
30-
:concat_basedir => '/var/lib/puppet/concat',
31-
:selinux => true,
32-
:iptables_persistent_version => '0.5.7',
23+
osfamily: 'RedHat',
24+
operatingsystem: 'Debian',
25+
puppetversion: Puppet.version,
26+
operatingsystemrelease: '6.0',
27+
kernel: 'Linux',
28+
concat_basedir: '/var/lib/puppet/concat',
29+
selinux: true,
30+
iptables_persistent_version: '0.5.7',
3331
}
3432
end
33+
3534
ttl_args.each do |ttl_arg|
3635
let(:params) do
3736
{
38-
ttl_arg => 'invalid_value'
37+
ttl_arg => 'invalid_value',
3938
}
4039
end
40+
4141
it "when using a value that does not match the validation regex for #{ttl_arg} puppetdb class" do
42-
expect { should contain_class('puppetdb') }.to raise_error(Puppet::Error)
42+
expect { is_expected.to contain_class('puppetdb') }.to raise_error(Puppet::Error)
4343
end
4444
end
4545
end

0 commit comments

Comments
 (0)