From bcaab1fbe537177a5773ab70bb5d6db8d3dfaec6 Mon Sep 17 00:00:00 2001 From: Will Yardley Date: Sat, 12 Nov 2016 14:55:50 -0800 Subject: [PATCH] Put keepalive at bottom of upstream_cfg_{append,prepend} sections (#641) (#969) --- spec/defines/resource_upstream_spec.rb | 22 +++++++++++----------- templates/upstream/upstream_footer.erb | 25 +++++++++++++++++-------- templates/upstream/upstream_header.erb | 25 +++++++++++++++++-------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index 81f0e558b..af28b1d32 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -53,22 +53,22 @@ attr: 'upstream_cfg_prepend', fragment: 'header', value: { - 'test3' => 'test value 3', - 'test6' => { 'subkey1' => %w(subvalue1 subvalue2) }, - 'test1' => 'test value 1', - 'test2' => 'test value 2', - 'test5' => { 'subkey1' => 'subvalue1' }, - 'test4' => ['test value 1', 'test value 2'] + 'test3' => 'test value 3', + 'test6' => { 'subkey1' => %w(subvalue1 subvalue2) }, + 'keepalive' => 'keepalive 1', + 'test2' => 'test value 2', + 'test5' => { 'subkey1' => 'subvalue1' }, + 'test4' => ['test value 1', 'test value 2'] }, match: [ - ' test1 test value 1;', ' test2 test value 2;', ' test3 test value 3;', ' test4 test value 1;', ' test4 test value 2;', ' test5 subkey1 subvalue1;', ' test6 subkey1 subvalue1;', - ' test6 subkey1 subvalue2;' + ' test6 subkey1 subvalue2;', + ' keepalive keepalive 1;' ] }, { @@ -89,20 +89,20 @@ value: { 'test3' => 'test value 3', 'test6' => { 'subkey1' => %w(subvalue1 subvalue2) }, - 'test1' => 'test value 1', + 'keepalive' => 'keepalive 1', 'test2' => 'test value 2', 'test5' => { 'subkey1' => 'subvalue1' }, 'test4' => ['test value 1', 'test value 2'] }, match: [ - ' test1 test value 1;', ' test2 test value 2;', ' test3 test value 3;', ' test4 test value 1;', ' test4 test value 2;', ' test5 subkey1 subvalue1;', ' test6 subkey1 subvalue1;', - ' test6 subkey1 subvalue2;' + ' test6 subkey1 subvalue2;', + ' keepalive keepalive 1;' ] } ].each do |param| diff --git a/templates/upstream/upstream_footer.erb b/templates/upstream/upstream_footer.erb index c212ab044..33b0bcd30 100644 --- a/templates/upstream/upstream_footer.erb +++ b/templates/upstream/upstream_footer.erb @@ -1,12 +1,21 @@ -<% if @upstream_cfg_append -%><% @upstream_cfg_append.sort_by{|k,v| k}.each do |key,value| %> -<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%> -<% Array(subvalue).each do |asubvalue| -%> +<% if @upstream_cfg_append %> +<%# Slightly less obtuse way to sort but put keepalive at end -%> +<% + @upstream_cfg_append = Hash[@upstream_cfg_append.sort] + @upstream_cfg_append['keepalive'] = @upstream_cfg_append.delete('keepalive') +-%> + <%- @upstream_cfg_append.each do |key,value| -%> + <%- if value.is_a?(Hash) -%> + <%- value.each do |subkey,subvalue| -%> + <%- Array(subvalue).each do |asubvalue| -%> <%= key %> <%= subkey %> <%= asubvalue %>; -<% end -%> -<% end -%><% else -%> -<% Array(value).each do |asubvalue| -%> + <%- end -%> + <%- end -%> + <%- else -%> + <%- Array(value).each do |asubvalue| -%> <%= key %> <%= asubvalue %>; + <%- end -%> + <%- end -%> + <%- end -%> <% end -%> -<% end -%> -<% end -%><% end -%> } diff --git a/templates/upstream/upstream_header.erb b/templates/upstream/upstream_header.erb index 4d945972d..7aed428d2 100644 --- a/templates/upstream/upstream_header.erb +++ b/templates/upstream/upstream_header.erb @@ -1,13 +1,22 @@ # MANAGED BY PUPPET upstream <%= @name %> { -<% if @upstream_cfg_prepend -%><% @upstream_cfg_prepend.sort_by{|k,v| k}.each do |key,value| %> -<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%> -<% Array(subvalue).each do |asubvalue| -%> +<% if @upstream_cfg_prepend -%> +<%# Slightly less obtuse way to sort but put keepalive at end -%> +<% + @upstream_cfg_prepend = Hash[@upstream_cfg_prepend.sort] + @upstream_cfg_prepend['keepalive'] = @upstream_cfg_prepend.delete('keepalive') +-%> + <%- @upstream_cfg_prepend.each do |key,value| -%> + <%- if value.is_a?(Hash) -%> + <%- value.each do |subkey,subvalue| -%> + <%- Array(subvalue).each do |asubvalue| -%> <%= key %> <%= subkey %> <%= asubvalue %>; -<% end -%> -<% end -%><% else -%> -<% Array(value).each do |asubvalue| -%> + <%- end -%> + <%- end -%> + <%- else -%> + <%- Array(value).each do |asubvalue| -%> <%= key %> <%= asubvalue %>; + <%- end -%> + <%- end -%> + <%- end -%> <% end -%> -<% end -%> -<% end -%><% end -%>