Skip to content

Commit

Permalink
Autofixes from rubocop
Browse files Browse the repository at this point in the history
There are a few remaining issues that need to be fixed, where the ruby code is
ambiguous, or something else weird is going on.
  • Loading branch information
DavidS committed Aug 1, 2018
1 parent a3f933d commit 46c8765
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 180 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/_load_choria.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
["/opt/puppetlabs/mcollective/plugins", "C:/ProgramData/PuppetLabs/mcollective/plugins"].each do |libdir|
['/opt/puppetlabs/mcollective/plugins', 'C:/ProgramData/PuppetLabs/mcollective/plugins'].each do |libdir|
next if $LOAD_PATH.include?(libdir)
next unless File.directory?(libdir)

$LOAD_PATH << libdir
end

require "mcollective/util/bolt_support"
require 'mcollective/util/bolt_support'
4 changes: 2 additions & 2 deletions lib/puppet/datatypes/choria/taskresult.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Puppet::DataTypes.create_type("Choria::TaskResult") do
Puppet::DataTypes.create_type('Choria::TaskResult') do
interface <<-PUPPET
attributes => {
"host" => Choria::Node,
Expand All @@ -14,7 +14,7 @@
}
PUPPET

require_relative "../../_load_choria"
require_relative '../../_load_choria'

implementation_class MCollective::Util::BoltSupport::TaskResult
end
4 changes: 2 additions & 2 deletions lib/puppet/datatypes/choria/taskresults.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Puppet::DataTypes.create_type("Choria::TaskResults") do
Puppet::DataTypes.create_type('Choria::TaskResults') do
interface <<-PUPPET
attributes => {
"results" => Array[Choria::TaskResult, 0],
Expand All @@ -18,7 +18,7 @@
}
PUPPET

require_relative "../../_load_choria"
require_relative '../../_load_choria'

implementation_class MCollective::Util::BoltSupport::TaskResults
end
12 changes: 6 additions & 6 deletions lib/puppet/functions/choria/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
Puppet::Functions.create_function(:"choria::data", Puppet::Functions::InternalFunction) do
dispatch :read do
scope_param
param "String", :item
param "Hash", :properties
param 'String', :item
param 'Hash', :properties
end

dispatch :write do
scope_param
param "String", :item
param "String", :value
param "Hash", :properties
param 'String', :item
param 'String', :value
param 'Hash', :properties
end

def init
require_relative "../../_load_choria"
require_relative '../../_load_choria'

MCollective::Util::BoltSupport.init_choria
end
Expand Down
11 changes: 5 additions & 6 deletions lib/puppet/functions/choria/discover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,22 @@
Puppet::Functions.create_function(:"choria::discover", Puppet::Functions::InternalFunction) do
dispatch :mcollective_discover do
scope_param
param "Hash", :options
param 'Hash', :options
end

dispatch :discover do
scope_param
param "String", :type
param "Hash", :options
param 'String', :type
param 'Hash', :options
end

def mcollective_discover(scope, options)
discover(scope, "mcollective", options)
discover(scope, 'mcollective', options)
end

def discover(scope, type, options)
require_relative "../../_load_choria"
require_relative '../../_load_choria'

MCollective::Util::BoltSupport.init_choria.discover_nodes(scope, type, options)
end
end

6 changes: 3 additions & 3 deletions lib/puppet/functions/choria/in_groups_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# will be done on the final yield to your lambda as shown above
Puppet::Functions.create_function(:"choria::in_groups_of") do
dispatch :handler do
param "Array", :items
param "Integer", :size
param 'Array', :items
param 'Integer', :size
block_param
end

Expand All @@ -29,7 +29,7 @@ def handler(items, chunk_size)

result = []

count.times {|s| result << arr[s * chunk_size, chunk_size]}
count.times { |s| result << arr[s * chunk_size, chunk_size] }

result.each_with_index do |a|
yield(a)
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/functions/choria/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
Puppet::Functions.create_function(:"choria::lock", Puppet::Functions::InternalFunction) do
dispatch :lock do
scope_param
param "String", :item
param "Hash", :properties
block_param "Callable", :block
param 'String', :item
param 'Hash', :properties
block_param 'Callable', :block
end

def lock(scope, item, properties, &blk)
require_relative "../../_load_choria"
require_relative '../../_load_choria'

MCollective::Util::BoltSupport.init_choria.data_lock(scope, item, properties, &blk)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/functions/choria/on_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
# @return [Any] The data that was passed in
Puppet::Functions.create_function(:"choria::on_error", Puppet::Functions::InternalFunction) do
dispatch :handler do
param "Any", :results
param 'Any', :results
block_param
return_type "Any"
return_type 'Any'
end

def handler(results)
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/functions/choria/on_success.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
# @return [Any] The data that was passed in
Puppet::Functions.create_function(:"choria::on_success", Puppet::Functions::InternalFunction) do
dispatch :handler do
param "Choria::TaskResults", :results
param 'Choria::TaskResults', :results
block_param
return_type "Choria::TaskResults"
return_type 'Choria::TaskResults'
end

