├── .travis.yml
├── virtualmachines
├── modules
│ ├── java7
│ │ ├── .gitignore
│ │ ├── files
│ │ │ └── java.preseed
│ │ ├── Modulefile
│ │ ├── README.md
│ │ └── manifests
│ │ │ └── init.pp
│ ├── apt
│ │ ├── spec
│ │ │ ├── fixtures
│ │ │ │ └── manifests
│ │ │ │ │ └── site.pp
│ │ │ ├── spec_helper.rb
│ │ │ ├── classes
│ │ │ │ ├── params_spec.rb
│ │ │ │ ├── debian_unstable_spec.rb
│ │ │ │ ├── release_spec.rb
│ │ │ │ ├── debian_testing_spec.rb
│ │ │ │ └── backports_spec.rb
│ │ │ └── defines
│ │ │ │ ├── builddep_spec.rb
│ │ │ │ ├── force_spec.rb
│ │ │ │ ├── pin_spec.rb
│ │ │ │ └── conf_spec.rb
│ │ ├── tests
│ │ │ ├── init.pp
│ │ │ ├── params.pp
│ │ │ ├── builddep.pp
│ │ │ ├── debian
│ │ │ │ ├── testing.pp
│ │ │ │ └── unstable.pp
│ │ │ ├── release.pp
│ │ │ ├── ppa.pp
│ │ │ ├── pin.pp
│ │ │ ├── force.pp
│ │ │ ├── key.pp
│ │ │ └── source.pp
│ │ ├── Rakefile
│ │ ├── templates
│ │ │ ├── pin.pref.erb
│ │ │ └── source.list.erb
│ │ ├── .fixtures.yml
│ │ ├── manifests
│ │ │ ├── update.pp
│ │ │ ├── release.pp
│ │ │ ├── conf.pp
│ │ │ ├── builddep.pp
│ │ │ ├── force.pp
│ │ │ ├── params.pp
│ │ │ ├── debian
│ │ │ │ ├── testing.pp
│ │ │ │ └── unstable.pp
│ │ │ ├── pin.pp
│ │ │ ├── backports.pp
│ │ │ └── ppa.pp
│ │ ├── Modulefile
│ │ └── LICENSE
│ └── stdlib
│ │ ├── tests
│ │ ├── init.pp
│ │ ├── has_ip_network.pp
│ │ ├── has_ip_address.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
│ │ │ │ │ ├── min_spec.rb
│ │ │ │ │ ├── parseyaml_spec.rb
│ │ │ │ │ ├── sort_spec.rb
│ │ │ │ │ ├── bool2num_spec.rb
│ │ │ │ │ ├── keys_spec.rb
│ │ │ │ │ ├── num2bool_spec.rb
│ │ │ │ │ ├── size_spec.rb
│ │ │ │ │ ├── empty_spec.rb
│ │ │ │ │ ├── abs_spec.rb
│ │ │ │ │ ├── upcase_spec.rb
│ │ │ │ │ ├── rstrip_spec.rb
│ │ │ │ │ ├── str2bool_spec.rb
│ │ │ │ │ ├── squeeze_spec.rb
│ │ │ │ │ ├── downcase_spec.rb
│ │ │ │ │ ├── unique_spec.rb
│ │ │ │ │ ├── member_spec.rb
│ │ │ │ │ ├── uriescape_spec.rb
│ │ │ │ │ ├── flatten_spec.rb
│ │ │ │ │ ├── shuffle_spec.rb
│ │ │ │ │ ├── time_spec.rb
│ │ │ │ │ ├── is_float_spec.rb
│ │ │ │ │ ├── is_numeric_spec.rb
│ │ │ │ │ ├── is_integer_spec.rb
│ │ │ │ │ ├── is_array_spec.rb
│ │ │ │ │ ├── is_hash_spec.rb
│ │ │ │ │ ├── strftime_spec.rb
│ │ │ │ │ ├── is_mac_address_spec.rb
│ │ │ │ │ ├── is_string_spec.rb
│ │ │ │ │ ├── pick_spec.rb
│ │ │ │ │ ├── range_spec.rb
│ │ │ │ │ ├── has_ip_network_spec.rb
│ │ │ │ │ ├── values_spec.rb
│ │ │ │ │ ├── has_ip_address_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
│ │ │ │ │ ├── merge_spec.rb
│ │ │ │ │ ├── to_bytes_spec.rb
│ │ │ │ │ ├── str2saltedsha512_spec.rb
│ │ │ │ │ ├── validate_bool_spec.rb
│ │ │ │ │ ├── validate_string_spec.rb
│ │ │ │ │ └── is_domain_name_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
│ │ └── watchr.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_numeric.rb
│ │ │ │ │ ├── is_string.rb
│ │ │ │ │ ├── get_module_path.rb
│ │ │ │ │ ├── empty.rb
│ │ │ │ │ ├── reject.rb
│ │ │ │ │ ├── reverse.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
│ │ │ │ │ ├── hash.rb
│ │ │ │ │ ├── upcase.rb
│ │ │ │ │ ├── capitalize.rb
│ │ │ │ │ ├── swapcase.rb
│ │ │ │ │ ├── validate_string.rb
│ │ │ │ │ ├── abs.rb
│ │ │ │ │ ├── chomp.rb
│ │ │ │ │ ├── join.rb
│ │ │ │ │ ├── validate_bool.rb
│ │ │ │ │ ├── uriescape.rb
│ │ │ │ │ ├── pick.rb
│ │ │ │ │ ├── str2saltedsha512.rb
│ │ │ │ │ ├── member.rb
│ │ │ │ │ ├── merge.rb
│ │ │ │ │ ├── prefix.rb
│ │ │ │ │ ├── chop.rb
│ │ │ │ │ ├── defined_with_params.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
│ │ │ │ │ ├── validate_re.rb
│ │ │ │ │ └── zip.rb
│ │ │ ├── type
│ │ │ │ └── anchor.rb
│ │ │ └── provider
│ │ │ │ └── file_line
│ │ │ │ └── ruby.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
└── manifests
│ └── default.pp
├── .gitignore
├── atlassian-ide-plugin.xml
└── src
└── main
└── java
└── com
└── beauhinks
├── purejavacomm
├── package-info.java
├── PureJavaCommDeviceAddress.java
└── PureJavaCommChannelOption.java
└── example
└── purejavacomm
└── PureJavaCommClientHandler.java
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/java7/.gitignore:
--------------------------------------------------------------------------------
1 | pkg/*
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/fixtures/manifests/site.pp:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/init.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/tests/init.pp:
--------------------------------------------------------------------------------
1 | include stdlib
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/params.pp:
--------------------------------------------------------------------------------
1 | include apt::params
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
3 | .idea/
4 | *.class
5 | *.iml
6 |
7 |
8 | .vagrant/
9 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/Rakefile:
--------------------------------------------------------------------------------
1 | require 'puppetlabs_spec_helper/rake_tasks'
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/.rspec:
--------------------------------------------------------------------------------
1 | --color
2 | --format
3 | progress
4 | --backtrace
5 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/.gitignore:
--------------------------------------------------------------------------------
1 | pkg/
2 | .DS_Store
3 | metadata.json
4 | coverage/
5 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'puppetlabs_spec_helper/module_spec_helper'
2 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/builddep.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 | apt::builddep{ 'glusterfs-server': }
3 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/debian/testing.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 | class { 'apt::debian::testing': }
3 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/debian/unstable.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 | class { 'apt::debian::unstable': }
3 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'puppetlabs_spec_helper/rake_tasks'
3 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/spec.opts:
--------------------------------------------------------------------------------
1 | --format
2 | s
3 | --colour
4 | --loadby
5 | mtime
6 | --backtrace
7 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/release.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 | class { 'apt::release':
3 | release_id => 'karmic'
4 | }
5 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/ppa.pp:
--------------------------------------------------------------------------------
1 | class { 'apt': }
2 |
3 | # Example declaration of an Apt PPA
4 | apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': }
5 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/pin.pp:
--------------------------------------------------------------------------------
1 | # pin a release in apt, useful for unstable repositories
2 | apt::pin { 'foo':
3 | packages => '*',
4 | priority => 0,
5 | }
6 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/templates/pin.pref.erb:
--------------------------------------------------------------------------------
1 | # <%= name %>
2 | Explanation: <%= explanation %>
3 | Package: <%= packages %>
4 | Pin: <%= pin %>
5 | Pin-Priority: <%= priority %>
6 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/.fixtures.yml:
--------------------------------------------------------------------------------
1 | fixtures:
2 | repositories:
3 | "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
4 | symlinks:
5 | "apt": "#{source_dir}"
6 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/force.pp:
--------------------------------------------------------------------------------
1 | # force.pp
2 | # force a package from a specific release
3 |
4 | apt::force { 'package':
5 | release => 'testing',
6 | version => false
7 | }
8 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/key.pp:
--------------------------------------------------------------------------------
1 | # Declare Apt key for apt.puppetlabs.com source
2 | apt::key { 'puppetlabs':
3 | key => '4BD6EC30',
4 | key_server => 'pgp.mit.edu',
5 | }
6 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/templates/source.list.erb:
--------------------------------------------------------------------------------
1 | # <%= name %>
2 | deb <%= location %> <%= release_real %> <%= repos %>
3 | <%- if include_src then -%>
4 | deb-src <%= location %> <%= release_real %> <%= repos %>
5 | <%- end -%>
6 |
--------------------------------------------------------------------------------
/virtualmachines/modules/java7/files/java.preseed:
--------------------------------------------------------------------------------
1 | oracle-java7-installer shared/present-oracle-license-v1-1 note
2 | oracle-java7-installer oracle-java7-installer/local string
3 | oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true
4 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/atlassian-ide-plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 453e6218-3d37-43e4-9635-a391f70fb4b1
5 |
6 |
--------------------------------------------------------------------------------
/src/main/java/com/beauhinks/purejavacomm/package-info.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | /**
4 | * A serial and parallel port communication transport based on PureJavaComm.
5 | */
6 | package com.beauhinks.purejavacomm;
7 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/update.pp:
--------------------------------------------------------------------------------
1 | class apt::update {
2 | include apt::params
3 |
4 | exec { 'apt_update':
5 | command => "${apt::params::provider} update",
6 | logoutput => 'on_failure',
7 | refreshonly => true,
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/release.pp:
--------------------------------------------------------------------------------
1 | # release.pp
2 |
3 | class apt::release (
4 | $release_id
5 | ) {
6 |
7 | include apt::params
8 |
9 | $root = $apt::params::root
10 |
11 | file { "${root}/apt.conf.d/01release":
12 | owner => root,
13 | group => root,
14 | mode => '0644',
15 | content => "APT::Default-Release \"${release_id}\";"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/conf.pp:
--------------------------------------------------------------------------------
1 | define apt::conf (
2 | $content,
3 | $ensure = present,
4 | $priority = '50'
5 | ) {
6 |
7 | include apt::params
8 |
9 | $apt_conf_d = $apt::params::apt_conf_d
10 |
11 | file { "${apt_conf_d}/${priority}${name}":
12 | ensure => $ensure,
13 | content => $content,
14 | owner => root,
15 | group => root,
16 | mode => '0644',
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/virtualmachines/modules/java7/Modulefile:
--------------------------------------------------------------------------------
1 | name 'softek-java7'
2 | version '0.1.0'
3 | source 'git://github.com/softek/puppet-java7.git'
4 | author 'Scott Smerchek'
5 | license ''
6 | summary 'Oracle Java7 Puppet Module'
7 | description 'This module manages Oracle Java7. Tested on Ubuntu'
8 | project_page 'http://github.com/softek/puppet-java7'
9 |
10 | ## Add dependencies, if any:
11 | dependency 'puppetlabs/apt', '>= 1.0.1'
12 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/builddep.pp:
--------------------------------------------------------------------------------
1 | # builddep.pp
2 |
3 | define apt::builddep() {
4 | include apt::update
5 |
6 | exec { "apt-builddep-${name}":
7 | command => "/usr/bin/apt-get -y --force-yes build-dep ${name}",
8 | logoutput => 'on_failure',
9 | notify => Exec['apt_update'],
10 | }
11 |
12 | # Need anchor to provide containment for dependencies.
13 | anchor { "apt::builddep::${name}":
14 | require => Class['apt::update'],
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/classes/params_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::params', :type => :class do
3 | let (:title) { 'my_package' }
4 |
5 | it { should contain_apt__params }
6 |
7 | # There are 4 resources in this class currently
8 | # there should not be any more resources because it is a params class
9 | # The resources are class[apt::params], class[main], class[settings], stage[main]
10 | it "Should not contain any resources" do
11 | subject.resources.size.should == 4
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/defines/builddep_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::builddep', :type => :define do
3 |
4 | let(:title) { 'my_package' }
5 |
6 | describe "should require apt-get update" do
7 | it { should contain_exec("apt_update").with({
8 | 'command' => "/usr/bin/apt-get update",
9 | 'refreshonly' => true
10 | })
11 | }
12 | it { should contain_anchor("apt::builddep::my_package").with({
13 | 'require' => 'Class[Apt::Update]',
14 | })
15 | }
16 | end
17 |
18 | end
19 |
--------------------------------------------------------------------------------
/virtualmachines/modules/java7/README.md:
--------------------------------------------------------------------------------
1 | # Java7 Puppet Module
2 | This module manages Oracle Java7.
3 |
4 | This module has been tested against 3.0.1 on Ubuntu 12.04 and Debian 6.
5 |
6 | Pull requests to add support for other operating systems are welcome.
7 |
8 | *NOTE:* This module may only be used if you agree to the Oracle license: http://www.oracle.com/technetwork/java/javase/terms/license/
9 |
10 | ### Usage
11 |
12 | include java7
13 |
14 | ### Author
15 | * Scott Smerchek
16 |
17 | ### Contributors:
18 | * flosell: Added Debian 6 support
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/Modulefile:
--------------------------------------------------------------------------------
1 | name 'puppetlabs-apt'
2 | version '1.1.0'
3 | source 'https://github.com/puppetlabs/puppetlabs-apt'
4 | author 'Evolving Web / Puppet Labs'
5 | license 'Apache License 2.0'
6 | summary 'Puppet Labs Apt Module'
7 | description 'APT Module for Puppet'
8 | project_page 'https://github.com/puppetlabs/puppetlabs-apt'
9 |
10 | ## Add dependencies, if any:
11 | #dependency 'puppetlabs/stdlib', '2.x'
12 | # The dependency should be written as above but librarian-puppet
13 | # does not support the expression as the PMT does.
14 | dependency 'puppetlabs/stdlib', '>= 2.2.1'
15 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/classes/debian_unstable_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::debian::unstable', :type => :class do
3 | it {
4 | should contain_apt__source("debian_unstable").with({
5 | "location" => "http://debian.mirror.iweb.ca/debian/",
6 | "release" => "unstable",
7 | "repos" => "main contrib non-free",
8 | "required_packages" => "debian-keyring debian-archive-keyring",
9 | "key" => "55BE302B",
10 | "key_server" => "subkeys.pgp.net",
11 | "pin" => "-10"
12 | })
13 | }
14 | end
15 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/classes/release_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::release', :type => :class do
3 | let (:title) { 'my_package' }
4 |
5 | let :param_set do
6 | { :release_id => 'precise' }
7 | end
8 |
9 | let (:params) { param_set }
10 |
11 | it { should include_class("apt::params") }
12 |
13 | it {
14 | should contain_file("/etc/apt/apt.conf.d/01release").with({
15 | "mode" => "0644",
16 | "owner" => "root",
17 | "group" => "root",
18 | "content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
19 | })
20 | }
21 | end
22 |
23 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/classes/debian_testing_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::debian::testing', :type => :class do
3 | it {
4 | should contain_apt__source("debian_testing").with({
5 | "location" => "http://debian.mirror.iweb.ca/debian/",
6 | "release" => "testing",
7 | "repos" => "main contrib non-free",
8 | "required_packages" => "debian-keyring debian-archive-keyring",
9 | "key" => "55BE302B",
10 | "key_server" => "subkeys.pgp.net",
11 | "pin" => "-10"
12 | })
13 | }
14 | end
15 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/force.pp:
--------------------------------------------------------------------------------
1 | # force.pp
2 | # force a package from a specific release
3 |
4 | define apt::force(
5 | $release = 'testing',
6 | $version = false,
7 | $timeout = 300
8 | ) {
9 |
10 | $version_string = $version ? {
11 | false => undef,
12 | default => "=${version}",
13 | }
14 |
15 | $install_check = $version ? {
16 | false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
17 | default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
18 | }
19 | exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}":
20 | unless => $install_check,
21 | logoutput => 'on_failure',
22 | timeout => $timeout,
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/virtualmachines/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 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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/params.pp:
--------------------------------------------------------------------------------
1 | class apt::params {
2 | $root = '/etc/apt'
3 | $provider = '/usr/bin/apt-get'
4 | $sources_list_d = "${root}/sources.list.d"
5 | $apt_conf_d = "${root}/apt.conf.d"
6 | $preferences_d = "${root}/preferences.d"
7 |
8 | case $::lsbdistid {
9 | 'debian': {
10 | $backports_location = 'http://backports.debian.org/debian-backports'
11 | }
12 | 'ubuntu': {
13 | case $::lsbdistcodename {
14 | 'hardy','lucid','maverick','natty','oneiric','precise': {
15 | $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
16 | }
17 | default: {
18 | $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
19 | }
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/debian/testing.pp:
--------------------------------------------------------------------------------
1 | # testing.pp
2 |
3 | class apt::debian::testing {
4 | include apt
5 |
6 | # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
7 | # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
8 | # Key: 55BE302B Server: subkeys.pgp.net
9 | # debian-keyring
10 | # debian-archive-keyring
11 |
12 | apt::source { 'debian_testing':
13 | location => 'http://debian.mirror.iweb.ca/debian/',
14 | release => 'testing',
15 | repos => 'main contrib non-free',
16 | required_packages => 'debian-keyring debian-archive-keyring',
17 | key => '55BE302B',
18 | key_server => 'subkeys.pgp.net',
19 | pin => '-10',
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/debian/unstable.pp:
--------------------------------------------------------------------------------
1 | # unstable.pp
2 |
3 | class apt::debian::unstable {
4 | include apt
5 |
6 | # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
7 | # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
8 | # Key: 55BE302B Server: subkeys.pgp.net
9 | # debian-keyring
10 | # debian-archive-keyring
11 |
12 | apt::source { 'debian_unstable':
13 | location => 'http://debian.mirror.iweb.ca/debian/',
14 | release => 'unstable',
15 | repos => 'main contrib non-free',
16 | required_packages => 'debian-keyring debian-archive-keyring',
17 | key => '55BE302B',
18 | key_server => 'subkeys.pgp.net',
19 | pin => '-10',
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/src/main/java/com/beauhinks/example/purejavacomm/PureJavaCommClientHandler.java:
--------------------------------------------------------------------------------
1 | package com.beauhinks.example.purejavacomm;
2 |
3 | import io.netty.channel.ChannelHandlerContext;
4 | import io.netty.channel.SimpleChannelInboundHandler;
5 |
6 |
7 |
8 | public class PureJavaCommClientHandler extends SimpleChannelInboundHandler {
9 |
10 | @Override
11 | public void channelActive(ChannelHandlerContext ctx) {
12 | ctx.writeAndFlush("AT\n");
13 | }
14 |
15 | @Override
16 | public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
17 | if ("OK".equals(msg)) {
18 | System.out.println("Serial port responded to AT");
19 | } else {
20 | System.out.println("Serial port responded with not-OK: " + msg);
21 | }
22 | ctx.close();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/manifests/default.pp:
--------------------------------------------------------------------------------
1 | define append_if_no_such_line($file, $line, $refreshonly = 'false') {
2 | exec { "/bin/echo '$line' >> '$file'":
3 | unless => "/bin/grep -Fxqe '$line' '$file'",
4 | path => "/bin",
5 | refreshonly => $refreshonly,
6 | }
7 | }
8 |
9 | class must-have {
10 | include apt
11 |
12 | exec { 'apt-get update':
13 | command => '/usr/bin/apt-get update',
14 | }
15 |
16 | package { [
17 | "bash",
18 | "wget"
19 | ]:
20 | ensure => present,
21 | require => Exec["apt-get update"],
22 | }
23 |
24 | file { "create-local-bin-folder":
25 | ensure => directory,
26 | path => "/home/vagrant/bin",
27 | owner => "vagrant",
28 | group => "vagrant",
29 | mode => '755',
30 | }
31 |
32 |
33 |
34 | }
35 |
36 | include java7
37 | include must-have
38 |
39 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 | end
30 |
--------------------------------------------------------------------------------
/src/main/java/com/beauhinks/purejavacomm/PureJavaCommDeviceAddress.java:
--------------------------------------------------------------------------------
1 | package com.beauhinks.purejavacomm;
2 |
3 | import java.net.SocketAddress;
4 |
5 | /**
6 | * A {@link SocketAddress} subclass to wrap the serial port address of a PureJavaComm
7 | * device (e.g. COM1, /dev/ttyUSB0).
8 | */
9 | public class PureJavaCommDeviceAddress extends SocketAddress {
10 |
11 | private static final long serialVersionUID = -2907820090993709523L;
12 |
13 | private final String value;
14 |
15 | /**
16 | * Creates a PureJavaCommDeviceAddress representing the address of the serial port.
17 | *
18 | * @param value the address of the device (e.g. COM1, /dev/ttyUSB0, ...)
19 | */
20 | public PureJavaCommDeviceAddress(String value) {
21 | this.value = value;
22 | }
23 |
24 | /**
25 | * @return The serial port address of the device (e.g. COM1, /dev/ttyUSB0, ...)
26 | */
27 | public String value() {
28 | return value;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 false if a string" do
26 | result = scope.function_is_numeric(["asdf"])
27 | result.should(eq(false))
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/virtualmachines/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 | end
30 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/tests/source.pp:
--------------------------------------------------------------------------------
1 | # Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d
2 | class { 'apt': }
3 |
4 | # Install the puppetlabs apt source
5 | # Release is automatically obtained from lsbdistcodename fact if available.
6 | apt::source { 'puppetlabs':
7 | location => 'http://apt.puppetlabs.com',
8 | repos => 'main',
9 | key => '4BD6EC30',
10 | key_server => 'pgp.mit.edu',
11 | }
12 |
13 | # test two sources with the same key
14 | apt::source { 'debian_testing':
15 | location => 'http://debian.mirror.iweb.ca/debian/',
16 | release => 'testing',
17 | repos => 'main contrib non-free',
18 | key => '55BE302B',
19 | key_server => 'subkeys.pgp.net',
20 | pin => '-10',
21 | }
22 | apt::source { 'debian_unstable':
23 | location => 'http://debian.mirror.iweb.ca/debian/',
24 | release => 'unstable',
25 | repos => 'main contrib non-free',
26 | key => '55BE302B',
27 | key_server => 'subkeys.pgp.net',
28 | pin => '-10',
29 | }
30 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 Evolving Web Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/defines/force_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::force', :type => :define do
3 | let :title do
4 | 'my_package'
5 | end
6 |
7 | let :default_params do
8 | {
9 | :release => 'testing',
10 | :version => false
11 | }
12 | end
13 |
14 | [{},
15 | {
16 | :release => 'stable',
17 | :version => '1'
18 | }
19 | ].each do |param_set|
20 | describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
21 | let :param_hash do
22 | default_params.merge(param_set)
23 | end
24 |
25 | let :params do
26 | param_set
27 | end
28 |
29 | let :unless_query do
30 | base_command = "/usr/bin/dpkg -s #{title} | grep -q "
31 | base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
32 | end
33 |
34 | let :exec_title do
35 | base_exec = "/usr/bin/aptitude -y -t #{param_hash[:release]} install #{title}"
36 | base_exec + (params[:version] ? "=#{params[:version]}" : "")
37 | end
38 | it { should contain_exec(exec_title).with_unless(unless_query) }
39 | end
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/pin.pp:
--------------------------------------------------------------------------------
1 | # pin.pp
2 | # pin a release in apt, useful for unstable repositories
3 |
4 | define apt::pin(
5 | $ensure = present,
6 | $explanation = "${::caller_module_name}: ${name}",
7 | $order = '',
8 | $packages = '*',
9 | $priority = 0,
10 | $release = '',
11 | $origin = '',
12 | $originator = '',
13 | $version = ''
14 | ) {
15 |
16 | include apt::params
17 |
18 | $preferences_d = $apt::params::preferences_d
19 |
20 | if $order != '' and !is_integer($order) {
21 | fail('Only integers are allowed in the apt::pin order param')
22 | }
23 |
24 | if $release != '' {
25 | $pin = "release a=${release}"
26 | } elsif $origin != '' {
27 | $pin = "origin \"${origin}\""
28 | } elsif $originator != '' {
29 | $pin = "release o=${originator}"
30 | } elsif $version != '' {
31 | $pin = "version ${version}"
32 | } else {
33 | $pin = "release a=${name}"
34 | }
35 |
36 | $path = $order ? {
37 | '' => "${preferences_d}/${name}.pref",
38 | default => "${preferences_d}/${order}-${name}.pref",
39 | }
40 | file { "${name}.pref":
41 | ensure => $ensure,
42 | path => $path,
43 | owner => root,
44 | group => root,
45 | mode => '0644',
46 | content => template('apt/pin.pref.erb'),
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/backports.pp:
--------------------------------------------------------------------------------
1 | # This adds the necessary components to get backports for ubuntu and debian
2 | #
3 | # == Parameters
4 | #
5 | # [*release*]
6 | # The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this
7 | # manually can cause undefined behavior. (Read: universe exploding)
8 | #
9 | # == Examples
10 | #
11 | # include apt::backports
12 | #
13 | # class { 'apt::backports':
14 | # release => 'natty',
15 | # }
16 | #
17 | # == Authors
18 | #
19 | # Ben Hughes, I think. At least blame him if this goes wrong.
20 | # I just added puppet doc.
21 | #
22 | # == Copyright
23 | #
24 | # Copyright 2011 Puppet Labs Inc, unless otherwise noted.
25 | class apt::backports(
26 | $release = $::lsbdistcodename,
27 | $location = $apt::params::backports_location
28 | ) inherits apt::params {
29 |
30 | $release_real = downcase($release)
31 | $key = $::lsbdistid ? {
32 | 'debian' => '55BE302B',
33 | 'ubuntu' => '437D05B5',
34 | }
35 | $repos = $::lsbdistid ? {
36 | 'debian' => 'main contrib non-free',
37 | 'ubuntu' => 'main universe multiverse restricted',
38 | }
39 |
40 | apt::source { 'backports':
41 | location => $location,
42 | release => "${release_real}-backports",
43 | repos => $repos,
44 | key => $key,
45 | key_server => 'pgp.mit.edu',
46 | pin => '200',
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/manifests/ppa.pp:
--------------------------------------------------------------------------------
1 | # ppa.pp
2 |
3 | define apt::ppa(
4 | $release = $::lsbdistcodename
5 | ) {
6 | include apt::params
7 | include apt::update
8 |
9 | $sources_list_d = $apt::params::sources_list_d
10 |
11 | if ! $release {
12 | fail('lsbdistcodename fact not available: release parameter required')
13 | }
14 |
15 | $filename_without_slashes = regsubst($name, '/', '-', G)
16 | $filename_without_dots = regsubst($filename_without_slashes, '\.', '_', G)
17 | $filename_without_ppa = regsubst($filename_without_dots, '^ppa:', '', G)
18 | $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
19 |
20 | $package = $::lsbdistrelease ? {
21 | /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
22 | default => 'software-properties-common',
23 | }
24 |
25 | if ! defined(Package[$package]) {
26 | package { $package: }
27 | }
28 |
29 | exec { "add-apt-repository-${name}":
30 | command => "/usr/bin/add-apt-repository ${name}",
31 | creates => "${sources_list_d}/${sources_list_d_filename}",
32 | logoutput => 'on_failure',
33 | require => [
34 | File[$sources_list_d],
35 | Package["${package}"],
36 | ],
37 | notify => Exec['apt_update'],
38 | }
39 |
40 | file { "${sources_list_d}/${sources_list_d_filename}":
41 | ensure => file,
42 | require => Exec["add-apt-repository-${name}"],
43 | }
44 |
45 | # Need anchor to provide containment for dependencies.
46 | anchor { "apt::ppa::${name}":
47 | require => Class['apt::update'],
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/defines/pin_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::pin', :type => :define do
3 | let(:title) { 'my_pin' }
4 |
5 | let :default_params do
6 | {
7 | :ensure => 'present',
8 | :order => '',
9 | :packages => '*',
10 | :priority => '0',
11 | :release => nil
12 | }
13 | end
14 |
15 | [ {},
16 | {
17 | :packages => 'apache',
18 | :priority => '1'
19 | },
20 | {
21 | :order => 50,
22 | :packages => 'apache',
23 | :priority => '1'
24 | },
25 | {
26 | :ensure => 'absent',
27 | :packages => 'apache',
28 | :priority => '1'
29 | },
30 | {
31 | :packages => 'apache',
32 | :priority => '1',
33 | :release => 'my_newpin'
34 | }
35 | ].each do |param_set|
36 | describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
37 | let :param_hash do
38 | default_params.merge(param_set)
39 | end
40 |
41 | let :params do
42 | param_set
43 | end
44 |
45 | it { should include_class("apt::params") }
46 |
47 | it { should contain_file("#{title}.pref").with({
48 | 'ensure' => param_hash[:ensure],
49 | 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
50 | 'owner' => 'root',
51 | 'group' => 'root',
52 | 'mode' => '0644',
53 | 'content' => "# #{title}\nExplanation: : #{title}\nPackage: #{param_hash[:packages]}\nPin: release a=#{param_hash[:release] || title}\nPin-Priority: #{param_hash[:priority]}\n",
54 | })
55 | }
56 | end
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/virtualmachines/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 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/lib/puppet/type/anchor.rb:
--------------------------------------------------------------------------------
1 | Puppet::Type.newtype(:anchor) do
2 | desc <<-'ENDOFDESC'
3 | A simple resource type intended to be used as an anchor in a composite class.
4 |
5 | In Puppet 2.6, when a class declares another class, the resources in the
6 | interior class are not contained by the exterior class. This interacts badly
7 | with the pattern of composing complex modules from smaller classes, as it
8 | makes it impossible for end users to specify order relationships between the
9 | exterior class and other modules.
10 |
11 | The anchor type lets you work around this. By sandwiching any interior
12 | classes between two no-op resources that _are_ contained by the exterior
13 | class, you can ensure that all resources in the module are contained.
14 |
15 | class ntp {
16 | # These classes will have the correct order relationship with each
17 | # other. However, without anchors, they won't have any order
18 | # relationship to Class['ntp'].
19 | class { 'ntp::package': }
20 | -> class { 'ntp::config': }
21 | -> class { 'ntp::service': }
22 |
23 | # These two resources "anchor" the composed classes within the ntp
24 | # class.
25 | anchor { 'ntp::begin': } -> Class['ntp::package']
26 | Class['ntp::service'] -> anchor { 'ntp::end': }
27 | }
28 |
29 | This allows the end user of the ntp module to establish require and before
30 | relationships with Class['ntp']:
31 |
32 | class { 'ntp': } -> class { 'mcollective': }
33 | class { 'mcollective': } -> class { 'ntp': }
34 |
35 | ENDOFDESC
36 |
37 | newparam :name do
38 | desc "The name of the anchor resource."
39 | end
40 |
41 | end
42 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/lib/puppet/provider/file_line/ruby.rb:
--------------------------------------------------------------------------------
1 |
2 | Puppet::Type.type(:file_line).provide(:ruby) do
3 |
4 | def exists?
5 | lines.find do |line|
6 | line.chomp == resource[:line].chomp
7 | end
8 | end
9 |
10 | def create
11 | if resource[:match]
12 | handle_create_with_match()
13 | else
14 | handle_create_without_match()
15 | end
16 | end
17 |
18 | def destroy
19 | local_lines = lines
20 | File.open(resource[:path],'w') do |fh|
21 | fh.write(local_lines.reject{|l| l.chomp == resource[:line] }.join(''))
22 | end
23 | end
24 |
25 | private
26 | def lines
27 | # If this type is ever used with very large files, we should
28 | # write this in a different way, using a temp
29 | # file; for now assuming that this type is only used on
30 | # small-ish config files that can fit into memory without
31 | # too much trouble.
32 | @lines ||= File.readlines(resource[:path])
33 | end
34 |
35 | def handle_create_with_match()
36 | regex = resource[:match] ? Regexp.new(resource[:match]) : nil
37 | match_count = lines.select { |l| regex.match(l) }.count
38 | if match_count > 1
39 | raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
40 | end
41 | File.open(resource[:path], 'w') do |fh|
42 | lines.each do |l|
43 | fh.puts(regex.match(l) ? resource[:line] : l)
44 | end
45 |
46 | if (match_count == 0)
47 | fh.puts(resource[:line])
48 | end
49 | end
50 | end
51 |
52 | def handle_create_without_match
53 | File.open(resource[:path], 'a') do |fh|
54 | fh.puts resource[:line]
55 | end
56 | end
57 |
58 |
59 | end
60 |
--------------------------------------------------------------------------------
/virtualmachines/modules/java7/manifests/init.pp:
--------------------------------------------------------------------------------
1 | # Class: java7
2 | #
3 | # This module manages Oracle Java7
4 | # Parameters: none
5 | # Requires:
6 | # apt
7 | # Sample Usage:
8 | # include java7
9 | class java7 {
10 | case $::operatingsystem {
11 | debian: {
12 | include apt
13 |
14 | apt::source { 'webupd8team':
15 | location => "http://ppa.launchpad.net/webupd8team/java/ubuntu",
16 | release => "precise",
17 | repos => "main",
18 | key => "EEA14886",
19 | key_server => "keyserver.ubuntu.com",
20 | include_src => true
21 | }
22 | package { 'oracle-java7-installer':
23 | responsefile => '/tmp/java.preseed',
24 | require => [
25 | Apt::Source['webupd8team'],
26 | File['/tmp/java.preseed']
27 | ],
28 | }
29 | }
30 | ubuntu: {
31 | include apt
32 |
33 | apt::ppa { 'ppa:webupd8team/java': }
34 | package { 'oracle-java7-installer':
35 | responsefile => '/tmp/java.preseed',
36 | require => [
37 | Apt::Ppa['ppa:webupd8team/java'],
38 | File['/tmp/java.preseed']
39 | ],
40 | }
41 | }
42 | default: { notice "Unsupported operatingsystem ${::operatingsystem}" }
43 | }
44 |
45 | case $::operatingsystem {
46 | debian, ubuntu: {
47 | file { '/tmp/java.preseed':
48 | source => 'puppet:///modules/java7/java.preseed',
49 | mode => '0600',
50 | backup => false,
51 | }
52 | }
53 | default: { notice "Unsupported operatingsystem ${::operatingsystem}" }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/defines/conf_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::conf', :type => :define do
3 | let :title do
4 | 'norecommends'
5 | end
6 |
7 | describe "when creating an apt preference" do
8 | let :params do
9 | {
10 | :priority => '00',
11 | :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
12 | }
13 | end
14 |
15 | let :filename do
16 | "/etc/apt/apt.conf.d/00norecommends"
17 | end
18 |
19 | it { should contain_apt__conf('norecommends').with({
20 | 'priority' => '00',
21 | 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
22 | })
23 | }
24 |
25 | it { should contain_file(filename).with({
26 | 'ensure' => 'present',
27 | 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
28 | 'owner' => 'root',
29 | 'group' => 'root',
30 | 'mode' => '0644',
31 | })
32 | }
33 | end
34 |
35 | describe "when removing an apt preference" do
36 | let :params do
37 | {
38 | :ensure => 'absent',
39 | :priority => '00',
40 | :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
41 | }
42 | end
43 |
44 | let :filename do
45 | "/etc/apt/apt.conf.d/00norecommends"
46 | end
47 |
48 | it { should contain_file(filename).with({
49 | 'ensure' => 'absent',
50 | 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
51 | 'owner' => 'root',
52 | 'group' => 'root',
53 | 'mode' => '0644',
54 | })
55 | }
56 | end
57 | end
58 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/lib/puppet/parser/functions/validate_re.rb:
--------------------------------------------------------------------------------
1 | module Puppet::Parser::Functions
2 | newfunction(:validate_re, :doc => <<-'ENDHEREDOC') do |args|
3 | Perform simple validation of a string against one or more regular
4 | expressions. The first argument of this function should be a string to
5 | test, and the second argument should be a stringified regular expression
6 | (without the // delimiters) or an array of regular expressions. If none
7 | of the regular expressions match the string passed in, compilation will
8 | abort with a parse error.
9 |
10 | If a third argument is specified, this will be the error message raised and
11 | seen by the user.
12 |
13 | The following strings will validate against the regular expressions:
14 |
15 | validate_re('one', '^one$')
16 | validate_re('one', [ '^one', '^two' ])
17 |
18 | The following strings will fail to validate, causing compilation to abort:
19 |
20 | validate_re('one', [ '^two', '^three' ])
21 |
22 | A helpful error message can be returned like this:
23 |
24 | validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
25 |
26 | ENDHEREDOC
27 | if (args.length < 2) or (args.length > 3) then
28 | raise Puppet::ParseError, ("validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)")
29 | end
30 |
31 | msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}"
32 |
33 | # We're using a flattened array here because we can't call String#any? in
34 | # Ruby 1.9 like we can in Ruby 1.8
35 | raise Puppet::ParseError, (msg) unless [args[1]].flatten.any? do |re_str|
36 | args[0] =~ Regexp.compile(re_str)
37 | end
38 |
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/src/main/java/com/beauhinks/purejavacomm/PureJavaCommChannelOption.java:
--------------------------------------------------------------------------------
1 | package com.beauhinks.purejavacomm;
2 |
3 | import io.netty.channel.ChannelOption;
4 | import com.beauhinks.purejavacomm.PureJavaCommChannelConfig.Databits;
5 | import com.beauhinks.purejavacomm.PureJavaCommChannelConfig.Paritybit;
6 | import com.beauhinks.purejavacomm.PureJavaCommChannelConfig.Stopbits;
7 |
8 | /**
9 | * Option for configuring a serial port connection
10 | */
11 | public final class PureJavaCommChannelOption extends ChannelOption {
12 | public static final PureJavaCommChannelOption BAUD_RATE =
13 | new PureJavaCommChannelOption("BAUD_RATE");
14 |
15 | public static final PureJavaCommChannelOption DTR =
16 | new PureJavaCommChannelOption("DTR");
17 |
18 | public static final PureJavaCommChannelOption RTS =
19 | new PureJavaCommChannelOption("RTS");
20 |
21 | public static final PureJavaCommChannelOption STOP_BITS =
22 | new PureJavaCommChannelOption("STOP_BITS");
23 |
24 | public static final PureJavaCommChannelOption DATA_BITS =
25 | new PureJavaCommChannelOption("DATA_BITS");
26 |
27 | public static final PureJavaCommChannelOption PARITY_BIT =
28 | new PureJavaCommChannelOption("PARITY_BIT");
29 |
30 | public static final PureJavaCommChannelOption WAIT_TIME =
31 | new PureJavaCommChannelOption("WAIT_TIME");
32 |
33 | public static final PureJavaCommChannelOption READ_TIMEOUT =
34 | new PureJavaCommChannelOption("READ_TIMEOUT");
35 |
36 | @SuppressWarnings("deprecation")
37 | private PureJavaCommChannelOption(String name) {
38 | super(name);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe Puppet::Parser::Functions.function(:merge) do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | describe 'when calling merge from puppet' do
9 | it "should not compile when no arguments are passed" do
10 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
11 | Puppet[:code] = '$x = merge()'
12 | expect {
13 | scope.compiler.compile
14 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
15 | end
16 |
17 | it "should not compile when 1 argument is passed" do
18 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
19 | Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
20 | expect {
21 | scope.compiler.compile
22 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
23 | end
24 | end
25 |
26 | describe 'when calling merge on the scope instance' do
27 | it 'should require all parameters are hashes' do
28 | expect { new_hash = scope.function_merge([{}, '2'])}.should raise_error(Puppet::ParseError, /unexpected argument type String/)
29 | end
30 |
31 | it 'should be able to merge two hashes' do
32 | new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
33 | new_hash['one'].should == '1'
34 | new_hash['two'].should == '2'
35 | new_hash['three'].should == '2'
36 | end
37 |
38 | it 'should merge multiple hashes' do
39 | hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
40 | hash['one'].should == '3'
41 | end
42 |
43 | it 'should accept empty hashes' do
44 | scope.function_merge([{},{},{}]).should == {}
45 | end
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe "the to_bytes function" do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | it "should exist" do
9 | Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
10 | end
11 |
12 | it "should raise a ParseError if there is less than 1 arguments" do
13 | lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
14 | end
15 |
16 | it "should convert kB to B" do
17 | result = scope.function_to_bytes(["4 kB"])
18 | result.should(eq(4096))
19 | end
20 |
21 | it "should work without B in unit" do
22 | result = scope.function_to_bytes(["4 k"])
23 | result.should(eq(4096))
24 | end
25 |
26 | it "should work without a space before unit" do
27 | result = scope.function_to_bytes(["4k"])
28 | result.should(eq(4096))
29 | end
30 |
31 | it "should work without a unit" do
32 | result = scope.function_to_bytes(["5678"])
33 | result.should(eq(5678))
34 | end
35 |
36 | it "should convert fractions" do
37 | result = scope.function_to_bytes(["1.5 kB"])
38 | result.should(eq(1536))
39 | end
40 |
41 | it "should convert scientific notation" do
42 | result = scope.function_to_bytes(["1.5e2 B"])
43 | result.should(eq(150))
44 | end
45 |
46 | it "should do nothing with a positive number" do
47 | result = scope.function_to_bytes([5678])
48 | result.should(eq(5678))
49 | end
50 |
51 | it "should should raise a ParseError if input isn't a number" do
52 | lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
53 | end
54 |
55 | it "should should raise a ParseError if prefix is unknown" do
56 | lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
57 | end
58 | end
59 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the str2saltedsha512 function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 argument" do
12 | expect { scope.function_str2saltedsha512([]) }.should( raise_error(Puppet::ParseError) )
13 | end
14 |
15 | it "should raise a ParseError if there is more than 1 argument" do
16 | expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.should( raise_error(Puppet::ParseError) )
17 | end
18 |
19 | it "should return a salted-sha512 password hash 136 characters in length" do
20 | result = scope.function_str2saltedsha512(["password"])
21 | result.length.should(eq(136))
22 | end
23 |
24 | it "should raise an error if you pass a non-string password" do
25 | expect { scope.function_str2saltedsha512([1234]) }.should( raise_error(Puppet::ParseError) )
26 | end
27 |
28 | it "should generate a valid password" do
29 | # Allow the function to generate a password based on the string 'password'
30 | password_hash = scope.function_str2saltedsha512(["password"])
31 |
32 | # Separate the Salt and Password from the Password Hash
33 | salt = password_hash[0..7]
34 | password = password_hash[8..-1]
35 |
36 | # Convert the Salt and Password from Hex to Binary Data
37 | str_salt = Array(salt.lines).pack('H*')
38 | str_password = Array(password.lines).pack('H*')
39 |
40 | # Combine the Binary Salt with 'password' and compare the end result
41 | saltedpass = Digest::SHA512.digest(str_salt + 'password')
42 | result = (str_salt + saltedpass).unpack('H*')[0]
43 | result.should == password_hash
44 | end
45 | end
46 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env/ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe Puppet::Parser::Functions.function(:validate_bool) do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 | describe 'when calling validate_bool from puppet' do
8 |
9 | %w{ true false }.each do |the_string|
10 |
11 | it "should not compile when #{the_string} is a string" do
12 | Puppet[:code] = "validate_bool('#{the_string}')"
13 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
14 | end
15 |
16 | it "should compile when #{the_string} is a bare word" do
17 | Puppet[:code] = "validate_bool(#{the_string})"
18 | scope.compiler.compile
19 | end
20 |
21 | end
22 |
23 | it "should not compile when an arbitrary string is passed" do
24 | Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
25 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
26 | end
27 |
28 | it "should not compile when no arguments are passed" do
29 | Puppet[:code] = 'validate_bool()'
30 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /wrong number of arguments/)
31 | end
32 |
33 | it "should compile when multiple boolean arguments are passed" do
34 | Puppet[:code] = <<-'ENDofPUPPETcode'
35 | $foo = true
36 | $bar = false
37 | validate_bool($foo, $bar, true, false)
38 | ENDofPUPPETcode
39 | scope.compiler.compile
40 | end
41 |
42 | it "should compile when multiple boolean arguments are passed" do
43 | Puppet[:code] = <<-'ENDofPUPPETcode'
44 | $foo = true
45 | $bar = false
46 | validate_bool($foo, $bar, true, false, 'jeff')
47 | ENDofPUPPETcode
48 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a boolean/)
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 |
3 | require 'spec_helper'
4 |
5 | describe Puppet::Parser::Functions.function(:validate_string) do
6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 |
8 | describe 'when calling validate_string from puppet' do
9 |
10 | %w{ foo bar baz }.each do |the_string|
11 |
12 | it "should compile when #{the_string} is a string" do
13 | Puppet[:code] = "validate_string('#{the_string}')"
14 | scope.compiler.compile
15 | end
16 |
17 | it "should compile when #{the_string} is a bare word" do
18 | Puppet[:code] = "validate_string(#{the_string})"
19 | scope.compiler.compile
20 | end
21 |
22 | end
23 |
24 | %w{ true false }.each do |the_string|
25 | it "should compile when #{the_string} is a string" do
26 | Puppet[:code] = "validate_string('#{the_string}')"
27 | scope.compiler.compile
28 | end
29 |
30 | it "should not compile when #{the_string} is a bare word" do
31 | Puppet[:code] = "validate_string(#{the_string})"
32 | expect { scope.compiler.compile }.should raise_error(Puppet::ParseError, /is not a string/)
33 | end
34 | end
35 |
36 | it "should compile when multiple string arguments are passed" do
37 | Puppet[:code] = <<-'ENDofPUPPETcode'
38 | $foo = ''
39 | $bar = 'two'
40 | validate_string($foo, $bar)
41 | ENDofPUPPETcode
42 | scope.compiler.compile
43 | end
44 |
45 | it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
46 | Puppet[:code] = <<-'ENDofPUPPETcode'
47 | $foo = undef
48 | validate_string($foo)
49 | ENDofPUPPETcode
50 | scope.compiler.compile
51 | end
52 |
53 | it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
54 | Puppet[:code] = <<-'ENDofPUPPETcode'
55 | validate_string($foobarbazishouldnotexist)
56 | ENDofPUPPETcode
57 | scope.compiler.compile
58 | end
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/virtualmachines/modules/apt/spec/classes/backports_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 | describe 'apt::backports', :type => :class do
3 |
4 | describe 'when turning on backports for ubuntu karmic' do
5 |
6 | let :facts do
7 | {
8 | 'lsbdistcodename' => 'Karmic',
9 | 'lsbdistid' => 'Ubuntu'
10 | }
11 | end
12 |
13 | it { should contain_apt__source('backports').with({
14 | 'location' => 'http://old-releases.ubuntu.com/ubuntu',
15 | 'release' => 'karmic-backports',
16 | 'repos' => 'main universe multiverse restricted',
17 | 'key' => '437D05B5',
18 | 'key_server' => 'pgp.mit.edu',
19 | 'pin' => '200',
20 | })
21 | }
22 | end
23 |
24 | describe "when turning on backports for debian squeeze" do
25 |
26 | let :facts do
27 | {
28 | 'lsbdistcodename' => 'Squeeze',
29 | 'lsbdistid' => 'Debian',
30 | }
31 | end
32 |
33 | it { should contain_apt__source('backports').with({
34 | 'location' => 'http://backports.debian.org/debian-backports',
35 | 'release' => 'squeeze-backports',
36 | 'repos' => 'main contrib non-free',
37 | 'key' => '55BE302B',
38 | 'key_server' => 'pgp.mit.edu',
39 | 'pin' => '200',
40 | })
41 | }
42 | end
43 |
44 | describe "when turning on backports for debian squeeze but using your own mirror" do
45 |
46 | let :facts do
47 | {
48 | 'lsbdistcodename' => 'Squeeze',
49 | 'lsbdistid' => 'Debian'
50 | }
51 | end
52 |
53 | let :location do
54 | 'http://mirrors.example.com/debian-backports'
55 | end
56 |
57 | let :params do
58 | { 'location' => location }
59 | end
60 |
61 | it { should contain_apt__source('backports').with({
62 | 'location' => location,
63 | 'release' => 'squeeze-backports',
64 | 'repos' => 'main contrib non-free',
65 | 'key' => '55BE302B',
66 | 'key_server' => 'pgp.mit.edu',
67 | 'pin' => '200',
68 | })
69 | }
70 | end
71 | end
72 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/lib/puppet/parser/functions/zip.rb:
--------------------------------------------------------------------------------
1 | #
2 | # zip.rb
3 | #
4 |
5 | module Puppet::Parser::Functions
6 | newfunction(:zip, :type => :rvalue, :doc => <<-EOS
7 | Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
8 |
9 | *Example:*
10 |
11 | zip(['1','2','3'],['4','5','6'])
12 |
13 | Would result in:
14 |
15 | ["1", "4"], ["2", "5"], ["3", "6"]
16 | EOS
17 | ) do |arguments|
18 |
19 | # Technically we support three arguments but only first is mandatory ...
20 | raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
21 | "given (#{arguments.size} for 2)") if arguments.size < 2
22 |
23 | a = arguments[0]
24 | b = arguments[1]
25 |
26 | unless a.is_a?(Array) and b.is_a?(Array)
27 | raise(Puppet::ParseError, 'zip(): Requires array to work with')
28 | end
29 |
30 | flatten = arguments[2] if arguments[2]
31 |
32 | if flatten
33 | klass = flatten.class
34 |
35 | # We can have either true or false, or string which resembles boolean ...
36 | unless [FalseClass, TrueClass, String].include?(klass)
37 | raise(Puppet::ParseError, 'zip(): Requires either ' +
38 | 'boolean or string to work with')
39 | end
40 |
41 | if flatten.is_a?(String)
42 | # We consider all the yes, no, y, n and so on too ...
43 | flatten = case flatten
44 | #
45 | # This is how undef looks like in Puppet ...
46 | # We yield false in this case.
47 | #
48 | when /^$/, '' then false # Empty string will be false ...
49 | when /^(1|t|y|true|yes)$/ then true
50 | when /^(0|f|n|false|no)$/ then false
51 | when /^(undef|undefined)$/ then false # This is not likely to happen ...
52 | else
53 | raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
54 | end
55 | end
56 | end
57 |
58 | result = a.zip(b)
59 | result = flatten ? result.flatten : result
60 |
61 | return result
62 | end
63 | end
64 |
65 | # vim: set ts=2 sw=2 et :
66 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env ruby -S rspec
2 | require 'spec_helper'
3 |
4 | describe "the is_domain_name function" do
5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6 |
7 | it "should exist" do
8 | Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
9 | end
10 |
11 | it "should raise a ParseError if there is less than 1 arguments" do
12 | lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
13 | end
14 |
15 | it "should return true if a valid short domain name" do
16 | result = scope.function_is_domain_name(["x.com"])
17 | result.should(be_true)
18 | end
19 |
20 | it "should return true if the domain is ." do
21 | result = scope.function_is_domain_name(["."])
22 | result.should(be_true)
23 | end
24 |
25 | it "should return true if the domain is x.com." do
26 | result = scope.function_is_domain_name(["x.com."])
27 | result.should(be_true)
28 | end
29 |
30 | it "should return true if a valid domain name" do
31 | result = scope.function_is_domain_name(["foo.bar.com"])
32 | result.should(be_true)
33 | end
34 |
35 | it "should allow domain parts to start with numbers" do
36 | result = scope.function_is_domain_name(["3foo.2bar.com"])
37 | result.should(be_true)
38 | end
39 |
40 | it "should allow domain to end with a dot" do
41 | result = scope.function_is_domain_name(["3foo.2bar.com."])
42 | result.should(be_true)
43 | end
44 |
45 | it "should allow a single part domain" do
46 | result = scope.function_is_domain_name(["orange"])
47 | result.should(be_true)
48 | end
49 |
50 | it "should return false if domain parts start with hyphens" do
51 | result = scope.function_is_domain_name(["-3foo.2bar.com"])
52 | result.should(be_false)
53 | end
54 |
55 | it "should return true if domain contains hyphens" do
56 | result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
57 | result.should(be_true)
58 | end
59 |
60 | it "should return false if domain name contains spaces" do
61 | result = scope.function_is_domain_name(["not valid"])
62 | result.should(be_false)
63 | end
64 | end
65 |
--------------------------------------------------------------------------------
/virtualmachines/modules/stdlib/spec/watchr.rb:
--------------------------------------------------------------------------------
1 | ENV['FOG_MOCK'] ||= 'true'
2 | ENV['AUTOTEST'] = 'true'
3 | ENV['WATCHR'] = '1'
4 |
5 | system 'clear'
6 |
7 | def growl(message)
8 | growlnotify = `which growlnotify`.chomp
9 | title = "Watchr Test Results"
10 | image = case message
11 | when /(\d+)\s+?(failure|error)/i
12 | ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
13 | else
14 | '~/.watchr_images/unknown.png'
15 | end
16 | options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
17 | system %(#{growlnotify} #{options} &)
18 | end
19 |
20 | def run(cmd)
21 | puts(cmd)
22 | `#{cmd}`
23 | end
24 |
25 | def run_spec_test(file)
26 | if File.exist? file
27 | result = run "rspec --format p --color #{file}"
28 | growl result.split("\n").last
29 | puts result
30 | else
31 | puts "FIXME: No test #{file} [#{Time.now}]"
32 | end
33 | end
34 |
35 | def filter_rspec(data)
36 | data.split("\n").find_all do |l|
37 | l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
38 | end.join("\n")
39 | end
40 |
41 | def run_all_tests
42 | system('clear')
43 | files = Dir.glob("spec/**/*_spec.rb").join(" ")
44 | result = run "rspec #{files}"
45 | growl_results = filter_rspec result
46 | growl growl_results
47 | puts result
48 | puts "GROWL: #{growl_results}"
49 | end
50 |
51 | # Ctrl-\
52 | Signal.trap 'QUIT' do
53 | puts " --- Running all tests ---\n\n"
54 | run_all_tests
55 | end
56 |
57 | @interrupted = false
58 |
59 | # Ctrl-C
60 | Signal.trap 'INT' do
61 | if @interrupted then
62 | @wants_to_quit = true
63 | abort("\n")
64 | else
65 | puts "Interrupt a second time to quit"
66 | @interrupted = true
67 | Kernel.sleep 1.5
68 | # raise Interrupt, nil # let the run loop catch it
69 | run_suite
70 | end
71 | end
72 |
73 | def file2spec(file)
74 | result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb')
75 | result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb')
76 | end
77 |
78 |
79 | watch( 'spec/.*_spec\.rb' ) do |md|
80 | #run_spec_test(md[0])
81 | run_all_tests
82 | end
83 | watch( 'lib/.*\.rb' ) do |md|
84 | # run_spec_test(file2spec(md[0]))
85 | run_all_tests
86 | end
87 |
--------------------------------------------------------------------------------