From 10f7710e8dccfbbc611d841e4c0c2ed3c8496d53 Mon Sep 17 00:00:00 2001 From: John Daniels Date: Fri, 12 Jun 2015 09:25:26 -0400 Subject: [PATCH 1/2] Moved conf.d/proxy.conf into nginx.conf. --- manifests/config.pp | 3 +-- templates/conf.d/nginx.conf.erb | 39 +++++++++++++++++++++++++++++++++ templates/conf.d/proxy.conf.erb | 15 ------------- 3 files changed, 40 insertions(+), 17 deletions(-) delete mode 100644 templates/conf.d/proxy.conf.erb diff --git a/manifests/config.pp b/manifests/config.pp index 3f99dd5..cc6954e 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -258,8 +258,7 @@ class nginx::config( } file { "${conf_dir}/conf.d/proxy.conf": - ensure => file, - content => template($proxy_conf_template), + ensure => absent, } file { "${conf_dir}/conf.d/default.conf": diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 4838a90..79fa313 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -64,6 +64,45 @@ http { gzip_disable "MSIE [1-6]\.(?!.*SV1)"; <% end -%> +<% if @client_body_temp_path -%> + client_body_temp_path <%= @client_body_temp_path %>; +<% end -%> +<% if @client_max_body_size -%> + client_max_body_size <%= @client_max_body_size %>; +<% end -%> +<% if @client_body_buffer_size -%> + client_body_buffer_size <%= @client_body_buffer_size %>; +<% end -%> +<% if @proxy_redirect -%> + proxy_redirect <%= @proxy_redirect %>; +<% end -%> +<% if @proxy_temp_path -%> + proxy_temp_path <%= @proxy_temp_path %>; +<% end -%> +<% if @proxy_connect_timeout -%> + proxy_connect_timeout <%= @proxy_connect_timeout %>; +<% end -%> +<% if @proxy_send_timeout -%> + proxy_send_timeout <%= @proxy_send_timeout %>; +<% end -%> +<% if @proxy_read_timeout -%> + proxy_read_timeout <%= @proxy_read_timeout %>; +<% end -%> +<% if @proxy_buffers -%> + proxy_buffers <%= @proxy_buffers %>; +<% end -%> +<% if @proxy_buffer_size -%> + proxy_buffer_size <%= @proxy_buffer_size %>; +<% end -%> +<% if @proxy_http_version -%> + proxy_http_version <%= @proxy_http_version %>; +<% end -%> +<% @proxy_set_header.each do |header| -%> + proxy_set_header <%= header %>; +<% end -%> +<% if @proxy_headers_hash_bucket_size -%> + proxy_headers_hash_bucket_size <%= @proxy_headers_hash_bucket_size %>; +<% end -%> <% if @proxy_cache_path -%> proxy_cache_path <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys_zone=<%= @proxy_cache_keys_zone %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; diff --git a/templates/conf.d/proxy.conf.erb b/templates/conf.d/proxy.conf.erb deleted file mode 100644 index d080132..0000000 --- a/templates/conf.d/proxy.conf.erb +++ /dev/null @@ -1,15 +0,0 @@ -proxy_temp_path <%= @proxy_temp_path %>; -client_body_temp_path <%= @client_body_temp_path %>; -proxy_redirect <%= @proxy_redirect %>; -client_max_body_size <%= @client_max_body_size %>; -client_body_buffer_size <%= @client_body_buffer_size %>; -proxy_connect_timeout <%= @proxy_connect_timeout %>; -proxy_send_timeout <%= @proxy_send_timeout %>; -proxy_read_timeout <%= @proxy_read_timeout %>; -proxy_buffers <%= @proxy_buffers %>; -proxy_buffer_size <%= @proxy_buffer_size %>; -<% if @proxy_http_version -%> -proxy_http_version <%= @proxy_http_version %>;<% end %> -<% @proxy_set_header.each do |header| %> -proxy_set_header <%= header %>;<% end %> -proxy_headers_hash_bucket_size <%= @proxy_headers_hash_bucket_size %>; From 310ed828c252de9b4f2946585d5436698eca5d79 Mon Sep 17 00:00:00 2001 From: John Daniels Date: Mon, 15 Jun 2015 08:44:16 -0400 Subject: [PATCH 2/2] Adjusted tests for proxy variables. --- spec/classes/config_spec.rb | 121 ++++++++++++++---------------------- 1 file changed, 45 insertions(+), 76 deletions(-) diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 8fcba48..fc7d0c6 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -48,12 +48,6 @@ describe 'nginx::config' do :group => 'root', :mode => '0644' )} - it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with( - :ensure => 'file', - :owner => 'root', - :group => 'root', - :mode => '0644' - )} it { is_expected.to contain_file("/tmp/nginx.d").with( :ensure => 'absent', :purge => true, @@ -379,6 +373,51 @@ describe 'nginx::config' do :value => false, :notmatch => /mail/, }, + { + :title => 'should set proxy_buffers', + :attr => 'proxy_buffers', + :value => '50 5k', + :match => ' proxy_buffers 50 5k;', + }, + { + :title => 'should set proxy_buffer_size', + :attr => 'proxy_buffer_size', + :value => '2k', + :match => ' proxy_buffer_size 2k;', + }, + { + :title => 'should set proxy_http_version', + :attr => 'proxy_http_version', + :value => '1.1', + :match => ' proxy_http_version 1.1;', + }, + { + :title => 'should not set proxy_http_version', + :attr => 'proxy_http_version', + :value => nil, + :notmatch => 'proxy_http_version', + }, + { + :title => 'should contain ordered appended directives', + :attr => 'proxy_set_header', + :value => ['header1','header2'], + :match => [ + ' proxy_set_header header1;', + ' proxy_set_header header2;', + ], + }, + { + :title => 'should set client_body_temp_path', + :attr => 'client_body_temp_path', + :value => '/path/to/body_temp', + :match => ' client_body_temp_path /path/to/body_temp;', + }, + { + :title => 'should set proxy_temp_path', + :attr => 'proxy_temp_path', + :value => '/path/to/proxy_temp', + :match => ' proxy_temp_path /path/to/proxy_temp;', + }, ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do let :params do { param[:attr].to_sym => param[:value] } end @@ -402,76 +441,6 @@ describe 'nginx::config' do end end - describe "proxy.conf template content" do - [ - { - :title => 'should set proxy_buffers', - :attr => 'proxy_buffers', - :value => '50 5k', - :match => 'proxy_buffers 50 5k;', - }, - { - :title => 'should set proxy_buffer_size', - :attr => 'proxy_buffer_size', - :value => '2k', - :match => 'proxy_buffer_size 2k;', - }, - { - :title => 'should set proxy_http_version', - :attr => 'proxy_http_version', - :value => '1.1', - :match => 'proxy_http_version 1.1;', - }, - { - :title => 'should not set proxy_http_version', - :attr => 'proxy_http_version', - :value => nil, - :notmatch => 'proxy_http_version', - }, - { - :title => 'should contain ordered appended directives', - :attr => 'proxy_set_header', - :value => ['header1','header2'], - :match => [ - 'proxy_set_header header1;', - 'proxy_set_header header2;', - ], - }, - { - :title => 'should set client_body_temp_path', - :attr => 'client_body_temp_path', - :value => '/path/to/body_temp', - :match => 'client_body_temp_path /path/to/body_temp;', - }, - { - :title => 'should set proxy_temp_path', - :attr => 'proxy_temp_path', - :value => '/path/to/proxy_temp', - :match => 'proxy_temp_path /path/to/proxy_temp;', - }, - ].each do |param| - context "when #{param[:attr]} is #{param[:value]}" do - let :params do { param[:attr].to_sym => param[:value] } end - - it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') } - it param[:title] do - matches = Array(param[:match]) - - if matches.all? { |m| m.is_a? Regexp } - matches.each { |item| is_expected.to contain_file('/etc/nginx/conf.d/proxy.conf').with_content(item) } - else - lines = catalogue.resource('file', '/etc/nginx/conf.d/proxy.conf').send(:parameters)[:content].split("\n") - expect(lines & Array(param[:match])).to eq(Array(param[:match])) - end - - Array(param[:notmatch]).each do |item| - is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item) - end - end - end - end - end - context "when conf_dir is /path/to/nginx" do let(:params) {{:conf_dir => '/path/to/nginx'}} it { is_expected.to contain_file('/path/to/nginx/nginx.conf').with_content(%r{include /path/to/nginx/mime\.types;}) }