diff --git a/manifests/init.pp b/manifests/init.pp index eb9b5bd..478f84b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,113 +1,113 @@ # == Class: varnish # # Configure Varnish proxy cache # # === Parameters # # [*addrepo*] # Whether to add the official Varnish repos # [*secret*] # Varnish secret (used by varnishadm etc). # Optional; will be autogenerated if not specified # [*vcl_conf*] # Location of Varnish config file template # [*listen*] # IP address for HTTP to listen on # [*listen_port*] # Port to listen on for HTTP requests # [*admin_listen*] # IP address for admin requests - defaults to 127.0.0.1 # [*admin_port*] # Port for Varnish admin to listen on # [*min_threads*] # Varnish minimum thread pool size # [*max_threads*] # Varnish maximum thread pool size # [*thread_timeout*] # Thread timeout # [*storage_type*] # Whether to use malloc (RAM only) or file storage for cache # [*storage_size*] # Size of cache # [*storage_additional*] # Hash of additional storage backends containing strings in the varnish format (passed to -s) # [*varnish_version*] # Major Varnish version to use # [*vcl_reload*] # Script to use to load new Varnish config # [*package_ensure*] # Ensure specific package version for Varnish, eg 3.0.5-1.el6 # [*runtime_params*] # Hash of key:value runtime parameters # class varnish ( Hash $runtime_params = {}, Boolean $addrepo = true, String $admin_listen = '127.0.0.1', Integer $admin_port = 6082, Variant[String,Array] $listen = '0.0.0.0', Integer $listen_port = 6081, Optional[String] $secret = undef, Stdlib::AbsolutePath $secret_file = '/etc/varnish/secret', Stdlib::AbsolutePath $vcl_conf = '/etc/varnish/default.vcl', Enum['file','malloc'] $storage_type = 'file', Stdlib::AbsolutePath $storage_file = '/var/lib/varnish/varnish_storage.bin', String $storage_size = '1G', Array $storage_additional = [], Integer $min_threads = 50, Integer $max_threads = 1000, Integer $thread_timeout = 120, - Pattern[/^[3-5]\.[0-9]/] $varnish_version = '4.1', + Pattern[/^[3-6]\.[0-9]/] $varnish_version = '4.1', Optional[String] $instance_name = undef, String $package_ensure = 'present', String $package_name = 'varnish', String $service_name = 'varnish', Optional[String] $vcl_reload_cmd = undef, String $vcl_reload_path = $::path, ) { if $package_ensure == 'present' { $version_major = regsubst($varnish_version, '^(\d+)\.(\d+).*$', '\1') $version_minor = regsubst($varnish_version, '^(\d+)\.(\d+).*$', '\2') $version_full = $varnish_version } else { $version_major = regsubst($package_ensure, '^(\d+)\.(\d+).*$', '\1') $version_minor = regsubst($package_ensure, '^(\d+)\.(\d+).*$', '\2') $version_full = "${version_major}.${version_minor}" if $varnish_version != "${version_major}.${version_minor}" { fail("Version mismatch, varnish_version is ${varnish_version}, but package_ensure is ${version_full}") } } include ::varnish::params if $vcl_reload_cmd == undef { $vcl_reload = $::varnish::params::vcl_reload } else { $vcl_reload = $vcl_reload_cmd } if $addrepo { class { '::varnish::repo': before => Class['::varnish::install'], } } include ::varnish::install class { '::varnish::secret': secret => $secret, require => Class['::varnish::install'], } class { '::varnish::config': require => Class['::varnish::secret'], notify => Class['::varnish::service'], } class { '::varnish::service': require => Class['::varnish::config'], } } diff --git a/spec/classes/varnish_spec.rb b/spec/classes/varnish_spec.rb index a2e3774..2d0d6f9 100644 --- a/spec/classes/varnish_spec.rb +++ b/spec/classes/varnish_spec.rb @@ -1,120 +1,120 @@ require 'spec_helper' describe 'varnish', type: :class do - ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2'].each do |version| + ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2', '6.0', '6.1' ].each do |version| on_supported_os.each do |os, facts| context "Varnish #{version} on #{os}" do let(:facts) do facts.merge(path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin') end let(:params) do { varnish_version: version, } end should_fail = 0 case version when '3.0' if facts[:lsbdistcodename] == 'xenial' it { is_expected.to raise_error(Puppet::Error, %r{Varnish 3 from Packagecloud is not supported on Ubuntu 16.04 \(Xenial\)}) } should_fail = 1 end when '5.0' if facts[:osfamily] == 'RedHat' case facts[:operatingsystemmajrelease] when '6' it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on RHEL\/CentOS 6}) } should_fail = 1 when '7' # rubocop:disable LineLength it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 on RHEL\/CentOS 7 has a known packaging bug in the varnish_reload_vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } # rubocop:enable LineLength should_fail = 1 end elsif facts[:osfamily] == 'Debian' case facts[:lsbdistcodename] when 'wheezy' it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 from Packagecloud is not supported on Debian 7 \(Wheezy\)}) } should_fail = 1 when 'trusty' # rubocop:disable LineLength it { is_expected.to raise_error(Puppet::Error, %r{Varnish 5.0 has a known packaging bug in the reload-vcl script, please use 5.1 instead. If the bug has been fixed, please submit a pull request to remove this message.}) } # rubocop:enable LineLength should_fail = 1 end end end if should_fail == 0 it { is_expected.to compile.with_all_deps } if (facts[:osfamily] == 'RedHat' && facts[:operatingsystemmajrelease] == '7' && version != '3.0') || (facts[:osfamily] == 'Debian' && (facts[:lsbdistcodename] == 'jessie' || facts[:lsbdistcodename] == 'xenial')) it { is_expected.to contain_file('/etc/systemd/system/varnish.service') } it { is_expected.to contain_exec('varnish_systemctl_daemon_reload') } end case facts[:osfamily] when 'RedHat' if facts[:operatingsystemmajrelease] == '6' && version != '3.0' it { is_expected.to contain_selinux__module('varnishpol') } end it { is_expected.to contain_file('/etc/sysconfig/varnish') } it { is_expected.to contain_yumrepo('varnish-cache') } it { is_expected.to contain_yumrepo('varnish-cache-source') } when 'Debian' it { is_expected.to contain_file('/etc/default/varnish') } it { is_expected.to contain_package('apt-transport-https') } it { is_expected.to contain_apt__source('varnish-cache') } end end end end end context 'supported operating systems' do let(:facts) do { osfamily: 'RedHat', operatingsystem: 'CentOS', operatingsystemmajrelease: '7', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', lsbdistrelease: nil, } end it { is_expected.to contain_class('varnish::params') } it { is_expected.to contain_class('varnish::repo').that_comes_before('Class[varnish::install]') } it { is_expected.to contain_class('varnish::install').that_comes_before('Class[varnish::secret]') } it { is_expected.to contain_class('varnish::secret').that_comes_before('Class[varnish::config]') } it { is_expected.to contain_class('varnish::config').that_notifies('Class[varnish::service]') } it { is_expected.to contain_class('varnish::config').that_comes_before('Class[varnish::service]') } it { is_expected.to contain_class('varnish::service') } it { is_expected.to contain_file('/etc/varnish/secret') } it { is_expected.to contain_exec('Generate Varnish secret file') } it { is_expected.to contain_package('varnish') } it { is_expected.to contain_service('varnish') } it { is_expected.to contain_exec('vcl_reload') } end context 'unsupported operating systems' do describe 'varnish class fail on unsupported OS' do let(:facts) do { osfamily: 'Darwin', operatingsystem: 'Darwin', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin:/opt/puppetlabs/bin', lsbdistrelease: nil, } end it { is_expected.to raise_error(Puppet::Error, %r{Darwin not supported}) } end end end