mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-22 19:58:03 +00:00
example code: python2 and python3 install modules, script generators and ctf vulnerability/challenge module wrappers
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'python class' do
|
||||
|
||||
context 'default parameters' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'python': }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'python class' do
|
||||
|
||||
context 'facts' do
|
||||
install_python = <<-EOS
|
||||
class { 'python' :
|
||||
version => 'system',
|
||||
pip => 'present',
|
||||
virtualenv => 'present',
|
||||
}
|
||||
EOS
|
||||
|
||||
fact_notices = <<-EOS
|
||||
notify{"pip_version: ${::pip_version}":}
|
||||
notify{"system_python_version: ${::system_python_version}":}
|
||||
notify{"python_version: ${::python_version}":}
|
||||
notify{"virtualenv_version: ${::virtualenv_version}":}
|
||||
EOS
|
||||
|
||||
it 'should output python facts when not installed' do
|
||||
apply_manifest(fact_notices, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/python_version: \S+/)
|
||||
expect(r.stdout).to match(/pip_version: \S+/)
|
||||
expect(r.stdout).to match(/virtualenv_version: \S+/)
|
||||
expect(r.stdout).to match(/system_python_version: \S+/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets up python' do
|
||||
apply_manifest(install_python, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should output python facts when installed' do
|
||||
apply_manifest(fact_notices, :catch_failures => true) do |r|
|
||||
expect(r.stdout).to match(/python_version: \S+/)
|
||||
expect(r.stdout).to match(/pip_version: \S+/)
|
||||
expect(r.stdout).to match(/virtualenv_version: \S+/)
|
||||
expect(r.stdout).to match(/system_python_version: \S+/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
centos-59-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-59-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
||||
@@ -0,0 +1,12 @@
|
||||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- dashboard
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
||||
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
centos-65-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-65-x64-vbox436-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
||||
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
debian-70rc1-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-70rc1-x64
|
||||
box : debian-70rc1-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
||||
@@ -0,0 +1,11 @@
|
||||
HOSTS:
|
||||
debian-73-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-7-amd64
|
||||
box : debian-73-x64-virtualbox-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
log_level: debug
|
||||
type: git
|
||||
@@ -0,0 +1,11 @@
|
||||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-server-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
||||
vagrant_ssh_port_random: true
|
||||
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-server-10044-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-10.04-amd64
|
||||
box : ubuntu-server-10044-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
||||
@@ -0,0 +1,10 @@
|
||||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
||||
@@ -0,0 +1,11 @@
|
||||
HOSTS:
|
||||
ubuntu-server-1404-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-14.04-amd64
|
||||
box : puppetlabs/ubuntu-14.04-64-nocm
|
||||
box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
log_level : debug
|
||||
type: git
|
||||
@@ -0,0 +1,34 @@
|
||||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'python class' do
|
||||
|
||||
context 'default parameters' do
|
||||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'python' :
|
||||
version => 'system',
|
||||
pip => 'present',
|
||||
virtualenv => 'present',
|
||||
}
|
||||
->
|
||||
python::virtualenv { 'venv' :
|
||||
ensure => 'present',
|
||||
systempkgs => false,
|
||||
venv_dir => '/opt/venv',
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
}
|
||||
->
|
||||
python::pip { 'rpyc' :
|
||||
ensure => '3.2.3',
|
||||
virtualenv => '/opt/venv',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,423 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'python', :type => :class do
|
||||
context "on Debian OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:lsbdistcodename => 'squeeze',
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
:concat_basedir => '/dne',
|
||||
}
|
||||
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("python-dev") }
|
||||
it { is_expected.to contain_package("pip") }
|
||||
# Basic python packages (from pip)
|
||||
it { is_expected.to contain_package("virtualenv")}
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "empty/default" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
|
||||
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 => true }}
|
||||
it { is_expected.to contain_package("virtualenv").with_ensure('present') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "without python::virtualenv" do
|
||||
context "default/empty" do
|
||||
let (:params) {{ :provider => '' }}
|
||||
it { is_expected.to contain_package("virtualenv").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "default/empty" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "EPEL does not exist for Debian" do
|
||||
context "default/empty" do
|
||||
it { should_not contain_class('epel') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "on a Fedora 22 OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'Fedora',
|
||||
:operatingsystemrelease => '22',
|
||||
:concat_basedir => '/dne',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
}
|
||||
end
|
||||
|
||||
describe "EPEL does not exist for Fedora" do
|
||||
context "default/empty" do
|
||||
it { should_not contain_class('epel') }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
context "on a Redhat 5 OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemrelease => '5',
|
||||
: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("python-dev").with_name("python-devel") }
|
||||
it { is_expected.to contain_package("python-dev").with_alias("python-devel") }
|
||||
it { is_expected.to contain_package("pip") }
|
||||
it { is_expected.to contain_package("pip").with_name('python-pip') }
|
||||
# Basic python packages (from pip)
|
||||
it { is_expected.to contain_package("virtualenv")}
|
||||
|
||||
describe "EPEL may be needed on EL" do
|
||||
context "default/empty" do
|
||||
it { should contain_class('epel') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "empty/default" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "default/empty" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "on a Redhat 6 OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemmajrelease => '6',
|
||||
: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") }
|
||||
it { is_expected.to contain_package("pip").with_name('python-pip') }
|
||||
end
|
||||
|
||||
context "on a Redhat 7 OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'RedHat',
|
||||
:operatingsystemmajrelease => '7',
|
||||
: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") }
|
||||
it { is_expected.to contain_package("pip").with_name('python2-pip') }
|
||||
end
|
||||
|
||||
context "on a SLES 11 SP3" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:lsbdistcodename => nil,
|
||||
:osfamily => 'Suse',
|
||||
:operatingsystem => 'SLES',
|
||||
:operatingsystemrelease => '11.3',
|
||||
: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 Suse packages.
|
||||
it { is_expected.to contain_package("python") }
|
||||
it { is_expected.to contain_package("python-dev").with_name("python-devel") }
|
||||
it { is_expected.to contain_package("python-dev").with_alias("python-devel") }
|
||||
it { is_expected.to contain_package("pip") }
|
||||
# Basic python packages (from pip)
|
||||
it { is_expected.to contain_package("virtualenv")}
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "empty/default" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
describe "with python::dev" do
|
||||
context "true" do
|
||||
let (:params) {{ :dev => 'present' }}
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('present') }
|
||||
end
|
||||
context "default/empty" do
|
||||
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "EPEL does not exist on Suse" do
|
||||
context "default/empty" do
|
||||
it { should_not contain_class('epel') }
|
||||
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
|
||||
@@ -0,0 +1,36 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'python::gunicorn', :type => :define do
|
||||
let(:title) { 'test-app' }
|
||||
context 'on Debian OS' do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:lsbdistcodename => 'squeeze',
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
:concat_basedir => '/dne',
|
||||
}
|
||||
end
|
||||
|
||||
describe 'test-app with default parameter values' do
|
||||
context 'configures test app with default parameter values' do
|
||||
let(:params) { { :dir => '/srv/testapp' } }
|
||||
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(/--log-level=error/) }
|
||||
end
|
||||
|
||||
context 'test-app with custom log level' do
|
||||
let(:params) { { :dir => '/srv/testapp', :log_level => 'info' } }
|
||||
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(/--log-level=info/) }
|
||||
end
|
||||
|
||||
context 'test-app with custom gunicorn preload arguments' do
|
||||
let(:params) { { :dir => '/srv/testapp', :args => ['--preload'] } }
|
||||
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(/--preload/) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,71 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'python::pip', :type => :define do
|
||||
let (:title) { 'rpyc' }
|
||||
context "on Debian OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:lsbdistcodename => 'squeeze',
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
:concat_basedir => '/dne',
|
||||
}
|
||||
end
|
||||
|
||||
describe "virtualenv as" do
|
||||
context "fails with non qualified path" do
|
||||
let (:params) {{ :virtualenv => "venv" }}
|
||||
it { is_expected.to raise_error(/"venv" is not an absolute path./) }
|
||||
end
|
||||
context "suceeds with qualified path" do
|
||||
let (:params) {{ :virtualenv => "/opt/venv" }}
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/opt/venv') }
|
||||
end
|
||||
context "defaults to system" do
|
||||
let (:params) {{ }}
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "proxy as" do
|
||||
context "defaults to empty" do
|
||||
let (:params) {{ }}
|
||||
it { should_not contain_exec("pip_install_rpyc").with_command(/--proxy/) }
|
||||
end
|
||||
context "does not add proxy to search command if set to latest and proxy is unset" do
|
||||
let (:params) {{ :ensure => 'latest' }}
|
||||
it { should_not contain_exec("pip_install_rpyc").with_command(/--proxy/) }
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").without_unless(/--proxy/) }
|
||||
end
|
||||
context "adds proxy to install command if proxy set" do
|
||||
let (:params) {{ :proxy => "http://my.proxy:3128" }}
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc ;}") }
|
||||
end
|
||||
context "adds proxy to search command if set to latest" do
|
||||
let (:params) {{ :proxy => "http://my.proxy:3128", :ensure => 'latest' }}
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --upgrade --proxy=http://my.proxy:3128 rpyc ;}") }
|
||||
it { is_expected.to contain_exec("pip_install_rpyc").with_unless('pip search --proxy=http://my.proxy:3128 rpyc | grep -i INSTALLED.*latest') }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'index as' do
|
||||
context 'defaults to empty' do
|
||||
let (:params) {{ }}
|
||||
it { should_not contain_exec('pip_install_rpyc').with_command(/--index-url/) }
|
||||
end
|
||||
context 'adds index to install command if index set' do
|
||||
let (:params) {{ :index => 'http://www.example.com/simple/' }}
|
||||
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --index-url=http://www.example.com/simple/ rpyc ;}") }
|
||||
end
|
||||
context 'adds index to search command if set to latest' do
|
||||
let (:params) {{ :index => 'http://www.example.com/simple/', :ensure => 'latest' }}
|
||||
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --upgrade --index-url=http://www.example.com/simple/ rpyc ;}") }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'python::pyvenv', :type => :define do
|
||||
let (:title) { '/opt/env' }
|
||||
let (:facts) do
|
||||
{
|
||||
:lsbdistcodename => 'jessie',
|
||||
:osfamily => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
it {
|
||||
is_expected.to contain_file( '/opt/env')
|
||||
is_expected.to contain_exec( "python_virtualenv_/opt/env").with_command("pyvenv --clear /opt/env")
|
||||
}
|
||||
|
||||
describe 'when ensure' do
|
||||
context "is absent" do
|
||||
let (:params) {{
|
||||
:ensure => 'absent'
|
||||
}}
|
||||
it {
|
||||
is_expected.to contain_file( '/opt/env').with_ensure('absent').with_purge( true)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'python::requirements', :type => :define do
|
||||
let (:title) { '/requirements.txt' }
|
||||
context "on Debian OS" do
|
||||
let :facts do
|
||||
{
|
||||
:id => 'root',
|
||||
:kernel => 'Linux',
|
||||
:lsbdistcodename => 'squeeze',
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
:operatingsystemrelease => '6',
|
||||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
|
||||
:concat_basedir => '/dne',
|
||||
}
|
||||
end
|
||||
|
||||
describe "requirements as" do
|
||||
context "/requirements.txt" do
|
||||
let (:params) {{ :requirements => "/requirements.txt" }}
|
||||
it { is_expected.to contain_file("/requirements.txt").with_mode('0644') }
|
||||
end
|
||||
context "/requirements.txt" do
|
||||
let (:params) {{ :requirements => "/requirements.txt", :manage_requirements => false }}
|
||||
it { is_expected.not_to contain_file("/requirements.txt") }
|
||||
end
|
||||
|
||||
describe "with owner" do
|
||||
context "bob:bob" do
|
||||
let (:params) {{
|
||||
:owner => 'bob',
|
||||
:group => 'bob'
|
||||
}}
|
||||
it do
|
||||
expect {
|
||||
is_expected.to compile
|
||||
}.to raise_error(/root user must be used when virtualenv is system/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with owner" do
|
||||
context "default" do
|
||||
it { is_expected.to contain_file("/requirements.txt").with_owner('root').with_group('root') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
||||
@@ -0,0 +1,18 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
|
||||
config.before :each do
|
||||
# Ensure that we don't accidentally cache facts and environment between
|
||||
# test cases. This requires each example group to explicitly load the
|
||||
# facts being exercised with something like
|
||||
# Facter.collection.loader.load(:ipaddress)
|
||||
Facter.clear
|
||||
Facter.clear_messages
|
||||
end
|
||||
config.default_facts = {
|
||||
:environment => 'rp_env',
|
||||
:operatingsystemmajrelease => '6',
|
||||
:osfamily => 'RedHat',
|
||||
}
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
require 'beaker-rspec'
|
||||
|
||||
UNSUPPORTED_PLATFORMS = [ 'windows' ]
|
||||
|
||||
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
|
||||
hosts.each do |host|
|
||||
if host.is_pe?
|
||||
install_pe
|
||||
else
|
||||
install_puppet
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Readable test descriptions
|
||||
c.formatter = :documentation
|
||||
|
||||
# Configure all nodes in nodeset
|
||||
c.before :suite do
|
||||
# Install module and dependencies
|
||||
hosts.each do |host|
|
||||
shell("rm -rf /etc/puppet/modules/python/")
|
||||
copy_module_to(host, :source => proj_root, :module_name => 'python')
|
||||
shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
|
||||
on host, puppet('module install puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
|
||||
on host, puppet('module install stahnma-epel'), { :acceptable_exit_codes => [0,1] }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Facter::Util::Fact do
|
||||
before {
|
||||
Facter.clear
|
||||
}
|
||||
|
||||
let(:pip_version_output) { <<-EOS
|
||||
pip 6.0.6 from /opt/boxen/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.6-py2.7.egg (python 2.7)
|
||||
EOS
|
||||
}
|
||||
|
||||
describe "pip_version" do
|
||||
context 'returns pip version when pip present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("pip").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("pip --version 2>&1").returns(pip_version_output)
|
||||
expect(Facter.value(:pip_version)).to eq("6.0.6")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when pip not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("pip").returns(false)
|
||||
expect(Facter.value(:pip_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,98 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Facter::Util::Fact do
|
||||
before {
|
||||
Facter.clear
|
||||
}
|
||||
|
||||
let(:python2_version_output) { <<-EOS
|
||||
Python 2.7.9
|
||||
EOS
|
||||
}
|
||||
let(:python3_version_output) { <<-EOS
|
||||
Python 3.3.0
|
||||
EOS
|
||||
}
|
||||
|
||||
describe "python_release" do
|
||||
context 'returns Python release when `python` present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python_release)).to eq("2.7")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python` not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(false)
|
||||
expect(Facter.value(:python_release)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "python2_release" do
|
||||
context 'returns Python 2 release when `python` is present and Python 2' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python2_release)).to eq('2.7')
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns Python 2 release when `python` is Python 3 and `python2` is present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python2 -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python2_release)).to eq('2.7')
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python` is Python 3 and `python2` is absent' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
|
||||
expect(Facter.value(:python2_release)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python2` and `python` are absent' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(false)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
|
||||
expect(Facter.value(:python2_release)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "python3_release" do
|
||||
context 'returns Python 3 release when `python3` present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python3").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python3 -V 2>&1").returns(python3_version_output)
|
||||
expect(Facter.value(:python3_release)).to eq("3.3")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python3` not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python3").returns(false)
|
||||
expect(Facter.value(:python3_release)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,98 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Facter::Util::Fact do
|
||||
before {
|
||||
Facter.clear
|
||||
}
|
||||
|
||||
let(:python2_version_output) { <<-EOS
|
||||
Python 2.7.9
|
||||
EOS
|
||||
}
|
||||
let(:python3_version_output) { <<-EOS
|
||||
Python 3.3.0
|
||||
EOS
|
||||
}
|
||||
|
||||
describe "python_version" do
|
||||
context 'returns Python version when `python` present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python_version)).to eq("2.7.9")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python` not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(false)
|
||||
expect(Facter.value(:python_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "python2_version" do
|
||||
context 'returns Python 2 version when `python` is present and Python 2' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python2_version)).to eq('2.7.9')
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns Python 2 version when `python` is Python 3 and `python2` is present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python2 -V 2>&1").returns(python2_version_output)
|
||||
expect(Facter.value(:python2_version)).to eq('2.7.9')
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python` is Python 3 and `python2` is absent' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
|
||||
expect(Facter.value(:python2_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python2` and `python` are absent' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python").returns(false)
|
||||
Facter::Util::Resolution.expects(:which).with("python2").returns(false)
|
||||
expect(Facter.value(:python2_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "python3_version" do
|
||||
context 'returns Python 3 version when `python3` present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python3").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("python3 -V 2>&1").returns(python3_version_output)
|
||||
expect(Facter.value(:python3_version)).to eq("3.3.0")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when `python3` not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("python3").returns(false)
|
||||
expect(Facter.value(:python3_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Facter::Util::Fact do
|
||||
before {
|
||||
Facter.clear
|
||||
}
|
||||
|
||||
let(:virtualenv_version_output) { <<-EOS
|
||||
12.0.7
|
||||
EOS
|
||||
}
|
||||
|
||||
describe "virtualenv_version" do
|
||||
context 'returns virtualenv version when virtualenv present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(true)
|
||||
Facter::Util::Resolution.expects(:exec).with("virtualenv --version 2>&1").returns(virtualenv_version_output)
|
||||
expect(Facter.value(:virtualenv_version)).to eq("12.0.7")
|
||||
end
|
||||
end
|
||||
|
||||
context 'returns nil when virtualenv not present' do
|
||||
it do
|
||||
Facter::Util::Resolution.stubs(:exec)
|
||||
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(false)
|
||||
expect(Facter.value(:virtualenv_version)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user