diff --git a/manifests/repo.pp b/manifests/repo.pp index 58bdab5..68759d3 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -1,102 +1,123 @@ # Add the Varnish repo class varnish::repo { $ver = "${::varnish::version_major}${::varnish::version_minor}${::varnish::version_lts}" case $::osfamily { 'RedHat': { if $ver == '50' { if $::operatingsystemmajrelease == '6' { fail('Varnish 5.0 from Packagecloud is not supported on RHEL/CentOS 6') } elsif $::operatingsystemmajrelease == '7' { # https://github.com/varnishcache/pkg-varnish-cache/issues/42 fail('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.') } } + if $::varnish::version_major == '6' and $::operatingsystemmajrelease == '6' { + fail('Varnish 6.0 and above from Packagecloud is not supported on RHEL/CentOS 6') + } + $package_require = undef # Varnish 4 and above need EPEL for jemalloc if $::varnish::version_major != '3' { include ::epel Yumrepo['varnish-cache','varnish-cache-source'] { require => Yumrepo['epel'], } } yumrepo { 'varnish-cache': descr => "varnishcache_varnish${ver}", baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${::operatingsystemmajrelease}/\$basearch", gpgkey => "https://packagecloud.io/varnishcache/varnish${ver}/gpgkey", metadata_expire => '300', repo_gpgcheck => '1', gpgcheck => '0', sslverify => '1', sslcacert => '/etc/pki/tls/certs/ca-bundle.crt', } yumrepo { 'varnish-cache-source': descr => "varnishcache_varnish${ver}-source", baseurl => "https://packagecloud.io/varnishcache/varnish${ver}/el/${::operatingsystemmajrelease}/SRPMS", gpgkey => "https://packagecloud.io/varnishcache/varnish${ver}/gpgkey", metadata_expire => '300', repo_gpgcheck => '1', gpgcheck => '0', sslverify => '1', sslcacert => '/etc/pki/tls/certs/ca-bundle.crt', } } 'Debian': { + case $::operatingsystem { + 'Debian': { + if $ver == '50' and $::lsbdistcodename == 'wheezy' { + fail('Varnish 5.0 from Packagecloud is not supported on Debian 7 (Wheezy)') + } - if $ver == '30' and $::lsbdistcodename == 'xenial' { - fail('Varnish 3 from Packagecloud is not supported on Ubuntu 16.04 (Xenial)') - } + if $::varnish::version_major == '6' and $::lsbdistcodename != 'stretch' { + fail('Varnish 6.0 and above is only supported on Debian 9 (Stretch)') + } + } - if $ver == '50' { - if $::lsbdistcodename == 'wheezy' { - fail('Varnish 5.0 from Packagecloud is not supported on Debian 7 (Wheezy)') - } elsif $::lsbdistcodename == 'trusty' { - fail('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.') + 'Ubuntu': { + if $ver == '30' and versioncmp($::operatingsystemmajrelease,'16.04') >= 0 { + fail('Varnish 3 from Packagecloud is not supported after Ubuntu 14.04 (Trusty)') + } + + if $ver == '50' and $::lsbdistcodename == 'trusty' { + fail('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.') + } + + if $::varnish::version_major == '6' and versioncmp($::operatingsystemmajrelease,'16.04') == -1 { + fail('Varnish 6.0 and above is only supported on Ubuntu 16.04 (Xenial) and newer') + } + } + + default: { + fail("Unsupported Debian OS: ${::operatingsystem}") } } ensure_packages('apt-transport-https') $os_lower = downcase($::operatingsystem) $package_require = Exec['apt_update'] $gpg_key_id = "${::varnish::version_major}.${::varnish::version_minor}${::varnish::version_lts}" ? { '6.1' => '4A066C99B76A0F55A40E3E1E387EF1F5742D76CC', '6.0lts' => '48D81A24CB0456F5D59431D94CFCFD6BA750EDCD', '6.0' => '7C5B46721AF00FD57E68E6E8D2605BF74E8B9DBA', '5.2' => '91CFD5635A1A5FAC0662BEDD2E9BA3FE86BE909D', '5.1' => '54DC32329C37703D8B2819E6414C46826B880524', '5.0' => '1487779B0E6C440214F07945632B6ED0FF6A1C76', '4.1' => '9C96F9CA0DC3F4EA78FF332834BF6E8ECBF5C49E', '4.0' => 'B7B16293AE0CC24216E9A83DD4E49AD8DE3FFEA4', '3.0' => '246BE381150865E2DC8C6B01FC1318ACEE2C594C', } ::apt::source { 'varnish-cache': comment => "Apt source for Varnish ${::varnish::version_major}.${::varnish::version_minor}${::varnish::version_lts}", location => "https://packagecloud.io/varnishcache/varnish${ver}/${os_lower}/", repos => 'main', require => Package['apt-transport-https'], key => { source => "https://packagecloud.io/varnishcache/varnish${ver}/gpgkey", id => $gpg_key_id, }, include => { 'deb' => true, 'src' => true, }, } } default: { fail("Unsupported repo osfamily: ${::osfamily}") } } } diff --git a/spec/classes/varnish_spec.rb b/spec/classes/varnish_spec.rb index 3bbaee8..861995c 100644 --- a/spec/classes/varnish_spec.rb +++ b/spec/classes/varnish_spec.rb @@ -1,120 +1,137 @@ require 'spec_helper' describe 'varnish', type: :class do - ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2', '6.0', '6.1'].each do |version| + ['3.0', '4.0', '4.1', '5.0', '5.1', '5.2', '6.0', '6.0lts', '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\)}) } + if facts[:operatingsystem] == 'Ubuntu' && Gem::Version.new(facts[:operatingsystemmajrelease]) >= Gem::Version.new('16.04') + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 3 from Packagecloud is not supported after Ubuntu 14.04 \(Trusty\)}) } 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 + when /6/ + if facts[:osfamily] == 'RedHat' + if facts[:operatingsystemmajrelease] == '6' + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above from Packagecloud is not supported on RHEL\/CentOS 6}) } + should_fail = 1 + end + elsif facts[:osfamily] == 'Debian' + if facts[:operatingsystem] == 'Debian' && facts[:lsbdistcodename] != 'stretch' + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above is only supported on Debian 9 \(Stretch\)}) } + should_fail = 1 + end + + if facts[:operatingsystem] == 'Ubuntu' && Gem::Version.new(facts[:operatingsystemmajrelease]) < Gem::Version.new('16.04') + it { is_expected.to raise_error(Puppet::Error, %r{Varnish 6.0 and above is only supported on Ubuntu 16.04 \(Xenial\) and newer}) } + 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