Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Jul 22, 2018
1 parent ba2acf1 commit 240386c
Show file tree
Hide file tree
Showing 20 changed files with 1,876 additions and 1,159 deletions.
472 changes: 472 additions & 0 deletions .rubocop.yml

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
source 'https://rubygems.org'

group :rake do
puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.0.0','< 6.0']
puppetversion = ENV.key?('PUPPET_VERSION') ? (ENV['PUPPET_VERSION']).to_s : ['>= 3.0.0', '< 6.0']
gem 'puppet', puppetversion
gem 'puppet-lint'
gem 'puppetlabs_spec_helper', '>=0.2.0'
# removed method last_comment (requires rspec 3.5.0)
gem 'rake'
gem 'rspec-system-puppet', :require => false
gem 'highline'
gem 'semantic_puppet'
gem 'librarian-puppet' , '>=2.0'
gem 'librarian-puppet', '>=2.0'
gem 'metadata-json-lint', require: false
gem 'nokogiri', '~> 1.8.1'
gem 'rake'
gem 'rspec-core', '>= 3.5.0'
gem 'rspec-puppet'
gem 'metadata-json-lint', :require => false
if RUBY_VERSION >= "2.2.0"
gem 'safe_yaml'
end
if RUBY_VERSION >= "2.3.0"
gem 'xmlrpc'
end
gem 'nokogiri', '~> 1.8.1'
gem 'rspec-system-puppet', require: false
gem 'safe_yaml' if RUBY_VERSION >= '2.2.0'
gem 'semantic_puppet'
gem 'xmlrpc' if RUBY_VERSION >= '2.3.0'
end

group :development do
gem 'rubocop', '>= 0.49.0'
gem 'puppet-blacksmith', '< 4.0.0'
end
gem 'rubocop', '>= 0.49.0'
end
22 changes: 10 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ require 'puppet-lint/tasks/puppet-lint'
require 'rspec-system/rake_task'
require 'puppetlabs_spec_helper/rake_tasks'
# blacksmith does not support ruby 1.8.7 anymore
require 'puppet_blacksmith/rake_tasks' if ENV['RAKE_ENV'] != 'ci' && RUBY_VERSION.split('.')[0,3].join.to_i > 187
require 'puppet_blacksmith/rake_tasks' if ENV['RAKE_ENV'] != 'ci' && RUBY_VERSION.split('.')[0, 3].join.to_i > 187

desc "Lint metadata.json file"
desc 'Lint metadata.json file'
task :meta do
sh "metadata-json-lint metadata.json"
sh 'metadata-json-lint metadata.json'
end

exclude_paths = [
"bundle/**/*",
"pkg/**/*",
"vendor/**/*",
"spec/**/*",
'bundle/**/*',
'pkg/**/*',
'vendor/**/*',
'spec/**/*'
]
Rake::Task[:lint].clear

Expand All @@ -29,16 +29,14 @@ PuppetLint.configuration.disable_class_parameter_defaults
PuppetLint.configuration.fail_on_warnings = true

PuppetLint::RakeTask.new :lint do |config|
config.ignore_paths = exclude_paths
config.ignore_paths = exclude_paths
end


# use librarian-puppet to manage fixtures instead of .fixtures.yml
# offers more possibilities like explicit version management, forge downloads,...
task :librarian_spec_prep do
sh 'librarian-puppet install --path=spec/fixtures/modules/'
end
task :spec_prep => :librarian_spec_prep

task :default => [:validate, :spec, :lint]
task spec_prep: :librarian_spec_prep

task default: %i[validate spec lint]
2 changes: 1 addition & 1 deletion lib/facter/mesos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
Facter::Util::Resolution.exec('mesos-master --version 2>&1').split(/ /)[1].strip
end
end
end
end
15 changes: 7 additions & 8 deletions lib/puppet/parser/functions/mesos_hash_parser.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@

#
# mesos_hash_parser.rb
#

module Puppet::Parser::Functions
newfunction(:mesos_hash_parser, :type => :rvalue, :doc => <<-EOS
newfunction(:mesos_hash_parser, type: :rvalue, doc: <<-EOS
This function converts simple key-value structure to a Hash
that is required by create_resources function
EOS
) do |args|
EOS
) do |args|

# Arguments: hash key_prefix [file_prefix]

if args.size < 1 || args.size > 3
if args.empty? || args.size > 3
raise(Puppet::ParseError, "mesos_hash_parser(): Wrong number of args, given #{args.size}, accepts either 1, 2 or 3")
end

