summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2016-04-22 21:54:51 +0300
committerSteve Kemp <steve@steve.org.uk>2016-04-22 21:54:51 +0300
commita5ad0029b634a19d4d50e9f49c51903c2fa82208 (patch)
tree869a46ea45f511952f38dee10f9db76aab8e8a68
parent85a9a63eb5d8690fd7945bba901b10ef8c3326c9 (diff)
More rubocop fixups.
These are again mostly based around whitespace-changes.
-rw-r--r--.rubocop.yml3
-rw-r--r--lib/custodian/alertfactory.rb4
-rw-r--r--lib/custodian/parser.rb44
-rw-r--r--lib/custodian/queue.rb10
-rw-r--r--lib/custodian/settings.rb12
-rw-r--r--lib/custodian/testfactory.rb6
-rw-r--r--lib/custodian/worker.rb16
7 files changed, 49 insertions, 46 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 46850c9..6fb8719 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -230,6 +230,9 @@ Style/HashSyntax:
Style/IfUnlessModifier:
Enabled: false
+Style/IfInsideElse:
+ Enabled: false
+
# Offense count: 1
# Cop supports --auto-correct.
Style/IndentArray:
diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb
index 42680a1..b00bd9c 100644
--- a/lib/custodian/alertfactory.rb
+++ b/lib/custodian/alertfactory.rb
@@ -46,8 +46,8 @@ module Custodian
#
def self.create(alert_type, obj)
- raise ArgumentError, 'The type of notifier to create cannot be nil' if alert_type.nil?
- raise ArgumentError, 'The type of notifier to create must be a string' unless alert_type.kind_of? String
+ raise ArgumentError, 'The type of notifier to create cannot be nil' if alert_type.nil?
+ raise ArgumentError, 'The type of notifier to create must be a string' unless alert_type.kind_of? String
c = @@subclasses[alert_type]
if c
diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb
index 2d08519..ae771db 100644
--- a/lib/custodian/parser.rb
+++ b/lib/custodian/parser.rb
@@ -123,13 +123,13 @@ module Custodian
#
# Get the name of the macro.
#
- name = $1.dup if line =~ /^([0-9A-Z_]+)\s+/
+ name = $1.dup if line =~ /^([0-9A-Z_]+)\s+/
#
# Get the value
#
- if line =~ /fetched\s+from\s+(.*)[\r\n\.]*$/
+ if line =~ /fetched\s+from\s+(.*)[\r\n\.]*$/
#
# HTTP-fetch
@@ -138,10 +138,10 @@ module Custodian
text = get_url_contents(uri)
text.split(/[\r\n]/).each do |line|
- val.push(line) if line.length > 0
+ val.push(line) if line.length > 0
end
- elsif line =~ /\s(is|are)\s+(.*)\.*$/
+ elsif line =~ /\s(is|are)\s+(.*)\.*$/
#
# Literal list of hosts
@@ -151,7 +151,7 @@ module Custodian
#
# If there is " and " then tokenize
#
- if hosts =~ /\s+and\s+/
+ if hosts =~ /\s+and\s+/
tmp = hosts.split(/\s+and\s+/)
tmp.each do |entry|
val.push(entry)
@@ -164,7 +164,7 @@ module Custodian
end
end
- if is_macro?(name)
+ if is_macro?(name)
raise ArgumentError, "The macro #{name} is already defined"
end
@@ -213,13 +213,13 @@ module Custodian
r = []
- if input =~ /^(\S+)\s+(.*)$/
+ if input =~ /^(\S+)\s+(.*)$/
macro = $1.dup
rest = $2.dup
end
- if is_macro?(macro)
+ if is_macro?(macro)
get_macro_targets(macro).each do |host|
r.push("#{host} #{rest}")
end
@@ -238,19 +238,19 @@ module Custodian
raise ArgumentError, "Line is not a string: #{line}" unless line.kind_of? String
- line.chomp! if !line.nil?
+ line.chomp! if !line.nil?
- line.strip! if !line.nil?
+ line.strip! if !line.nil?
#
# A blank line, or a comment may be skipped.
#
- return nil if (line.nil?) || (line =~ /^#/) || (line.length < 1)
+ return nil if (line.nil?) || (line =~ /^#/) || (line.length < 1)
#
# Look for a time period.
#
- if line =~ /between\s+([0-9]+)-([0-9]+)/i
+ if line =~ /between\s+([0-9]+)-([0-9]+)/i
#
# The starting/ending hours.
@@ -271,23 +271,23 @@ module Custodian
#
# Should we exclude the test?
#
- if line =~ /except\s+between/i
- return nil if inside
+ if line =~ /except\s+between/i
+ return nil if inside
else
- return nil if !inside
+ return nil if !inside
end
end
#
# Look for macro definitions, inline
#
- if line =~ /^([0-9A-Z]_+)\s+are\s+fetched\s+from\s+([^\s]+)\.?/
+ if line =~ /^([0-9A-Z]_+)\s+are\s+fetched\s+from\s+([^\s]+)\.?/
define_macro(line)
- elsif line =~ /^([0-9A-Z_]+)\s+(is|are)\s+/
+ elsif line =~ /^([0-9A-Z_]+)\s+(is|are)\s+/
define_macro(line)
- elsif line =~ /^(\S+)\s+must\s+ping(.*)/
+ elsif line =~ /^(\S+)\s+must\s+ping(.*)/
#
# Ping is a special case because the configuration file entry
# would read:
@@ -309,7 +309,7 @@ module Custodian
new_line = "#{pre} must run ping #{post}"
return(parse_line(new_line))
- elsif line =~ /^\S+\s+must(\s+not)?\s+run\s+([^\s]+)(\s+|\.|$)/i
+ elsif line =~ /^\S+\s+must(\s+not)?\s+run\s+([^\s]+)(\s+|\.|$)/i
#
# Expand the macro if we should
@@ -367,8 +367,8 @@ module Custodian
#
# If we're given a string then split it on newline
#
- if text.kind_of?(String)
- a = text.split(/[\r\n]/)
+ if text.kind_of?(String)
+ a = text.split(/[\r\n]/)
text = a
end
@@ -410,7 +410,7 @@ module Custodian
#
def parse_file(filename)
- raise ArgumentError, 'Missing configuration file!' if filename.nil?
+ raise ArgumentError, 'Missing configuration file!' if filename.nil?
raise ArgumentError, "File not found: #{@file}" unless File.exist?(filename)
#
diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb
index 7caad1a..9c33825 100644
--- a/lib/custodian/queue.rb
+++ b/lib/custodian/queue.rb
@@ -88,7 +88,7 @@ module Custodian
job = job[0]
# Remove from the queue
- @redis.zrem('zset', job );
+ @redis.zrem('zset', job)
return job
else
@@ -110,7 +110,7 @@ module Custodian
# Count the number of times we attempt to add the test
#
attempts = 0
- added = false
+ added = false
#
@@ -119,12 +119,12 @@ module Custodian
# (a) the score is missing
# (b) the zadd function succeeds
#
- while( attempts < 40 ) do
+ while (attempts < 40) do
#
# Only update if no score is set
#
- if !@redis.zscore("zset", test)
+ if !@redis.zscore('zset', test)
#
# If MULTI returns nil, the transaction failed, so we need to try
@@ -144,7 +144,7 @@ module Custodian
#
# Bump the count of attempts.
#
- attempts = attempts + 1
+ attempts += 1
end
#
diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb
index 181ced0..60e5a2e 100644
--- a/lib/custodian/settings.rb
+++ b/lib/custodian/settings.rb
@@ -55,8 +55,8 @@ module Custodian
# Load and "parse" the key=value content.
#
File.open(file, 'r').each_line do |line|
- next if line.nil? || line =~ /^#/
- if line =~ /^(.*)=(.*)$/
+ next if line.nil? || line =~ /^#/
+ if line =~ /^(.*)=(.*)$/
key = $1.dup
val = $2.dup
key.strip!
@@ -101,7 +101,7 @@ module Custodian
def timeout
_load unless _loaded?
- if @settings['timeout']
+ if @settings['timeout']
@settings['timeout'].to_i
else
30
@@ -117,7 +117,7 @@ module Custodian
def retries
_load unless _loaded?
- if @settings['retries']
+ if @settings['retries']
@settings['retries'].to_i
else
5
@@ -137,7 +137,7 @@ module Custodian
def retry_delay
_load unless _loaded?
- if @settings['retry_delay']
+ if @settings['retry_delay']
@settings['retry_delay'].to_i
else
0
@@ -208,7 +208,7 @@ module Custodian
# Find the alerting method.
#
# if we have something setup then use it.
- if @settings["#{alert}_target"]
+ if @settings["#{alert}_target"]
return(@settings["#{alert}_target"])
end
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb
index 770227f..db3f339 100644
--- a/lib/custodian/testfactory.rb
+++ b/lib/custodian/testfactory.rb
@@ -60,8 +60,8 @@ module Custodian
def self.create(line)
- raise ArgumentError, 'The type of test to create cannot be nil' if line.nil?
- raise ArgumentError, 'The type of test to create must be a string' unless line.kind_of? String
+ raise ArgumentError, 'The type of test to create cannot be nil' if line.nil?
+ raise ArgumentError, 'The type of test to create must be a string' unless line.kind_of? String
#
# The array of tests we return.
@@ -127,7 +127,7 @@ module Custodian
# Register a new test type - this must be called by our derived classes
#
def self.register_test_type(name)
- @@subclasses[name] ||= []
+ @@subclasses[name] ||= []
@@subclasses[name].push(self)
end
diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb
index 3c71838..cb26fb6 100644
--- a/lib/custodian/worker.rb
+++ b/lib/custodian/worker.rb
@@ -73,7 +73,7 @@ module Custodian
@settings = settings
# Connect to the queue
- @queue = RedisQueueType.new()
+ @queue = RedisQueueType.new
# Get the alerter-type(s) to instantiate
@alerter = @settings.alerter
@@ -93,7 +93,7 @@ module Custodian
# Show a message on STDOUT if "--verbose" was specified.
#
def log_message(msg)
- puts msg if ENV['VERBOSE']
+ puts msg if ENV['VERBOSE']
end
@@ -162,7 +162,7 @@ module Custodian
#
# We exit here if we receive a single success.
#
- while (count < (@retry_count + 1)) && (run == true)
+ while (count < (@retry_count + 1)) && (run == true)
log_message("Running test - [#{count}/#{@retry_count}]")
@@ -216,12 +216,12 @@ module Custodian
# but no more than "@retry_count" times.
#
#
- if (run == true) && (@retry_delay > 0) && (count < @retry_count)
+ if (run == true) && (@retry_delay > 0) && (count < @retry_count)
#
# If the test disabled itself then we don't need to delay
#
- unless( result == Custodian::TestResult::TEST_SKIPPED)
+ unless (result == Custodian::TestResult::TEST_SKIPPED)
log_message("Delaying re-test by #{@retry_delay} seconds due to failure - : #{test.error}")
sleep(@retry_delay)
end
@@ -248,8 +248,8 @@ module Custodian
# Record that, if we have any alerters that are interested
# in run-times.
#
- if (result == Custodian::TestResult::TEST_FAILED) ||
- (result == Custodian::TestResult::TEST_PASSED)
+ if (result == Custodian::TestResult::TEST_FAILED) ||
+ (result == Custodian::TestResult::TEST_PASSED)
do_duration(test, duration)
end
@@ -338,7 +338,7 @@ module Custodian
# give the alerter a reference to the settings object.
alert.set_settings(@settings)
- alert.duration(duration) if alert.respond_to? 'duration'
+ alert.duration(duration) if alert.respond_to? 'duration'
end
end