From 6ff507750cf04914093a559e8ba111505e54fb3b Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 8 Oct 2016 21:09:14 +0100 Subject: [PATCH] Add support, tests and documentation for Gentoo --- README.md | 1 + manifests/init.pp | 2 +- manifests/install.pp | 27 ++++++++++---- manifests/params.pp | 1 + spec/classes/python_spec.rb | 72 +++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 28f82930..ba3d924a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ This module has been tested to work on the following systems. * EL 5 * EL 6 * EL 7 +* Gentoo (and Sabayon) * Suse 11 * Ubuntu 10.04 * Ubuntu 12.04 diff --git a/manifests/init.pp b/manifests/init.pp index c0aa6f23..8b3caf30 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -127,7 +127,7 @@ validate_bool($use_epel) # Module compatibility check - $compatible = [ 'Debian', 'RedHat', 'Suse' ] + $compatible = [ 'Debian', 'RedHat', 'Suse', 'Gentoo' ] if ! ($::osfamily in $compatible) { fail("Module is not compatible with ${::operatingsystem}") } diff --git a/manifests/install.pp b/manifests/install.pp index 57d50735..6d3cb7e3 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -25,6 +25,7 @@ 'RedHat' => "${python}-devel", 'Debian' => "${python}-dev", 'Suse' => "${python}-devel", + 'Gentoo' => undef, } $dev_ensure = $python::dev ? { @@ -63,9 +64,11 @@ require => Package['python'], } - package { 'python-dev': - ensure => $dev_ensure, - name => $pythondev, + if $pythondev { + package { 'python-dev': + ensure => $dev_ensure, + name => $pythondev, + } } # Install pip without pip, see https://pip.pypa.io/en/stable/installing/. @@ -175,9 +178,11 @@ require => Package['python'], } - package { 'python-dev': - ensure => $dev_ensure, - name => $pythondev, + if $pythondev { + package { 'python-dev': + ensure => $dev_ensure, + name => $pythondev, + } } if $::osfamily == 'RedHat' { @@ -198,19 +203,27 @@ } else { if $::lsbdistcodename == 'jessie' { $virtualenv_package = 'virtualenv' + } elsif $::osfamily == 'Gentoo' { + $virtualenv_package = 'virtualenv' } else { $virtualenv_package = 'python-virtualenv' } } if $::python::version =~ /^3/ { + $pip_category = undef $pip_package = 'python3-pip' + } elsif $::osfamily == 'Gentoo' { + $pip_category = 'dev-python' + $pip_package = 'pip' } else { + $pip_category = undef $pip_package = 'python-pip' } Package <| title == 'pip' |> { - name => $pip_package, + name => $pip_package, + category => $pip_category, } Package <| title == 'virtualenv' |> { diff --git a/manifests/params.pp b/manifests/params.pp index ee0a7b97..a64d0a38 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,6 +15,7 @@ 'RedHat' => ['3','27','33'], 'Debian' => ['3', '3.3', '2.7'], 'Suse' => [], + 'Gentoo' => ['2.7', '3.3', '3.4', '3.5'] } $use_epel = true diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index f494c33e..64ee412a 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -272,4 +272,76 @@ end end end + + context "on a Gentoo OS" do + let :facts do + { + :id => 'root', + :kernel => 'Linux', + :lsbdistcodename => 'n/a', + :osfamily => 'Gentoo', + :operatingsystem => 'Gentoo', + :concat_basedir => '/dne', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + } + end + it { is_expected.to contain_class("python::install") } + # Base debian packages. + it { is_expected.to contain_package("python") } + it { is_expected.to contain_package("pip").with({"category" => "dev-python"}) } + # Basic python packages (from pip) + it { is_expected.to contain_package("virtualenv")} + # Python::Dev + it { is_expected.not_to contain_package("python-dev") } + + describe "with manage_gunicorn" do + context "true" do + let (:params) {{ :manage_gunicorn => true }} + it { is_expected.to contain_package("gunicorn") } + end + context "empty args" do + #let (:params) {{ :manage_gunicorn => '' }} + it { is_expected.to contain_package("gunicorn") } + end + context "false" do + let (:params) {{ :manage_gunicorn => false }} + it {is_expected.not_to contain_package("gunicorn")} + end + end + + describe "with python::provider" do + context "pip" do + let (:params) {{ :provider => 'pip' }} + + it { is_expected.to contain_package("virtualenv").with( + 'provider' => 'pip' + )} + it { is_expected.to contain_package("pip").with( + 'provider' => 'pip' + )} + end + + # python::provider + context "default" do + let (:params) {{ :provider => '' }} + it { is_expected.to contain_package("virtualenv")} + it { is_expected.to contain_package("pip")} + + describe "with python::virtualenv" do + context "true" do + let (:params) {{ :provider => '', :virtualenv => 'present' }} + it { is_expected.to contain_package("virtualenv").with_ensure('present') } + end + end + + describe "with python::virtualenv" do + context "default/empty" do + let (:params) {{ :provider => '' }} + it { is_expected.to contain_package("virtualenv").with_ensure('absent') } + end + end + end + end + end + end