Skip to content

Commit 16cee5c

Browse files
committed
rubocop fixes, split a really long line
1 parent 368d513 commit 16cee5c

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

lib/puppet/provider/network_config/interfaces.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(msg = nil)
3636

3737
def self.raise_malformed
3838
@failed = true
39-
fail MalformedInterfacesError
39+
raise MalformedInterfacesError
4040
end
4141

4242
class Instance
@@ -193,7 +193,7 @@ def self.parse_file(_filename, contents)
193193
when /^mapping/
194194
# XXX dox
195195
status = :mapping
196-
fail Puppet::DevError, 'Debian interfaces mapping parsing not implemented.'
196+
raise Puppet::DevError, 'Debian interfaces mapping parsing not implemented.'
197197

198198
else
199199
# We're currently examining a line that is within a mapping or iface
@@ -221,7 +221,7 @@ def self.parse_file(_filename, contents)
221221
end
222222
end
223223
when :mapping
224-
fail Puppet::DevError, 'Debian interfaces mapping parsing not implemented.'
224+
raise Puppet::DevError, 'Debian interfaces mapping parsing not implemented.'
225225
when :none
226226
raise_malformed
227227
end
@@ -254,8 +254,8 @@ def self.format_file(_filename, providers)
254254
# Build iface stanzas
255255
providers.sort_by(&:name).each do |provider|
256256
# TODO: add validation method
257-
fail Puppet::Error, "#{provider.name} does not have a method." if provider.method.nil?
258-
fail Puppet::Error, "#{provider.name} does not have a family." if provider.family.nil?
257+
raise Puppet::Error, "#{provider.name} does not have a method." if provider.method.nil?
258+
raise Puppet::Error, "#{provider.name} does not have a family." if provider.family.nil?
259259

