Alexandros Kosiaris has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/403699 )
Change subject: network: reword slice_network_constants' errors
......................................................................
network: reword slice_network_constants' errors
Too long/verbose and also raising ArgumentError instead of ParseError.
Change-Id: I18b17e58db42507ac859cee5d5b17a5a4e749d2b
---
M modules/network/lib/puppet/parser/functions/slice_network_constants.rb
M modules/network/spec/functions/slice_network_constants_spec.rb
2 files changed, 17 insertions(+), 10 deletions(-)
Approvals:
Alexandros Kosiaris: Verified; Looks good to me, approved
diff --git
a/modules/network/lib/puppet/parser/functions/slice_network_constants.rb
b/modules/network/lib/puppet/parser/functions/slice_network_constants.rb
index 322dd07..28e2493 100644
--- a/modules/network/lib/puppet/parser/functions/slice_network_constants.rb
+++ b/modules/network/lib/puppet/parser/functions/slice_network_constants.rb
@@ -37,8 +37,11 @@
#
module Puppet::Parser::Functions
newfunction(:slice_network_constants, :type => :rvalue, :arity => -2) do
|args|
- fail ArgumentError, 'slice_network_constants() requires an argument' if
args.empty?
- fail ArgumentError, 'slice_network_constants() cannot handle more than 2
values' if args.length > 2
+ if args.empty? || args.length > 2
+ raise(ArgumentError, "slice_network_constants(): " +
+ "Wrong number of arguments given (#{args.length})")
+ end
+
all_network_subnets = lookupvar('all_network_subnets')
realm = args[0]
options = args[1] if args.length > 1
@@ -48,16 +51,20 @@
description = options['description'] if options
unless all_network_subnets.key?(realm)
- fail ArgumentError, 'slice_network_constants() realm non existant in
network::subnets'
+ raise(Puppet::ParseError, "slice_network_constants(): " +
+ "realm non-existent in network::subnets")
end
if requested_site && (!all_network_subnets[realm].key? requested_site)
- fail ArgumentError, "slice_network_constants() site specified must be
present in network::subnets[#{realm}]. #{requested_site} was provided"
+ raise(Puppet::ParseError, "slice_network_constants(): " +
+ "site #{requested_site} not in network::subnets[#{realm}]")
end
if requested_sphere && (!['public', 'private'].include? requested_sphere)
- fail ArgumentError, "slice_network_constants() sphere can only be
public/private. #{requested_sphere} was provided"
+ raise(Puppet::ParseError, "slice_network_constants(): " +
+ "sphere #{requested_sphere} is not valid")
end
if af && (!['ipv4', 'ipv6'].include? af)
- fail ArgumentError, "slice_network_constants() address family
specified can only be ipv4 or ipv6. #{af} was provided"
+ raise(Puppet::ParseError, "slice_network_constants(): " +
+ "address family #{af} is not valid")
end
# And let's get our data back
diff --git a/modules/network/spec/functions/slice_network_constants_spec.rb
b/modules/network/spec/functions/slice_network_constants_spec.rb
index 9cafb24..b9f2f79 100644
--- a/modules/network/spec/functions/slice_network_constants_spec.rb
+++ b/modules/network/spec/functions/slice_network_constants_spec.rb
@@ -20,7 +20,7 @@
# Test realm
it "should complain about invalid realm" do
scope.stubs(:lookupvar).with('all_network_subnets').returns(all_network_subnets)
- expect { scope.function_slice_network_constants(['nosuchrealm']) }.to
raise_error(ArgumentError)
+ expect { scope.function_slice_network_constants(['nosuchrealm']) }.to
raise_error(Puppet::ParseError)
end
it "should return for valid realm" do
@@ -32,7 +32,7 @@
# Test site
it "should complain about invalid site" do
scope.stubs(:lookupvar).with('all_network_subnets').returns(all_network_subnets)
- expect { scope.function_slice_network_constants(['production', { 'site' =>
'nosuchsite'}])}.to raise_error(ArgumentError)
+ expect { scope.function_slice_network_constants(['production', { 'site' =>
'nosuchsite'}])}.to raise_error(Puppet::ParseError)
end
it "should return for valid site" do
@@ -45,7 +45,7 @@
# Test sphere
it "should complain about invalid sphere" do
scope.stubs(:lookupvar).with('all_network_subnets').returns(all_network_subnets)
- expect{ scope.function_slice_network_constants(['production', { 'sphere'
=> 'nosuchsphere'}])}.to raise_error(ArgumentError)
+ expect{ scope.function_slice_network_constants(['production', { 'sphere'
=> 'nosuchsphere'}])}.to raise_error(Puppet::ParseError)
end
it "should return for valid sphere" do
@@ -58,7 +58,7 @@
# Test AF
it "should complain about invalid af" do
scope.stubs(:lookupvar).with('all_network_subnets').returns(all_network_subnets)
- expect{ scope.function_slice_network_constants(['production', { 'af' =>
'nosuchaf'}])}.to raise_error(ArgumentError)
+ expect{ scope.function_slice_network_constants(['production', { 'af' =>
'nosuchaf'}])}.to raise_error(Puppet::ParseError)
end
it "should return for valid af" do
--
To view, visit https://gerrit.wikimedia.org/r/403699
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I18b17e58db42507ac859cee5d5b17a5a4e749d2b
Gerrit-PatchSet: 5
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Alexandros Kosiaris <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits