Skip to content

Commit

Permalink
another round of bugfixes, added more under tests dir, updates README
Browse files Browse the repository at this point in the history
  • Loading branch information
maxchk committed Mar 24, 2014
1 parent d516254 commit 6565042
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 58 deletions.
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,18 @@ For more details on parameters, check class varnish.

### varnish backend

Definition `varnish::backend` allows to configure Varnish backend.
Definition `varnish::backend` allows to configure Varnish backend.
If you have a single backend, you can name it `default` and ignore
`selector` sections:
`selector` sections.
For more examples see `tests/vcl_backend_default.pp` and `tests/vcl_backends.pp`

varnish::backend { 'srv1': host => '172.16.0.1', port => '80', probe => 'health_check1' }
varnish::backend { 'srv2': host => '172.16.0.2', port => '80', probe => 'health_check1' }

### varnish director

Definition `varnish::director` allows to configure Varnish director.
If you have a single director, you can name it `default` and ignore
`selector` sections:
NOTE: you can't have backend `default` and director `deafult` in the same config
For more examples see `tests/vcl_backends_probes_directors.pp`

varnish::director { 'cluster1': backends => [ 'srv1', 'srv2' ] }

Expand All @@ -109,13 +108,13 @@ For more details on parameters, check class varnish.
You cannot define 2 or more backends/directors and not to use them.
This will result in VCL compilation failure.

Parameter `selectors` gives access to req.backend inside vcl_recv.
Parameter `selectors` gives access to req.backend inside `vcl_recv`.
Code:

varnish::selector { 'cluster1': condition => 'req.url ~ "^/cluster1"' }
varnish::selector { 'cluster2': condition => 'true' } # will act as backend set by else statement

Will result in following VCL configuration to be generated:
Will result in following VCL configuration to be generated:

if (req.url ~ "^/cluster1") {
set req.backend = cluster1;
Expand All @@ -124,11 +123,7 @@ Will result in following VCL configuration to be generated:
set req.backend = cluster2;
}

`condition => 'true'`will act as backend set by else statement
As an alternative, you can use name `default` when configuring
backend or director.
You need no `condition => 'true'` in this case bacause Varnish
will use `default` backend/director as a default destination
For more examples see `tests/vcl_backends_probes_directors.pp`

## Usaging class varnish::vcl

Expand All @@ -143,7 +138,7 @@ Will result in following VCL configuration to be generated:
timeout => '5s',
threshold => '3',
interval => '5s',
request => [ "GET /action/healthCheck1 HTTP/1.1", "Host: www.example1.com", "Connection: close" ]
request => [ "GET /healthCheck2 HTTP/1.1", "Host: www.example1.com", "Connection: close" ]
}

# configure backends
Expand Down
10 changes: 2 additions & 8 deletions manifests/backend.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
fail("Backend host $host is not an IP Address!")
}

if $title == 'default' {
$set_target = "${varnish::vcl::includedir}/default_backend.vcl"
} else {
$set_target = "${varnish::vcl::includedir}/backends.vcl"
}

concat::fragment { "$title-backend":
target => $set_target,
target => "${varnish::vcl::includedir}/backends.vcl",
content => template('varnish/includes/backends.vcl.erb'),
order => '02',
order => '02',
}
}
10 changes: 2 additions & 8 deletions manifests/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@

validate_re($title,'^[A-Za-z0-9_]*$', "Invalid characters in director name $title. Only letters, numbers and underscore are allowed.")

if $title == 'default' {
$set_target = "${varnish::vcl::includedir}/default_director.vcl"
} else {
$set_target = "${varnish::vcl::includedir}/directors.vcl"
}

concat::fragment { "$title-director":
target => $set_target,
target => "${varnish::vcl::includedir}/directors.vcl",
content => template('varnish/includes/directors.vcl.erb'),
order => '02',
order => '02',
}
}
21 changes: 1 addition & 20 deletions manifests/vcl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
file { "$includedir":
ensure => directory,
}
$includefiles = ["probes", "backends", "default_backend", "directors", "default_director", "acls", "backendselection", "waf"]
$includefiles = ["probes", "backends", "directors", "acls", "backendselection", "waf"]
includefile { $includefiles: }
}

Expand Down Expand Up @@ -121,25 +121,6 @@
validate_hash($selectors)
create_resources(varnish::selector,$selectors)

# if $selectors != {} {
# validate_hash($selectors)
# concat::fragment { "selectors-header":
# target => "${varnish::vcl::includedir}/backendselection.vcl",
# content => 'if (false) {
#',
# order => '02',
# }
# create_resources(varnish::selector,$selectors)
# concat::fragment { "selectors-footer":
# target => "${varnish::vcl::includedir}/backendselection.vcl",
# content => '} else {
# error 403 "Access denied";
#}
#',
# order => '99',
# }
# }

#ACLs
validate_hash($acls)
$default_acls = {
Expand Down
2 changes: 0 additions & 2 deletions templates/varnish-vcl.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ include "includes/probes.vcl";

#Import file with backend definitions
include "includes/backends.vcl";
include "includes/default_backend.vcl";

#Import file with director definitions;
include "includes/directors.vcl";
include "includes/default_director.vcl";

#Import file with acl definitions
include "includes/acls.vcl";
Expand Down
12 changes: 12 additions & 0 deletions tests/vcl_backend_default.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# NOTE: don't run these tests on Production servers
#

# if you are/were using 0.x.x syntax, please check file vcl_class_config_by_params.pp
# to see the diff between syntax for versions 0.x.x and 1.x.x
#
class { 'varnish::vcl':
backends => {}, # without this line you will not be able to redefine backend 'default'
}

# configure single backend, named 'default'
varnish::backend { 'default': host => '172.16.0.1', port => '80' }
15 changes: 15 additions & 0 deletions tests/vcl_backends.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# NOTE: don't run these tests on Production servers
#

# if you are/were using 0.x.x syntax, please check file vcl_class_config_by_params.pp
# to see the diff between syntax for versions 0.x.x and 1.x.x
#
class { 'varnish::vcl': }

# configure backends
varnish::backend { 'srv1': host => '172.16.0.1', port => '80' }
varnish::backend { 'srv2': host => '172.16.0.2', port => '80' }

# configure selectors
varnish::selector { 'srv1': condition => 'req.url ~ "^/server1"' }
varnish::selector { 'srv2': condition => 'true' } # will be used as default by Varnish
25 changes: 25 additions & 0 deletions tests/vcl_backends_probes.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# NOTE: don't run these tests on Production servers
#

# if you are/were using 0.x.x syntax, please check file vcl_class_config_by_params.pp
# to see the diff between syntax for versions 0.x.x and 1.x.x
#
class { 'varnish::vcl': }

# configure probes
varnish::probe { 'health_check1': url => '/health_check_url1' }
varnish::probe { 'health_check2':
window => '8',
timeout => '5s',
threshold => '3',
interval => '5s',
request => [ "GET /healthCheck2 HTTP/1.1", "Host: www.example1.com", "Connection: close" ]
}
# configure backends
varnish::backend { 'srv1': host => '172.16.0.1', port => '80', probe => 'health_check1' }
varnish::backend { 'srv2': host => '172.16.0.2', port => '80', probe => 'health_check2' }
# configure selectors
varnish::selector { 'srv1': condition => 'req.url ~ "^/url_on_srv1"' }
varnish::selector { 'srv2': condition => 'true' } # will be used as default by Varnish
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: don't run these tests on Production servers
# NOTE: don't run these tests on Production servers
#

# if you are/were using 0.x.x syntax, please check file vcl_class_config_by_params.pp
Expand All @@ -8,12 +8,12 @@

# configure probes
varnish::probe { 'health_check1': url => '/health_check_url1' }
varnish::probe { 'health_check2':
varnish::probe { 'health_check2':
window => '8',
timeout => '5s',
threshold => '3',
interval => '5s',
request => [ "GET /action/healthCheck1 HTTP/1.1", "Host: www.example1.com", "Connection: close" ]
request => [ "GET /healthCheck2 HTTP/1.1", "Host: www.example1.com", "Connection: close" ]
}
# configure backends
Expand All @@ -30,7 +30,4 @@
# configure selectors
varnish::selector { 'cluster1': condition => 'req.url ~ "^/cluster1"' }
varnish::selector { 'cluster2': condition => 'true' } # will act as backend set by else statement
# configure acl
#varnish::acl { 'acl1': hosts => [ "localhost", "172.16.0.1" ] }
varnish::selector { 'cluster2': condition => 'true' } # will be used as default by Varnish

0 comments on commit 6565042

Please sign in to comment.