diff --git a/.fixtures.yml b/.fixtures.yml index ff58632c..19707730 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,9 +1,9 @@ fixtures: repositories: - stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" - apt: "git://github.com/puppetlabs/puppetlabs-apt.git" - zypprepo: "git://github.com/deadpoint/puppet-zypprepo.git" - inifile: "git://github.com/puppetlabs/puppetlabs-inifile.git" - archive: "git://github.com/voxpupuli/puppet-archive.git" + stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + apt: "https://github.com/puppetlabs/puppetlabs-apt.git" + zypprepo: "https://github.com/deadpoint/puppet-zypprepo.git" + inifile: "https://github.com/puppetlabs/puppetlabs-inifile.git" + archive: "https://github.com/voxpupuli/puppet-archive.git" symlinks: php: "#{source_dir}" diff --git a/.travis.yml b/.travis.yml index 6214a554..78ebaf7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,23 +16,23 @@ matrix: fast_finish: true include: - rvm: 1.9.3 - env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test SYSTEM_TESTS="no" - rvm: 1.9.3 - env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test SYSTEM_TESTS="no" - rvm: 2.1.9 - env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test + env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test SYSTEM_TESTS="no" - rvm: 2.1.9 - env: PUPPET_VERSION="~> 4.0" CHECK=test + env: PUPPET_VERSION="~> 4.0" CHECK=test SYSTEM_TESTS="no" - rvm: 2.2.6 - env: PUPPET_VERSION="~> 4.0" CHECK=test + env: PUPPET_VERSION="~> 4.0" CHECK=test SYSTEM_TESTS="no" - rvm: 2.3.3 - env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes + env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes SYSTEM_TESTS="no" - rvm: 2.3.3 - env: PUPPET_VERSION="~> 4.0" CHECK=rubocop + env: PUPPET_VERSION="~> 4.0" CHECK=rubocop SYSTEM_TESTS="no" - rvm: 2.3.3 - env: PUPPET_VERSION="~> 4.0" CHECK=test + env: PUPPET_VERSION="~> 4.0" CHECK=test SYSTEM_TESTS="no" - rvm: 2.4.0 - env: PUPPET_VERSION="~> 4.0" CHECK=test + env: PUPPET_VERSION="~> 4.0" CHECK=test SYSTEM_TESTS="no" allow_failures: - rvm: 2.4.0 branches: diff --git a/Gemfile b/Gemfile index e8db724e..a397366b 100644 --- a/Gemfile +++ b/Gemfile @@ -42,16 +42,18 @@ group :development do end group :system_tests do - if beaker_version = ENV['BEAKER_VERSION'] - gem 'beaker', *location_for(beaker_version) + if ENV['SYSTEM_TESTS'] == 'yes' + if beaker_version = ENV['BEAKER_VERSION'] + gem 'beaker', *location_for(beaker_version) + end + if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false + gem 'beaker-puppet_install_helper', :require => false end - if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] - gem 'beaker-rspec', *location_for(beaker_rspec_version) - else - gem 'beaker-rspec', :require => false - end - gem 'serverspec', :require => false - gem 'beaker-puppet_install_helper', :require => false end diff --git a/README.md b/README.md index f810f889..fd35e52d 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ Alternative to the Puppet DSL code examples above, you may optionally define you Below are all the examples you see above, but defined in YAML format for use with Hiera. ```yaml + --- php::ensure: latest php::manage_repos: true @@ -192,7 +193,7 @@ The older Ubuntu PPAs run by Ondřej have been deprecated (ondrej/php5, ondrej/p in favor of a new PPA: ondrej/php which contains all 3 versions of PHP: 5.5, 5.6, and 7.0 Here's an example in hiera of getting PHP 5.6 installed with php-fpm, pear/pecl, and composer: -``` +```puppet php::globals::php_version: '5.6' php::fpm: true php::dev: true @@ -213,6 +214,83 @@ We prefer using php-fpm. You can find an example Apache vhost in `manifests/apache_vhost.pp` that shows you how to use `mod_proxy_fcgi` to connect to php-fpm. + +### RedHat/CentOS SCL Users +If you plan to use the SCL repositories with this module you must do the following adjustments: + +#### General config +This ensures that the module will create configurations in the directory ``/etc/opt/rh//` (also in php.d/ +for extensions). Anyway you have to manage the SCL repo's by your own. + +```puppet +class { '::php::globals': + php_version => 'rh-php56', + rhscl => true, +}-> +class { '::php': + manage_repos => false +} +``` + +#### Extensions +Extensions in SCL are being installed with packaged that cover 1 or more .so files. This is kinda incompatible with +this module, since this module specifies an extension by name and relates the name of the package and the config (.ini) +from it. To manage extensions with SCL with this module you must use the following parameters: + +```puppet +class { '::php': + ... + extensions => { + bz2 => { package_name => 'common', config_file_prefix => '20-'}, + calendar => { package_name => 'common', config_file_prefix => '20-'}, + } +} +``` + +By this you tell the module to configure bz2 and calender while ensuring only the package `common`. Further the configs +will be created with the schema ``. + +A list of commonly used modules: +```puppet + calendar => { package_name => 'common', config_file_prefix => '20-'}, + ctype => { package_name => 'common', config_file_prefix => '20-'}, + curl => { package_name => 'common', config_file_prefix => '20-'}, + exif => { package_name => 'common', config_file_prefix => '20-'}, + fileinfo => { package_name => 'common', config_file_prefix => '20-'}, + ftp => { package_name => 'common', config_file_prefix => '20-'}, + gettext => { package_name => 'common', config_file_prefix => '20-'}, + iconv => { package_name => 'common', config_file_prefix => '20-'}, + phar => { package_name => 'common', config_file_prefix => '20-'}, + sockets => { package_name => 'common', config_file_prefix => '20-'}, + tokenizer => { package_name => 'common', config_file_prefix => '20-'}, + zip => { package_name => 'common', config_file_prefix => '20-'}, + dom => { package_name => 'xml', config_file_prefix => '20-'}, + simplexml => { package_name => 'xml', config_file_prefix => '20-'}, + xmlwriter => { package_name => 'xml', config_file_prefix => '20-'}, + xsl => { package_name => 'xml', config_file_prefix => '20-'}, + wddx => { package_name => 'xml', config_file_prefix => '30-'}, + xmlreader => { package_name => 'xml', config_file_prefix => '30-'}, + soap => { config_file_prefix => '20-'}, + pdo => { package_name => 'pdo', config_file_prefix => '20-'}, + pdo_sqlite => { package_name => 'pdo', config_file_prefix => '30-'}, + sqlite3 => { package_name => 'pdo', config_file_prefix => '20-'}, + imap => { config_file_prefix => '20-'}, + posix => { package_name => 'process', config_file_prefix => '20-'}, + shmop => { package_name => 'process', config_file_prefix => '20-'}, + sysvmsg => { package_name => 'process', config_file_prefix => '20-'}, + sysvsem => { package_name => 'process', config_file_prefix => '20-'}, + sysvshm => { package_name => 'process', config_file_prefix => '20-'}, + intl => { config_file_prefix => '20-'}, + gd => { config_file_prefix => '20-'}, + mysqlnd => { package_name => 'mysqlnd', config_file_prefix => '20-'}, + mysql => { package_name => 'mysqlnd', config_file_prefix => '30-'}, + mysqli => { package_name => 'mysqlnd', config_file_prefix => '30-'}, + pdo_mysql => { package_name => 'mysqlnd', config_file_prefix => '30-'}, + mbstring => { config_file_prefix => '20-'}, + xmlrpc => { config_file_prefix => '30-'}, + json => { provider => 'pecl', package_name => 'jsonc', config_file_prefix => '40-'}, +``` + ### Facts We deliver a `phpversion` fact with this module. This is explicitly **NOT** intended diff --git a/Rakefile b/Rakefile index d00f2470..917d71dd 100644 --- a/Rakefile +++ b/Rakefile @@ -30,4 +30,19 @@ task test: [ :metadata_lint, :release_checks, ] + +desc 'Run spec tests of exactly one specfile' +# usage: bundle exec rake spec_single[] +task :spec_single, [:specfile] do |t, args| + RSpec::Core::RakeTask.new(:spec_onetest) do |t| + t.pattern = args[:specfile] + t.rspec_opts = ['--color'] + end + + Rake::Task[:spec_prep].invoke + Rake::Task[:spec_onetest].invoke + # Rake::Task[:spec_clean].invoke +end + + # vim: syntax=ruby diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index dbbf8e9c..535ae115 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -24,11 +24,13 @@ def self.pearlist(hash) list = list.map do |set| %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) { |m| channel = m[1].downcase } + # if hash[:justme] is specified this should only put something into pearhash if + # the line matched the string in hash[:justme] if hash[:justme] && set =~ %r{^#{hash[:justme]}} pearhash = pearsplit(set, channel) pearhash[:provider] = :pear pearhash - elsif (pearhash = pearsplit(set, channel)) + elsif !hash[:justme] && (pearhash = pearsplit(set, channel)) pearhash[:provider] = :pear pearhash end @@ -102,6 +104,7 @@ def latest end def query + Puppet.debug format("doing the pearlist for '%s'", @resource[:name]) self.class.pearlist(justme: @resource[:name]) end diff --git a/manifests/cli.pp b/manifests/cli.pp index b07ad665..e0008af4 100644 --- a/manifests/cli.pp +++ b/manifests/cli.pp @@ -20,10 +20,31 @@ validate_absolute_path($inifile) validate_hash($settings) + if $php::globals::rhscl_mode { + # stupid fixes for scl + file {'/usr/bin/pear': + ensure => 'link', + target => "${$php::params::php_bin_dir}/pear", + } + + file {'/usr/bin/pecl': + ensure => 'link', + target => "${$php::params::php_bin_dir}/pecl", + } + + file {'/usr/bin/php': + ensure => 'link', + target => "${$php::params::php_bin_dir}/php", + } + } + $real_settings = deep_merge($settings, hiera_hash('php::cli::settings', {})) - ::php::config { 'cli': - file => $inifile, - config => $real_settings, + if $inifile != $php::params::config_root_inifile { + # only create a cli specific inifile if the filenames are different + ::php::config { 'cli': + file => $inifile, + config => $real_settings, + } } } diff --git a/manifests/embedded.pp b/manifests/embedded.pp index 6837c22f..9128337e 100644 --- a/manifests/embedded.pp +++ b/manifests/embedded.pp @@ -35,17 +35,21 @@ ) $real_package = $::osfamily ? { - 'Debian' => "lib${package}", + 'Debian' => "lib${package}", default => $package, } package { $real_package: ensure => $ensure, require => Class['::php::packages'], - }-> - ::php::config { 'embedded': - file => $inifile, - config => $real_settings, + before => Php::Config['embedded'], + } + + if $inifile != $php::params::config_root_inifile { + ::php::config { 'embedded': + file => $inifile, + config => $real_settings, + } } } diff --git a/manifests/extension.pp b/manifests/extension.pp index d171384f..2114ba25 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -55,6 +55,15 @@ # [*pipe*] # String parameter to input answers during extension setup. Supported # *provider*: pecl. +# [*package_name*] +# String parameter, which can be used to override the package name. This can be useful if you have multiple extensions +# grouped into one package. Just specify multiple php::extension with the same package name. +# Defaults to namevar +# +# [*config_file_prefix*] +# String parameter, to add a prefix to config files created for this extension. This is there to make the define able +# to work with SCL packages which add forced ordering to their configs (like 20-pdo.ini) +# Defaults to namevar # define php::extension ( $ensure = 'installed', @@ -71,6 +80,8 @@ $settings_prefix = false, $sapi = 'ALL', $pipe = undef, + $package_name = undef, + $config_file_prefix = undef, ) { if ! defined(Class['php']) { @@ -84,6 +95,8 @@ validate_string($sapi) validate_array($header_packages) validate_bool($zend) + validate_string($package_name) + validate_string($config_file_prefix) if $source and $pecl_source { fail('Only one of $source and $pecl_source can be specified.') @@ -96,13 +109,20 @@ $real_source = $pecl_source } + if $package_name { + $real_package_name = $package_name + } + else { + $real_package_name = $title + } + if $provider != 'none' { if $provider == 'pecl' { - $real_package = "pecl-${title}" + $real_package = "pecl-${real_package_name}" } else { - $real_package = "${package_prefix}${title}" + $real_package = "${package_prefix}${real_package_name}" } unless empty($header_packages) { @@ -110,36 +130,39 @@ Package[$header_packages] -> Package[$real_package] } - if $provider == 'pecl' { - ensure_packages( [ $real_package ], { - ensure => $ensure, - provider => $provider, - source => $real_source, - pipe => $pipe, - require => [ - Class['::php::pear'], - Class['::php::dev'], - ], - }) - - unless empty($compiler_packages) { - ensure_resource('package', $compiler_packages) - Package[$compiler_packages] -> Package[$real_package] + if !($real_package_name in $::php::params::common_package_suffixes) and !defined(Package[$real_package]) { + if $provider == 'pecl' { + ensure_resource('package', [ $real_package ], { + ensure => $ensure, + provider => $provider, + source => $real_source, + pipe => $pipe, + require => [ + Class['::php::pear'], + Class['::php::dev'] + ], + }) + + unless empty($compiler_packages) { + ensure_resource('package', $compiler_packages) + Package[$compiler_packages] -> Package[$real_package] + } } - } - else { - if $pipe != undef { - warning("pipe param is not supported by php::extension provider ${provider}") + else { + if $pipe != undef { + warning("pipe param is not supported by php::extension provider ${provider}") + } + + ensure_resource('package', $real_package, { + ensure => $ensure, + provider => $provider, + source => $real_source, + }) } - - ensure_packages( [ $real_package ], { - ensure => $ensure, - provider => $provider, - source => $real_source, - }) } $package_depends = "Package[${real_package}]" + } else { $package_depends = undef } @@ -177,6 +200,13 @@ $full_settings = $settings } + if $config_file_prefix { + $real_config_file_name = "${config_file_prefix}${lowercase_title}.ini" + } + else { + $real_config_file_name = "${lowercase_title}.ini" + } + $final_settings = deep_merge( {"${extension_key}" => "${module_path}${so_name}.so"}, $full_settings @@ -184,7 +214,7 @@ $config_root_ini = pick_default($::php::config_root_ini, $::php::params::config_root_ini) ::php::config { $title: - file => "${config_root_ini}/${lowercase_title}.ini", + file => "${config_root_ini}/${real_config_file_name}", config => $final_settings, require => $package_depends, } diff --git a/manifests/fpm.pp b/manifests/fpm.pp index 0743b052..f666b8c6 100644 --- a/manifests/fpm.pp +++ b/manifests/fpm.pp @@ -51,6 +51,7 @@ $service_provider = $::php::fpm_service_provider, $package = $::php::real_fpm_package, $inifile = $::php::fpm_inifile, + $pid_file = $::php::params::fpm_pid_file, $settings = $::php::real_settings, $global_pool_settings = $::php::real_fpm_global_pool_settings, $pools = $::php::real_fpm_pools, @@ -87,8 +88,10 @@ settings => $real_settings, log_owner => $log_owner, log_group => $log_group, + pid_file => $pid_file, require => Package[$real_package], } + contain '::php::fpm::config' contain '::php::fpm::service' diff --git a/manifests/fpm/config.pp b/manifests/fpm/config.pp index 636706b3..acec01d6 100644 --- a/manifests/fpm/config.pp +++ b/manifests/fpm/config.pp @@ -137,6 +137,12 @@ mode => '0644', } + ensure_resource('file', ['/var/run/php-fpm/', '/var/log/php-fpm/'], { + ensure => directory, + owner => $user, + group => $group, + }) + file { $pool_base_dir: ensure => directory, owner => root, @@ -151,8 +157,10 @@ } } - ::php::config { 'fpm': - file => $inifile, - config => $settings, + if $inifile != $php::params::config_root_inifile { + ::php::config { 'fpm': + file => $inifile, + config => $settings, + } } } diff --git a/manifests/globals.pp b/manifests/globals.pp index b0094bbc..57ee1535 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -10,14 +10,27 @@ # # [*fpm_pid_file*] # Path to pid file for fpm +# +# [*rhscl_mode*] +# The mode specifies the specifics in paths for the various RedHat SCL environments so that the module is configured +# correctly on their pathnames. +# +# Valid modes are: 'rhscl', 'remi' +# class php::globals ( $php_version = undef, $config_root = undef, $fpm_pid_file = undef, + $rhscl_mode = undef, ) { if $php_version != undef { - validate_re($php_version, '^[57].[0-9]') + if $rhscl_mode { + validate_re($php_version, '^(rh-)?php[57][0-9]') + } + else { + validate_re($php_version, '^[57].[0-9]') + } } if $config_root != undef { validate_absolute_path($config_root) @@ -45,54 +58,54 @@ if $::operatingsystem == 'Ubuntu' { case $globals_php_version { /^5\.4/: { - $default_config_root = '/etc/php5' + $default_config_root = '/etc/php5' $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" - $fpm_error_log = '/var/log/php5-fpm.log' - $fpm_service_name = 'php5-fpm' - $ext_tool_enable = '/usr/sbin/php5enmod' - $ext_tool_query = '/usr/sbin/php5query' - $package_prefix = 'php5-' + $fpm_error_log = '/var/log/php5-fpm.log' + $fpm_service_name = 'php5-fpm' + $ext_tool_enable = '/usr/sbin/php5enmod' + $ext_tool_query = '/usr/sbin/php5query' + $package_prefix = 'php5-' } /^[57].[0-9]/: { - $default_config_root = "/etc/php/${globals_php_version}" + $default_config_root = "/etc/php/${globals_php_version}" $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" - $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" - $fpm_service_name = "php${globals_php_version}-fpm" - $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" - $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" - $package_prefix = "php${globals_php_version}-" + $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" + $fpm_service_name = "php${globals_php_version}-fpm" + $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" + $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" + $package_prefix = "php${globals_php_version}-" } default: { # Default php installation from Ubuntu official repository use the following paths until 16.04 # For PPA please use the $php_version to override it. - $default_config_root = '/etc/php5' + $default_config_root = '/etc/php5' $default_fpm_pid_file = '/var/run/php5-fpm.pid' - $fpm_error_log = '/var/log/php5-fpm.log' - $fpm_service_name = 'php5-fpm' - $ext_tool_enable = '/usr/sbin/php5enmod' - $ext_tool_query = '/usr/sbin/php5query' - $package_prefix = 'php5-' + $fpm_error_log = '/var/log/php5-fpm.log' + $fpm_service_name = 'php5-fpm' + $ext_tool_enable = '/usr/sbin/php5enmod' + $ext_tool_query = '/usr/sbin/php5query' + $package_prefix = 'php5-' } } } else { case $globals_php_version { /^7/: { - $default_config_root = "/etc/php/${globals_php_version}" + $default_config_root = "/etc/php/${globals_php_version}" $default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid" - $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" - $fpm_service_name = "php${globals_php_version}-fpm" - $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" - $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" - $package_prefix = 'php7.0-' + $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log" + $fpm_service_name = "php${globals_php_version}-fpm" + $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}" + $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}" + $package_prefix = 'php7.0-' } default: { - $default_config_root = '/etc/php5' + $default_config_root = '/etc/php5' $default_fpm_pid_file = '/var/run/php5-fpm.pid' - $fpm_error_log = '/var/log/php5-fpm.log' - $fpm_service_name = 'php5-fpm' - $ext_tool_enable = '/usr/sbin/php5enmod' - $ext_tool_query = '/usr/sbin/php5query' - $package_prefix = 'php5-' + $fpm_error_log = '/var/log/php5-fpm.log' + $fpm_service_name = 'php5-fpm' + $ext_tool_enable = '/usr/sbin/php5enmod' + $ext_tool_query = '/usr/sbin/php5query' + $package_prefix = 'php5-' } } } @@ -100,33 +113,56 @@ 'Suse': { case $globals_php_version { /^7/: { - $default_config_root = '/etc/php7' - $package_prefix = 'php7-' + $default_config_root = '/etc/php7' + $package_prefix = 'php7-' $default_fpm_pid_file = '/var/run/php7-fpm.pid' - $fpm_error_log = '/var/log/php7-fpm.log' + $fpm_error_log = '/var/log/php7-fpm.log' } default: { - $default_config_root = '/etc/php5' - $package_prefix = 'php5-' + $default_config_root = '/etc/php5' + $package_prefix = 'php5-' $default_fpm_pid_file = '/var/run/php5-fpm.pid' - $fpm_error_log = '/var/log/php5-fpm.log' + $fpm_error_log = '/var/log/php5-fpm.log' } } } 'RedHat': { - $default_config_root = '/etc/php.d' - $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid' + case $rhscl_mode { + 'remi': { + $rhscl_root = "/opt/remi/${php_version}/root" + $default_config_root = "${rhscl_root}/etc" + $default_fpm_pid_file = "${rhscl_root}/var/run/php-fpm/php-fpm.pid" + $package_prefix = "${php_version}-php-" + $fpm_service_name = "${php_version}-php-fpm" + } + 'rhscl': { + $rhscl_root = "/opt/rh/${php_version}/root" + $default_config_root = "/etc/opt/rh/${php_version}" # rhscl registers contents by copy in /etc/opt/rh + $default_fpm_pid_file = "/var/opt/rh/${php_version}/run/php-fpm/php-fpm.pid" + $package_prefix = "${php_version}-php-" + $fpm_service_name = "${php_version}-php-fpm" + } + undef: { + $default_config_root = '/etc/php.d' + $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid' + $fpm_service_name = undef + $package_prefix = undef + } + default: { + fail("Unsupported rhscl_mode '${rhscl_mode}'") + } + } } 'FreeBSD': { $default_config_root = '/usr/local/etc' $default_fpm_pid_file = '/var/run/php-fpm.pid' + $fpm_service_name = undef } default: { fail("Unsupported osfamily: ${::osfamily}") } } - $globals_config_root = pick($config_root, $default_config_root) - - $globals_fpm_pid_file = pick($fpm_pid_file, $default_fpm_pid_file) + $globals_config_root = pick($config_root, $default_config_root) + $globals_fpm_pid_file = pick($fpm_pid_file, $default_fpm_pid_file) } diff --git a/manifests/params.pp b/manifests/params.pp index df29edd9..df5db03f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -101,25 +101,52 @@ } } 'RedHat': { - $config_root_ini = '/etc/php.d' - $config_root_inifile = '/etc/php.ini' + case $php::globals::rhscl_mode { + 'remi': { + $config_root_ini = "${php::globals::globals_config_root}/php.d" + $config_root_inifile = "${php::globals::globals_config_root}/php.ini" + $cli_inifile = $config_root_inifile + $fpm_inifile = $config_root_inifile + $fpm_config_file = "${php::globals::globals_config_root}/php-fpm.conf" + $fpm_pool_dir = "${php::globals::globals_config_root}/php-fpm.d" + $php_bin_dir = "${php::globals::rhscl_root}/bin" + + } + 'rhscl': { + $config_root_ini = "${php::globals::globals_config_root}/php.d" + $config_root_inifile = "${php::globals::globals_config_root}/php.ini" + $cli_inifile = "${php::globals::globals_config_root}/php-cli.ini" + $fpm_inifile = "${php::globals::globals_config_root}/php-fpm.ini" + $fpm_config_file = "${php::globals::globals_config_root}/php-fpm.conf" + $fpm_pool_dir = "${php::globals::globals_config_root}/php-fpm.d" + $php_bin_dir = "${php::globals::rhscl_root}/bin" + } + undef: { + $config_root_ini = $php::globals::globals_config_root + $config_root_inifile = '/etc/php.ini' + $cli_inifile = '/etc/php-cli.ini' + $fpm_inifile = '/etc/php-fpm.ini' + $fpm_config_file = '/etc/php-fpm.conf' + $fpm_pool_dir = '/etc/php-fpm.d' + } + default: { + fail("Unsupported rhscl_mode '${php::globals::rhscl_mode}'") + } + } + + $apache_inifile = $config_root_inifile + $embedded_inifile = $config_root_inifile $common_package_names = [] $common_package_suffixes = ['cli', 'common'] - $cli_inifile = '/etc/php-cli.ini' $dev_package_suffix = 'devel' $fpm_pid_file = $php::globals::globals_fpm_pid_file - $fpm_config_file = '/etc/php-fpm.conf' $fpm_error_log = '/var/log/php-fpm/error.log' - $fpm_inifile = '/etc/php-fpm.ini' $fpm_package_suffix = 'fpm' - $fpm_pool_dir = '/etc/php-fpm.d' - $fpm_service_name = 'php-fpm' + $fpm_service_name = pick($php::globals::fpm_service_name, 'php-fpm') $fpm_user = 'apache' $fpm_group = 'apache' - $apache_inifile = '/etc/php.ini' $embedded_package_suffix = 'embedded' - $embedded_inifile = '/etc/php.ini' - $package_prefix = 'php-' + $package_prefix = pick($php::globals::package_prefix, 'php-') $compiler_packages = ['gcc', 'gcc-c++', 'make'] $manage_repos = false $root_group = 'root' diff --git a/spec/classes/php_fpm_config_spec.rb b/spec/classes/php_fpm_config_spec.rb index bf78b3ce..3e6d4c91 100644 --- a/spec/classes/php_fpm_config_spec.rb +++ b/spec/classes/php_fpm_config_spec.rb @@ -1,3 +1,4 @@ +require 'rspec' require 'spec_helper' describe 'php::fpm::config' do diff --git a/spec/classes/php_spec.rb b/spec/classes/php_spec.rb index c8b7d85f..08806fed 100644 --- a/spec/classes/php_spec.rb +++ b/spec/classes/php_spec.rb @@ -8,6 +8,11 @@ end describe 'when called with no parameters' do + case facts[:osfamily] + when 'Suse', 'RedHat', 'CentOS' + it { is_expected.to contain_class('php::global') } + end + case facts[:osfamily] when 'Debian' it { is_expected.not_to contain_class('php::global') } @@ -18,35 +23,49 @@ it { is_expected.to contain_package('php-pear').with_ensure('present') } it { is_expected.to contain_class('php::composer') } when 'Suse' - it { is_expected.to contain_class('php::global') } it { is_expected.to contain_package('php5').with_ensure('present') } it { is_expected.to contain_package('php5-devel').with_ensure('present') } it { is_expected.to contain_package('php5-pear').with_ensure('present') } it { is_expected.not_to contain_package('php5-cli') } it { is_expected.not_to contain_package('php5-dev') } it { is_expected.not_to contain_package('php-pear') } + when 'RedHat', 'CentOS' + it { is_expected.to contain_package('php-cli').with_ensure('present') } + it { is_expected.to contain_package('php-common').with_ensure('present') } end end describe 'when called with package_prefix parameter' do - let(:params) { { package_prefix: 'myphp-' } } + package_prefix = 'myphp-' + let(:params) { { package_prefix: package_prefix } } + + case facts[:osfamily] + when 'Suse', 'RedHat', 'CentOS' + it { is_expected.to contain_class('php::global') } + end + + case facts[:osfamily] + when 'Debian', 'RedHat', 'CentOS' + it { is_expected.to contain_package("#{package_prefix}cli").with_ensure('present') } + end + case facts[:osfamily] when 'Debian' it { is_expected.not_to contain_class('php::global') } it { is_expected.to contain_class('php::fpm') } - it { is_expected.to contain_package('myphp-cli').with_ensure('present') } - it { is_expected.to contain_package('myphp-fpm').with_ensure('present') } - it { is_expected.to contain_package('myphp-dev').with_ensure('present') } - it { is_expected.to contain_package('php-pear').with_ensure('present') } it { is_expected.to contain_class('php::composer') } + it { is_expected.to contain_package('php-pear').with_ensure('present') } + it { is_expected.to contain_package("#{package_prefix}dev").with_ensure('present') } + it { is_expected.to contain_package("#{package_prefix}fpm").with_ensure('present') } when 'Suse' - it { is_expected.to contain_class('php::global') } it { is_expected.to contain_package('php5').with_ensure('present') } - it { is_expected.to contain_package('myphp-devel').with_ensure('present') } - it { is_expected.to contain_package('myphp-pear').with_ensure('present') } - it { is_expected.not_to contain_package('myphp-cli') } - it { is_expected.not_to contain_package('myphp-dev') } + it { is_expected.to contain_package("#{package_prefix}devel").with_ensure('present') } + it { is_expected.to contain_package("#{package_prefix}pear").with_ensure('present') } + it { is_expected.not_to contain_package("#{package_prefix}cli").with_ensure('present') } + it { is_expected.not_to contain_package("#{package_prefix}dev") } it { is_expected.not_to contain_package('php-pear') } + when 'RedHat', 'CentOS' + it { is_expected.to contain_package("#{package_prefix}common").with_ensure('present') } end end @@ -54,10 +73,59 @@ let(:params) { { fpm: false } } it { is_expected.not_to contain_class('php::fpm') } end + describe 'when composer is disabled' do let(:params) { { composer: false } } it { is_expected.not_to contain_class('php::composer') } end + + if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS' + describe 'when called with global option for rhscl_mode' do + describe 'when called with mode "remi"' do + scl_php_version = 'php56' + rhscl_mode = 'remi' + let(:pre_condition) do + "class {'::php::globals': + php_version => '#{scl_php_version}', + rhscl_mode => '#{rhscl_mode}' + }" + end + let(:params) do + { settings: { 'Date/date.timezone' => 'Europe/Berlin' } } + end + + it { is_expected.to contain_class('php::global') } + it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') } + it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') } + it { is_expected.to contain_php__config('global').with(file: "/opt/#{rhscl_mode}/#{scl_php_version}/root/etc/php.ini") } + it { is_expected.not_to contain_php__config('cli') } + + # see: https://github.com/voxpupuli/puppet-php/blob/master/lib/puppet/parser/functions/to_hash_settings.rb + it { is_expected.to contain_php__config__setting("/opt/#{rhscl_mode}/#{scl_php_version}/root/etc/php.ini: Date/date.timezone").with_value('Europe/Berlin') } + end + + describe 'when called with mode "rhscl"' do + scl_php_version = 'rh-php56' + rhscl_mode = 'rhscl' + let(:pre_condition) do + "class {'::php::globals': + php_version => '#{scl_php_version}', + rhscl_mode => '#{rhscl_mode}' + }" + end + let(:params) do + { settings: { 'Date/date.timezone' => 'Europe/Berlin' } } + end + + it { is_expected.to contain_class('php::global') } + it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') } + it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') } + it { is_expected.to contain_php__config('global').with(file: "/etc/opt/rh/#{scl_php_version}/php.ini") } + it { is_expected.to contain_php__config('cli').with(file: "/etc/opt/rh/#{scl_php_version}/php-cli.ini") } + it { is_expected.to contain_php__config__setting("/etc/opt/rh/#{scl_php_version}/php.ini: Date/date.timezone").with_value('Europe/Berlin') } + end + end + end end end end diff --git a/spec/defines/extension_rhscl_spec.rb b/spec/defines/extension_rhscl_spec.rb new file mode 100644 index 00000000..4ff40dd6 --- /dev/null +++ b/spec/defines/extension_rhscl_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'php::extension' do + on_supported_os.each do |os, facts| + next unless facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS' + + context "on #{os}" do + let :facts do + facts + end + + describe 'with rhscl_mode "remi" enabled: install one extension' do + scl_php_version = 'php56' + rhscl_mode = 'remi' + configs_root = "/opt/#{rhscl_mode}/#{scl_php_version}/root/etc" + + let(:pre_condition) do + "class {'::php::globals': + php_version => '#{scl_php_version}', + rhscl_mode => '#{rhscl_mode}' + }-> + class {'::php': + ensure => installed, + manage_repos => false, + fpm => false, + dev => true, # must be true since we are using the provider => pecl (option installs header files) + composer => false, + pear => true, + phpunit => false, + }" + end + + let(:title) { 'bz2' } + let(:params) do + { + package_name: 'common', + config_file_prefix: '20-', + settings: { 'Date/date.timezone' => 'Europe/Berlin' } + } + end + + it { is_expected.to contain_class('php::global') } + it { is_expected.to contain_class('php') } + it { is_expected.to contain_php__config('bz2').with(file: "#{configs_root}/php.d/20-bz2.ini") } + it { is_expected.to contain_php__config__setting("#{configs_root}/php.d/20-bz2.ini: Date/date.timezone").with_value('Europe/Berlin') } + end + end + end +end diff --git a/spec/defines/extension_spec.rb b/spec/defines/extension_spec.rb index cc5ae19a..21eb0a86 100644 --- a/spec/defines/extension_spec.rb +++ b/spec/defines/extension_spec.rb @@ -6,7 +6,6 @@ let :facts do facts end - let(:pre_condition) { 'include php' } unless facts[:osfamily] == 'Suse' || facts[:osfamily] == 'FreeBSD' # FIXME: something is wrong on these