def handler(results)
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/functions/choria/run_playbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
Puppet::Functions.create_function(:"choria::run_playbook", Puppet::Functions::InternalFunction) do
dispatch :run_playbook do
scope_param
param "String", :playbook
optional_param "Hash", :named_args
param 'String', :playbook
optional_param 'Hash', :named_args
end

def run_playbook(scope, playbook, named_args = {})
unless Puppet[:tasks]
raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: "run_playbook"
Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: 'run_playbook'
)
end

args = named_args.reject {|a| a.start_with?("_") }
args = named_args.reject { |a| a.start_with?('_') }
result = []

begin
Expand All @@ -49,9 +49,9 @@ def run_playbook(scope, playbook, named_args = {})
return results
end
rescue Puppet::Error
raise unless named_args["_catch_errors"]
raise unless named_args['_catch_errors']

return MCollective::Util::BoltSupport::TaskResults.new([], $!)
return MCollective::Util::BoltSupport::TaskResults.new([], $ERROR_INFO)
end

raise(ArgumentError, "Function choria::run_playbook(): Unknown playbook: '%s'" % playbook)
Expand Down
14 changes: 7 additions & 7 deletions lib/puppet/functions/choria/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@
Puppet::Functions.create_function(:"choria::task", Puppet::Functions::InternalFunction) do
dispatch :run_task do
scope_param
param "String", :type
param "Hash", :properties
return_type "Choria::TaskResults"
param 'String', :type
param 'Hash', :properties
return_type 'Choria::TaskResults'
end

dispatch :run_mcollective_task do
scope_param
param "Hash", :properties
return_type "Choria::TaskResults"
param 'Hash', :properties
return_type 'Choria::TaskResults'
end

def run_mcollective_task(scope, properties)
run_task(scope, "mcollective", properties)
run_task(scope, 'mcollective', properties)
end

def run_task(scope, type, properties)
require_relative "../../_load_choria"
require_relative '../../_load_choria'

MCollective::Util::BoltSupport.init_choria.run_task(scope, type, properties)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/functions/choria/tasks/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# the required Puppet Server configuration were complete
Puppet::Functions.create_function(:"choria::tasks::metadata") do
dispatch :fetch do
param "String", :task
param 'String', :task
end

def init
require_relative "../../../_load_choria"
require_relative '../../../_load_choria'
end

def choria
@_choria ||= begin
init
MCollective::Util::Choria.new
init
MCollective::Util::Choria.new
end
end

Expand All @@ -24,6 +24,6 @@ def tasks_support
end

def fetch(task)
tasks_support.task_metadata(task, "production")
tasks_support.task_metadata(task, 'production')
end
end
10 changes: 5 additions & 5 deletions lib/puppet/functions/choria/tasks/validate_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
# @returns [Boolean]
Puppet::Functions.create_function(:"choria::tasks::validate_input") do
dispatch :validate do
param "Hash", :input
param "Hash", :metadata
param 'Hash', :input
param 'Hash', :metadata
end

def init
require_relative "../../../_load_choria"
require_relative '../../../_load_choria'
end

def choria
@_choria ||= begin
init
MCollective::Util::Choria.new
init
MCollective::Util::Choria.new
end
end

Expand Down
40 changes: 20 additions & 20 deletions spec/classes/broker/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
require "spec_helper"
require 'spec_helper'

describe("choria::broker::service") do
describe('choria::broker::service') do
before(:each) do
Puppet::Parser::Functions.newfunction(:assert_private, :type => :rvalue) {|_| }
Puppet::Parser::Functions.newfunction(:assert_private, type: :rvalue) { |_| }
end

let(:facts) do
{
"aio_agent_version" => "1.7.0",
"operatingsystem" => "CentOS",
"osfamily" => "RedHat",
"operatingsystemmajrelease" => "7",
"os" => {
"family" => "RedHat"
}
'aio_agent_version' => '1.7.0',
'operatingsystem' => 'CentOS',
'osfamily' => 'RedHat',
'operatingsystemmajrelease' => '7',
'os' => {
'family' => 'RedHat',
},
}
end

context("when present") do
context('when present') do
let(:pre_condition) { 'class {"choria": }' }

it { should compile.with_all_deps }
it { is_expected.to compile.with_all_deps }

it "should use the correct ensure value" do
is_expected.to contain_service("choria-broker").with_ensure("running")
is_expected.to contain_service("choria-broker").with_enable(true)
it 'uses the correct ensure value' do
is_expected.to contain_service('choria-broker').with_ensure('running')
is_expected.to contain_service('choria-broker').with_enable(true)
end
end

context("when absent") do
context('when absent') do
let(:pre_condition) { 'class {"choria": ensure => "absent"}' }

it { should compile.with_all_deps }
it { is_expected.to compile.with_all_deps }

it "should use the correct ensure value" do
is_expected.to contain_service("choria-broker").with_ensure("stopped")
is_expected.to contain_service("choria-broker").with_enable(false)
it 'uses the correct ensure value' do
is_expected.to contain_service('choria-broker').with_ensure('stopped')
is_expected.to contain_service('choria-broker').with_enable(false)
end
end
end
Loading

0 comments on commit 46c8765

Please sign in to comment.