├── puppet
├── modules
│ ├── concat
│ │ ├── files
│ │ │ └── null
│ │ │ │ └── .gitignore
│ │ ├── spec
│ │ │ ├── fixtures
│ │ │ │ └── manifests
│ │ │ │ │ └── site.pp
│ │ │ └── spec_helper.rb
│ │ ├── Rakefile
│ │ ├── lib
│ │ │ └── facter
│ │ │ │ └── concat_basedir.rb
│ │ ├── Modulefile
│ │ ├── LICENSE
│ │ └── metadata.json
│ ├── stdlib
│ │ ├── tests
│ │ │ ├── init.pp
│ │ │ ├── has_ip_address.pp
│ │ │ ├── has_ip_network.pp
│ │ │ ├── file_line.pp
│ │ │ └── has_interface_with.pp
│ │ ├── .rspec
│ │ ├── .gitignore
│ │ ├── Rakefile
│ │ ├── spec
│ │ │ ├── spec.opts
│ │ │ ├── monkey_patches
│ │ │ │ ├── alias_should_to_must.rb
│ │ │ │ └── publicize_methods.rb
│ │ │ ├── unit
│ │ │ │ ├── puppet
│ │ │ │ │ ├── type
│ │ │ │ │ │ └── anchor_spec.rb
│ │ │ │ │ └── parser
│ │ │ │ │ │ └── functions
│ │ │ │ │ │ ├── zip_spec.rb
│ │ │ │ │ │ ├── strip_spec.rb
│ │ │ │ │ │ ├── chop_spec.rb
│ │ │ │ │ │ ├── chomp_spec.rb
│ │ │ │ │ │ ├── lstrip_spec.rb
│ │ │ │ │ │ ├── join_spec.rb
│ │ │ │ │ │ ├── reverse_spec.rb
│ │ │ │ │ │ ├── swapcase_spec.rb
│ │ │ │ │ │ ├── hash_spec.rb
│ │ │ │ │ │ ├── prefix_spec.rb
│ │ │ │ │ │ ├── capitalize_spec.rb
│ │ │ │ │ │ ├── grep_spec.rb
│ │ │ │ │ │ ├── reject_spec.rb
│ │ │ │ │ │ ├── delete_at_spec.rb
│ │ │ │ │ │ ├── parsejson_spec.rb
│ │ │ │ │ │ ├── max_spec.rb
│ │ │ │ │ │ ├── parseyaml_spec.rb
│ │ │ │ │ │ ├── min_spec.rb
│ │ │ │ │ │ ├── sort_spec.rb
│ │ │ │ │ │ ├── bool2num_spec.rb
│ │ │ │ │ │ ├── keys_spec.rb
│ │ │ │ │ │ ├── num2bool_spec.rb
│ │ │ │ │ │ ├── size_spec.rb
│ │ │ │ │ │ ├── abs_spec.rb
│ │ │ │ │ │ ├── empty_spec.rb
│ │ │ │ │ │ ├── upcase_spec.rb
│ │ │ │ │ │ ├── rstrip_spec.rb
│ │ │ │ │ │ ├── str2bool_spec.rb
│ │ │ │ │ │ ├── downcase_spec.rb
│ │ │ │ │ │ ├── squeeze_spec.rb
│ │ │ │ │ │ ├── unique_spec.rb
│ │ │ │ │ │ ├── member_spec.rb
│ │ │ │ │ │ ├── uriescape_spec.rb
│ │ │ │ │ │ ├── flatten_spec.rb
│ │ │ │ │ │ ├── shuffle_spec.rb
│ │ │ │ │ │ ├── time_spec.rb
│ │ │ │ │ │ ├── is_array_spec.rb
│ │ │ │ │ │ ├── is_hash_spec.rb
│ │ │ │ │ │ ├── strftime_spec.rb
│ │ │ │ │ │ ├── is_mac_address_spec.rb
│ │ │ │ │ │ ├── is_string_spec.rb
│ │ │ │ │ │ ├── is_float_spec.rb
│ │ │ │ │ │ ├── is_integer_spec.rb
│ │ │ │ │ │ ├── pick_spec.rb
│ │ │ │ │ │ ├── range_spec.rb
│ │ │ │ │ │ ├── has_ip_network_spec.rb
│ │ │ │ │ │ ├── values_spec.rb
│ │ │ │ │ │ ├── has_ip_address_spec.rb
│ │ │ │ │ │ ├── is_numeric_spec.rb
│ │ │ │ │ │ ├── is_ip_address_spec.rb
│ │ │ │ │ │ ├── type_spec.rb
│ │ │ │ │ │ ├── delete_spec.rb
│ │ │ │ │ │ ├── getvar_spec.rb
│ │ │ │ │ │ ├── validate_array_spec.rb
│ │ │ │ │ │ ├── fqdn_rotate_spec.rb
│ │ │ │ │ │ ├── validate_hash_spec.rb
│ │ │ │ │ │ ├── values_at_spec.rb
│ │ │ │ │ │ ├── has_key_spec.rb
│ │ │ │ │ │ └── join_keys_to_values_spec.rb
│ │ │ │ └── facter
│ │ │ │ │ ├── util
│ │ │ │ │ └── puppet_settings_spec.rb
│ │ │ │ │ └── root_home_spec.rb
│ │ │ ├── spec_helper.rb
│ │ │ └── functions
│ │ │ │ ├── ensure_packages_spec.rb
│ │ │ │ ├── defined_with_params_spec.rb
│ │ │ │ └── ensure_resource_spec.rb
│ │ ├── .gemfile
│ │ ├── .travis.yml
│ │ ├── Modulefile
│ │ ├── lib
│ │ │ ├── puppet
│ │ │ │ └── parser
│ │ │ │ │ └── functions
│ │ │ │ │ ├── max.rb
│ │ │ │ │ ├── min.rb
│ │ │ │ │ ├── is_hash.rb
│ │ │ │ │ ├── is_array.rb
│ │ │ │ │ ├── parseyaml.rb
│ │ │ │ │ ├── loadyaml.rb
│ │ │ │ │ ├── parsejson.rb
│ │ │ │ │ ├── keys.rb
│ │ │ │ │ ├── sort.rb
│ │ │ │ │ ├── is_float.rb
│ │ │ │ │ ├── is_integer.rb
│ │ │ │ │ ├── is_string.rb
│ │ │ │ │ ├── get_module_path.rb
│ │ │ │ │ ├── is_numeric.rb
│ │ │ │ │ ├── empty.rb
│ │ │ │ │ ├── reverse.rb
│ │ │ │ │ ├── reject.rb
│ │ │ │ │ ├── grep.rb
│ │ │ │ │ ├── is_mac_address.rb
│ │ │ │ │ ├── getvar.rb
│ │ │ │ │ ├── is_ip_address.rb
│ │ │ │ │ ├── flatten.rb
│ │ │ │ │ ├── has_ip_network.rb
│ │ │ │ │ ├── has_ip_address.rb
│ │ │ │ │ ├── rstrip.rb
│ │ │ │ │ ├── values.rb
│ │ │ │ │ ├── ensure_packages.rb
│ │ │ │ │ ├── has_key.rb
│ │ │ │ │ ├── lstrip.rb
│ │ │ │ │ ├── downcase.rb
│ │ │ │ │ ├── squeeze.rb
│ │ │ │ │ ├── strip.rb
│ │ │ │ │ ├── to_bytes.rb
│ │ │ │ │ ├── validate_hash.rb
│ │ │ │ │ ├── validate_array.rb
│ │ │ │ │ ├── upcase.rb
│ │ │ │ │ ├── hash.rb
│ │ │ │ │ ├── capitalize.rb
│ │ │ │ │ ├── swapcase.rb
│ │ │ │ │ ├── validate_string.rb
│ │ │ │ │ ├── abs.rb
│ │ │ │ │ ├── chomp.rb
│ │ │ │ │ ├── join.rb
│ │ │ │ │ ├── validate_bool.rb
│ │ │ │ │ ├── uriescape.rb
│ │ │ │ │ ├── pick.rb
│ │ │ │ │ ├── member.rb
│ │ │ │ │ ├── str2saltedsha512.rb
│ │ │ │ │ ├── merge.rb
│ │ │ │ │ ├── prefix.rb
│ │ │ │ │ ├── defined_with_params.rb
│ │ │ │ │ ├── chop.rb
│ │ │ │ │ ├── num2bool.rb
│ │ │ │ │ ├── time.rb
│ │ │ │ │ ├── unique.rb
│ │ │ │ │ ├── delete.rb
│ │ │ │ │ ├── type.rb
│ │ │ │ │ ├── shuffle.rb
│ │ │ │ │ ├── fqdn_rotate.rb
│ │ │ │ │ ├── str2bool.rb
│ │ │ │ │ ├── delete_at.rb
│ │ │ │ │ ├── size.rb
│ │ │ │ │ ├── ensure_resource.rb
│ │ │ │ │ ├── is_domain_name.rb
│ │ │ │ │ ├── has_interface_with.rb
│ │ │ │ │ ├── join_keys_to_values.rb
│ │ │ │ │ └── bool2num.rb
│ │ │ └── facter
│ │ │ │ ├── root_home.rb
│ │ │ │ ├── util
│ │ │ │ └── puppet_settings.rb
│ │ │ │ ├── puppet_vardir.rb
│ │ │ │ └── pe_version.rb
│ │ ├── manifests
│ │ │ ├── init.pp
│ │ │ └── stages.pp
│ │ ├── LICENSE
│ │ ├── RELEASE_PROCESS.markdown
│ │ └── README_DEVELOPER.markdown
│ ├── memcached
│ │ └── manifests
│ │ │ └── init.pp
│ ├── redis
│ │ └── manifests
│ │ │ └── init.pp
│ ├── beanstalkd
│ │ └── manifests
│ │ │ └── init.pp
│ ├── postgresql
│ │ ├── templates
│ │ │ └── pg_hba_rule.conf
│ │ ├── spec
│ │ │ ├── unit
│ │ │ │ ├── functions
│ │ │ │ │ └── postgresql_password_spec.rb
│ │ │ │ ├── classes
│ │ │ │ │ ├── client_spec.rb
│ │ │ │ │ ├── devel_spec.rb
│ │ │ │ │ ├── params_spec.rb
│ │ │ │ │ ├── contrib_spec.rb
│ │ │ │ │ ├── server_spec.rb
│ │ │ │ │ └── init_spec.rb
│ │ │ │ ├── defines
│ │ │ │ │ ├── role_spec.pp
│ │ │ │ │ ├── database_spec.rb
│ │ │ │ │ ├── tablespace_spec.pp
│ │ │ │ │ ├── database_user_spec.rb
│ │ │ │ │ ├── db_spec.rb
│ │ │ │ │ ├── psql_spec.rb
│ │ │ │ │ ├── database_grant_spec.rb
│ │ │ │ │ ├── pg_hba_spec.rb
│ │ │ │ │ └── validate_db_connection_spec.rb
│ │ │ │ └── facts
│ │ │ │ │ └── postgres_default_version_spec.rb
│ │ │ ├── system
│ │ │ │ ├── distros
│ │ │ │ │ ├── centos5_64
│ │ │ │ │ │ ├── non_default_pg_spec.rb
│ │ │ │ │ │ ├── system_default_pg_spec.rb
│ │ │ │ │ │ └── Vagrantfile
│ │ │ │ │ ├── centos6_64
│ │ │ │ │ │ ├── non_default_pg_spec.rb
│ │ │ │ │ │ ├── system_default_pg_spec.rb
│ │ │ │ │ │ └── Vagrantfile
│ │ │ │ │ └── ubuntu_lucid_64
│ │ │ │ │ │ ├── non_default_pg_spec.rb
│ │ │ │ │ │ ├── system_default_pg_spec.rb
│ │ │ │ │ │ └── Vagrantfile
│ │ │ │ ├── test_module
│ │ │ │ │ └── manifests
│ │ │ │ │ │ └── system_default
│ │ │ │ │ │ ├── test_pgconf_include.pp
│ │ │ │ │ │ ├── test_pgconf_include_cleanup.pp
│ │ │ │ │ │ ├── test_initdb.pp
│ │ │ │ │ │ ├── test_db.pp
│ │ │ │ │ │ ├── test_psql.pp
│ │ │ │ │ │ ├── test_ruby_psql.pp
│ │ │ │ │ │ ├── test_user.pp
│ │ │ │ │ │ └── test_grant_create.pp
│ │ │ │ └── base.pp
│ │ │ ├── support
│ │ │ │ ├── postgres_test_config.rb
│ │ │ │ ├── postgres_test_utils.rb
│ │ │ │ ├── vagrant_common.rb
│ │ │ │ └── shared_contexts
│ │ │ │ │ └── pg_vm_context.rb
│ │ │ ├── spec_helper.rb
│ │ │ └── classes
│ │ │ │ ├── postgresql_python_spec.rb
│ │ │ │ └── postgresql_java_spec.rb
│ │ ├── manifests
│ │ │ ├── pg_hba.pp
│ │ │ ├── python.pp
│ │ │ ├── devel.pp
│ │ │ ├── java.pp
│ │ │ ├── contrib.pp
│ │ │ ├── client.pp
│ │ │ ├── package_source
│ │ │ │ ├── yum_postgresql_org.pp
│ │ │ │ └── apt_postgresql_org.pp
│ │ │ └── pg_hba_rule.pp
│ │ └── lib
│ │ │ └── puppet
│ │ │ └── parser
│ │ │ └── functions
│ │ │ └── postgresql_password.rb
│ ├── bootstrap
│ │ └── manifests
│ │ │ └── init.pp
│ ├── composer
│ │ └── manifests
│ │ │ └── init.pp
│ ├── php55
│ │ └── manifests
│ │ │ └── init.pp
│ ├── other
│ │ └── manifests
│ │ │ └── init.pp
│ ├── phpmyadmin
│ │ └── manifests
│ │ │ └── init.pp
│ ├── mysql
│ │ └── manifests
│ │ │ └── init.pp
│ ├── apache
│ │ └── manifests
│ │ │ └── init.pp
│ └── php
│ │ └── manifests
│ │ └── init.pp
├── templates
│ ├── ondrej-php5-precise.list
│ └── vhost
├── scripts
│ ├── enable_remote_mysql_access.sql
│ └── enable_remote_mysql_access.sh
└── manifests
│ └── phpbase.pp
├── www
└── index.html
├── readme.md
└── .gitignore
/puppet/modules/concat/files/null/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/puppet/modules/concat/spec/fixtures/manifests/site.pp:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/tests/init.pp:
--------------------------------------------------------------------------------
1 | include stdlib
2 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --format
3 | progress
4 | --backtrace
5 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/.gitignore:
--------------------------------------------------------------------------------
1 | pkg/
2 | .DS_Store
3 | metadata.json
4 | coverage/
5 |
--------------------------------------------------------------------------------
/puppet/modules/concat/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'puppetlabs_spec_helper/module_spec_helper'
2 |
--------------------------------------------------------------------------------
/puppet/modules/concat/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'puppetlabs_spec_helper/rake_tasks'
3 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'puppetlabs_spec_helper/rake_tasks'
3 |
--------------------------------------------------------------------------------
/puppet/templates/ondrej-php5-precise.list:
--------------------------------------------------------------------------------
1 | deb http://ppa.launchpad.net/ondrej/php5/ubuntu precise main
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/spec.opts:
--------------------------------------------------------------------------------
1 | --format
2 | s
3 | --colour
4 | --loadby
5 | mtime
6 | --backtrace
7 |
--------------------------------------------------------------------------------
/puppet/modules/concat/lib/facter/concat_basedir.rb:
--------------------------------------------------------------------------------
1 | Facter.add("concat_basedir") do
2 | setcode do
3 | File.join(Puppet[:vardir],"concat")
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Работает!
5 |
6 |
7 |
8 | Работает
9 |
10 |
11 |
--------------------------------------------------------------------------------
/puppet/modules/memcached/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class memcached {
2 | package { 'memcached':
3 | ensure => present,
4 | require => Exec['apt-get update']
5 | }
6 | }
--------------------------------------------------------------------------------
/puppet/modules/redis/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class redis {
2 | package { 'redis-server':
3 | ensure => installed,
4 | require => Exec['apt-get update']
5 | }
6 | }
--------------------------------------------------------------------------------
/puppet/modules/beanstalkd/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class beanstalkd {
2 | package { 'beanstalkd':
3 | ensure => present,
4 | require => Exec['apt-get update']
5 | }
6 | }
--------------------------------------------------------------------------------
/puppet/modules/stdlib/tests/has_ip_address.pp:
--------------------------------------------------------------------------------
1 | include stdlib
2 | info("has_ip_address('192.168.1.256'):", has_ip_address('192.168.1.256'))
3 | info("has_ip_address('127.0.0.1'):", has_ip_address('127.0.0.1'))
4 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/tests/has_ip_network.pp:
--------------------------------------------------------------------------------
1 | include stdlib
2 | info("has_ip_network('127.0.0.0'):", has_ip_network('127.0.0.0'))
3 | info("has_ip_network('128.0.0.0'):", has_ip_network('128.0.0.0'))
4 |
5 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/.gemfile:
--------------------------------------------------------------------------------
1 | source :rubygems
2 |
3 | puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
4 | gem 'puppet', puppetversion
5 | gem 'puppetlabs_spec_helper', '>= 0.1.0'
6 |
--------------------------------------------------------------------------------
/puppet/scripts/enable_remote_mysql_access.sql:
--------------------------------------------------------------------------------
1 | GRANT ALL PRIVILEGES ON * . * TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
2 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/templates/pg_hba_rule.conf:
--------------------------------------------------------------------------------
1 |
2 | # Rule Name: <%=@name%>
3 | # Description: <%=@description%>
4 | # Order: <%=@order%>
5 | <%=@type%> <%=@database%> <%=@user%> <%=@address%> <%=@auth_method%> <%=@auth_option%>
6 |
--------------------------------------------------------------------------------
/puppet/scripts/enable_remote_mysql_access.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | mysql -uroot < "/vagrant/puppet/scripts/enable_remote_mysql_access.sql"
4 | sed -i "s/^bind-address/#bind-address/" /etc/mysql/my.cnf
5 | sudo service mysql restart
6 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb:
--------------------------------------------------------------------------------
1 | require 'rspec'
2 |
3 | class Object
4 | # This is necessary because the RAL has a 'should'
5 | # method.
6 | alias :must :should
7 | alias :must_not :should_not
8 | end
9 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/tests/file_line.pp:
--------------------------------------------------------------------------------
1 | # This is a simple smoke test
2 | # of the file_line resource type.
3 | file { '/tmp/dansfile':
4 | ensure => present
5 | }->
6 | file_line { 'dans_line':
7 | line => 'dan is awesome',
8 | path => '/tmp/dansfile',
9 | }
10 |
--------------------------------------------------------------------------------
/puppet/modules/bootstrap/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class bootstrap
2 | {
3 | group
4 | {
5 | "puppet":
6 | ensure => "present",
7 | }
8 |
9 | if $virtual == "virtualbox" and $fqdn == '' {
10 | $fqdn = "localhost"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/functions/postgresql_password_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql_password', :type => :puppet_function do
4 | it { should run.with_params('foo', 'bar').
5 | and_return('md596948aad3fcae80c08a35c9b5958cd89') }
6 | end
7 |
--------------------------------------------------------------------------------
/puppet/modules/concat/Modulefile:
--------------------------------------------------------------------------------
1 | name 'ripienaar-concat'
2 | version '0.2.0'
3 | source 'git://github.com/ripienaar/puppet-concat.git'
4 | author 'R.I.Pienaar'
5 | license 'Apache'
6 | summary 'Concat module'
7 | description 'Concat module'
8 | project_page 'http://github.com/ripienaar/puppet-concat'
9 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos5_64/non_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/non_default_postgres'
2 |
3 | describe "CentOS 5, 64-bit: non-default postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :centos5 }
6 | it_behaves_like :non_default_postgres
7 | end
8 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos6_64/non_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/non_default_postgres'
2 |
3 | describe "CentOS6, 64-bit: non-default postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :centos6 }
6 | it_behaves_like :non_default_postgres
7 | end
8 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'puppet'
4 |
5 | anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin")
6 |
7 | describe anchor do
8 | it "should stringify normally" do
9 | anchor.to_s.should == "Anchor[ntp::begin]"
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/ubuntu_lucid_64/non_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/non_default_postgres'
2 |
3 | describe "Ubuntu Lucid, 64-bit: non-default postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :lucid }
6 | it_behaves_like :non_default_postgres
7 | end
8 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/client_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::client', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | it { should include_class("postgresql::client") }
11 | end
12 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/devel_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::devel', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | it { should include_class("postgresql::devel") }
11 | end
12 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/params_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::params', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | it { should include_class("postgresql::params") }
11 | end
12 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/contrib_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::contrib', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | it { should include_class("postgresql::contrib") }
11 | end
12 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | rvm:
3 | - 1.8.7
4 | before_script:
5 | after_script:
6 | script: "rake spec_full"
7 | branches:
8 | only:
9 | - master
10 | env:
11 | - PUPPET_VERSION=2.7.13
12 | - PUPPET_VERSION=2.7.6
13 | - PUPPET_VERSION=2.6.9
14 | notifications:
15 | email: false
16 | gemfile: .gemfile
17 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos5_64/system_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/system_default_postgres'
2 |
3 | describe "CentOS 5, 64-bit: default system postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :centos5 }
6 | let(:service_name) { 'postgresql' }
7 | it_behaves_like :system_default_postgres
8 | end
9 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos6_64/system_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/system_default_postgres'
2 |
3 | describe "CentOS6, 64-bit: default system postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :centos6 }
6 | let(:service_name) { 'postgresql' }
7 | it_behaves_like :system_default_postgres
8 | end
9 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/role_spec.pp:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::role', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | it { should include_class("postgresql::params") }
14 | end
15 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/ubuntu_lucid_64/system_default_pg_spec.rb:
--------------------------------------------------------------------------------
1 | require 'support/shared_examples/system_default_postgres'
2 |
3 | describe "Ubuntu Lucid, 64-bit: default system postgres" do
4 | let(:vagrant_dir) { File.dirname(__FILE__) }
5 | let(:vm) { :lucid }
6 | let(:service_name) { 'postgresql-8.4' }
7 | it_behaves_like :system_default_postgres
8 | end
9 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/server_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::server', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | :concat_basedir => tmpfilename('server'),
9 | }
10 | end
11 | it { should include_class("postgresql::server") }
12 | end
13 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/database_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::database', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | it { should include_class("postgresql::params") }
14 | end
15 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/tablespace_spec.pp:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::tablespace', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | it { should include_class("postgresql::params") }
14 | end
15 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_pgconf_include.pp:
--------------------------------------------------------------------------------
1 | class postgresql_tests::system_default::test_pgconf_include {
2 |
3 | require postgresql::params
4 |
5 | $pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
6 |
7 | file { $pg_conf_include_file :
8 | content => 'max_connections = 123'
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_pgconf_include_cleanup.pp:
--------------------------------------------------------------------------------
1 | class postgresql_tests::system_default::test_pgconf_include_cleanup {
2 |
3 | require postgresql::params
4 |
5 | $pg_conf_include_file = "${postgresql::params::confdir}/postgresql_puppet_extras.conf"
6 |
7 | file { $pg_conf_include_file :
8 | ensure => absent
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Bitrix / Vagrant
2 |
3 | * 8888 - Apache
4 | * 8889 - MySQL
5 | * 5433 - PostgreSQL
6 |
7 | ### PHPmyAdmin
8 |
9 | http://localhost:8888/phpmyadmin
10 |
11 | ----
12 | ##### VM #####
13 |
14 | * OS - Ubuntu 12.04
15 | * Apache - 2.4.6
16 | * PHP - 5.5.4
17 | * MySQL - 5.5.32
18 | * PostgreSQL - 9.1
19 | * Beanstalkd - 1.4.6
20 | * Redis - 2.2.12
21 | * Memcached - 1.4.13
22 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/Modulefile:
--------------------------------------------------------------------------------
1 | name 'puppetlabs-stdlib'
2 | version '3.2.0'
3 | source 'git://github.com/puppetlabs/puppetlabs-stdlib'
4 | author 'puppetlabs'
5 | license 'Apache 2.0'
6 | summary 'Puppet Module Standard Library'
7 | description 'Standard Library for Puppet Modules'
8 | project_page 'https://github.com/puppetlabs/puppetlabs-stdlib'
9 |
10 | ## Add dependencies, if any:
11 | # dependency 'username/name', '>= 1.2.0'
12 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:max, :type => :rvalue, :doc => <<-EOS
3 | Returns the highest value of all arguments.
4 | Requires at least one argument.
5 | EOS
6 | ) do |args|
7 |
8 | raise(Puppet::ParseError, "max(): Wrong number of arguments " +
9 | "need at least one") if args.size == 0
10 |
11 | return args.max
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:min, :type => :rvalue, :doc => <<-EOS
3 | Returns the lowest value of all arguments.
4 | Requires at least one argument.
5 | EOS
6 | ) do |args|
7 |
8 | raise(Puppet::ParseError, "min(): Wrong number of arguments " +
9 | "need at least one") if args.size == 0
10 |
11 | return args.min
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos5_64/Vagrantfile:
--------------------------------------------------------------------------------
1 | require File.expand_path(File.join(__FILE__, '../../../../support/vagrant_common'))
2 |
3 | Vagrant::Config.run do |config|
4 |
5 | config.vm.define :centos5 do |vm_config|
6 | vm_config.vm.box = "centos-58-x64"
7 | vm_config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-58-x64.box"
8 | end
9 |
10 | apply_common_vagrant_config(config)
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/centos6_64/Vagrantfile:
--------------------------------------------------------------------------------
1 | require File.expand_path(File.join(__FILE__, '../../../../support/vagrant_common'))
2 |
3 | Vagrant::Config.run do |config|
4 |
5 | config.vm.define :centos6 do |vm_config|
6 | vm_config.vm.box = "cent63_64"
7 | vm_config.vm.box_url = "https://dl.dropbox.com/u/7225008/Vagrant/CentOS-6.3-x86_64-minimal.box"
8 | end
9 |
10 | apply_common_vagrant_config(config)
11 |
12 | end
13 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/distros/ubuntu_lucid_64/Vagrantfile:
--------------------------------------------------------------------------------
1 | require File.expand_path(File.join(__FILE__, '../../../../support/vagrant_common'))
2 |
3 | Vagrant::Config.run do |config|
4 |
5 | config.vm.define :lucid do |vm_config|
6 | # Test on 64 bit lucid
7 | vm_config.vm.box = "lucid64"
8 | vm_config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
9 | end
10 |
11 | apply_common_vagrant_config(config)
12 |
13 | end
14 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb:
--------------------------------------------------------------------------------
1 | # Some monkey-patching to allow us to test private methods.
2 | class Class
3 | def publicize_methods(*methods)
4 | saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods
5 |
6 | self.class_eval { public(*saved_private_instance_methods) }
7 | yield
8 | self.class_eval { private(*saved_private_instance_methods) }
9 | end
10 | end
11 |
12 |
--------------------------------------------------------------------------------
/puppet/templates/vhost:
--------------------------------------------------------------------------------
1 |
2 | DocumentRoot /var/www
3 |
4 |
5 | Options FollowSymLinks
6 | AllowOverride None
7 |
8 |
9 |
10 | Options Indexes FollowSymLinks MultiViews
11 | AllowOverride All
12 | Order allow,deny
13 | allow from all
14 |
15 |
16 | ErrorLog /var/log/apache2/error.log
17 | LogLevel warn
18 | CustomLog /var/log/apache2/access.log combined
19 |
20 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/database_user_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::database_user', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | let :params do
14 | {
15 | :password_hash => 'test',
16 | }
17 | end
18 | it { should include_class("postgresql::params") }
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/db_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::db', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | let :params do
14 | {
15 | :user => 'test',
16 | :password => 'test',
17 | }
18 | end
19 | it { should include_class("postgresql::params") }
20 | end
21 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/psql_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::psql', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | let :params do
14 | {
15 | :db => 'test',
16 | :unless => 'test',
17 | }
18 | end
19 | it { should include_class("postgresql::params") }
20 | end
21 |
--------------------------------------------------------------------------------
/puppet/modules/composer/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class composer
2 | {
3 |
4 | exec { 'install composer':
5 | command => 'curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin',
6 | require => Package['php5-cli'],
7 | unless => "[ -f /usr/local/bin/composer ]"
8 | }
9 |
10 | exec { 'global composer':
11 | command => "sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer",
12 | require => Exec['install composer'],
13 | unless => "[ -f /usr/local/bin/composer ]"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/manifests/init.pp:
--------------------------------------------------------------------------------
1 | # Class: stdlib
2 | #
3 | # This module manages stdlib. Most of stdlib's features are automatically
4 | # loaded by Puppet, but this class should be declared in order to use the
5 | # standardized run stages.
6 | #
7 | # Parameters: none
8 | #
9 | # Actions:
10 | #
11 | # Declares all other classes in the stdlib module. Currently, this consists
12 | # of stdlib::stages.
13 | #
14 | # Requires: nothing
15 | #
16 | class stdlib {
17 |
18 | class { 'stdlib::stages': }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/database_grant_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::database_grant', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | let :params do
14 | {
15 | :privilege => 'ALL',
16 | :db => 'test',
17 | :role => 'test',
18 | }
19 | end
20 | it { should include_class("postgresql::params") }
21 | end
22 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/pg_hba_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::pg_hba', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | :concat_basedir => tmpfilename('pg_hba'),
9 | }
10 | end
11 | let :title do
12 | 'test'
13 | end
14 | let :params do
15 | {
16 | :target => tmpfilename('pg_hba_target'),
17 | }
18 | end
19 | it { should include_class("postgresql::params") }
20 | end
21 |
--------------------------------------------------------------------------------
/puppet/modules/php55/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class php55
2 | {
3 |
4 | #PHP 5.5 setup
5 |
6 | package
7 | {
8 | "python-software-properties":
9 | ensure => present,
10 | require => Exec['php55 apt update']
11 | }
12 |
13 | #https://launchpad.net/~ondrej/+archive/php5
14 | exec
15 | {
16 | 'add php55 apt-repo':
17 | command => '/usr/bin/add-apt-repository ppa:ondrej/php5 -y',
18 | require => [Package['python-software-properties']],
19 | }
20 |
21 | exec { "php55 apt update":
22 | command => 'apt-get update',
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/pg_hba.pp:
--------------------------------------------------------------------------------
1 | # This resource manages a pg_hba file, collecting fragments of pg_hba_rules
2 | # to build up the final file.
3 | define postgresql::pg_hba(
4 | $target = $postgresql::params::pg_hba_conf_path,
5 | $owner = 0,
6 | $group = $postgresql::params::group
7 | ) {
8 | include postgresql::params
9 | include concat::setup
10 |
11 | # Collect file from fragments
12 | concat { $target:
13 | owner => $owner,
14 | group => $group,
15 | mode => '0640',
16 | warn => true,
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vagrant
2 | package.box
3 |
4 | # Numerous always-ignore extensions
5 | *.diff
6 | *.err
7 | *.orig
8 | *.log
9 | *.rej
10 | *.swo
11 | *.swp
12 | *.vi
13 | *~
14 | *.sass-cache
15 |
16 | # OS or Editor folders
17 | .DS_Store
18 | Thumbs.db
19 | .cache
20 | .project
21 | .settings
22 | .tmproj
23 | *.esproj
24 | nbproject
25 |
26 |
27 | # Dreamweaver added files
28 | _notes
29 | dwsync.xml
30 |
31 | # Komodo
32 | *.komodoproject
33 | .komodotools
34 |
35 | # Folders to ignore
36 | .hg
37 | .svn
38 | .CVS
39 | .idea
40 | composer.phar
41 | composer.lock
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the zip function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should raise a ParseError if there is less than 1 arguments" do
8 | lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError))
9 | end
10 |
11 | it "should be able to zip an array" do
12 | result = scope.function_zip([['1','2','3'],['4','5','6']])
13 | result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_hash.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_hash.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable passed to this function is a hash.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size != 1
13 |
14 | type = arguments[0]
15 |
16 | result = type.is_a?(Hash)
17 |
18 | return result
19 | end
20 | end
21 |
22 | # vim: set ts=2 sw=2 et :
23 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/python.pp:
--------------------------------------------------------------------------------
1 | # Class: postgresql::python
2 | # This class installs the python libs for postgresql.
3 | #
4 | # Parameters:
5 | # [*ensure*] - ensure state for package.
6 | # can be specified as version.
7 | # [*package_name*] - name of package
8 | class postgresql::python(
9 | $package_name = $postgresql::params::python_package_name,
10 | $package_ensure = 'present'
11 | ) inherits postgresql::params {
12 |
13 | package { 'python-psycopg2':
14 | ensure => $package_ensure,
15 | name => $package_name,
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_array.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable passed to this function is an array.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | type = arguments[0]
15 |
16 | result = type.is_a?(Array)
17 |
18 | return result
19 | end
20 | end
21 |
22 | # vim: set ts=2 sw=2 et :
23 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/defines/validate_db_connection_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::validate_db_connection', :type => :define do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | let :title do
11 | 'test'
12 | end
13 | let :params do
14 | {
15 | :database_host => 'test',
16 | :database_name => 'test',
17 | :database_password => 'test',
18 | :database_username => 'test',
19 | }
20 | end
21 | it { should include_class("postgresql::params") }
22 | end
23 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/facts/postgres_default_version_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgres_default_version', :type => :fact do
4 | it 'should handle redhat 6.0' do
5 | Facter.fact(:osfamily).stubs(:value).returns 'RedHat'
6 | Facter.fact(:operatingsystemrelease).stubs(:value).returns '6.0'
7 | Facter.fact(:postgres_default_version).value.should == '8.4'
8 | end
9 |
10 | it 'should return unknown if osfamily is unknown' do
11 | Facter.fact(:osfamily).expects(:value).returns 'test'
12 | Facter.fact(:postgres_default_version).value.should eq 'unknown'
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb:
--------------------------------------------------------------------------------
1 | #
2 | # parseyaml.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
7 | This function accepts YAML as a string and converts it into the correct
8 | Puppet structure.
9 | EOS
10 | ) do |arguments|
11 |
12 | if (arguments.size != 1) then
13 | raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+
14 | "given #{arguments.size} for 1")
15 | end
16 |
17 | require 'yaml'
18 |
19 | YAML::load(arguments[0])
20 |
21 | end
22 | end
23 |
24 | # vim: set ts=2 sw=2 et :
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4 | Load a YAML file containing an array, string, or hash, and return the data
5 | in the corresponding native data type.
6 |
7 | For example:
8 |
9 | $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
10 | ENDHEREDOC
11 |
12 | unless args.length == 1
13 | raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)")
14 | end
15 |
16 | YAML.load_file(args[0])
17 |
18 | end
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/puppet/modules/concat/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2012 R.I.Pienaar
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the strip function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 | it "should exist" do
7 | Puppet::Parser::Functions.function("strip").should == "function_strip"
8 | end
9 |
10 | it "should raise a ParseError if there is less than 1 arguments" do
11 | lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError))
12 | end
13 |
14 | it "should strip a string" do
15 | result = scope.function_strip([" ab cd "])
16 | result.should(eq('ab cd'))
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the chop function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("chop").should == "function_chop"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should chop the end of a string" do
16 | result = scope.function_chop(["asdf\n"])
17 | result.should(eq("asdf"))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb:
--------------------------------------------------------------------------------
1 | #
2 | # parsejson.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
7 | This function accepts JSON as a string and converts into the correct Puppet
8 | structure.
9 | EOS
10 | ) do |arguments|
11 |
12 | if (arguments.size != 1) then
13 | raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
14 | "given #{arguments.size} for 1")
15 | end
16 |
17 | json = arguments[0]
18 |
19 | # PSON is natively available in puppet
20 | PSON.load(json)
21 | end
22 | end
23 |
24 | # vim: set ts=2 sw=2 et :
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the chomp function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("chomp").should == "function_chomp"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should chomp the end of a string" do
16 | result = scope.function_chomp(["abc\n"])
17 | result.should(eq("abc"))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the lstrip function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should lstrip a string" do
16 | result = scope.function_lstrip([" asdf"])
17 | result.should(eq('asdf'))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb:
--------------------------------------------------------------------------------
1 | #
2 | # keys.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:keys, :type => :rvalue, :doc => <<-EOS
7 | Returns the keys of a hash as an array.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "keys(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | hash = arguments[0]
15 |
16 | unless hash.is_a?(Hash)
17 | raise(Puppet::ParseError, 'keys(): Requires hash to work with')
18 | end
19 |
20 | result = hash.keys
21 |
22 | return result
23 | end
24 | end
25 |
26 | # vim: set ts=2 sw=2 et :
27 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/lib/puppet/parser/functions/postgresql_password.rb:
--------------------------------------------------------------------------------
1 | # hash a string as mysql's "PASSWORD()" function would do it
2 | require 'digest/md5'
3 |
4 | module Puppet::Parser::Functions
5 | newfunction(:postgresql_password, :type => :rvalue, :doc => <<-EOS
6 | Returns the postgresql password hash from the clear text username / password.
7 | EOS
8 | ) do |args|
9 |
10 | raise(Puppet::ParseError, "postgresql_password(): Wrong number of arguments " +
11 | "given (#{args.size} for 2)") if args.size != 2
12 |
13 | username = args[0]
14 | password = args[1]
15 |
16 | 'md5' + Digest::MD5.hexdigest(password + username)
17 | end
18 | end
19 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb:
--------------------------------------------------------------------------------
1 | #
2 | # sort.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:sort, :type => :rvalue, :doc => <<-EOS
7 | Sorts strings and arrays lexically.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | value = arguments[0]
17 |
18 | if value.is_a?(Array) then
19 | value.sort
20 | elsif value.is_a?(String) then
21 | value.split("").sort.join("")
22 | end
23 |
24 | end
25 | end
26 |
27 | # vim: set ts=2 sw=2 et :
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the join function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("join").should == "function_join"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should join an array into a string" do
16 | result = scope.function_join([["a","b","c"], ":"])
17 | result.should(eq("a:b:c"))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the reverse function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("reverse").should == "function_reverse"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should reverse a string" do
16 | result = scope.function_reverse(["asdfghijkl"])
17 | result.should(eq('lkjihgfdsa'))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the swapcase function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("swapcase").should == "function_swapcase"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should swapcase a string" do
16 | result = scope.function_swapcase(["aaBBccDD"])
17 | result.should(eq('AAbbCCdd'))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the hash function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("hash").should == "function_hash"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should convert an array to a hash" do
16 | result = scope.function_hash([['a',1,'b',2,'c',3]])
17 | result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/devel.pp:
--------------------------------------------------------------------------------
1 | # Class: postgresql::devel
2 | #
3 | # This class installs postgresql development libraries
4 | #
5 | # Parameters:
6 | # [*package_name*] - The name of the postgresql development package.
7 | # [*package_ensure*] - The ensure value of the package
8 | #
9 | # Actions:
10 | #
11 | # Requires:
12 | #
13 | # Sample Usage:
14 | #
15 | class postgresql::devel(
16 | $package_name = $postgresql::params::devel_package_name,
17 | $package_ensure = 'present'
18 | ) inherits postgresql::params {
19 |
20 | package { 'postgresql-devel':
21 | ensure => $package_ensure,
22 | name => $package_name,
23 | tag => 'postgresql',
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/facter/root_home.rb:
--------------------------------------------------------------------------------
1 | # A facter fact to determine the root home directory.
2 | # This varies on PE supported platforms and may be
3 | # reconfigured by the end user.
4 |
5 | module Facter::Util::RootHome
6 | class << self
7 | def get_root_home
8 | root_ent = Facter::Util::Resolution.exec("getent passwd root")
9 | # The home directory is the sixth element in the passwd entry
10 | # If the platform doesn't have getent, root_ent will be nil and we should
11 | # return it straight away.
12 | root_ent && root_ent.split(":")[5]
13 | end
14 | end
15 | end
16 |
17 | Facter.add(:root_home) do
18 | setcode { Facter::Util::RootHome.get_root_home }
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the prefix function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("prefix").should == "function_prefix"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return a prefixed array" do
16 | result = scope.function_prefix([['a','b','c'], 'p'])
17 | result.should(eq(['pa','pb','pc']))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/java.pp:
--------------------------------------------------------------------------------
1 | # Class: postgresql::java
2 | #
3 | # This class installs the postgresql jdbc connector.
4 | #
5 | # Parameters:
6 | # [*package_name*] - The name of the postgresql java package.
7 | # [*package_ensure*] - The ensure value of the package.
8 | #
9 | # Actions:
10 | #
11 | # Requires:
12 | #
13 | # Sample Usage:
14 | #
15 | # class { 'postgresql::java': }
16 | #
17 | class postgresql::java (
18 | $package_name = $postgresql::params::java_package_name,
19 | $package_ensure = 'present'
20 | ) inherits postgresql::params {
21 |
22 | package { 'postgresql-jdbc':
23 | ensure => $package_ensure,
24 | name => $package_name,
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_float.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable passed to this function is a float.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | value = arguments[0]
17 |
18 | if value != value.to_f.to_s and !value.is_a? Float then
19 | return false
20 | else
21 | return true
22 | end
23 |
24 | end
25 | end
26 |
27 | # vim: set ts=2 sw=2 et :
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the capitalize function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should capitalize the beginning of a string" do
16 | result = scope.function_capitalize(["abc"])
17 | result.should(eq("Abc"))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the grep function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("grep").should == "function_grep"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should grep contents from an array" do
16 | result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
17 | result.should(eq(["aaabbb","bbbccc"]))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/contrib.pp:
--------------------------------------------------------------------------------
1 | # Class: postgresql::contrib
2 | #
3 | # This class installs the postgresql contrib package.
4 | #
5 | # Parameters:
6 | # [*package_name*] - The name of the postgresql contrib package.
7 | # [*package_ensure*] - The ensure value of the package.
8 | #
9 | # Actions:
10 | #
11 | # Requires:
12 | #
13 | # Sample Usage:
14 | #
15 | # class { 'postgresql::contrib': }
16 | #
17 | class postgresql::contrib (
18 | $package_name = $postgresql::params::contrib_package_name,
19 | $package_ensure = 'present'
20 | ) inherits postgresql::params {
21 |
22 | package { 'postgresql-contrib':
23 | ensure => $package_ensure,
24 | name => $package_name,
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_integer.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable returned to this string is an integer.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | value = arguments[0]
17 |
18 | if value != value.to_i.to_s and !value.is_a? Fixnum then
19 | return false
20 | else
21 | return true
22 | end
23 |
24 | end
25 | end
26 |
27 | # vim: set ts=2 sw=2 et :
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_string.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_string, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable passed to this function is a string.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | type = arguments[0]
15 |
16 | result = type.is_a?(String)
17 |
18 | if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
19 | return false
20 | end
21 |
22 | return result
23 | end
24 | end
25 |
26 | # vim: set ts=2 sw=2 et :
27 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'spec_helper'
4 |
5 | describe "the reject function" do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | it "should exist" do
9 | Puppet::Parser::Functions.function("reject").should == "function_reject"
10 | end
11 |
12 | it "should raise a ParseError if there is less than 1 arguments" do
13 | lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError))
14 | end
15 |
16 | it "should reject contents from an array" do
17 | result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"])
18 | result.should(eq(["1111", "dddeee"]))
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the delete_at function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("delete_at").should == "function_delete_at"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should delete an item at specified location from an array" do
16 | result = scope.function_delete_at([['a','b','c'],1])
17 | result.should(eq(['a','c']))
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT
3 | Returns the absolute path of the specified module for the current
4 | environment.
5 |
6 | Example:
7 | $module_path = get_module_path('stdlib')
8 | EOT
9 | ) do |args|
10 | raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
11 | if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
12 | module_path.path
13 | else
14 | raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}")
15 | end
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_numeric.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable passed to this function is a number.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | value = arguments[0]
17 |
18 | if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then
19 | return true
20 | else
21 | return false
22 | end
23 |
24 | end
25 | end
26 |
27 | # vim: set ts=2 sw=2 et :
28 |
--------------------------------------------------------------------------------
/puppet/modules/other/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class other
2 | {
3 | package
4 | {
5 | "curl":
6 | ensure => present,
7 | require => Exec['apt-get update']
8 | }
9 | package
10 | {
11 | "sqlite":
12 | ensure => present,
13 | require => Exec['apt-get update']
14 | }
15 | package
16 | {
17 | "git":
18 | ensure => present,
19 | require => Exec['apt-get update']
20 | }
21 | package
22 | {
23 | "mc":
24 | ensure => present,
25 | require => Exec['apt-get update']
26 | }
27 | package
28 | {
29 | "screen":
30 | ensure => present,
31 | require => Exec['apt-get update']
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2011 Puppet Labs Inc
2 |
3 | and some parts:
4 |
5 | Copyright (C) 2011 Krzysztof Wilczynski
6 |
7 | Puppet Labs can be contacted at: info@puppetlabs.com
8 |
9 | Licensed under the Apache License, Version 2.0 (the "License");
10 | you may not use this file except in compliance with the License.
11 | You may obtain a copy of the License at
12 |
13 | http://www.apache.org/licenses/LICENSE-2.0
14 |
15 | Unless required by applicable law or agreed to in writing, software
16 | distributed under the License is distributed on an "AS IS" BASIS,
17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 | See the License for the specific language governing permissions and
19 | limitations under the License.
20 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the parsejson function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should convert JSON to a data structure" do
16 | json = <<-EOS
17 | ["aaa","bbb","ccc"]
18 | EOS
19 | result = scope.function_parsejson([json])
20 | result.should(eq(['aaa','bbb','ccc']))
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb:
--------------------------------------------------------------------------------
1 | #
2 | # empty.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:empty, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the variable is empty.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, Hash, String].include?(klass)
18 | raise(Puppet::ParseError, 'empty(): Requires either ' +
19 | 'array, hash or string to work with')
20 | end
21 |
22 | result = value.empty?
23 |
24 | return result
25 | end
26 | end
27 |
28 | # vim: set ts=2 sw=2 et :
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb:
--------------------------------------------------------------------------------
1 | #
2 | # reverse.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
7 | Reverses the order of a string or array.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, String].include?(klass)
18 | raise(Puppet::ParseError, 'reverse(): Requires either ' +
19 | 'array or string to work with')
20 | end
21 |
22 | result = value.reverse
23 |
24 | return result
25 | end
26 | end
27 |
28 | # vim: set ts=2 sw=2 et :
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb:
--------------------------------------------------------------------------------
1 | #
2 | # reject.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args|
7 | This function searches through an array and rejects all elements that match
8 | the provided regular expression.
9 |
10 | *Examples:*
11 |
12 | reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
13 |
14 | Would return:
15 |
16 | ['bbb','ccc']
17 | EOS
18 |
19 | if (args.size != 2)
20 | raise Puppet::ParseError,
21 | "reject(): Wrong number of arguments given #{args.size} for 2"
22 | end
23 |
24 | ary = args[0]
25 | pattern = Regexp.new(args[1])
26 |
27 | ary.reject { |e| e =~ pattern }
28 | end
29 | end
30 |
31 | # vim: set ts=2 sw=2 et :
32 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe "the max function" do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | it "should exist" do
9 | Puppet::Parser::Functions.function("max").should == "function_max"
10 | end
11 |
12 | it "should raise a ParseError if there is less than 1 arguments" do
13 | lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
14 | end
15 |
16 | it "should be able to compare strings" do
17 | scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
18 | end
19 |
20 | it "should be able to compare numbers" do
21 | scope.function_max([6,8,4]).should(eq(8))
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the parseyaml function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should convert YAML to a data structure" do
16 | yaml = <<-EOS
17 | - aaa
18 | - bbb
19 | - ccc
20 | EOS
21 | result = scope.function_parseyaml([yaml])
22 | result.should(eq(['aaa','bbb','ccc']))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe "the min function" do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | it "should exist" do
9 | Puppet::Parser::Functions.function("min").should == "function_min"
10 | end
11 |
12 | it "should raise a ParseError if there is less than 1 arguments" do
13 | lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
14 | end
15 |
16 | it "should be able to compare strings" do
17 | scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
18 | end
19 |
20 | it "should be able to compare numbers" do
21 | scope.function_min([6,8,4]).should(eq(4))
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb:
--------------------------------------------------------------------------------
1 | module Facter
2 | module Util
3 | module PuppetSettings
4 | # This method is intended to provide a convenient way to evaluate a
5 | # Facter code block only if Puppet is loaded. This is to account for the
6 | # situation where the fact happens to be in the load path, but Puppet is
7 | # not loaded for whatever reason. Perhaps the user is simply running
8 | # facter without the --puppet flag and they happen to be working in a lib
9 | # directory of a module.
10 | def self.with_puppet
11 | begin
12 | Module.const_get("Puppet")
13 | rescue NameError
14 | nil
15 | else
16 | yield
17 | end
18 | end
19 | end
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the sort function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("sort").should == "function_sort"
9 | end
10 |
11 | it "should raise a ParseError if there is not 1 arguments" do
12 | lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should sort an array" do
16 | result = scope.function_sort([["a","c","b"]])
17 | result.should(eq(['a','b','c']))
18 | end
19 |
20 | it "should sort a string" do
21 | result = scope.function_sort(["acb"])
22 | result.should(eq('abc'))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/tests/has_interface_with.pp:
--------------------------------------------------------------------------------
1 | include stdlib
2 | info("has_interface_with('lo'):", has_interface_with('lo'))
3 | info("has_interface_with('loX'):", has_interface_with('loX'))
4 | info("has_interface_with('ipaddress', '127.0.0.1'):", has_interface_with('ipaddress', '127.0.0.1'))
5 | info("has_interface_with('ipaddress', '127.0.0.100'):", has_interface_with('ipaddress', '127.0.0.100'))
6 | info("has_interface_with('network', '127.0.0.0'):", has_interface_with('network', '127.0.0.0'))
7 | info("has_interface_with('network', '128.0.0.0'):", has_interface_with('network', '128.0.0.0'))
8 | info("has_interface_with('netmask', '255.0.0.0'):", has_interface_with('netmask', '255.0.0.0'))
9 | info("has_interface_with('netmask', '256.0.0.0'):", has_interface_with('netmask', '256.0.0.0'))
10 |
11 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/support/postgres_test_config.rb:
--------------------------------------------------------------------------------
1 | module PostgresTestConfig
2 | # Tests are pretty slow w/sahara, and when we destroy the VMs at the beginning
3 | # of the test run. This can be a hindrance for development but is very
4 | # valuable for final testing. This constant allows you to toggle between
5 | # strict testing and less strict testing--the latter being useful for
6 | # development purposes.
7 | HardCoreTesting = true
8 |
9 | # If this value is set to true, then each VM will be suspended after the tests
10 | # against it are completed. This will slow things down a ton during
11 | # iterative development, but will save a lot of system resources by not
12 | # keeping all of the VMs running at the same time.
13 | SuspendVMsAfterSuite = true
14 | end
15 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb:
--------------------------------------------------------------------------------
1 | #
2 | # grep.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:grep, :type => :rvalue, :doc => <<-EOS
7 | This function searches through an array and returns any elements that match
8 | the provided regular expression.
9 |
10 | *Examples:*
11 |
12 | grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
13 |
14 | Would return:
15 |
16 | ['aaa','aaaddd']
17 | EOS
18 | ) do |arguments|
19 |
20 | if (arguments.size != 2) then
21 | raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
22 | "given #{arguments.size} for 2")
23 | end
24 |
25 | a = arguments[0]
26 | pattern = Regexp.new(arguments[1])
27 |
28 | a.grep(pattern)
29 |
30 | end
31 | end
32 |
33 | # vim: set ts=2 sw=2 et :
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_mac_address.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the string passed to this function is a valid mac address.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | mac = arguments[0]
17 |
18 | if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then
19 | return true
20 | else
21 | return false
22 | end
23 |
24 | end
25 | end
26 |
27 | # vim: set ts=2 sw=2 et :
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the bool2num function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should convert true to 1" do
16 | result = scope.function_bool2num([true])
17 | result.should(eq(1))
18 | end
19 |
20 | it "should convert false to 0" do
21 | result = scope.function_bool2num([false])
22 | result.should(eq(0))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the keys function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("keys").should == "function_keys"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return an array of keys when given a hash" do
16 | result = scope.function_keys([{'a'=>1, 'b'=>2}])
17 | # =~ performs 'array with same elements' (set) matching
18 | # For more info see RSpec::Matchers::MatchArray
19 | result.should =~ ['a','b']
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the num2bool function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if 1" do
16 | result = scope.function_num2bool(["1"])
17 | result.should(be_true)
18 | end
19 |
20 | it "should return false if 0" do
21 | result = scope.function_num2bool(["0"])
22 | result.should(be_false)
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the size function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("size").should == "function_size"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return the size of a string" do
16 | result = scope.function_size(["asdf"])
17 | result.should(eq(4))
18 | end
19 |
20 | it "should return the size of an array" do
21 | result = scope.function_size([["a","b","c"]])
22 | result.should(eq(3))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/getvar.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4 | Lookup a variable in a remote namespace.
5 |
6 | For example:
7 |
8 | $foo = getvar('site::data::foo')
9 | # Equivalent to $foo = $site::data::foo
10 |
11 | This is useful if the namespace itself is stored in a string:
12 |
13 | $datalocation = 'site::data'
14 | $bar = getvar("${datalocation}::bar")
15 | # Equivalent to $bar = $site::data::bar
16 | ENDHEREDOC
17 |
18 | unless args.length == 1
19 | raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
20 | end
21 |
22 | self.lookupvar("#{args[0]}")
23 |
24 | end
25 |
26 | end
27 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_ip_address.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the string passed to this function is a valid IP address.
8 | EOS
9 | ) do |arguments|
10 |
11 | require 'ipaddr'
12 |
13 | if (arguments.size != 1) then
14 | raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
15 | "given #{arguments.size} for 1")
16 | end
17 |
18 | begin
19 | ip = IPAddr.new(arguments[0])
20 | rescue ArgumentError
21 | return false
22 | end
23 |
24 | if ip.ipv4? or ip.ipv6? then
25 | return true
26 | else
27 | return false
28 | end
29 | end
30 | end
31 |
32 | # vim: set ts=2 sw=2 et :
33 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe "the abs function" do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | it "should exist" do
9 | Puppet::Parser::Functions.function("abs").should == "function_abs"
10 | end
11 |
12 | it "should raise a ParseError if there is less than 1 arguments" do
13 | lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
14 | end
15 |
16 | it "should convert a negative number into a positive" do
17 | result = scope.function_abs(["-34"])
18 | result.should(eq(34))
19 | end
20 |
21 | it "should do nothing with a positive number" do
22 | result = scope.function_abs(["5678"])
23 | result.should(eq(5678))
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the empty function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 | it "should exist" do
7 | Puppet::Parser::Functions.function("empty").should == "function_empty"
8 | end
9 |
10 | it "should raise a ParseError if there is less than 1 arguments" do
11 | lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
12 | end
13 |
14 | it "should return a true for an empty string" do
15 | result = scope.function_empty([''])
16 | result.should(eq(true))
17 | end
18 |
19 | it "should return a false for a non-empty string" do
20 | result = scope.function_empty(['asdf'])
21 | result.should(eq(false))
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the upcase function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("upcase").should == "function_upcase"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should upcase a string" do
16 | result = scope.function_upcase(["abc"])
17 | result.should(eq('ABC'))
18 | end
19 |
20 | it "should do nothing if a string is already upcase" do
21 | result = scope.function_upcase(["ABC"])
22 | result.should(eq('ABC'))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'puppetlabs_spec_helper/module_spec_helper'
2 |
3 | RSpec.configure do |c|
4 | c.include PuppetlabsSpec::Files
5 |
6 | c.before :each do
7 | # Ensure that we don't accidentally cache facts and environment
8 | # between test cases.
9 | Facter::Util::Loader.any_instance.stubs(:load_all)
10 | Facter.clear
11 | Facter.clear_messages
12 |
13 | # Store any environment variables away to be restored later
14 | @old_env = {}
15 | ENV.each_key {|k| @old_env[k] = ENV[k]}
16 | end
17 |
18 | c.after :each do
19 | PuppetlabsSpec::Files.cleanup
20 | end
21 | end
22 |
23 | # Convenience helper for returning parameters for a type from the
24 | # catalogue.
25 | def param(type, title, param)
26 | param_value(catalogue, type, title, param)
27 | end
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the rstrip function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("rstrip").should == "function_rstrip"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should rstrip a string" do
16 | result = scope.function_rstrip(["asdf "])
17 | result.should(eq('asdf'))
18 | end
19 |
20 | it "should rstrip each element in an array" do
21 | result = scope.function_rstrip([["a ","b ", "c "]])
22 | result.should(eq(['a','b','c']))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the str2bool function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("str2bool").should == "function_str2bool"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should convert string 'true' to true" do
16 | result = scope.function_str2bool(["true"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should convert string 'undef' to false" do
21 | result = scope.function_str2bool(["undef"])
22 | result.should(eq(false))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/client.pp:
--------------------------------------------------------------------------------
1 | # Class: postgresql::client
2 | #
3 | # This class installs postgresql client software.
4 | #
5 | # *Note* don't forget to make sure to add any necessary yum or apt
6 | # repositories if specifying a custom version.
7 | #
8 | # Parameters:
9 | # [*package_name*] - The name of the postgresql client package.
10 | # [*ensure*] - the ensure parameter passed to the postgresql client package resource
11 | # Actions:
12 | #
13 | # Requires:
14 | #
15 | # Sample Usage:
16 | #
17 | class postgresql::client (
18 | $package_name = $postgresql::params::client_package_name,
19 | $package_ensure = 'present'
20 | ) inherits postgresql::params {
21 |
22 | package { 'postgresql-client':
23 | ensure => $package_ensure,
24 | name => $package_name,
25 | tag => 'postgresql',
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb:
--------------------------------------------------------------------------------
1 | #
2 | # flatten.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
7 | This function flattens any deeply nested arrays and returns a single flat array
8 | as a result.
9 |
10 | *Examples:*
11 |
12 | flatten(['a', ['b', ['c']]])
13 |
14 | Would return: ['a','b','c']
15 | EOS
16 | ) do |arguments|
17 |
18 | raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
19 | "given (#{arguments.size} for 1)") if arguments.size < 1
20 |
21 | array = arguments[0]
22 |
23 | unless array.is_a?(Array)
24 | raise(Puppet::ParseError, 'flatten(): Requires array to work with')
25 | end
26 |
27 | result = array.flatten
28 |
29 | return result
30 | end
31 | end
32 |
33 | # vim: set ts=2 sw=2 et :
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the downcase function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("downcase").should == "function_downcase"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should downcase a string" do
16 | result = scope.function_downcase(["ASFD"])
17 | result.should(eq("asfd"))
18 | end
19 |
20 | it "should do nothing to a string that is already downcase" do
21 | result = scope.function_downcase(["asdf asdf"])
22 | result.should(eq("asdf asdf"))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the squeeze function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("squeeze").should == "function_squeeze"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 2 arguments" do
12 | lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should squeeze a string" do
16 | result = scope.function_squeeze(["aaabbbbcccc"])
17 | result.should(eq('abc'))
18 | end
19 |
20 | it "should squeeze all elements in an array" do
21 | result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
22 | result.should(eq(['abc','df']))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/package_source/yum_postgresql_org.pp:
--------------------------------------------------------------------------------
1 | class postgresql::package_source::yum_postgresql_org(
2 | $version
3 | ) {
4 |
5 | $version_parts = split($version, '[.]')
6 | $package_version = "${version_parts[0]}${version_parts[1]}"
7 |
8 | file { "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}":
9 | source => 'puppet:///modules/postgresql/RPM-GPG-KEY-PGDG'
10 | } ->
11 |
12 | yumrepo { 'yum.postgresql.org':
13 | descr => "PostgreSQL ${version} \$releasever - \$basearch",
14 | baseurl => "http://yum.postgresql.org/${version}/redhat/rhel-\$releasever-\$basearch",
15 | enabled => 1,
16 | gpgcheck => 1,
17 | gpgkey => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-${package_version}",
18 | }
19 |
20 | Yumrepo['yum.postgresql.org'] -> Package<|tag == 'postgresql'|>
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the unique function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("unique").should == "function_unique"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should remove duplicate elements in a string" do
16 | result = scope.function_unique(["aabbc"])
17 | result.should(eq('abc'))
18 | end
19 |
20 | it "should remove duplicate elements in an array" do
21 | result = scope.function_unique([["a","a","b","b","c"]])
22 | result.should(eq(['a','b','c']))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the member function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("member").should == "function_member"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if a member is in an array" do
16 | result = scope.function_member([["a","b","c"], "a"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if a member is not in an array" do
21 | result = scope.function_member([["a","b","c"], "d"])
22 | result.should(eq(false))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb:
--------------------------------------------------------------------------------
1 | #
2 | # has_ip_network
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the client has an IP address within the requested network.
8 |
9 | This function iterates through the 'interfaces' fact and checks the
10 | 'network_IFACE' facts, performing a simple string comparision.
11 | EOS
12 | ) do |args|
13 |
14 | raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " +
15 | "given (#{args.size} for 1)") if args.size != 1
16 |
17 | Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
18 | unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
19 |
20 | function_has_interface_with(['network', args[0]])
21 |
22 | end
23 | end
24 |
25 | # vim:sts=2 sw=2
26 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb:
--------------------------------------------------------------------------------
1 | #
2 | # has_ip_address
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the client has the requested IP address on some interface.
8 |
9 | This function iterates through the 'interfaces' fact and checks the
10 | 'ipaddress_IFACE' facts, performing a simple string comparison.
11 | EOS
12 | ) do |args|
13 |
14 | raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " +
15 | "given (#{args.size} for 1)") if args.size != 1
16 |
17 | Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
18 | unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
19 |
20 | function_has_interface_with(['ipaddress', args[0]])
21 |
22 | end
23 | end
24 |
25 | # vim:sts=2 sw=2
26 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/package_source/apt_postgresql_org.pp:
--------------------------------------------------------------------------------
1 | class postgresql::package_source::apt_postgresql_org {
2 | # Here we have tried to replicate the instructions on the PostgreSQL site:
3 | #
4 | # http://www.postgresql.org/download/linux/debian/
5 | #
6 | apt::pin { 'apt.postgresql.org':
7 | originator => 'apt.postgresql.org',
8 | priority => 500,
9 | }->
10 | apt::source { 'apt.postgresql.org':
11 | location => 'http://apt.postgresql.org/pub/repos/apt/',
12 | release => "${::lsbdistcodename}-pgdg",
13 | repos => 'main',
14 | required_packages => 'pgdg-keyring',
15 | key => 'ACCC4CF8',
16 | key_source => 'http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc',
17 | include_src => false,
18 | }
19 |
20 | Apt::Source['apt.postgresql.org']->Package<|tag == 'postgresql'|>
21 | }
22 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb:
--------------------------------------------------------------------------------
1 | #
2 | # rstrip.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
7 | Strips leading spaces to the right of the string.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, String].include?(klass)
18 | raise(Puppet::ParseError, 'rstrip(): Requires either ' +
19 | 'array or string to work with')
20 | end
21 |
22 | if value.is_a?(Array)
23 | result = value.collect { |i| i.is_a?(String) ? i.rstrip : i }
24 | else
25 | result = value.rstrip
26 | end
27 |
28 | return result
29 | end
30 | end
31 |
32 | # vim: set ts=2 sw=2 et :
33 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb:
--------------------------------------------------------------------------------
1 | #
2 | # values.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:values, :type => :rvalue, :doc => <<-EOS
7 | When given a hash this function will return the values of that hash.
8 |
9 | *Examples:*
10 |
11 | $hash = {
12 | 'a' => 1,
13 | 'b' => 2,
14 | 'c' => 3,
15 | }
16 | values($hash)
17 |
18 | This example would return:
19 |
20 | [1,2,3]
21 | EOS
22 | ) do |arguments|
23 |
24 | raise(Puppet::ParseError, "values(): Wrong number of arguments " +
25 | "given (#{arguments.size} for 1)") if arguments.size < 1
26 |
27 | hash = arguments[0]
28 |
29 | unless hash.is_a?(Hash)
30 | raise(Puppet::ParseError, 'values(): Requires hash to work with')
31 | end
32 |
33 | result = hash.values
34 |
35 | return result
36 | end
37 | end
38 |
39 | # vim: set ts=2 sw=2 et :
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the uriescape function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should uriescape a string" do
16 | result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "])
17 | result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20'))
18 | end
19 |
20 | it "should do nothing if a string is already safe" do
21 | result = scope.function_uriescape(["ABCdef"])
22 | result.should(eq('ABCdef'))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the flatten function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 | it "should exist" do
7 | Puppet::Parser::Functions.function("flatten").should == "function_flatten"
8 | end
9 |
10 | it "should raise a ParseError if there is less than 1 arguments" do
11 | lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
12 | end
13 |
14 | it "should flatten a complex data structure" do
15 | result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
16 | result.should(eq(["a","b","c","d","e","f","g"]))
17 | end
18 |
19 | it "should do nothing to a structure that is already flat" do
20 | result = scope.function_flatten([["a","b","c","d"]])
21 | result.should(eq(["a","b","c","d"]))
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the shuffle function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("shuffle").should == "function_shuffle"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should shuffle a string and the result should be the same size" do
16 | result = scope.function_shuffle(["asdf"])
17 | result.size.should(eq(4))
18 | end
19 |
20 | it "should shuffle a string but the sorted contents should still be the same" do
21 | result = scope.function_shuffle(["adfs"])
22 | result.split("").sort.join("").should(eq("adfs"))
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb:
--------------------------------------------------------------------------------
1 | #
2 | # ensure_packages.rb
3 | #
4 | require 'puppet/parser/functions'
5 |
6 | module Puppet::Parser::Functions
7 | newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
8 | Takes a list of packages and only installs them if they don't already exist.
9 | EOS
10 | ) do |arguments|
11 |
12 | raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
13 | "given (#{arguments.size} for 1)") if arguments.size != 1
14 | raise(Puppet::ParseError, "ensure_packages(): Requires array " +
15 | "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array)
16 |
17 | Puppet::Parser::Functions.function(:ensure_resource)
18 | arguments[0].each { |package_name|
19 | function_ensure_resource(['package', package_name, {'ensure' => 'present' } ])
20 | }
21 | end
22 | end
23 |
24 | # vim: set ts=2 sw=2 et :
25 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_initdb.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_initdb {
20 |
21 | include postgresql::initdb
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4 | Determine if a hash has a certain key value.
5 |
6 | Example:
7 |
8 | $my_hash = {'key_one' => 'value_one'}
9 | if has_key($my_hash, 'key_two') {
10 | notice('we will not reach here')
11 | }
12 | if has_key($my_hash, 'key_one') {
13 | notice('this will be printed')
14 | }
15 |
16 | ENDHEREDOC
17 |
18 | unless args.length == 2
19 | raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
20 | end
21 | unless args[0].is_a?(Hash)
22 | raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
23 | end
24 | args[0].has_key?(args[1])
25 |
26 | end
27 |
28 | end
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the time function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("time").should == "function_time"
9 | end
10 |
11 | it "should raise a ParseError if there is more than 2 arguments" do
12 | lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return a number" do
16 | result = scope.function_time([])
17 | result.should be_an(Integer)
18 | end
19 |
20 | it "should be higher then when I wrote this test" do
21 | result = scope.function_time([])
22 | result.should(be > 1311953157)
23 | end
24 |
25 | it "should be lower then 1.5 trillion" do
26 | result = scope.function_time([])
27 | result.should(be < 1500000000)
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb:
--------------------------------------------------------------------------------
1 | #
2 | # lstrip.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
7 | Strips leading spaces to the left of a string.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, String].include?(klass)
18 | raise(Puppet::ParseError, 'lstrip(): Requires either ' +
19 | 'array or string to work with')
20 | end
21 |
22 | if value.is_a?(Array)
23 | # Numbers in Puppet are often string-encoded which is troublesome ...
24 | result = value.collect { |i| i.is_a?(String) ? i.lstrip : i }
25 | else
26 | result = value.lstrip
27 | end
28 |
29 | return result
30 | end
31 | end
32 |
33 | # vim: set ts=2 sw=2 et :
34 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/support/postgres_test_utils.rb:
--------------------------------------------------------------------------------
1 | module PostgresTestUtils
2 | def sudo_and_log(vm, cmd)
3 | @logger.debug("Running command: '#{cmd}'")
4 | result = ""
5 | @env.vms[vm].channel.sudo("cd /tmp && #{cmd}") do |ch, data|
6 | result << data
7 | @logger.debug(data)
8 | end
9 | result
10 | end
11 |
12 | def sudo_psql_and_log(vm, psql_cmd, user = 'postgres', extras = '')
13 | sudo_and_log(vm, "su #{user} -c 'psql #{psql_cmd}' #{extras}")
14 | end
15 |
16 | def sudo_psql_and_expect_result(vm, psql_cmd, expected, user = 'postgres')
17 | result = sudo_and_log(vm, "su #{user} -c 'psql -t #{psql_cmd}'")
18 |
19 | result.sub!(/stdin: is not a tty/, '')
20 | result.strip!
21 |
22 | ok = result == expected
23 | @logger.debug("Expected: #{expected} => #{ok ? 'OK' : 'BAD'}")
24 |
25 | if !ok
26 | raise "An unexpected result returned - result: '#{result}' / expected: '#{expected}'"
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_array function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_array").should == "function_is_array"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if passed an array" do
16 | result = scope.function_is_array([[1,2,3]])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if passed a hash" do
21 | result = scope.function_is_array([{'a'=>1}])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if passed a string" do
26 | result = scope.function_is_array(["asdf"])
27 | result.should(eq(false))
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_hash function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_hash").should == "function_is_hash"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if passed a hash" do
16 | result = scope.function_is_hash([{"a"=>1,"b"=>2}])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if passed an array" do
21 | result = scope.function_is_hash([["a","b"]])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if passed a string" do
26 | result = scope.function_is_hash(["asdf"])
27 | result.should(eq(false))
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/phpmyadmin/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class phpmyadmin
2 | {
3 | package
4 | {
5 | "phpmyadmin":
6 | ensure => present,
7 | require => [
8 | Exec['apt-get update'],
9 | Package["php5", "php5-mysql", "apache2"],
10 | ]
11 | }
12 |
13 | file
14 | {
15 | "/etc/apache2/conf-enabled/phpmyadmin.conf":
16 | ensure => link,
17 | target => "/etc/phpmyadmin/apache.conf",
18 | require => Package['apache2'],
19 | notify => Service["apache2"]
20 | }
21 |
22 | file
23 | {
24 | "/etc/phpmyadmin/config.inc.php":
25 | ensure => present,
26 | owner => root, group => root,
27 | mode => '0775',
28 | notify => Service['apache2'],
29 | source => "/vagrant/puppet/modules/phpmyadmin/templates/config.inc.php",
30 | require => [Package['phpmyadmin'], Package['apache2']],
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb:
--------------------------------------------------------------------------------
1 | #
2 | # downcase.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
7 | Converts the case of a string or all strings in an array to lower case.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, String].include?(klass)
18 | raise(Puppet::ParseError, 'downcase(): Requires either ' +
19 | 'array or string to work with')
20 | end
21 |
22 | if value.is_a?(Array)
23 | # Numbers in Puppet are often string-encoded which is troublesome ...
24 | result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
25 | else
26 | result = value.downcase
27 | end
28 |
29 | return result
30 | end
31 | end
32 |
33 | # vim: set ts=2 sw=2 et :
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb:
--------------------------------------------------------------------------------
1 | #
2 | # squeeze.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
7 | Returns a new string where runs of the same character that occur in this set are replaced by a single character.
8 | EOS
9 | ) do |arguments|
10 |
11 | if ((arguments.size != 2) and (arguments.size != 1)) then
12 | raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
13 | "given #{arguments.size} for 2 or 1")
14 | end
15 |
16 | item = arguments[0]
17 | squeezeval = arguments[1]
18 |
19 | if item.is_a?(Array) then
20 | if squeezeval then
21 | item.collect { |i| i.squeeze(squeezeval) }
22 | else
23 | item.collect { |i| i.squeeze }
24 | end
25 | else
26 | if squeezeval then
27 | item.squeeze(squeezeval)
28 | else
29 | item.squeeze
30 | end
31 | end
32 |
33 | end
34 | end
35 |
36 | # vim: set ts=2 sw=2 et :
37 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_db.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_db($db) {
20 |
21 | include postgresql::server
22 |
23 | postgresql::db { $db:
24 | user => $db,
25 | password => $db,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb:
--------------------------------------------------------------------------------
1 | #
2 | # strip.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:strip, :type => :rvalue, :doc => <<-EOS
7 | This function removes leading and trailing whitespace from a string or from
8 | every string inside an array.
9 |
10 | *Examples:*
11 |
12 | strip(" aaa ")
13 |
14 | Would result in: "aaa"
15 | EOS
16 | ) do |arguments|
17 |
18 | raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
19 | "given (#{arguments.size} for 1)") if arguments.size < 1
20 |
21 | value = arguments[0]
22 | klass = value.class
23 |
24 | unless [Array, String].include?(klass)
25 | raise(Puppet::ParseError, 'strip(): Requires either ' +
26 | 'array or string to work with')
27 | end
28 |
29 | if value.is_a?(Array)
30 | result = value.collect { |i| i.is_a?(String) ? i.strip : i }
31 | else
32 | result = value.strip
33 | end
34 |
35 | return result
36 | end
37 | end
38 |
39 | # vim: set ts=2 sw=2 et :
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the strftime function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("strftime").should == "function_strftime"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "using %s should be higher then when I wrote this test" do
16 | result = scope.function_strftime(["%s"])
17 | result.to_i.should(be > 1311953157)
18 | end
19 |
20 | it "using %s should be lower then 1.5 trillion" do
21 | result = scope.function_strftime(["%s"])
22 | result.to_i.should(be < 1500000000)
23 | end
24 |
25 | it "should return a date when given %Y-%m-%d" do
26 | result = scope.function_strftime(["%Y-%m-%d"])
27 | result.should =~ /^\d{4}-\d{2}-\d{2}$/
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS
3 | Converts the argument into bytes, for example 4 kB becomes 4096.
4 | Takes a single string value as an argument.
5 | EOS
6 | ) do |arguments|
7 |
8 | raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " +
9 | "given (#{arguments.size} for 1)") if arguments.size != 1
10 |
11 | arg = arguments[0]
12 |
13 | return arg if arg.is_a? Numeric
14 |
15 | value,prefix = */([0-9.e+-]*)\s*([^bB]?)/.match(arg)[1,2]
16 |
17 | value = value.to_f
18 | case prefix
19 | when '' then return value.to_i
20 | when 'k' then return (value*(1<<10)).to_i
21 | when 'M' then return (value*(1<<20)).to_i
22 | when 'G' then return (value*(1<<30)).to_i
23 | when 'T' then return (value*(1<<40)).to_i
24 | when 'E' then return (value*(1<<50)).to_i
25 | else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}"
26 | end
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args|
4 | Validate that all passed values are hash data structures. Abort catalog
5 | compilation if any value fails this check.
6 |
7 | The following values will pass:
8 |
9 | $my_hash = { 'one' => 'two' }
10 | validate_hash($my_hash)
11 |
12 | The following values will fail, causing compilation to abort:
13 |
14 | validate_hash(true)
15 | validate_hash('some_string')
16 | $undefined = undef
17 | validate_hash($undefined)
18 |
19 | ENDHEREDOC
20 |
21 | unless args.length > 0 then
22 | raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
23 | end
24 |
25 | args.each do |arg|
26 | unless arg.is_a?(Hash)
27 | raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}")
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/facter/puppet_vardir.rb:
--------------------------------------------------------------------------------
1 | # This facter fact returns the value of the Puppet vardir setting for the node
2 | # running puppet or puppet agent. The intent is to enable Puppet modules to
3 | # automatically have insight into a place where they can place variable data,
4 | # regardless of the node's platform.
5 | #
6 | # The value should be directly usable in a File resource path attribute.
7 |
8 |
9 | begin
10 | require 'facter/util/puppet_settings'
11 | rescue LoadError => e
12 | # puppet apply does not add module lib directories to the $LOAD_PATH (See
13 | # #4248). It should (in the future) but for the time being we need to be
14 | # defensive which is what this rescue block is doing.
15 | rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
16 | load rb_file if File.exists?(rb_file) or raise e
17 | end
18 |
19 | Facter.add(:puppet_vardir) do
20 | setcode do
21 | # This will be nil if Puppet is not available.
22 | Facter::Util::PuppetSettings.with_puppet do
23 | Puppet[:vardir]
24 | end
25 | end
26 | end
27 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args|
4 | Validate that all passed values are array data structures. Abort catalog
5 | compilation if any value fails this check.
6 |
7 | The following values will pass:
8 |
9 | $my_array = [ 'one', 'two' ]
10 | validate_array($my_array)
11 |
12 | The following values will fail, causing compilation to abort:
13 |
14 | validate_array(true)
15 | validate_array('some_string')
16 | $undefined = undef
17 | validate_array($undefined)
18 |
19 | ENDHEREDOC
20 |
21 | unless args.length > 0 then
22 | raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
23 | end
24 |
25 | args.each do |arg|
26 | unless arg.is_a?(Array)
27 | raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}")
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/manifests/stages.pp:
--------------------------------------------------------------------------------
1 | # Class: stdlib::stages
2 | #
3 | # This class manages a standard set of run stages for Puppet. It is managed by
4 | # the stdlib class, and should not be declared independently.
5 | #
6 | # The high level stages are (in order):
7 | #
8 | # * setup
9 | # * main
10 | # * runtime
11 | # * setup_infra
12 | # * deploy_infra
13 | # * setup_app
14 | # * deploy_app
15 | # * deploy
16 | #
17 | # Parameters: none
18 | #
19 | # Actions:
20 | #
21 | # Declares various run-stages for deploying infrastructure,
22 | # language runtimes, and application layers.
23 | #
24 | # Requires: nothing
25 | #
26 | # Sample Usage:
27 | #
28 | # node default {
29 | # include stdlib
30 | # class { java: stage => 'runtime' }
31 | # }
32 | #
33 | class stdlib::stages {
34 |
35 | stage { 'setup': before => Stage['main'] }
36 | stage { 'runtime': require => Stage['main'] }
37 | -> stage { 'setup_infra': }
38 | -> stage { 'deploy_infra': }
39 | -> stage { 'setup_app': }
40 | -> stage { 'deploy_app': }
41 | -> stage { 'deploy': }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_mac_address function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if a valid mac address" do
16 | result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if octets are out of range" do
21 | result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if not valid" do
26 | result = scope.function_is_mac_address(["not valid"])
27 | result.should(eq(false))
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb:
--------------------------------------------------------------------------------
1 | #
2 | # upcase.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:upcase, :type => :rvalue, :doc => <<-EOS
7 | Converts a string or an array of strings to uppercase.
8 |
9 | *Examples:*
10 |
11 | upcase("abcd")
12 |
13 | Will return:
14 |
15 | ASDF
16 | EOS
17 | ) do |arguments|
18 |
19 | raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
20 | "given (#{arguments.size} for 1)") if arguments.size < 1
21 |
22 | value = arguments[0]
23 | klass = value.class
24 |
25 | unless [Array, String].include?(klass)
26 | raise(Puppet::ParseError, 'upcase(): Requires either ' +
27 | 'array or string to work with')
28 | end
29 |
30 | if value.is_a?(Array)
31 | # Numbers in Puppet are often string-encoded which is troublesome ...
32 | result = value.collect { |i| i.is_a?(String) ? i.upcase : i }
33 | else
34 | result = value.upcase
35 | end
36 |
37 | return result
38 | end
39 | end
40 |
41 | # vim: set ts=2 sw=2 et :
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb:
--------------------------------------------------------------------------------
1 | #
2 | # hash.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:hash, :type => :rvalue, :doc => <<-EOS
7 | This function converts and array into a hash.
8 |
9 | *Examples:*
10 |
11 | hash(['a',1,'b',2,'c',3])
12 |
13 | Would return: {'a'=>1,'b'=>2,'c'=>3}
14 | EOS
15 | ) do |arguments|
16 |
17 | raise(Puppet::ParseError, "hash(): Wrong number of arguments " +
18 | "given (#{arguments.size} for 1)") if arguments.size < 1
19 |
20 | array = arguments[0]
21 |
22 | unless array.is_a?(Array)
23 | raise(Puppet::ParseError, 'hash(): Requires array to work with')
24 | end
25 |
26 | result = {}
27 |
28 | begin
29 | # This is to make it compatible with older version of Ruby ...
30 | array = array.flatten
31 | result = Hash[*array]
32 | rescue Exception
33 | raise(Puppet::ParseError, 'hash(): Unable to compute ' +
34 | 'hash from array given')
35 | end
36 |
37 | return result
38 | end
39 | end
40 |
41 | # vim: set ts=2 sw=2 et :
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb:
--------------------------------------------------------------------------------
1 | #
2 | # capitalize.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
7 | Capitalizes the first letter of a string or array of strings.
8 | Requires either a single string or an array as an input.
9 | EOS
10 | ) do |arguments|
11 |
12 | raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
13 | "given (#{arguments.size} for 1)") if arguments.size < 1
14 |
15 | value = arguments[0]
16 | klass = value.class
17 |
18 | unless [Array, String].include?(klass)
19 | raise(Puppet::ParseError, 'capitalize(): Requires either ' +
20 | 'array or string to work with')
21 | end
22 |
23 | if value.is_a?(Array)
24 | # Numbers in Puppet are often string-encoded which is troublesome ...
25 | result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
26 | else
27 | result = value.capitalize
28 | end
29 |
30 | return result
31 | end
32 | end
33 |
34 | # vim: set ts=2 sw=2 et :
35 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/swapcase.rb:
--------------------------------------------------------------------------------
1 | #
2 | # swapcase.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS
7 | This function will swap the existing case of a string.
8 |
9 | *Examples:*
10 |
11 | swapcase("aBcD")
12 |
13 | Would result in: "AbCd"
14 | EOS
15 | ) do |arguments|
16 |
17 | raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " +
18 | "given (#{arguments.size} for 1)") if arguments.size < 1
19 |
20 | value = arguments[0]
21 | klass = value.class
22 |
23 | unless [Array, String].include?(klass)
24 | raise(Puppet::ParseError, 'swapcase(): Requires either ' +
25 | 'array or string to work with')
26 | end
27 |
28 | if value.is_a?(Array)
29 | # Numbers in Puppet are often string-encoded which is troublesome ...
30 | result = value.collect { |i| i.is_a?(String) ? i.swapcase : i }
31 | else
32 | result = value.swapcase
33 | end
34 |
35 | return result
36 | end
37 | end
38 |
39 | # vim: set ts=2 sw=2 et :
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | dir = File.expand_path(File.dirname(__FILE__))
2 | $LOAD_PATH.unshift File.join(dir, 'lib')
3 |
4 | # Don't want puppet getting the command line arguments for rake or autotest
5 | ARGV.clear
6 |
7 | require 'puppet'
8 | require 'facter'
9 | require 'mocha'
10 | gem 'rspec', '>=2.0.0'
11 | require 'rspec/expectations'
12 |
13 | require 'puppetlabs_spec_helper/module_spec_helper'
14 |
15 | RSpec.configure do |config|
16 | # FIXME REVISIT - We may want to delegate to Facter like we do in
17 | # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
18 | # this behavior is a duplication of the spec_helper in Facter.
19 | config.before :each do
20 | # Ensure that we don't accidentally cache facts and environment between
21 | # test cases. This requires each example group to explicitly load the
22 | # facts being exercised with something like
23 | # Facter.collection.loader.load(:ipaddress)
24 | Facter::Util::Loader.any_instance.stubs(:load_all)
25 | Facter.clear
26 | Facter.clear_messages
27 | end
28 | end
29 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args|
4 | Validate that all passed values are string data structures. Abort catalog
5 | compilation if any value fails this check.
6 |
7 | The following values will pass:
8 |
9 | $my_string = "one two"
10 | validate_string($my_string, 'three')
11 |
12 | The following values will fail, causing compilation to abort:
13 |
14 | validate_string(true)
15 | validate_string([ 'some', 'array' ])
16 | $undefined = undef
17 | validate_string($undefined)
18 |
19 | ENDHEREDOC
20 |
21 | unless args.length > 0 then
22 | raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
23 | end
24 |
25 | args.each do |arg|
26 | unless arg.is_a?(String)
27 | raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
28 | end
29 | end
30 |
31 | end
32 |
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb:
--------------------------------------------------------------------------------
1 | #
2 | # abs.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:abs, :type => :rvalue, :doc => <<-EOS
7 | Returns the absolute value of a number, for example -34.56 becomes
8 | 34.56. Takes a single integer and float value as an argument.
9 | EOS
10 | ) do |arguments|
11 |
12 | raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
13 | "given (#{arguments.size} for 1)") if arguments.size < 1
14 |
15 | value = arguments[0]
16 |
17 | # Numbers in Puppet are often string-encoded which is troublesome ...
18 | if value.is_a?(String)
19 | if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
20 | value = value.to_f
21 | elsif value.match(/^-?\d+$/)
22 | value = value.to_i
23 | else
24 | raise(Puppet::ParseError, 'abs(): Requires float or ' +
25 | 'integer to work with')
26 | end
27 | end
28 |
29 | # We have numeric value to handle ...
30 | result = value.abs
31 |
32 | return result
33 | end
34 | end
35 |
36 | # vim: set ts=2 sw=2 et :
37 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb:
--------------------------------------------------------------------------------
1 | #
2 | # chomp.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
7 | Removes the record separator from the end of a string or an array of
8 | strings, for example `hello\n` becomes `hello`.
9 | Requires a single string or array as an input.
10 | EOS
11 | ) do |arguments|
12 |
13 | raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
14 | "given (#{arguments.size} for 1)") if arguments.size < 1
15 |
16 | value = arguments[0]
17 | klass = value.class
18 |
19 | unless [Array, String].include?(klass)
20 | raise(Puppet::ParseError, 'chomp(): Requires either ' +
21 | 'array or string to work with')
22 | end
23 |
24 | if value.is_a?(Array)
25 | # Numbers in Puppet are often string-encoded which is troublesome ...
26 | result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
27 | else
28 | result = value.chomp
29 | end
30 |
31 | return result
32 | end
33 | end
34 |
35 | # vim: set ts=2 sw=2 et :
36 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb:
--------------------------------------------------------------------------------
1 | #
2 | # join.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:join, :type => :rvalue, :doc => <<-EOS
7 | This function joins an array into a string using a seperator.
8 |
9 | *Examples:*
10 |
11 | join(['a','b','c'], ",")
12 |
13 | Would result in: "a,b,c"
14 | EOS
15 | ) do |arguments|
16 |
17 | # Technically we support two arguments but only first is mandatory ...
18 | raise(Puppet::ParseError, "join(): Wrong number of arguments " +
19 | "given (#{arguments.size} for 1)") if arguments.size < 1
20 |
21 | array = arguments[0]
22 |
23 | unless array.is_a?(Array)
24 | raise(Puppet::ParseError, 'join(): Requires array to work with')
25 | end
26 |
27 | suffix = arguments[1] if arguments[1]
28 |
29 | if suffix
30 | unless suffix.is_a?(String)
31 | raise(Puppet::ParseError, 'join(): Requires string to work with')
32 | end
33 | end
34 |
35 | result = suffix ? array.join(suffix) : array.join
36 |
37 | return result
38 | end
39 | end
40 |
41 | # vim: set ts=2 sw=2 et :
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/RELEASE_PROCESS.markdown:
--------------------------------------------------------------------------------
1 | # Contributing to this module #
2 |
3 | * Work in a topic branch
4 | * Submit a github pull request
5 | * Address any comments / feeback
6 | * Merge into master using --no-ff
7 |
8 | # Releasing this module #
9 |
10 | * This module adheres to http://semver.org/
11 | * Look for API breaking changes using git diff vX.Y.Z..master
12 | * If no API breaking changes, the minor version may be bumped.
13 | * If there are API breaking changes, the major version must be bumped.
14 | * If there are only small minor changes, the patch version may be bumped.
15 | * Update the CHANGELOG
16 | * Update the Modulefile
17 | * Commit these changes with a message along the lines of "Update CHANGELOG and
18 | Modulefile for release"
19 | * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the
20 | leading v as per semver.org)
21 | * Push the tag with git push origin --tags
22 | * Build a new package with puppet-module or the rake build task if it exists
23 | * Publish the new package to the forge
24 | * Bonus points for an announcement to puppet-users.
25 |
26 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 |
3 | newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args|
4 | Validate that all passed values are either true or false. Abort catalog
5 | compilation if any value fails this check.
6 |
7 | The following values will pass:
8 |
9 | $iamtrue = true
10 | validate_bool(true)
11 | validate_bool(true, true, false, $iamtrue)
12 |
13 | The following values will fail, causing compilation to abort:
14 |
15 | $some_array = [ true ]
16 | validate_bool("false")
17 | validate_bool("true")
18 | validate_bool($some_array)
19 |
20 | ENDHEREDOC
21 |
22 | unless args.length > 0 then
23 | raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
24 | end
25 |
26 | args.each do |arg|
27 | unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass))
28 | raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}")
29 | end
30 | end
31 |
32 | end
33 |
34 | end
35 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_string function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_string").should == "function_is_string"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if a string" do
16 | result = scope.function_is_string(["asdf"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if an integer" do
21 | result = scope.function_is_string(["3"])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if a float" do
26 | result = scope.function_is_string(["3.23"])
27 | result.should(eq(false))
28 | end
29 |
30 | it "should return false if an array" do
31 | result = scope.function_is_string([["a","b","c"]])
32 | result.should(eq(false))
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb:
--------------------------------------------------------------------------------
1 | #
2 | # uriescape.rb
3 | #
4 | require 'uri'
5 |
6 | module Puppet::Parser::Functions
7 | newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS
8 | Urlencodes a string or array of strings.
9 | Requires either a single string or an array as an input.
10 | EOS
11 | ) do |arguments|
12 |
13 | raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " +
14 | "given (#{arguments.size} for 1)") if arguments.size < 1
15 |
16 | value = arguments[0]
17 | klass = value.class
18 | unsafe = ":/?#[]@!$&'()*+,;= "
19 |
20 | unless [Array, String].include?(klass)
21 | raise(Puppet::ParseError, 'uriescape(): Requires either ' +
22 | 'array or string to work with')
23 | end
24 |
25 | if value.is_a?(Array)
26 | # Numbers in Puppet are often string-encoded which is troublesome ...
27 | result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i }
28 | else
29 | result = URI.escape(value,unsafe)
30 | end
31 |
32 | return result
33 | end
34 | end
35 |
36 | # vim: set ts=2 sw=2 et :
37 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/classes/postgresql_python_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::python', :type => :class do
4 |
5 | describe 'on a redhat based os' do
6 | let :facts do {
7 | :osfamily => 'RedHat',
8 | :postgres_default_version => 'foo',
9 | }
10 | end
11 | it { should contain_package('python-psycopg2').with(
12 | :name => 'python-psycopg2',
13 | :ensure => 'present'
14 | )}
15 | end
16 |
17 | describe 'on a debian based os' do
18 | let :facts do {
19 | :osfamily => 'Debian',
20 | :postgres_default_version => 'foo',
21 | }
22 | end
23 | it { should contain_package('python-psycopg2').with(
24 | :name => 'python-psycopg2',
25 | :ensure => 'present'
26 | )}
27 | end
28 |
29 | describe 'on any other os' do
30 | let :facts do {
31 | :osfamily => 'foo',
32 | :postgres_default_version => 'foo',
33 | }
34 | end
35 |
36 | it 'should fail' do
37 | expect { subject }.to raise_error(/Unsupported osfamily: foo/)
38 | end
39 | end
40 |
41 | end
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_float function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_float").should == "function_is_float"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if a float" do
16 | result = scope.function_is_float(["0.12"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if a string" do
21 | result = scope.function_is_float(["asdf"])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if an integer" do
26 | result = scope.function_is_float(["3"])
27 | result.should(eq(false))
28 | end
29 | it "should return true if a float is created from an arithmetical operation" do
30 | result = scope.function_is_float([3.2*2])
31 | result.should(eq(true))
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/manifests/phpbase.pp:
--------------------------------------------------------------------------------
1 | # Enable XDebug ("0" | "1")
2 | $use_xdebug = "0"
3 |
4 | # Default path
5 | Exec
6 | {
7 | path => ["/usr/bin", "/bin", "/usr/sbin", "/sbin", "/usr/local/bin", "/usr/local/sbin"]
8 | }
9 |
10 | exec
11 | {
12 | 'apt-get update':
13 | command => '/usr/bin/apt-get update',
14 | require => Exec['add php55 apt-repo']
15 | }
16 |
17 | include bootstrap
18 | include other #curl and sqlite
19 | include php55 #specific setup steps for 5.5
20 | include php
21 | include apache
22 | include mysql
23 | include phpmyadmin
24 | include beanstalkd
25 | include redis
26 | include memcached
27 | include composer
28 |
29 |
30 | class { 'postgresql::server':
31 | config_hash => {
32 | 'ip_mask_deny_postgres_user' => '0.0.0.0/32',
33 | 'ip_mask_allow_all_users' => '0.0.0.0/0',
34 | 'listen_addresses' => '*',
35 | 'manage_redhat_firewall' => true,
36 | 'postgres_password' => 'bitrix',
37 | },
38 | require => [Exec['apt-get update'], Package['python-software-properties']]
39 | }
40 |
41 | postgresql::db { 'database':
42 | user => 'root',
43 | password => 'root'
44 | }
45 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | require 'facter/util/puppet_settings'
3 |
4 | describe Facter::Util::PuppetSettings do
5 |
6 | describe "#with_puppet" do
7 | context "Without Puppet loaded" do
8 | before(:each) do
9 | Module.expects(:const_get).with("Puppet").raises(NameError)
10 | end
11 |
12 | it 'should be nil' do
13 | subject.with_puppet { Puppet[:vardir] }.should be_nil
14 | end
15 | it 'should not yield to the block' do
16 | Puppet.expects(:[]).never
17 | subject.with_puppet { Puppet[:vardir] }.should be_nil
18 | end
19 | end
20 | context "With Puppet loaded" do
21 | module Puppet; end
22 | let(:vardir) { "/var/lib/puppet" }
23 |
24 | before :each do
25 | Puppet.expects(:[]).with(:vardir).returns vardir
26 | end
27 | it 'should yield to the block' do
28 | subject.with_puppet { Puppet[:vardir] }
29 | end
30 | it 'should return the nodes vardir' do
31 | subject.with_puppet { Puppet[:vardir] }.should eq vardir
32 | end
33 | end
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_integer function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_integer").should == "function_is_integer"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if an integer" do
16 | result = scope.function_is_integer(["3"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return false if a float" do
21 | result = scope.function_is_integer(["3.2"])
22 | result.should(eq(false))
23 | end
24 |
25 | it "should return false if a string" do
26 | result = scope.function_is_integer(["asdf"])
27 | result.should(eq(false))
28 | end
29 |
30 | it "should return true if an integer is created from an arithmetical operation" do
31 | result = scope.function_is_integer([3*2])
32 | result.should(eq(true))
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the pick function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("pick").should == "function_pick"
9 | end
10 |
11 | it 'should return the correct value' do
12 | scope.function_pick(['first', 'second']).should == 'first'
13 | end
14 |
15 | it 'should return the correct value if the first value is empty' do
16 | scope.function_pick(['', 'second']).should == 'second'
17 | end
18 |
19 | it 'should remove empty string values' do
20 | scope.function_pick(['', 'first']).should == 'first'
21 | end
22 |
23 | it 'should remove :undef values' do
24 | scope.function_pick([:undef, 'first']).should == 'first'
25 | end
26 |
27 | it 'should remove :undefined values' do
28 | scope.function_pick([:undefined, 'first']).should == 'first'
29 | end
30 |
31 | it 'should error if no values are passed' do
32 | expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./)
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:pick, :type => :rvalue, :doc => <<-EOS
3 |
4 | This function is similar to a coalesce function in SQL in that it will return
5 | the first value in a list of values that is not undefined or an empty string
6 | (two things in Puppet that will return a boolean false value). Typically,
7 | this function is used to check for a value in the Puppet Dashboard/Enterprise
8 | Console, and failover to a default value like the following:
9 |
10 | $real_jenkins_version = pick($::jenkins_version, '1.449')
11 |
12 | The value of $real_jenkins_version will first look for a top-scope variable
13 | called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
14 | Enterprise Console are brought into Puppet as top-scope variables), and,
15 | failing that, will use a default value of 1.449.
16 |
17 | EOS
18 | ) do |args|
19 | args = args.compact
20 | args.delete(:undef)
21 | args.delete(:undefined)
22 | args.delete("")
23 | if args[0].to_s.empty? then
24 | fail "Must provide non empty value."
25 | else
26 | return args[0]
27 | end
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the range function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("range").should == "function_range"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return a letter range" do
16 | result = scope.function_range(["a","d"])
17 | result.should(eq(['a','b','c','d']))
18 | end
19 |
20 | it "should return a number range" do
21 | result = scope.function_range(["1","4"])
22 | result.should(eq([1,2,3,4]))
23 | end
24 |
25 | it "should work with padded hostname like strings" do
26 | expected = ("host01".."host10").to_a
27 | scope.function_range(["host01","host10"]).should eq expected
28 | end
29 |
30 | it "should coerce zero padded digits to integers" do
31 | expected = (0..10).to_a
32 | scope.function_range(["00", "10"]).should eq expected
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_psql.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_psql($command = $title, $unless) {
20 |
21 | include postgresql::server
22 |
23 | postgresql::psql { $title:
24 | db => 'postgres',
25 | user => 'postgres',
26 | command => $command,
27 | unless => $unless,
28 | require => Class['postgresql::server'],
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe Puppet::Parser::Functions.function(:has_ip_network) do
5 |
6 | let(:scope) do
7 | PuppetlabsSpec::PuppetInternals.scope
8 | end
9 |
10 | subject do
11 | function_name = Puppet::Parser::Functions.function(:has_ip_network)
12 | scope.method(function_name)
13 | end
14 |
15 | context "On Linux Systems" do
16 | before :each do
17 | scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
18 | scope.stubs(:lookupvar).with('network').returns(:undefined)
19 | scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0')
20 | scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1')
21 | end
22 |
23 | it 'should have primary network (10.0.2.0)' do
24 | subject.call(['10.0.2.0']).should be_true
25 | end
26 |
27 | it 'should have loopback network (127.0.0.0)' do
28 | subject.call(['127.0.0.1']).should be_true
29 | end
30 |
31 | it 'should not have other network' do
32 | subject.call(['192.168.1.0']).should be_false
33 | end
34 | end
35 | end
36 |
37 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the values function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("values").should == "function_values"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return values from a hash" do
16 | result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
17 | # =~ is the RSpec::Matchers::MatchArray matcher.
18 | # A.K.A. "array with same elements" (multiset) matching
19 | result.should =~ %w{ 1 2 3 }
20 | end
21 |
22 | it "should return a multiset" do
23 | result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
24 | result.should =~ %w{ 1 3 3 }
25 | result.should_not =~ %w{ 1 3 }
26 | end
27 |
28 | it "should raise a ParseError unless a Hash is provided" do
29 | lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError))
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_ruby_psql.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_ruby_psql($command = $title, $unless) {
20 |
21 | include postgresql::server
22 |
23 | postgresql_psql { $title:
24 | db => 'postgres',
25 | psql_user => 'postgres',
26 | command => $command,
27 | unless => $unless,
28 | require => Class['postgresql::server'],
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/member.rb:
--------------------------------------------------------------------------------
1 | #
2 | # member.rb
3 | #
4 |
5 | # TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
6 | # TODO(Krzysztof Wilczynski): Support for strings and hashes too ...
7 |
8 | module Puppet::Parser::Functions
9 | newfunction(:member, :type => :rvalue, :doc => <<-EOS
10 | This function determines if a variable is a member of an array.
11 |
12 | *Examples:*
13 |
14 | member(['a','b'], 'b')
15 |
16 | Would return: true
17 |
18 | member(['a','b'], 'c')
19 |
20 | Would return: false
21 | EOS
22 | ) do |arguments|
23 |
24 | raise(Puppet::ParseError, "member(): Wrong number of arguments " +
25 | "given (#{arguments.size} for 2)") if arguments.size < 2
26 |
27 | array = arguments[0]
28 |
29 | unless array.is_a?(Array)
30 | raise(Puppet::ParseError, 'member(): Requires array to work with')
31 | end
32 |
33 | item = arguments[1]
34 |
35 | raise(Puppet::ParseError, 'member(): You must provide item ' +
36 | 'to search for within array given') if item.empty?
37 |
38 | result = array.include?(item)
39 |
40 | return result
41 | end
42 | end
43 |
44 | # vim: set ts=2 sw=2 et :
45 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb:
--------------------------------------------------------------------------------
1 | #
2 | # str2saltedsha512.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-EOS
7 | This converts a string to a salted-SHA512 password hash (which is used for
8 | OS X versions >= 10.7). Given any simple string, you will get a hex version
9 | of a salted-SHA512 password hash that can be inserted into your Puppet
10 | manifests as a valid password attribute.
11 | EOS
12 | ) do |arguments|
13 | require 'digest/sha2'
14 |
15 | raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " +
16 | "passed (#{arguments.size} but we require 1)") if arguments.size != 1
17 |
18 | password = arguments[0]
19 |
20 | unless password.is_a?(String)
21 | raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' +
22 | "String argument, you passed: #{password.class}")
23 | end
24 |
25 | seedint = rand(2**31 - 1)
26 | seedstring = Array(seedint).pack("L")
27 | saltedpass = Digest::SHA512.digest(seedstring + password)
28 | (seedstring + saltedpass).unpack('H*')[0]
29 | end
30 | end
31 |
32 | # vim: set ts=2 sw=2 et :
33 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/unit/classes/init_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql', :type => :class do
4 | let :facts do
5 | {
6 | :postgres_default_version => '8.4',
7 | :osfamily => 'Debian',
8 | }
9 | end
10 | it { should include_class("postgresql") }
11 |
12 | context 'support override params' do
13 | let(:params) {{
14 | :version => '8.4',
15 | :manage_package_repo => true,
16 | :package_source => '',
17 | :locale => 'en_NG',
18 | :charset => 'UTF8',
19 | :datadir => '/srv/pgdata',
20 | :confdir => '/opt/pg/etc',
21 | :bindir => '/opt/pg/bin',
22 | :client_package_name => 'my-postgresql-client',
23 | :server_package_name => 'my-postgresql-server',
24 | :contrib_package_name => 'my-postgresql-contrib',
25 | :devel_package_name => 'my-postgresql-devel',
26 | :java_package_name => 'my-postgresql-java',
27 | :service_name => 'my-postgresql',
28 | :user => 'my-postgresql',
29 | :group => 'my-postgresql',
30 | :run_initdb => true,
31 | }}
32 |
33 | it { should include_class("postgresql") }
34 | it { should include_class("postgresql::params") }
35 | end
36 | end
37 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/support/vagrant_common.rb:
--------------------------------------------------------------------------------
1 | def apply_common_vagrant_config(config)
2 | # Resolve DNS via NAT
3 | config.vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
4 |
5 | # Share the various required modules
6 | # TODO: it would be better to install this via the puppet module tool
7 | config.vm.share_folder "puppetlabs-stdlib-module", "/usr/share/puppet/modules/stdlib", "../../../../../puppetlabs-stdlib"
8 | config.vm.share_folder "puppetlabs-apt-module", "/usr/share/puppet/modules/apt", "../../../../../puppetlabs-apt"
9 | config.vm.share_folder "ripienaar-concat-module", "/usr/share/puppet/modules/concat", "../../../../../puppet-concat"
10 |
11 | # Share the postgressql module
12 | config.vm.share_folder "puppet-postgresql-module", "/usr/share/puppet/modules/postgresql", "../../../.."
13 |
14 | # Share the module of test classes
15 | config.vm.share_folder "puppet-postgresql-tests", "/usr/share/puppet/modules/postgresql_tests", "../../test_module"
16 |
17 | # Provision with a base puppet config just so we don't have to repeat the puppet user/group
18 | config.vm.provision :puppet do |puppet|
19 | puppet.manifests_path = "../../"
20 | puppet.manifest_file = "base.pp"
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
3 | Merges two or more hashes together and returns the resulting hash.
4 |
5 | For example:
6 |
7 | $hash1 = {'one' => 1, 'two', => 2}
8 | $hash2 = {'two' => 'dos', 'three', => 'tres'}
9 | $merged_hash = merge($hash1, $hash2)
10 | # The resulting hash is equivalent to:
11 | # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
12 |
13 | When there is a duplicate key, the key in the rightmost hash will "win."
14 |
15 | ENDHEREDOC
16 |
17 | if args.length < 2
18 | raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)")
19 | end
20 |
21 | # The hash we accumulate into
22 | accumulator = Hash.new
23 | # Merge into the accumulator hash
24 | args.each do |arg|
25 | unless arg.is_a?(Hash)
26 | raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments"
27 | end
28 | accumulator.merge!(arg)
29 | end
30 | # Return the fully merged hash
31 | accumulator
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb:
--------------------------------------------------------------------------------
1 | #
2 | # prefix.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
7 | This function applies a prefix to all elements in an array.
8 |
9 | *Examles:*
10 |
11 | prefix(['a','b','c'], 'p')
12 |
13 | Will return: ['pa','pb','pc']
14 | EOS
15 | ) do |arguments|
16 |
17 | # Technically we support two arguments but only first is mandatory ...
18 | raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
19 | "given (#{arguments.size} for 1)") if arguments.size < 1
20 |
21 | array = arguments[0]
22 |
23 | unless array.is_a?(Array)
24 | raise(Puppet::ParseError, 'prefix(): Requires array to work with')
25 | end
26 |
27 | prefix = arguments[1] if arguments[1]
28 |
29 | if prefix
30 | unless prefix.is_a?(String)
31 | raise(Puppet::ParseError, 'prefix(): Requires string to work with')
32 | end
33 | end
34 |
35 | # Turn everything into string same as join would do ...
36 | result = array.collect do |i|
37 | i = i.to_s
38 | prefix ? prefix + i : i
39 | end
40 |
41 | return result
42 | end
43 | end
44 |
45 | # vim: set ts=2 sw=2 et :
46 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb:
--------------------------------------------------------------------------------
1 | # Test whether a given class or definition is defined
2 | require 'puppet/parser/functions'
3 |
4 | Puppet::Parser::Functions.newfunction(:defined_with_params,
5 | :type => :rvalue,
6 | :doc => <<-'ENDOFDOC'
7 | Takes a resource reference and an optional hash of attributes.
8 |
9 | Returns true if a resource with the specified attributes has already been added
10 | to the catalog, and false otherwise.
11 |
12 | user { 'dan':
13 | ensure => present,
14 | }
15 |
16 | if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
17 | user { 'dan': ensure => present, }
18 | }
19 | ENDOFDOC
20 | ) do |vals|
21 | reference, params = vals
22 | raise(ArgumentError, 'Must specify a reference') unless reference
23 | if (! params) || params == ''
24 | params = {}
25 | end
26 | ret = false
27 | if resource = findresource(reference.to_s)
28 | matches = params.collect do |key, value|
29 | resource[key] == value
30 | end
31 | ret = params.empty? || !matches.include?(false)
32 | end
33 | Puppet.debug("Resource #{reference} was not determined to be defined")
34 | ret
35 | end
36 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb:
--------------------------------------------------------------------------------
1 | #
2 | # chop.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
7 | Returns a new string with the last character removed. If the string ends
8 | with `\r\n`, both characters are removed. Applying chop to an empty
9 | string returns an empty string. If you wish to merely remove record
10 | separators then you should use the `chomp` function.
11 | Requires a string or array of strings as input.
12 | EOS
13 | ) do |arguments|
14 |
15 | raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
16 | "given (#{arguments.size} for 1)") if arguments.size < 1
17 |
18 | value = arguments[0]
19 | klass = value.class
20 |
21 | unless [Array, String].include?(klass)
22 | raise(Puppet::ParseError, 'chop(): Requires either an ' +
23 | 'array or string to work with')
24 | end
25 |
26 | if value.is_a?(Array)
27 | # Numbers in Puppet are often string-encoded which is troublesome ...
28 | result = value.collect { |i| i.is_a?(String) ? i.chop : i }
29 | else
30 | result = value.chop
31 | end
32 |
33 | return result
34 | end
35 | end
36 |
37 | # vim: set ts=2 sw=2 et :
38 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/base.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | group {'puppet':
20 | ensure => present,
21 | }
22 |
23 | user {'puppet':
24 | ensure => present,
25 | gid => 'puppet',
26 | }
27 |
28 | file { '/etc/sudoers.d':
29 | ensure => directory,
30 | mode => '0750',
31 | owner => root,
32 | group => root,
33 | }
34 |
35 | file {'/etc/sudoers.d/puppet_postgresql_tests':
36 | ensure => file,
37 | content => 'vagrant ALL=(ALL) ALL',
38 | mode => '0440',
39 | owner => root,
40 | group => root,
41 | }
42 |
--------------------------------------------------------------------------------
/puppet/modules/concat/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "license": "Apache",
3 | "dependencies": [
4 |
5 | ],
6 | "source": "git://github.com/ripienaar/puppet-concat.git",
7 | "version": "0.2.0",
8 | "description": "Concat module",
9 | "summary": "Concat module",
10 | "types": [
11 |
12 | ],
13 | "author": "R.I.Pienaar",
14 | "project_page": "http://github.com/ripienaar/puppet-concat",
15 | "name": "ripienaar-concat",
16 | "checksums": {
17 | "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e",
18 | "files/concatfragments.sh": "256169ee61115a6b717b2844d2ea3128",
19 | "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
20 | "README.markdown": "f0605b99afffca3404e3a80dad951d83",
21 | "Modulefile": "5dda7c51425f5337bb3234993a52732f",
22 | "CHANGELOG": "543eb3beeb56b779171cff6e181a44cb",
23 | "manifests/fragment.pp": "a34e1f60a31bb64eaed22745f70a88e7",
24 | "lib/facter/concat_basedir.rb": "f2e991697602ffb3e80e0cc9efa37f3a",
25 | "spec/defines/init_spec.rb": "cc8ce111b49906033dbf7837bc6b7495",
26 | "manifests/init.pp": "7128c08a525c7bbc8bf4a721ad1c4f3e",
27 | "manifests/setup.pp": "dc8d30bc47d447c5bde2c390fd34541c",
28 | "Rakefile": "f37e6131fe7de9a49b09d31596f5fbf1",
29 | "LICENSE": "f5a76685d453424cd63dde1535811cf0"
30 | }
31 | }
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_user.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_user($user, $password) {
20 |
21 | include postgresql::server
22 |
23 | # Since we are not testing pg_hba or any of that, make a local user for ident auth
24 | user { $user:
25 | ensure => present,
26 | }
27 |
28 | postgresql::database_user { $user:
29 | password_hash => postgresql_password($user, $password),
30 | require => [ Class['postgresql::server'],
31 | User[$user] ],
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb:
--------------------------------------------------------------------------------
1 | #
2 | # num2bool.rb
3 | #
4 |
5 | # TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
6 |
7 | module Puppet::Parser::Functions
8 | newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
9 | This function converts a number into a true boolean. Zero becomes false. Numbers
10 | higher then 0 become true.
11 | EOS
12 | ) do |arguments|
13 |
14 | raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
15 | "given (#{arguments.size} for 1)") if arguments.size < 1
16 |
17 | number = arguments[0]
18 |
19 | # Only numbers allowed ...
20 | unless number.match(/^\-?\d+$/)
21 | raise(Puppet::ParseError, 'num2bool(): Requires integer to work with')
22 | end
23 |
24 | result = case number
25 | when /^0$/
26 | false
27 | when /^\-?\d+$/
28 | # Numbers in Puppet are often string-encoded which is troublesome ...
29 | number = number.to_i
30 | # We yield true for any positive number and false otherwise ...
31 | number > 0 ? true : false
32 | else
33 | raise(Puppet::ParseError, 'num2bool(): Unknown numeric format given')
34 | end
35 |
36 | return result
37 | end
38 | end
39 |
40 | # vim: set ts=2 sw=2 et :
41 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb:
--------------------------------------------------------------------------------
1 | #
2 | # time.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:time, :type => :rvalue, :doc => <<-EOS
7 | This function will return the current time since epoch as an integer.
8 |
9 | *Examples:*
10 |
11 | time()
12 |
13 | Will return something like: 1311972653
14 | EOS
15 | ) do |arguments|
16 |
17 | # The Time Zone argument is optional ...
18 | time_zone = arguments[0] if arguments[0]
19 |
20 | if (arguments.size != 0) and (arguments.size != 1) then
21 | raise(Puppet::ParseError, "time(): Wrong number of arguments "+
22 | "given #{arguments.size} for 0 or 1")
23 | end
24 |
25 | time = Time.new
26 |
27 | # There is probably a better way to handle Time Zone ...
28 | if time_zone and not time_zone.empty?
29 | original_zone = ENV['TZ']
30 |
31 | local_time = time.clone
32 | local_time = local_time.utc
33 |
34 | ENV['TZ'] = time_zone
35 |
36 | time = local_time.localtime
37 |
38 | ENV['TZ'] = original_zone
39 | end
40 |
41 | # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
42 | result = time.strftime('%s')
43 | result = result.to_i
44 |
45 | return result
46 | end
47 | end
48 |
49 | # vim: set ts=2 sw=2 et :
50 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb:
--------------------------------------------------------------------------------
1 | #
2 | # unique.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:unique, :type => :rvalue, :doc => <<-EOS
7 | This function will remove duplicates from strings and arrays.
8 |
9 | *Examples:*
10 |
11 | unique("aabbcc")
12 |
13 | Will return:
14 |
15 | abc
16 |
17 | You can also use this with arrays:
18 |
19 | unique(["a","a","b","b","c","c"])
20 |
21 | This returns:
22 |
23 | ["a","b","c"]
24 | EOS
25 | ) do |arguments|
26 |
27 | raise(Puppet::ParseError, "unique(): Wrong number of arguments " +
28 | "given (#{arguments.size} for 1)") if arguments.size < 1
29 |
30 | value = arguments[0]
31 | klass = value.class
32 |
33 | unless [Array, String].include?(klass)
34 | raise(Puppet::ParseError, 'unique(): Requires either ' +
35 | 'array or string to work with')
36 | end
37 |
38 | result = value.clone
39 |
40 | string = value.is_a?(String) ? true : false
41 |
42 | # We turn any string value into an array to be able to shuffle ...
43 | result = string ? result.split('') : result
44 | result = result.uniq # Remove duplicates ...
45 | result = string ? result.join : result
46 |
47 | return result
48 | end
49 | end
50 |
51 | # vim: set ts=2 sw=2 et :
52 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb:
--------------------------------------------------------------------------------
1 | #
2 | # delete.rb
3 | #
4 |
5 | # TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
6 |
7 | module Puppet::Parser::Functions
8 | newfunction(:delete, :type => :rvalue, :doc => <<-EOS
9 | Deletes all instances of a given element from an array, substring from a
10 | string, or key from a hash.
11 |
12 | *Examples:*
13 |
14 | delete(['a','b','c','b'], 'b')
15 | Would return: ['a','c']
16 |
17 | delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
18 | Would return: {'a'=>1,'c'=>3}
19 |
20 | delete('abracadabra', 'bra')
21 | Would return: 'acada'
22 | EOS
23 | ) do |arguments|
24 |
25 | if (arguments.size != 2) then
26 | raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
27 | "given #{arguments.size} for 2.")
28 | end
29 |
30 | collection = arguments[0]
31 | item = arguments[1]
32 |
33 | case collection
34 | when Array, Hash
35 | collection.delete item
36 | when String
37 | collection.gsub! item, ''
38 | else
39 | raise(TypeError, "delete(): First argument must be an Array, " +
40 | "String, or Hash. Given an argument of class #{collection.class}.")
41 | end
42 | collection
43 | end
44 | end
45 |
46 | # vim: set ts=2 sw=2 et :
47 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe Puppet::Parser::Functions.function(:has_ip_address) do
5 |
6 | let(:scope) do
7 | PuppetlabsSpec::PuppetInternals.scope
8 | end
9 |
10 | subject do
11 | function_name = Puppet::Parser::Functions.function(:has_ip_address)
12 | scope.method(function_name)
13 | end
14 |
15 | context "On Linux Systems" do
16 | before :each do
17 | scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
18 | scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15')
19 | scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15')
20 | scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1')
21 | end
22 |
23 | it 'should have primary address (10.0.2.15)' do
24 | subject.call(['10.0.2.15']).should be_true
25 | end
26 |
27 | it 'should have lookupback address (127.0.0.1)' do
28 | subject.call(['127.0.0.1']).should be_true
29 | end
30 |
31 | it 'should not have other address' do
32 | subject.call(['192.1681.1.1']).should be_false
33 | end
34 |
35 | it 'should not have "mspiggy" on an interface' do
36 | subject.call(['mspiggy']).should be_false
37 | end
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb:
--------------------------------------------------------------------------------
1 | #
2 | # type.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:type, :type => :rvalue, :doc => <<-EOS
7 | Returns the type when passed a variable. Type can be one of:
8 |
9 | * string
10 | * array
11 | * hash
12 | * float
13 | * integer
14 | * boolean
15 | EOS
16 | ) do |arguments|
17 |
18 | raise(Puppet::ParseError, "type(): Wrong number of arguments " +
19 | "given (#{arguments.size} for 1)") if arguments.size < 1
20 |
21 | value = arguments[0]
22 |
23 | klass = value.class
24 |
25 | if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
26 | raise(Puppet::ParseError, 'type(): Unknown type')
27 | end
28 |
29 | klass = klass.to_s # Ugly ...
30 |
31 | # We note that Integer is the parent to Bignum and Fixnum ...
32 | result = case klass
33 | when /^(?:Big|Fix)num$/ then 'integer'
34 | when /^(?:True|False)Class$/ then 'boolean'
35 | else klass
36 | end
37 |
38 | if result == "String" then
39 | if value == value.to_i.to_s then
40 | result = "Integer"
41 | elsif value == value.to_f.to_s then
42 | result = "Float"
43 | end
44 | end
45 |
46 | return result.downcase
47 | end
48 | end
49 |
50 | # vim: set ts=2 sw=2 et :
51 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_numeric function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 argument" do
12 | lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if an integer" do
16 | result = scope.function_is_numeric(["3"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return true if a float" do
21 | result = scope.function_is_numeric(["3.2"])
22 | result.should(eq(true))
23 | end
24 |
25 | it "should return true if an integer is created from an arithmetical operation" do
26 | result = scope.function_is_numeric([3*2])
27 | result.should(eq(true))
28 | end
29 |
30 | it "should return true if a float is created from an arithmetical operation" do
31 | result = scope.function_is_numeric([3.2*2])
32 | result.should(eq(true))
33 | end
34 |
35 | it "should return false if a string" do
36 | result = scope.function_is_numeric(["asdf"])
37 | result.should(eq(false))
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb:
--------------------------------------------------------------------------------
1 | #
2 | # shuffle.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS
7 | Randomizes the order of a string or array elements.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 |
17 | unless [Array, String].include?(klass)
18 | raise(Puppet::ParseError, 'shuffle(): Requires either ' +
19 | 'array or string to work with')
20 | end
21 |
22 | result = value.clone
23 |
24 | string = value.is_a?(String) ? true : false
25 |
26 | # Check whether it makes sense to shuffle ...
27 | return result if result.size <= 1
28 |
29 | # We turn any string value into an array to be able to shuffle ...
30 | result = string ? result.split('') : result
31 |
32 | elements = result.size
33 |
34 | # Simple implementation of Fisher–Yates in-place shuffle ...
35 | elements.times do |i|
36 | j = rand(elements - i) + i
37 | result[j], result[i] = result[i], result[j]
38 | end
39 |
40 | result = string ? result.join : result
41 |
42 | return result
43 | end
44 | end
45 |
46 | # vim: set ts=2 sw=2 et :
47 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb:
--------------------------------------------------------------------------------
1 | #
2 | # fqdn_rotate.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS
7 | Rotates an array a random number of times based on a nodes fqdn.
8 | EOS
9 | ) do |arguments|
10 |
11 | raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
13 |
14 | value = arguments[0]
15 | klass = value.class
16 | require 'digest/md5'
17 |
18 | unless [Array, String].include?(klass)
19 | raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
20 | 'array or string to work with')
21 | end
22 |
23 | result = value.clone
24 |
25 | string = value.is_a?(String) ? true : false
26 |
27 | # Check whether it makes sense to rotate ...
28 | return result if result.size <= 1
29 |
30 | # We turn any string value into an array to be able to rotate ...
31 | result = string ? result.split('') : result
32 |
33 | elements = result.size
34 |
35 | srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex)
36 | rand(elements).times {
37 | result.push result.shift
38 | }
39 |
40 | result = string ? result.join : result
41 |
42 | return result
43 | end
44 | end
45 |
46 | # vim: set ts=2 sw=2 et :
47 |
--------------------------------------------------------------------------------
/puppet/modules/mysql/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class mysql
2 | {
3 | $mysqlPassword = ""
4 |
5 | package
6 | {
7 | "mysql-server":
8 | ensure => present,
9 | require => Exec['apt-get update']
10 | }
11 |
12 | service
13 | {
14 | "mysql":
15 | enable => true,
16 | ensure => running,
17 | require => Package["mysql-server"],
18 | }
19 |
20 | # Make sure that any previously setup boxes are gracefully
21 | # transitioned to the new empty root password.
22 | exec
23 | {
24 | "set-mysql-password":
25 | onlyif => "mysqladmin -uroot -proot status",
26 | command => "mysqladmin -uroot -proot password $mysqlPassword",
27 | require => Service["mysql"],
28 | }
29 |
30 | exec
31 | {
32 | "create-default-db":
33 | unless => "/usr/bin/mysql -uroot -p$mysqlPassword database",
34 | command => "/usr/bin/mysql -uroot -p$mysqlPassword -e 'create database `database`;'",
35 | require => [Service["mysql"], Exec["set-mysql-password"]]
36 | }
37 |
38 | exec
39 | {
40 | "grant-default-db":
41 | command => "/usr/bin/mysql -uroot -p$mysqlPassword -e 'grant all on `database`.* to `root@localhost`;'",
42 | require => [Service["mysql"], Exec["create-default-db"]]
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_ip_address function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if an IPv4 address" do
16 | result = scope.function_is_ip_address(["1.2.3.4"])
17 | result.should(eq(true))
18 | end
19 |
20 | it "should return true if a full IPv6 address" do
21 | result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
22 | result.should(eq(true))
23 | end
24 |
25 | it "should return true if a compressed IPv6 address" do
26 | result = scope.function_is_ip_address(["fe00::1"])
27 | result.should(eq(true))
28 | end
29 |
30 | it "should return false if not valid" do
31 | result = scope.function_is_ip_address(["asdf"])
32 | result.should(eq(false))
33 | end
34 |
35 | it "should return false if IP octets out of range" do
36 | result = scope.function_is_ip_address(["1.1.1.300"])
37 | result.should(eq(false))
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb:
--------------------------------------------------------------------------------
1 | #
2 | # str2bool.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
7 | This converts a string to a boolean. This attempt to convert strings that
8 | contain things like: y, 1, t, true to 'true' and strings that contain things
9 | like: 0, f, n, false, no to 'false'.
10 | EOS
11 | ) do |arguments|
12 |
13 | raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " +
14 | "given (#{arguments.size} for 1)") if arguments.size < 1
15 |
16 | string = arguments[0]
17 |
18 | unless string.is_a?(String)
19 | raise(Puppet::ParseError, 'str2bool(): Requires either ' +
20 | 'string to work with')
21 | end
22 |
23 | # We consider all the yes, no, y, n and so on too ...
24 | result = case string
25 | #
26 | # This is how undef looks like in Puppet ...
27 | # We yield false in this case.
28 | #
29 | when /^$/, '' then false # Empty string will be false ...
30 | when /^(1|t|y|true|yes)$/ then true
31 | when /^(0|f|n|false|no)$/ then false
32 | when /^(undef|undefined)$/ then false # This is not likely to happen ...
33 | else
34 | raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given')
35 | end
36 |
37 | return result
38 | end
39 | end
40 |
41 | # vim: set ts=2 sw=2 et :
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb:
--------------------------------------------------------------------------------
1 | #
2 | # delete_at.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
7 | Deletes a determined indexed value from an array.
8 |
9 | *Examples:*
10 |
11 | delete_at(['a','b','c'], 1)
12 |
13 | Would return: ['a','c']
14 | EOS
15 | ) do |arguments|
16 |
17 | raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
18 | "given (#{arguments.size} for 2)") if arguments.size < 2
19 |
20 | array = arguments[0]
21 |
22 | unless array.is_a?(Array)
23 | raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
24 | end
25 |
26 | index = arguments[1]
27 |
28 | if index.is_a?(String) and not index.match(/^\d+$/)
29 | raise(Puppet::ParseError, 'delete_at(): You must provide ' +
30 | 'non-negative numeric index')
31 | end
32 |
33 | result = array.clone
34 |
35 | # Numbers in Puppet are often string-encoded which is troublesome ...
36 | index = index.to_i
37 |
38 | if index > result.size - 1 # First element is at index 0 is it not?
39 | raise(Puppet::ParseError, 'delete_at(): Given index ' +
40 | 'exceeds size of array given')
41 | end
42 |
43 | result.delete_at(index) # We ignore the element that got deleted ...
44 |
45 | return result
46 | end
47 | end
48 |
49 | # vim: set ts=2 sw=2 et :
50 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb:
--------------------------------------------------------------------------------
1 | #
2 | # size.rb
3 | #
4 |
5 | # TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
6 |
7 | module Puppet::Parser::Functions
8 | newfunction(:size, :type => :rvalue, :doc => <<-EOS
9 | Returns the number of elements in a string or array.
10 | EOS
11 | ) do |arguments|
12 |
13 | raise(Puppet::ParseError, "size(): Wrong number of arguments " +
14 | "given (#{arguments.size} for 1)") if arguments.size < 1
15 |
16 | item = arguments[0]
17 |
18 | if item.is_a?(String)
19 |
20 | begin
21 | #
22 | # Check whether your item is a numeric value or not ...
23 | # This will take care about positive and/or negative numbers
24 | # for both integer and floating-point values ...
25 | #
26 | # Please note that Puppet has no notion of hexadecimal
27 | # nor octal numbers for its DSL at this point in time ...
28 | #
29 | Float(item)
30 |
31 | raise(Puppet::ParseError, 'size(): Requires either ' +
32 | 'string or array to work with')
33 |
34 | rescue ArgumentError
35 | result = item.size
36 | end
37 |
38 | elsif item.is_a?(Array)
39 | result = item.size
40 | else
41 | raise(Puppet::ParseError, 'size(): Unknown type given')
42 | end
43 |
44 | return result
45 | end
46 | end
47 |
48 | # vim: set ts=2 sw=2 et :
49 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/facter/pe_version.rb:
--------------------------------------------------------------------------------
1 | # Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
2 | #
3 | # Purpose: Return various facts about the PE state of the system
4 | #
5 | # Resolution: Uses a regex match against puppetversion to determine whether the
6 | # machine has Puppet Enterprise installed, and what version (overall, major,
7 | # minor, patch) is installed.
8 | #
9 | # Caveats:
10 | #
11 | Facter.add("pe_version") do
12 | setcode do
13 | pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
14 | pe_ver[1] if pe_ver
15 | end
16 | end
17 |
18 | Facter.add("is_pe") do
19 | setcode do
20 | if Facter.value(:pe_version).to_s.empty? then
21 | false
22 | else
23 | true
24 | end
25 | end
26 | end
27 |
28 | Facter.add("pe_major_version") do
29 | confine :is_pe => true
30 | setcode do
31 | if pe_version = Facter.value(:pe_version)
32 | pe_version.to_s.split('.')[0]
33 | end
34 | end
35 | end
36 |
37 | Facter.add("pe_minor_version") do
38 | confine :is_pe => true
39 | setcode do
40 | if pe_version = Facter.value(:pe_version)
41 | pe_version.to_s.split('.')[1]
42 | end
43 | end
44 | end
45 |
46 | Facter.add("pe_patch_version") do
47 | confine :is_pe => true
48 | setcode do
49 | if pe_version = Facter.value(:pe_version)
50 | pe_version.to_s.split('.')[2]
51 | end
52 | end
53 | end
54 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb:
--------------------------------------------------------------------------------
1 | # Test whether a given class or definition is defined
2 | require 'puppet/parser/functions'
3 |
4 | Puppet::Parser::Functions.newfunction(:ensure_resource,
5 | :type => :statement,
6 | :doc => <<-'ENDOFDOC'
7 | Takes a resource type, title, and a list of attributes that describe a
8 | resource.
9 |
10 | user { 'dan':
11 | ensure => present,
12 | }
13 |
14 | This example only creates the resource if it does not already exist:
15 |
16 | ensure_resource('user, 'dan', {'ensure' => 'present' })
17 |
18 | If the resource already exists but does not match the specified parameters,
19 | this function will attempt to recreate the resource leading to a duplicate
20 | resource definition error.
21 |
22 | ENDOFDOC
23 | ) do |vals|
24 | type, title, params = vals
25 | raise(ArgumentError, 'Must specify a type') unless type
26 | raise(ArgumentError, 'Must specify a title') unless title
27 | params ||= {}
28 | Puppet::Parser::Functions.function(:defined_with_params)
29 | if function_defined_with_params(["#{type}[#{title}]", params])
30 | Puppet.debug("Resource #{type}[#{title}] not created b/c it already exists")
31 | else
32 | Puppet::Parser::Functions.function(:create_resources)
33 | function_create_resources([type.capitalize, { title => params }])
34 | end
35 | end
36 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb:
--------------------------------------------------------------------------------
1 | #
2 | # is_domain_name.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS
7 | Returns true if the string passed to this function is a syntactically correct domain name.
8 | EOS
9 | ) do |arguments|
10 |
11 | if (arguments.size != 1) then
12 | raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
13 | "given #{arguments.size} for 1")
14 | end
15 |
16 | domain = arguments[0]
17 |
18 | # Limits (rfc1035, 3.1)
19 | domain_max_length=255
20 | label_min_length=1
21 | label_max_length=63
22 |
23 | # Allow ".", it is the top level domain
24 | return true if domain == '.'
25 |
26 | # Remove the final dot, if present.
27 | domain.chomp!('.')
28 |
29 | # Check the whole domain
30 | return false if domain.empty?
31 | return false if domain.length > domain_max_length
32 |
33 | # Check each label in the domain
34 | labels = domain.split('.')
35 | vlabels = labels.each do |label|
36 | break if label.length < label_min_length
37 | break if label.length > label_max_length
38 | break if label[-1..-1] == '-'
39 | break if label[0..0] == '-'
40 | break unless /^[a-z\d-]+$/i.match(label)
41 | end
42 | return vlabels == labels
43 |
44 | end
45 | end
46 |
47 | # vim: set ts=2 sw=2 et :
48 |
--------------------------------------------------------------------------------
/puppet/modules/apache/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class apache
2 | {
3 | package
4 | {
5 | "apache2":
6 | ensure => present,
7 | require => [Exec['apt-get update'], Package['php5'], Package['php5-dev'], Package['php5-cli']]
8 | }
9 |
10 | service
11 | {
12 | "apache2":
13 | ensure => running,
14 | enable => true,
15 | require => Package['apache2'],
16 | subscribe => [
17 | File["/etc/apache2/mods-enabled/rewrite.load"],
18 | File["/etc/apache2/sites-available/000-default.conf"],
19 | File["/etc/apache2/conf-enabled/phpmyadmin.conf"]
20 | ],
21 | }
22 |
23 | file
24 | {
25 | "/etc/apache2/mods-enabled/rewrite.load":
26 | ensure => link,
27 | target => "/etc/apache2/mods-available/rewrite.load",
28 | require => Package['apache2'],
29 | }
30 |
31 | file
32 | {
33 | "/etc/apache2/sites-available/000-default.conf":
34 | ensure => present,
35 | owner => root, group => root,
36 | source => "/vagrant/puppet/templates/vhost",
37 | require => Package['apache2'],
38 | }
39 |
40 | exec
41 | {
42 | 'echo "ServerName localhost" | sudo tee /etc/apache2/conf-enabled/fqdn.conf':
43 | require => Package['apache2'],
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the type function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 | it "should exist" do
7 | Puppet::Parser::Functions.function("type").should == "function_type"
8 | end
9 |
10 | it "should raise a ParseError if there is less than 1 arguments" do
11 | lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
12 | end
13 |
14 | it "should return string when given a string" do
15 | result = scope.function_type(["aaabbbbcccc"])
16 | result.should(eq('string'))
17 | end
18 |
19 | it "should return array when given an array" do
20 | result = scope.function_type([["aaabbbbcccc","asdf"]])
21 | result.should(eq('array'))
22 | end
23 |
24 | it "should return hash when given a hash" do
25 | result = scope.function_type([{"a"=>1,"b"=>2}])
26 | result.should(eq('hash'))
27 | end
28 |
29 | it "should return integer when given an integer" do
30 | result = scope.function_type(["1"])
31 | result.should(eq('integer'))
32 | end
33 |
34 | it "should return float when given a float" do
35 | result = scope.function_type(["1.34"])
36 | result.should(eq('float'))
37 | end
38 |
39 | it "should return boolean when given a boolean" do
40 | result = scope.function_type([true])
41 | result.should(eq('boolean'))
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb:
--------------------------------------------------------------------------------
1 | #
2 | # has_interface_with
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS
7 | Returns boolean based on kind and value:
8 | * macaddress
9 | * netmask
10 | * ipaddress
11 | * network
12 |
13 | has_interface_with("macaddress", "x:x:x:x:x:x")
14 | has_interface_with("ipaddress", "127.0.0.1") => true
15 | etc.
16 |
17 | If no "kind" is given, then the presence of the interface is checked:
18 | has_interface_with("lo") => true
19 | EOS
20 | ) do |args|
21 |
22 | raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
23 | "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
24 |
25 | interfaces = lookupvar('interfaces')
26 |
27 | # If we do not have any interfaces, then there are no requested attributes
28 | return false if (interfaces == :undefined)
29 |
30 | interfaces = interfaces.split(',')
31 |
32 | if args.size == 1
33 | return interfaces.member?(args[0])
34 | end
35 |
36 | kind, value = args
37 |
38 | if lookupvar(kind) == value
39 | return true
40 | end
41 |
42 | result = false
43 | interfaces.each do |iface|
44 | if value == lookupvar("#{kind}_#{iface}")
45 | result = true
46 | break
47 | end
48 | end
49 |
50 | result
51 | end
52 | end
53 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/classes/postgresql_java_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'postgresql::java', :type => :class do
4 |
5 | describe 'on a debian based os' do
6 | let :facts do {
7 | :osfamily => 'Debian',
8 | :postgres_default_version => 'foo',
9 | }
10 | end
11 | it { should contain_package('postgresql-jdbc').with(
12 | :name => 'libpostgresql-jdbc-java',
13 | :ensure => 'present'
14 | )}
15 | end
16 |
17 | describe 'on a redhat based os' do
18 | let :facts do {
19 | :osfamily => 'RedHat',
20 | :postgres_default_version => 'foo',
21 | }
22 | end
23 | it { should contain_package('postgresql-jdbc').with(
24 | :name => 'postgresql-jdbc',
25 | :ensure => 'present'
26 | )}
27 | describe 'when parameters are supplied' do
28 | let :params do
29 | {:package_ensure => 'latest', :package_name => 'somepackage'}
30 | end
31 | it { should contain_package('postgresql-jdbc').with(
32 | :name => 'somepackage',
33 | :ensure => 'latest'
34 | )}
35 | end
36 | end
37 |
38 | describe 'on any other os' do
39 | let :facts do {
40 | :osfamily => 'foo',
41 | :postgres_default_version => 'foo',
42 | }
43 | end
44 |
45 | it 'should fail' do
46 | expect { subject }.to raise_error(/Unsupported osfamily: foo/)
47 | end
48 | end
49 |
50 | end
51 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the delete function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("delete").should == "function_delete"
9 | end
10 |
11 | it "should raise a ParseError if there are fewer than 2 arguments" do
12 | lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should raise a ParseError if there are greater than 2 arguments" do
16 | lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
17 | end
18 |
19 | it "should raise a TypeError if a number is passed as the first argument" do
20 | lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError))
21 | end
22 |
23 | it "should delete all instances of an element from an array" do
24 | result = scope.function_delete([['a','b','c','b'],'b'])
25 | result.should(eq(['a','c']))
26 | end
27 |
28 | it "should delete all instances of a substring from a string" do
29 | result = scope.function_delete(['foobarbabarz','bar'])
30 | result.should(eq('foobaz'))
31 | end
32 |
33 | it "should delete a key from a hash" do
34 | result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b'])
35 | result.should(eq({ 'a' => 1, 'c' => 3 }))
36 | end
37 |
38 | end
39 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe Puppet::Parser::Functions.function(:getvar) do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 | describe 'when calling getvar from puppet' do
7 |
8 | it "should not compile when no arguments are passed" do
9 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
10 | Puppet[:code] = '$foo = getvar()'
11 | expect {
12 | scope.compiler.compile
13 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
14 | end
15 |
16 | it "should not compile when too many arguments are passed" do
17 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
18 | Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
19 | expect {
20 | scope.compiler.compile
21 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
22 | end
23 |
24 | it "should lookup variables in other namespaces" do
25 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
26 | Puppet[:code] = <<-'ENDofPUPPETcode'
27 | class site::data { $foo = 'baz' }
28 | include site::data
29 | $foo = getvar("site::data::foo")
30 | if $foo != 'baz' {
31 | fail('getvar did not return what we expect')
32 | }
33 | ENDofPUPPETcode
34 | scope.compiler.compile
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe Puppet::Parser::Functions.function(:validate_array) do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 | describe 'when calling validate_array from puppet' do
8 |
9 | %w{ true false }.each do |the_string|
10 | it "should not compile when #{the_string} is a string" do
11 | Puppet[:code] = "validate_array('#{the_string}')"
12 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
13 | end
14 |
15 | it "should not compile when #{the_string} is a bare word" do
16 | Puppet[:code] = "validate_array(#{the_string})"
17 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
18 | end
19 | end
20 |
21 | it "should compile when multiple array arguments are passed" do
22 | Puppet[:code] = <<-'ENDofPUPPETcode'
23 | $foo = [ ]
24 | $bar = [ 'one', 'two' ]
25 | validate_array($foo, $bar)
26 | ENDofPUPPETcode
27 | scope.compiler.compile
28 | end
29 |
30 | it "should not compile when an undef variable is passed" do
31 | Puppet[:code] = <<-'ENDofPUPPETcode'
32 | $foo = undef
33 | validate_array($foo)
34 | ENDofPUPPETcode
35 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not an Array/)
36 | end
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/manifests/pg_hba_rule.pp:
--------------------------------------------------------------------------------
1 | # This resource manages an individual rule that applies to the file defined in
2 | # $target.
3 | define postgresql::pg_hba_rule(
4 | $type,
5 | $database,
6 | $user,
7 | $auth_method,
8 | $address = undef,
9 | $description = 'none',
10 | $auth_option = undef,
11 | $target = $postgresql::params::pg_hba_conf_path,
12 | $order = '150'
13 | ) {
14 | include postgresql::params
15 |
16 | validate_re($type, '^(local|host|hostssl|hostnossl)$',
17 | "The type you specified [${type}] must be one of: local, host, hostssl, hostnosssl")
18 | validate_re($auth_method, '^(trust|reject|md5|crypt|password|gss|sspi|krb5|ident|peer|ldap|radius|cert|pam)$',
19 | "The auth_method you specified [${auth_method}] must be one of: trust, reject, md5, crypt, password, krb5, ident, ldap, pam")
20 |
21 | if($type =~ /^host/ and $address == undef) {
22 | fail('You must specify an address property when type is host based')
23 | }
24 |
25 | # This is required to make sure concat::setup is initialized first. This
26 | # probably points to a bug inside ripienaar-concat.
27 | include concat::setup
28 |
29 | # Create a rule fragment
30 | $fragname = "pg_hba_rule_${name}"
31 | concat::fragment { $fragname:
32 | target => $target,
33 | content => template('postgresql/pg_hba_rule.conf'),
34 | order => $order,
35 | owner => $::id,
36 | mode => '0600',
37 | }
38 |
39 | Class['concat::setup']->
40 | Concat::Fragment[$fragname]
41 | }
42 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the fqdn_rotate function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should rotate a string and the result should be the same size" do
16 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
17 | result = scope.function_fqdn_rotate(["asdf"])
18 | result.size.should(eq(4))
19 | end
20 |
21 | it "should rotate a string to give the same results for one host" do
22 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
23 | scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
24 | end
25 |
26 | it "should rotate a string to give different values on different hosts" do
27 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
28 | val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
29 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
30 | val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
31 | val1.should_not eql(val2)
32 | end
33 | end
34 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby
2 |
3 | require 'spec_helper'
4 | require 'rspec-puppet'
5 |
6 | describe 'ensure_packages' do
7 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 |
9 | describe 'argument handling' do
10 | it 'fails with no arguments' do
11 | should run.with_params().and_raise_error(Puppet::ParseError)
12 | end
13 | it 'requires an array' do
14 | lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
15 | end
16 | it 'fails when given a string' do
17 | should run.with_params('foo').and_raise_error(Puppet::ParseError)
18 | end
19 | end
20 |
21 | context 'given a catalog containing Package[puppet]{ensure => absent}' do
22 | let :pre_condition do
23 | 'package { puppet: ensure => absent }'
24 | end
25 |
26 | # NOTE: should run.with_params has the side effect of making the compiler
27 | # available to the test harness.
28 | it 'has no effect on Package[puppet]' do
29 | should run.with_params(['puppet'])
30 | rsrc = compiler.catalog.resource('Package[puppet]')
31 | rsrc.to_hash.should == {:ensure => "absent"}
32 | end
33 | end
34 |
35 | context 'given a clean catalog' do
36 | it 'declares package resources with ensure => present' do
37 | should run.with_params(['facter'])
38 | rsrc = compiler.catalog.resource('Package[facter]')
39 | rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe Puppet::Parser::Functions.function(:validate_hash) do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | describe 'when calling validate_hash from puppet' do
9 |
10 | %w{ true false }.each do |the_string|
11 |
12 | it "should not compile when #{the_string} is a string" do
13 | Puppet[:code] = "validate_hash('#{the_string}')"
14 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
15 | end
16 |
17 | it "should not compile when #{the_string} is a bare word" do
18 | Puppet[:code] = "validate_hash(#{the_string})"
19 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
20 | end
21 |
22 | end
23 |
24 | it "should compile when multiple hash arguments are passed" do
25 | Puppet[:code] = <<-'ENDofPUPPETcode'
26 | $foo = {}
27 | $bar = { 'one' => 'two' }
28 | validate_hash($foo, $bar)
29 | ENDofPUPPETcode
30 | scope.compiler.compile
31 | end
32 |
33 | it "should not compile when an undef variable is passed" do
34 | Puppet[:code] = <<-'ENDofPUPPETcode'
35 | $foo = undef
36 | validate_hash($foo)
37 | ENDofPUPPETcode
38 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a Hash/)
39 | end
40 |
41 | end
42 |
43 | end
44 |
45 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb:
--------------------------------------------------------------------------------
1 | #
2 | # join.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS
7 | This function joins each key of a hash to that key's corresponding value with a
8 | separator. Keys and values are cast to strings. The return value is an array in
9 | which each element is one joined key/value pair.
10 |
11 | *Examples:*
12 |
13 | join_keys_to_values({'a'=>1,'b'=>2}, " is ")
14 |
15 | Would result in: ["a is 1","b is 2"]
16 | EOS
17 | ) do |arguments|
18 |
19 | # Validate the number of arguments.
20 | if arguments.size != 2
21 | raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " +
22 | "arguments, but #{arguments.size} given.")
23 | end
24 |
25 | # Validate the first argument.
26 | hash = arguments[0]
27 | if not hash.is_a?(Hash)
28 | raise(TypeError, "join_keys_to_values(): The first argument must be a " +
29 | "hash, but a #{hash.class} was given.")
30 | end
31 |
32 | # Validate the second argument.
33 | separator = arguments[1]
34 | if not separator.is_a?(String)
35 | raise(TypeError, "join_keys_to_values(): The second argument must be a " +
36 | "string, but a #{separator.class} was given.")
37 | end
38 |
39 | # Join the keys to their values.
40 | hash.map do |k,v|
41 | String(k) + separator + String(v)
42 | end
43 |
44 | end
45 | end
46 |
47 | # vim: set ts=2 sw=2 et :
48 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/README_DEVELOPER.markdown:
--------------------------------------------------------------------------------
1 | Puppet Specific Facts
2 | =====================
3 |
4 | Facter is meant to stand alone and apart from Puppet. However, Facter often
5 | runs inside Puppet and all custom facts included in the stdlib module will
6 | almost always be evaluated in the context of Puppet and Facter working
7 | together.
8 |
9 | Still, we don't want to write custom facts that blow up in the users face if
10 | Puppet is not loaded in memory. This is often the case if the user runs
11 | `facter` without also supplying the `--puppet` flag.
12 |
13 | Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
14 | supplies `--facter`! You might say...
15 |
16 | Not (always) true I say! If the user happens to have a CWD of
17 | `/stdlib/lib` then the facts will automatically be evaluated and
18 | blow up.
19 |
20 | In any event, it's pretty easy to write a fact that has no value if Puppet is
21 | not loaded. Simply do it like this:
22 |
23 | Facter.add(:node_vardir) do
24 | setcode do
25 | # This will be nil if Puppet is not available.
26 | Facter::Util::PuppetSettings.with_puppet do
27 | Puppet[:vardir]
28 | end
29 | end
30 | end
31 |
32 | The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
33 | yields to it only if the Puppet library is loaded. If the Puppet library is
34 | not loaded, then the method silently returns `nil` which Facter interprets as
35 | an undefined fact value. The net effect is that the fact won't be set.
36 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | require 'facter/root_home'
3 |
4 | describe Facter::Util::RootHome do
5 | context "solaris" do
6 | let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
7 | let(:expected_root_home) { "/" }
8 |
9 | it "should return /" do
10 | Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
11 | Facter::Util::RootHome.get_root_home.should == expected_root_home
12 | end
13 | end
14 | context "linux" do
15 | let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
16 | let(:expected_root_home) { "/root" }
17 |
18 | it "should return /root" do
19 | Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
20 | Facter::Util::RootHome.get_root_home.should == expected_root_home
21 | end
22 | end
23 | context "macosx" do
24 | let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
25 | let(:expected_root_home) { "/var/root" }
26 |
27 | it "should return /var/root" do
28 | Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
29 | Facter::Util::RootHome.get_root_home.should == expected_root_home
30 | end
31 | end
32 | context "windows" do
33 | before :each do
34 | Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
35 | end
36 | it "should be nil on windows" do
37 | Facter::Util::RootHome.get_root_home.should be_nil
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/functions/defined_with_params_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | require 'rspec-puppet'
5 | describe 'defined_with_params' do
6 | describe 'when a resource is not specified' do
7 | it { should run.with_params().and_raise_error(ArgumentError) }
8 | end
9 | describe 'when compared against a resource with no attributes' do
10 | let :pre_condition do
11 | 'user { "dan": }'
12 | end
13 | it do
14 | should run.with_params('User[dan]', {}).and_return(true)
15 | should run.with_params('User[bob]', {}).and_return(false)
16 | should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
17 | end
18 | end
19 |
20 | describe 'when compared against a resource with attributes' do
21 | let :pre_condition do
22 | 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
23 | end
24 | it do
25 | should run.with_params('User[dan]', {}).and_return(true)
26 | should run.with_params('User[dan]', '').and_return(true)
27 | should run.with_params('User[dan]', {'ensure' => 'present'}
28 | ).and_return(true)
29 | should run.with_params('User[dan]',
30 | {'ensure' => 'present', 'managehome' => false}
31 | ).and_return(true)
32 | should run.with_params('User[dan]',
33 | {'ensure' => 'absent', 'managehome' => false}
34 | ).and_return(false)
35 | end
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the values_at function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("values_at").should == "function_values_at"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should raise a ParseError if you try to use a range where stop is greater then start" do
16 | lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
17 | end
18 |
19 | it "should return a value at from an array" do
20 | result = scope.function_values_at([['a','b','c'],"1"])
21 | result.should(eq(['b']))
22 | end
23 |
24 | it "should return a value at from an array when passed a range" do
25 | result = scope.function_values_at([['a','b','c'],"0-1"])
26 | result.should(eq(['a','b']))
27 | end
28 |
29 | it "should return chosen values from an array when passed number of indexes" do
30 | result = scope.function_values_at([['a','b','c'],["0","2"]])
31 | result.should(eq(['a','c']))
32 | end
33 |
34 | it "should return chosen values from an array when passed ranges and multiple indexes" do
35 | result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
36 | result.should(eq(['a','c','e','f']))
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | require 'rspec-puppet'
5 | describe 'ensure_resource' do
6 | describe 'when a type or title is not specified' do
7 | it do
8 | should run.with_params().and_raise_error(ArgumentError)
9 | should run.with_params(['type']).and_raise_error(ArgumentError)
10 | end
11 | end
12 | describe 'when compared against a resource with no attributes' do
13 | let :pre_condition do
14 | 'user { "dan": }'
15 | end
16 | it do
17 | should run.with_params('user', 'dan', {})
18 | compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
19 | end
20 | end
21 |
22 | describe 'when compared against a resource with attributes' do
23 | let :pre_condition do
24 | 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
25 | end
26 | it do
27 | # these first three should not fail
28 | should run.with_params('User', 'dan', {})
29 | should run.with_params('User', 'dan', '')
30 | should run.with_params('User', 'dan', {'ensure' => 'present'})
31 | should run.with_params('User', 'dan',
32 | {'ensure' => 'present', 'managehome' => false}
33 | )
34 | # test that this fails
35 | should run.with_params('User', 'dan',
36 | {'ensure' => 'absent', 'managehome' => false}
37 | ).and_raise_error(Puppet::Error)
38 | end
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/puppet/modules/php/manifests/init.pp:
--------------------------------------------------------------------------------
1 | class php
2 | {
3 |
4 | $packages = [
5 | "php5",
6 | "php5-cli",
7 | "php5-mysql",
8 | "php-pear",
9 | "php5-dev",
10 | "php-apc",
11 | "php5-mcrypt",
12 | "php5-gd",
13 | "php5-curl",
14 | "libapache2-mod-php5",
15 | "php5-xdebug",
16 | "php5-memcache",
17 | "php5-memcached",
18 | "php5-pgsql",
19 | "php5-sqlite",
20 | "php5-imagick",
21 | "php5-ldap"
22 | ]
23 |
24 | package
25 | {
26 | $packages:
27 | ensure => latest,
28 | require => [Exec['apt-get update'], Package['python-software-properties']]
29 | }
30 |
31 | # exec
32 | # {
33 | # "sed -i 's|#|//|' /etc/php5/cli/conf.d/mcrypt.ini":
34 | # require => Package['php5'],
35 | # }
36 |
37 | file
38 | {
39 | "/etc/php5/apache2/php.ini":
40 | ensure => present,
41 | owner => root, group => root,
42 | notify => Service['apache2'],
43 | #source => "/vagrant/puppet/templates/php.ini",
44 | content => template('php/php.ini.erb'),
45 | require => [Package['php5'], Package['apache2']],
46 | }
47 |
48 | file
49 | {
50 | "/etc/php5/cli/php.ini":
51 | ensure => present,
52 | owner => root, group => root,
53 | notify => Service['apache2'],
54 | content => template('php/cli.php.ini.erb'),
55 | require => [Package['php5']],
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/support/shared_contexts/pg_vm_context.rb:
--------------------------------------------------------------------------------
1 | require 'logger'
2 | require 'vagrant'
3 | require 'support/postgres_test_config'
4 |
5 |
6 | if PostgresTestConfig::HardCoreTesting
7 | # this will just make sure that we throw an error if the user tries to
8 | # run w/o having Sahara installed
9 | require 'sahara'
10 | end
11 |
12 | shared_context :pg_vm_context do
13 | before(:all) do
14 | @logger = Logger.new(STDOUT)
15 | @logger.level = Logger::DEBUG # TODO: get from environment or rspec?
16 |
17 | @env = Vagrant::Environment::new(:cwd => vagrant_dir)
18 |
19 | if PostgresTestConfig::HardCoreTesting
20 | @env.cli("destroy", vm.to_s, "--force") # Takes too long
21 | end
22 |
23 | @env.cli("up", vm.to_s)
24 |
25 | if PostgresTestConfig::HardCoreTesting
26 | sudo_and_log(vm, 'if [ "$(facter osfamily)" == "Debian" ] ; then apt-get update ; fi')
27 | end
28 |
29 | install_postgres
30 |
31 | #sudo_and_log(vm, 'puppet apply -e "include postgresql::server"')
32 |
33 | if PostgresTestConfig::HardCoreTesting
34 | # Sahara ignores :cwd so we have to chdir for now, see https://github.com/jedi4ever/sahara/issues/9
35 | Dir.chdir(vagrant_dir)
36 | @env.cli("sandbox", "on", vm.to_s)
37 | end
38 | end
39 |
40 | after(:all) do
41 | if PostgresTestConfig::SuspendVMsAfterSuite
42 | @logger.debug("Suspending VM")
43 | @env.cli("suspend", vm.to_s)
44 | end
45 | end
46 |
47 |
48 | after(:each) do
49 | if PostgresTestConfig::HardCoreTesting
50 | @env.cli("sandbox", "rollback", vm.to_s)
51 | end
52 | end
53 |
54 | end
55 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe Puppet::Parser::Functions.function(:has_key) do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | describe 'when calling has_key from puppet' do
8 | it "should not compile when no arguments are passed" do
9 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
10 | Puppet[:code] = '$x = has_key()'
11 | expect {
12 | scope.compiler.compile
13 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
14 | end
15 |
16 | it "should not compile when 1 argument is passed" do
17 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
18 | Puppet[:code] = "$x = has_key('foo')"
19 | expect {
20 | scope.compiler.compile
21 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
22 | end
23 |
24 | it "should require the first value to be a Hash" do
25 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
26 | Puppet[:code] = "$x = has_key('foo', 'bar')"
27 | expect {
28 | scope.compiler.compile
29 | }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/)
30 | end
31 | end
32 |
33 | describe 'when calling the function has_key from a scope instance' do
34 | it 'should detect existing keys' do
35 | scope.function_has_key([{'one' => 1}, 'one']).should be_true
36 | end
37 |
38 | it 'should detect existing keys' do
39 | scope.function_has_key([{'one' => 1}, 'two']).should be_false
40 | end
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/puppet/modules/postgresql/spec/system/test_module/manifests/system_default/test_grant_create.pp:
--------------------------------------------------------------------------------
1 | # puppet-postgresql
2 | # For all details and documentation:
3 | # http://github.com/inkling/puppet-postgresql
4 | #
5 | # Copyright 2012- Inkling Systems, Inc.
6 | #
7 | # Licensed under the Apache License, Version 2.0 (the "License");
8 | # you may not use this file except in compliance with the License.
9 | # You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing, software
14 | # distributed under the License is distributed on an "AS IS" BASIS,
15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | # See the License for the specific language governing permissions and
17 | # limitations under the License.
18 |
19 | class postgresql_tests::system_default::test_grant_create($user, $password, $db) {
20 |
21 | include postgresql::server
22 |
23 | # Since we are not testing pg_hba or any of that, make a local user for ident auth
24 | user { $user:
25 | ensure => present,
26 | }
27 |
28 | postgresql::database_user { $user:
29 | password_hash => postgresql_password($user, $password),
30 | require => [ Class['postgresql::server'],
31 | User[$user] ],
32 | }
33 |
34 | postgresql::database { $db:
35 | require => Class['postgresql::server'],
36 | }
37 |
38 | postgresql::database_grant { 'grant create test':
39 | privilege => 'CREATE',
40 | db => $db,
41 | role => $user,
42 | require => [ Postgresql::Database[$db],
43 | Postgresql::Database_user[$user] ],
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the join_keys_to_values function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
9 | end
10 |
11 | it "should raise a ParseError if there are fewer than two arguments" do
12 | lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
13 | end
14 |
15 | it "should raise a ParseError if there are greater than two arguments" do
16 | lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
17 | end
18 |
19 | it "should raise a TypeError if the first argument is an array" do
20 | lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
21 | end
22 |
23 | it "should raise a TypeError if the second argument is an array" do
24 | lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
25 | end
26 |
27 | it "should raise a TypeError if the second argument is a number" do
28 | lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
29 | end
30 |
31 | it "should return an empty array given an empty hash" do
32 | result = scope.function_join_keys_to_values([{}, ":"])
33 | result.should == []
34 | end
35 |
36 | it "should join hash's keys to its values" do
37 | result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
38 | result.should =~ ['a:1','2:foo','b:']
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb:
--------------------------------------------------------------------------------
1 | #
2 | # bool2num.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
7 | Converts a boolean to a number. Converts the values:
8 | false, f, 0, n, and no to 0
9 | true, t, 1, y, and yes to 1
10 | Requires a single boolean or string as an input.
11 | EOS
12 | ) do |arguments|
13 |
14 | raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
15 | "given (#{arguments.size} for 1)") if arguments.size < 1
16 |
17 | value = arguments[0]
18 | klass = value.class
19 |
20 | # We can have either true or false, or string which resembles boolean ...
21 | unless [FalseClass, TrueClass, String].include?(klass)
22 | raise(Puppet::ParseError, 'bool2num(): Requires either ' +
23 | 'boolean or string to work with')
24 | end
25 |
26 | if value.is_a?(String)
27 | # We consider all the yes, no, y, n and so on too ...
28 | value = case value
29 | #
30 | # This is how undef looks like in Puppet ...
31 | # We yield 0 (or false if you wish) in this case.
32 | #
33 | when /^$/, '' then false # Empty string will be false ...
34 | when /^(1|t|y|true|yes)$/ then true
35 | when /^(0|f|n|false|no)$/ then false
36 | when /^(undef|undefined)$/ then false # This is not likely to happen ...
37 | else
38 | raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
39 | end
40 | end
41 |
42 | # We have real boolean values as well ...
43 | result = value ? 1 : 0
44 |
45 | return result
46 | end
47 | end
48 |
49 | # vim: set ts=2 sw=2 et :
50 |
--------------------------------------------------------------------------------