From 7af0eaa927405aa1dc15f0a60451dd86ab9f8f74 Mon Sep 17 00:00:00 2001 From: "Montague, Brent" Date: Thu, 14 Apr 2016 18:59:26 -0400 Subject: [PATCH 1/2] Fix uniq for nil:NilClass error introduced in 3.2.2 - Add default values for listen_ports and listen_addresses - Add test case in test cookbook --- libraries/listen.rb | 4 ++-- test/fixtures/cookbooks/apache2_test/attributes/default.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/listen.rb b/libraries/listen.rb index 97d1b8e19..716fe02ca 100644 --- a/libraries/listen.rb +++ b/libraries/listen.rb @@ -34,8 +34,8 @@ def self.converted_listen_ports_and_addresses(node) return [] unless node['apache']['listen_ports'] || node['apache']['listen_addresses'] Chef::Log.warn "node['apache']['listen_ports'] and node['apache']['listen_addresses'] are deprecated in favor of node['apache']['listen']. Please adjust your cookbooks" - node['apache']['listen_addresses'].uniq.each_with_object([]) do |address, listen| - node['apache']['listen_ports'].uniq.each do |port| + (node['apache']['listen_addresses'] || []).uniq.each_with_object([]) do |address, listen| + (node['apache']['listen_ports'] || []).uniq.each do |port| listen << "#{address}:#{port}" end end diff --git a/test/fixtures/cookbooks/apache2_test/attributes/default.rb b/test/fixtures/cookbooks/apache2_test/attributes/default.rb index 48f8ef04d..5d2e98ff2 100644 --- a/test/fixtures/cookbooks/apache2_test/attributes/default.rb +++ b/test/fixtures/cookbooks/apache2_test/attributes/default.rb @@ -17,6 +17,7 @@ # limitations under the License. # +default['apache']['listen_ports'] = ['80'] default['apache_test']['auth_username'] = 'bork' default['apache_test']['auth_password'] = 'secret' default['apache_test']['cache_expiry_seconds'] = 60 From 70a26c2c017421491d98c3602a794faa95f0bc26 Mon Sep 17 00:00:00 2001 From: "Montague, Brent" Date: Tue, 19 Apr 2016 17:57:14 -0400 Subject: [PATCH 2/2] Add sane defaults for nil address or port attributes - Sets the address to * if not specified in attributes - Sets the ports to 80 & 443 if not specifid in attributes --- libraries/listen.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/listen.rb b/libraries/listen.rb index 716fe02ca..ebd51e228 100644 --- a/libraries/listen.rb +++ b/libraries/listen.rb @@ -34,8 +34,9 @@ def self.converted_listen_ports_and_addresses(node) return [] unless node['apache']['listen_ports'] || node['apache']['listen_addresses'] Chef::Log.warn "node['apache']['listen_ports'] and node['apache']['listen_addresses'] are deprecated in favor of node['apache']['listen']. Please adjust your cookbooks" - (node['apache']['listen_addresses'] || []).uniq.each_with_object([]) do |address, listen| - (node['apache']['listen_ports'] || []).uniq.each do |port| + # Defaults to * for addresses or 80 / 443 for ports if not specified + (node['apache']['listen_addresses'] || %w(*)).uniq.each_with_object([]) do |address, listen| + (node['apache']['listen_ports'] || %w(80 443)).uniq.each do |port| listen << "#{address}:#{port}" end end