From: Sharif Nassar Date: Tue, 27 Nov 2012 22:32:46 +0000 (-0800) Subject: (#14463) Fix to pass unit tests X-Git-Tag: 0.1.0~12^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b4d2e071376f861f61136bba8b2c9add9d8d0637;p=puppet-modules%2Fpuppetlabs-firewall.git (#14463) Fix to pass unit tests * Add default protocol to fix the test for converting a string 'ssh' to a port number was failing like so: 1) Puppet::Type::Firewall dport should convert a port name for dport to its number Failure/Error: @resource[port] = 'ssh' Puppet::Error: Parameter dport failed: Munging failed for value "ssh" in class dport: no such service ssh/proto # ./lib/puppet/type/../../puppet/util/firewall.rb:84:in `getservbyname' # ./lib/puppet/type/../../puppet/util/firewall.rb:84:in `string_to_port' # ./lib/puppet/type/firewall.rb:164:in `unsafe_munge' # ./spec/unit/puppet/type/firewall_spec.rb:161 * Always convert the response .to_s --- diff --git a/lib/puppet/util/firewall.rb b/lib/puppet/util/firewall.rb index 7ee8cdd..cdf20aa 100644 --- a/lib/puppet/util/firewall.rb +++ b/lib/puppet/util/firewall.rb @@ -65,14 +65,18 @@ module Puppet::Util::Firewall end end - # This method takes a string and attempts to convert it to a port number - # if valid. + # This method takes a string and a protocol and attempts to convert + # it to a port number if valid. # # If the string already contains a port number or perhaps a range of ports # in the format 22:1000 for example, it simply returns the string and does # nothing. def string_to_port(value, proto) proto = proto.to_s + unless proto =~ /^(tcp|udp)$/ + proto = 'tcp' + end + if value.kind_of?(String) if value.match(/^\d+(-\d+)?$/) return value @@ -80,7 +84,7 @@ module Puppet::Util::Firewall return Socket.getservbyname(value, proto).to_s end else - Socket.getservbyname(value.to_s, proto) + Socket.getservbyname(value.to_s, proto).to_s end end