260260
stanza = []
261261
stanza << %(iface #{provider.name} #{provider.family} #{provider.method})
@@ -287,7 +287,7 @@ def self.format_file(_filename, providers)
287287
elsif val.is_a? Array
288288
val.each { |entry| stanza << " #{key} #{entry}" }
289289
else
290-
fail Puppet::Error, "#{self} options key #{key} expects a String or Array, got #{val.class}"
290+
raise Puppet::Error, "#{self} options key #{key} expects a String or Array, got #{val.class}"
291291
end
292292
end
293293
end

lib/puppet/provider/network_config/redhat.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def self.parse_file(filename, contents)
9595

9696
# Convert the data into key/value pairs
9797
pairs = lines.each_with_object({}) do |line, hash|
98-
fail Puppet::Error, %(#{filename} is malformed; "#{line}" did not match "#{pair_regex}") unless line.match(pair_regex) do |m|
98+
raise Puppet::Error, %(#{filename} is malformed; "#{line}" did not match "#{pair_regex}") unless line.match(pair_regex) do |m|
9999
key = m[1].strip
100100
val = m[2].strip
101101
hash[key] = val
@@ -171,11 +171,10 @@ def self.munge(pairs)
171171
end
172172

173173
def self.format_file(filename, providers)
174-
if providers.length == 0
175-
return ''
176-
elsif providers.length > 1
177-
fail Puppet::DevError, "Unable to support multiple interfaces [#{providers.map(&:name).join(',')}] in a single file #{filename}"
178-
end
174+
return '' if providers.empty?
175+
raise Puppet::DevError,
176+
"Unable to support multiple interfaces [#{providers.map(&:name).join(',')}] in a single file #{filename}"\
177+
if providers.length > 1
179178

180179
provider = providers[0]
181180
props = {}

lib/puppet/provider/network_route/redhat.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,21 @@ def self.parse_file(_filename, contents)
4141

4242
route = line.split(' ', 6)
4343
if route.length < 4
44-
fail Puppet::Error, 'Malformed redhat route file, cannot instantiate network_route resources'
44+
raise Puppet::Error, 'Malformed redhat route file, cannot instantiate network_route resources'
4545
end
4646

4747
new_route = {}
4848

49+
new_route[:gateway] = route[2]
50+
new_route[:interface] = route[4]
51+
new_route[:options] = route[5] if route[5]
52+
4953
if route[0] == 'default'
5054
cidr_target = 'default'
5155

5256
new_route[:name] = cidr_target
5357
new_route[:network] = 'default'
5458
new_route[:netmask] = '0.0.0.0'
55-
new_route[:gateway] = route[2]
56-
new_route[:interface] = route[4]
57-
new_route[:options] = route[5] if route[5]
5859
else
5960
# use the CIDR version of the target as :name
6061
network, netmask = route[0].split('/')
@@ -63,9 +64,6 @@ def self.parse_file(_filename, contents)
6364
new_route[:name] = cidr_target
6465
new_route[:network] = network
6566
new_route[:netmask] = netmask
66-
new_route[:gateway] = route[2]
67-
new_route[:interface] = route[4]
68-
new_route[:options] = route[5] if route[5]
6967
end
7068

7169
routes << new_route
@@ -81,7 +79,7 @@ def self.format_file(_filename, providers)
8179
# Build routes
8280
providers.sort_by(&:name).each do |provider|
8381
[:network, :netmask, :gateway, :interface].each do |prop|
84-
fail Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil?
82+
raise Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil?
8583
end
8684
contents << if provider.network == 'default'
8785
"#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n"

lib/puppet/provider/network_route/routes.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def initialize(msg = nil)
4141

4242
def self.raise_malformed
4343
@failed = true
44-
fail MalformedRoutesError
44+
raise MalformedRoutesError
4545
end
4646

4747
def self.parse_file(_filename, contents)
@@ -86,10 +86,10 @@ def self.format_file(_filename, providers)
8686

8787
# Build routes
8888
providers.sort_by(&:name).each do |provider|
89-
fail Puppet::Error, "#{provider.name} is missing the required parameter 'network'." if provider.network.nil?
90-
fail Puppet::Error, "#{provider.name} is missing the required parameter 'netmask'." if provider.netmask.nil?
91-
fail Puppet::Error, "#{provider.name} is missing the required parameter 'gateway'." if provider.gateway.nil?
92-
fail Puppet::Error, "#{provider.name} is missing the required parameter 'interface'." if provider.interface.nil?
89+
raise Puppet::Error, "#{provider.name} is missing the required parameter 'network'." if provider.network.nil?
90+
raise Puppet::Error, "#{provider.name} is missing the required parameter 'netmask'." if provider.netmask.nil?
91+
raise Puppet::Error, "#{provider.name} is missing the required parameter 'gateway'." if provider.gateway.nil?
92+
raise Puppet::Error, "#{provider.name} is missing the required parameter 'interface'." if provider.interface.nil?
9393

9494
contents << "#{provider.network} #{provider.netmask} #{provider.gateway} #{provider.interface} #{provider.options}\n"
9595
end

lib/puppet/type/network_config.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
newproperty(:ipaddress) do
2828
desc 'The IP address of the network interfaces'
2929
validate do |value|
30-
fail ArgumentError, "#{self.class} requires a valid ipaddress for the ipaddress property" unless IPAddress.valid? value
30+
raise ArgumentError, "#{self.class} requires a valid ipaddress for the ipaddress property" unless IPAddress.valid? value
3131
# provider.validate
3232
end
3333
end
3434

3535
newproperty(:netmask) do
3636
desc 'The subnet mask to apply to the interface'
3737
validate do |value|
38-
fail ArgumentError, "#{self.class} requires a valid netmask for the netmask property" unless IPAddress.valid_ipv4_netmask? value
38+
raise ArgumentError, "#{self.class} requires a valid netmask for the netmask property" unless IPAddress.valid_ipv4_netmask? value
3939
# provider.validate
4040
end
4141
end
@@ -79,7 +79,7 @@
7979
# reject floating point and negative integers
8080
# XXX this lets 1500.0 pass
8181
unless value =~ /^\d+$/
82-
fail ArgumentError, "#{value} is not a valid mtu (must be a positive integer)"
82+
raise ArgumentError, "#{value} is not a valid mtu (must be a positive integer)"
8383
end
8484

8585
# Intel 82598 & 82599 chips support MTUs up to 16110; is there any
@@ -92,7 +92,7 @@
9292
min_mtu = 42
9393
max_mtu = 65_536
9494
unless (min_mtu..max_mtu).cover?(value.to_i)
95-
fail ArgumentError, "#{value} is not in the valid mtu range (#{min_mtu} .. #{max_mtu})"
95+
raise ArgumentError, "#{value} is not in the valid mtu range (#{min_mtu} .. #{max_mtu})"
9696
end
9797
end
9898
end
@@ -122,7 +122,7 @@ def should_to_s(hash = @should)
122122
defaultto {}
123123

124124
validate do |value|
125-
fail ArgumentError, "#{self.class} requires a hash for the options property" unless value.is_a? Hash
125+
raise ArgumentError, "#{self.class} requires a hash for the options property" unless value.is_a? Hash
126126
# provider.validate
127127
end
128128
end

lib/puppet/type/network_route.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
validate do |value|
3232
unless value.length <= 2 || value =~ IPV4_ADDRESS_REGEX
33-
fail("Invalid value for argument netmask: #{value}")
33+
raise("Invalid value for argument netmask: #{value}")
3434
end
3535
end
3636

@@ -69,7 +69,7 @@
6969
desc 'Provider specific options to be passed to the provider'
7070

7171
validate do |value|
72-
fail ArgumentError, "#{self.class} requires a string for the options property" unless value.is_a?(String)
72+
raise ArgumentError, "#{self.class} requires a string for the options property" unless value.is_a?(String)
7373
end
7474
end
7575
end

0 commit comments

Comments
 (0)