if args[0].class != Hash
raise(Puppet::ParseError, "mesos_hash_parser(): first argument must be a Hash, you passed a " + args[0].class.to_s)
raise(Puppet::ParseError, 'mesos_hash_parser(): first argument must be a Hash, you passed a ' + args[0].class.to_s)
end

res = {}
Expand All @@ -28,8 +27,8 @@ module Puppet::Parser::Functions
file = file_prefix ? "#{file_prefix}_#{key}" : key
key = "#{key_prefix}_#{key}" if key_prefix
res[key] = {
"value" => val,
"file" => file,
'value' => val,
'file' => file
}
end
res
Expand Down
33 changes: 16 additions & 17 deletions lib/puppet/parser/functions/zookeeper_servers_url.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Puppet::Parser::Functions
newfunction(:zookeeper_servers_url, :type => :rvalue, :doc => <<-EOS
newfunction(:zookeeper_servers_url, type: :rvalue, doc: <<-EOS
This function converts an array of ZooKeeper hostnames into a combined URL for
ZooKeeper HA. Optionally you can pass custom path in ZooKeeper and default
ZooKeeper port (applies only for servers without specified port)
Usage: zookeeper_servers_url([10.0.0.1,10.0.0.2],'mesos', 2181)
EOS
) do |args|
EOS
) do |args|

# Only 1 argument should be passed
if args.size > 3
Expand All @@ -20,25 +20,24 @@ module Puppet::Parser::Functions

# The argument should be an Array
case args[0].class.name
when 'Array'
zookeeper_servers = args[0].clone
when 'String'
# backward compatibility, will be removed in 1.x
return args[0]
else
raise(Puppet::ParseError, 'zookeeper_servers_url() accepts an Array, you passed a ' + args[0].class.name)
when 'Array'
zookeeper_servers = args[0].clone
when 'String'
# backward compatibility, will be removed in 1.x
return args[0]
else
raise(Puppet::ParseError, 'zookeeper_servers_url() accepts an Array, you passed a ' + args[0].class.name)
end

uri = 'zk://'
zookeeper_servers.each_with_index do |server, i|
uri << ',' if i > 0
if server.index(':')
uri << server
else
uri << "#{server}:#{zk_port}"
end
uri << if server.index(':')
server
else
"#{server}:#{zk_port}"
end
end
return "#{uri}/#{zk_path}"
return "#{uri}/#{zk_path}"
end
end

62 changes: 33 additions & 29 deletions spec/classes/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
require 'spec_helper'

describe 'mesos::cli', :type => :class do

describe 'mesos::cli', type: :class do
let(:owner) { 'mesos' }
let(:group) { 'mesos' }

let(:params){{
:owner => owner,
:group => group,
:manage_pip => true,
}}

let(:facts) {{
# still old fact is needed due to this
# https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3
:osfamily => 'Debian',
:os => {
:family => 'Debian',
:name => 'Debian',
:distro => { :codename => 'stretch'},
:release => { :major => '9', :minor => '1', :full => '9.1' },
},
:puppetversion => Puppet.version,
}}
let(:params) do
{
owner: owner,
group: group,
manage_pip: true
}
end

let(:facts) do
{
# still old fact is needed due to this
# https://github.com/puppetlabs/puppetlabs-apt/blob/master/manifests/params.pp#L3
osfamily: 'Debian',
os: {
family: 'Debian',
name: 'Debian',
distro: { codename: 'stretch' },
release: { major: '9', minor: '1', full: '9.1' }
},
puppetversion: Puppet.version
}
end

before(:each) do
puppet_debug_override
end

it { is_expected.to contain_package('python-pip') }
it { is_expected.to contain_class('mesos::cli') }
it { is_expected.to contain_package('mesos.cli').with({'provider' => 'pip'}) }
it { is_expected.to contain_package('mesos.interface').with({'provider' => 'pip'}) }
it { is_expected.to contain_package('mesos.cli').with('provider' => 'pip') }
it { is_expected.to contain_package('mesos.interface').with('provider' => 'pip') }

context 'set zookeeper url' do
let(:params) do
{
:zookeeper => 'zk://192.168.1.100:2181/mesos',
:owner => owner,
:group => group,
zookeeper: 'zk://192.168.1.100:2181/mesos',
owner: owner,
group: group
}
end

it do is_expected.to contain_file('/etc/.mesos.json').with({
'ensure' => 'present',
it do
is_expected.to contain_file('/etc/.mesos.json').with(
'ensure' => 'present',
'owner' => owner,
'group' => group,
'mode' => '0644',
})
'mode' => '0644'
)
end

it do
Expand Down
Loading

0 comments on commit 240386c

Please sign in to comment.