From c4146cc11d362363a707db477a016caf9b622a77 Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Fri, 27 Feb 2015 15:36:27 +0100 Subject: [PATCH] Update staging to bc434a71e19aae54223d57c274e2e1a7f9546d5e bc434a71e19aae54223d57c274e2e1a7f9546d5e Release 1.0.4 f1362d4cb8173e908b0dcf40a5291c1fb0ff395e Merge pull request #57 from nanliu/windows a36d22c39586bfc14fc13a3f1af3c43f4dabc22a Only use source_permission on Puppet 3.4 or higher b430e0809de176cacc522ffc29775278264224c3 Support windows local files. 40aef62affa3ece60717219bdf17988292d4e429 Merge pull request #55 from nanliu/release 2b1d15efa4eafae2d6ee0e2ce47bd62da2f667ae Release 1.0.3 255a508177d8a289a0e8c0245f00d67c7101a535 Merge pull request #54 from nanliu/documentation cc0a874daf75682292851ab57acabe5e998149ad Update staging::file documentation. 0095ec4cf3e16d51e588f1264928e997e4b34e72 Merge pull request #52 from bogdando/fix_MODULES-1651 4e772568afc5ab6aa7376cf64fdddebfcf3e9366 Merge pull request #53 from joshsamuelson/powershell 6350a031275847c40d865c01161e97d3831025ea Check for powershell first to avoid aliases for curl & wget 4aa0bee014c1cd1770a19d292388514acc646849 Add retries for the file transfer 39387eb528d42919ef08d3c81bfa70421c35bad0 Merge pull request #50 from madelaney/master 89debf2d7c2686358d6668163b715b126e6c309e -- Adding support for FreeBSD 798f98035705f5643a222b8794e3ec3fa94df2d9 Merge pull request #48 from kgeis/patch-1 f905dac8125902d15069b2bdb37c4159c5e0f0a1 Update metadata.json e9aae523a2c79ea5314a71bc6ea1afddd3168a03 Release 1.0.2 df5bdf4688a5a4c4747bb9ff51277184b1f9c91a Merge pull request #46 from nanliu/fixture 0df9482a8f81fc393464f27f155e58ef322d7570 Update Gemfile and Rakefile ffc158d05c30c2d8d6e8cdf88372c30620ae7191 Merge pull request #43 from mhaskel/strict_variables 325558fab31105aabdd70b7e0f1e3f0bda93feef Fix for strict variables support 6452b80b62a9cc7f9dd9896a7a454276b01fd51b Merge pull request #38 from nanliu/ENTERPRISE-258 e93d005809f91cfa6eb11d5f4d409ed0e458420e Release 1.0.0 for module team. 4ae247a28f6a3925d5da3143dcd0536e05be73e2 Merge pull request #39 from epelletier/master 60aa376219e0e00118c863502c4575d6b336cdf2 Added S3 support. 09638af3a92482add1472aef1cb023f38ef8b030 Added S3 support. f405a38974fc018660919557797ebd3941154a4d Fix conflict with pe_staging. ebfb56c0c693374f8312b581f8729009dacab7be Merge pull request #36 from nanliu/release ec1ce78c1ec0c82d440cb5d1b98a065c858d3c0e Release 0.4.1 for forge. 9f331f5a93284cf254a180d2cbf1babc65fede17 Merge pull request #34 from nanliu/readme a041781023078506135e4ad0c24d22bb63bfb1d5 Update gitignore and readme example. 3dcb8934308cf710436d34694e9376a007004209 Merge pull request #33 from reidmv/fix_windows_mode d7ccedb29c61928a4f6809134a6b9c1b423e2d53 Merge pull request #31 from mcanevet/fix/strict_variables 8c58bebf3ce9df9a017e8572d222217225c2051b Fix staging::extract with strict_variables 6a7c02a406212789ca01067018295c555410b110 Add missing facts in unit tests b9be7175404f54696b4ef051069c8bfa1b2cee45 Use strict_variables when puppet version >= 3.5 1a4ce6fc6a815960f799cda37f93f5aff8eda925 Merge pull request #30 from mhaskel/strip 8c0c77bf19d55b67deb459ec44296bd66cf6366e Add support for GNU tar's --strip option. 7a2667c589a7618b95b7c09674cab5c7eb7b7740 Merge pull request #24 from reidmv/fix_target_path 2ece902cc7c5bc3a5eeba3fccbfd36d436ca81c1 Merge pull request #27 from justinclayton/patch-2 be3b1371d9f4130a0d13b27cca4c240ea9a4d54a fix typo in error message 69c0c7cd84039c5520bc6d51800d2f7d7d7f36b7 On Windows, use well-known SIDs to set ownership 060121340f77e198795997ddb722dd25cce1408a Update spec tests to reflect absolute target 2b63b2763f4a599a2d11109e0259e817803c7bce Use $target_file in *_get variables, not $name --- Puppetfile | 2 +- staging/.fixtures.yml | 2 +- staging/.gitignore | 2 + staging/.travis.yml | 22 ++-- staging/Gemfile | 20 +--- staging/Modulefile | 10 -- staging/README.md | 61 ++++++---- staging/Rakefile | 52 +-------- staging/lib/facter/staging_http_get.rb | 2 +- staging/manifests/extract.pp | 20 +++- staging/manifests/file.pp | 46 ++++++-- staging/manifests/init.pp | 13 ++- staging/manifests/params.pp | 13 ++- staging/metadata.json | 105 ++++++++++++++++++ staging/spec/defines/staging_deploy_spec.rb | 1 + staging/spec/defines/staging_extract_spec.rb | 46 ++++++++ staging/spec/defines/staging_file_spec.rb | 41 +++++-- staging/spec/spec_helper.rb | 27 +++++ .../parser/functions/staging_parse_spec.rb | 0 19 files changed, 333 insertions(+), 152 deletions(-) delete mode 100644 staging/Modulefile create mode 100644 staging/metadata.json mode change 100755 => 100644 staging/spec/unit/puppet/parser/functions/staging_parse_spec.rb diff --git a/Puppetfile b/Puppetfile index 535eab130..fd7e0b61f 100644 --- a/Puppetfile +++ b/Puppetfile @@ -167,7 +167,7 @@ mod 'ssh', :git => 'https://github.com/saz/puppet-ssh.git' mod 'staging', - :commit => '887275d8fb20e148c6f9eb327f1f6c8ea5ee280f', + :commit => 'bc434a71e19aae54223d57c274e2e1a7f9546d5e', :git => 'https://github.com/nanliu/puppet-staging.git' mod 'stdlib', diff --git a/staging/.fixtures.yml b/staging/.fixtures.yml index d64f95571..178f5ba64 100644 --- a/staging/.fixtures.yml +++ b/staging/.fixtures.yml @@ -1,5 +1,5 @@ fixtures: repositories: - stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' + stdlib: 'http://github.com/puppetlabs/puppetlabs-stdlib.git' symlinks: staging: "#{source_dir}" diff --git a/staging/.gitignore b/staging/.gitignore index 499cbe502..8b7221c84 100644 --- a/staging/.gitignore +++ b/staging/.gitignore @@ -1,4 +1,6 @@ .bundle .pkg +.ruby-version .vagrant Gemfile.lock +spec/fixtures diff --git a/staging/.travis.yml b/staging/.travis.yml index 1a4302e6d..ca688afab 100644 --- a/staging/.travis.yml +++ b/staging/.travis.yml @@ -1,22 +1,16 @@ language: ruby script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" -before_install: - - gem update bundler - - bundle --version - - gem update --system 2.1.11 - - gem --version -rvm: - - 1.8.7 - - 1.9.3 -env: - - PUPPET_GEM_VERSION="~> 3.2.0" - - PUPPET_GEM_VERSION=">= 3.0.0" branches: only: - master matrix: - exclude: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION=">= 3.0.0" + fast_finish: true + include: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.3.0" FACTER_GEM_VERSION="~> 1.7.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" notifications: email: false diff --git a/staging/Gemfile b/staging/Gemfile index dbc5ead10..7bfafd715 100644 --- a/staging/Gemfile +++ b/staging/Gemfile @@ -1,25 +1,7 @@ source "https://rubygems.org" group :development, :test do - gem 'rake' + gem 'bodeco_module_helper', :git => 'https://github.com/bodeco/bodeco_module_helper.git' gem 'rspec', "~> 2.11.0", :require => false gem 'mocha', "~> 0.10.5", :require => false - gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-puppet', :require => false - gem 'puppet-lint' -end - -facterversion = ENV['GEM_FACTER_VERSION'] -if facterversion - gem 'facter', facterversion -else - gem 'facter', :require => false -end - -ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] -puppetversion = ENV['GEM_PUPPET_VERSION'] -if puppetversion - gem 'puppet', puppetversion -else - gem 'puppet', :require => false end diff --git a/staging/Modulefile b/staging/Modulefile deleted file mode 100644 index 3750abc30..000000000 --- a/staging/Modulefile +++ /dev/null @@ -1,10 +0,0 @@ -name 'nanliu-staging' -version '0.4.0' -source 'git@github.com:nanliu/puppet-staging.git' -author 'nanliu' -license 'Apache License Version 2.0' -summary 'Compressed file staging and deployment' -description 'Manages compressed file staging and deployment.' -project_page 'https://github.com/nanliu/puppet-staging' - -## Add dependencies, if any: diff --git a/staging/README.md b/staging/README.md index a0d3e37cc..ebb5b02c2 100644 --- a/staging/README.md +++ b/staging/README.md @@ -6,44 +6,57 @@ Manages staging directory, along with download/extraction of compressed files. WARNING: Version 0.2.0 no longer uses hiera functions. The same behavior should be available in Puppet 3.0. +NOTE: Version 1.0.0 will be the last feature release. New functionality such as checksum will be implemented in a type/provider module [puppet-archive](https://www.github.com/nanliu/puppet-archive). + ## Usage Specify a different default staging path (must be declared before using resource): - - class { 'staging': - path => '/var/staging', - owner => 'puppet', - group => 'puppet', - } +```puppet +class { 'staging': + path => '/var/staging', + owner => 'puppet', + group => 'puppet', +} +``` Staging files from various sources: +```puppet +staging::file { 'sample': + source => 'puppet://modules/staging/sample', +} - staging::file { 'sample': - source => 'puppet://modules/staging/sample', - } - - staging::file { 'apache-tomcat-6.0.35': - source => 'http://apache.cs.utah.edu/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz', - } - +staging::file { 'apache-tomcat-6.0.35': + source => 'http://apache.cs.utah.edu/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.tar.gz', +} +``` Staging and extracting files: - - staging::file { 'sample.tar.gz': - source => 'puppet:///modules/staging/sample.tar.gz' - } - - staging::extract { 'sample.tar.gz': - target => '/tmp/staging', - creates => '/tmp/staging/sample', - require => Staging::File['sample.tar.gz'], - } +```puppet +staging::file { 'sample.tar.gz': + source => 'puppet:///modules/staging/sample.tar.gz' +} + +staging::extract { 'sample.tar.gz': + target => '/tmp/staging', + creates => '/tmp/staging/sample', + require => Staging::File['sample.tar.gz'], +} +``` + +Deploying a file (combining staging and extract): +```puppet +staging::deploy { 'sample.tar.gz': + source => 'puppet:///modules/staging/sample.tar.gz', + target => '/usr/local', +} +``` Staging files currently support the following source: * http(s):// * puppet:// * ftp:// +* s3:// (requires aws cli to be installed and configured.) * local (though this doesn't serve any real purpose.) ## Contributor diff --git a/staging/Rakefile b/staging/Rakefile index 5bc13983e..7cae97284 100644 --- a/staging/Rakefile +++ b/staging/Rakefile @@ -1,51 +1 @@ -require 'rubygems' -require 'puppetlabs_spec_helper/rake_tasks' - -def io_popen(command) - IO.popen(command) do |io| - io.each do |line| - print line - yield line if block_given? - end - end -end - -# Customize lint option -task :lint do - PuppetLint.configuration.send("disable_80chars") - PuppetLint.configuration.send("disable_class_parameter_defaults") -end - -desc "Validate manifests, templates, and ruby files in lib." -task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" - end - Dir['lib/**/*.rb'].each do |lib_file| - sh "ruby -c #{lib_file}" - end - Dir['templates/**/*.erb'].each do |template| - sh "erb -P -x -T '-' #{template} | ruby -c" - end -end - -# Initialize vagrant instance for testing -desc "Powers on Vagrant VMs with specific manifests" -task :vagrant, :manifest do |t, args| - Rake::Task["spec_prep"].execute - - prefix = "VAGRANT_MANIFEST='#{args[:manifest]||'init.pp'}'" - - puts args[:manifest] - provision = false - io_popen("export #{prefix}; vagrant up --provider=vmware_fusion") do |line| - provision = true if line =~ /Machine is already running./ - end - io_popen("export #{prefix}; vagrant provision") if provision -end - -# Cleanup vagrant environment -task :vagrant_clean do - `vagrant destroy -f` - Rake::Task["spec_clean"].execute -end +require 'bodeco_module_helper/rake_tasks' diff --git a/staging/lib/facter/staging_http_get.rb b/staging/lib/facter/staging_http_get.rb index 19784a690..9f55b47a5 100644 --- a/staging/lib/facter/staging_http_get.rb +++ b/staging/lib/facter/staging_http_get.rb @@ -17,7 +17,7 @@ result end - ['curl', 'wget', 'powershell'].each do |cmd| + ['powershell', 'curl', 'wget'].each do |cmd| available = which.call(cmd) fact = available ? cmd : nil break if fact diff --git a/staging/manifests/extract.pp b/staging/manifests/extract.pp index 163da1492..a48abba7f 100644 --- a/staging/manifests/extract.pp +++ b/staging/manifests/extract.pp @@ -8,6 +8,7 @@ $user = undef, #: extract file as this user. $group = undef, #: extract file as this group. $environment = undef, #: environment variables. + $strip = undef, #: extract file with the --strip=X option. Only works with GNU tar. $subdir = $caller_module_name #: subdir per module in staging directory. ) { @@ -32,6 +33,8 @@ $folder = staging_parse($name, 'basename') } $creates_path = "${target}/${folder}" + } else { + $creates_path = undef } if scope_defaults('Exec','path') { @@ -59,21 +62,32 @@ } } + if $strip { + if $::osfamily == 'Solaris' or $name !~ /(.tar|.tgz|.tar.gz|.tar.bz2)$/ { + warning('strip is only supported with GNU tar, ignoring the parameter') + $strip_opt = '' + } else { + $strip_opt = " --strip=${strip}" + } + } else { + $strip_opt = '' + } + case $name { /.tar$/: { - $command = "tar xf ${source_path}" + $command = "tar xf ${source_path}${strip_opt}" } /(.tgz|.tar.gz)$/: { if $::osfamily == 'Solaris' { $command = "gunzip -dc < ${source_path} | tar xf - " } else { - $command = "tar xzf ${source_path}" + $command = "tar xzf ${source_path}${strip_opt}" } } /.tar.bz2$/: { - $command = "tar xjf ${source_path}" + $command = "tar xjf ${source_path}${strip_opt}" } /.zip$/: { diff --git a/staging/manifests/file.pp b/staging/manifests/file.pp index 60b69d796..adda4d957 100644 --- a/staging/manifests/file.pp +++ b/staging/manifests/file.pp @@ -10,8 +10,8 @@ # resource as necessary. # define staging::file ( - $source, #: the source file location, supports local files, puppet://, http://, https://, ftp:// - $target = undef, #: the target staging directory, if unspecified ${staging::path}/${caller_module_name} + $source, #: the source file location, supports local files, puppet://, http://, https://, ftp://, s3:// + $target = undef, #: the target file location, if unspecified ${staging::path}/${subdir}/${name} $username = undef, #: https or ftp username $certificate = undef, #: https certificate file $password = undef, #: https or ftp user password or https certificate password @@ -19,6 +19,8 @@ $timeout = undef, #: the the time to wait for the file transfer to complete $curl_option = undef, #: options to pass to curl $wget_option = undef, #: options to pass to wget + $tries = undef, #: amount of retries for the file transfer when non transient connection errors exist + $try_sleep = undef, #: time to wait between retries for the file transfer $subdir = $caller_module_name ) { @@ -46,21 +48,23 @@ cwd => $staging_dir, creates => $target_file, timeout => $timeout, + try_sleep => $try_sleep, + tries => $tries, logoutput => on_failure, } case $::staging_http_get { 'curl', default: { - $http_get = "curl ${curl_option} -f -L -o ${name} ${quoted_source}" - $http_get_passwd = "curl ${curl_option} -f -L -o ${name} -u ${username}:${password} ${quoted_source}" - $http_get_cert = "curl ${curl_option} -f -L -o ${name} -E ${certificate}:${password} ${quoted_source}" - $ftp_get = "curl ${curl_option} -o ${name} ${quoted_source}" - $ftp_get_passwd = "curl ${curl_option} -o ${name} -u ${username}:${password} ${quoted_source}" + $http_get = "curl ${curl_option} -f -L -o ${target_file} ${quoted_source}" + $http_get_passwd = "curl ${curl_option} -f -L -o ${target_file} -u ${username}:${password} ${quoted_source}" + $http_get_cert = "curl ${curl_option} -f -L -o ${target_file} -E ${certificate}:${password} ${quoted_source}" + $ftp_get = "curl ${curl_option} -o ${target_file} ${quoted_source}" + $ftp_get_passwd = "curl ${curl_option} -o ${target_file} -u ${username}:${password} ${quoted_source}" } 'wget': { - $http_get = "wget ${wget_option} -O ${name} ${quoted_source}" - $http_get_passwd = "wget ${wget_option} -O ${name} --user=${username} --password=${password} ${quoted_source}" - $http_get_cert = "wget ${wget_option} -O ${name} --user=${username} --certificate=${certificate} ${quoted_source}" + $http_get = "wget ${wget_option} -O ${target_file} ${quoted_source}" + $http_get_passwd = "wget ${wget_option} -O ${target_file} --user=${username} --password=${password} ${quoted_source}" + $http_get_cert = "wget ${wget_option} -O ${target_file} --user=${username} --certificate=${certificate} ${quoted_source}" $ftp_get = $http_get $ftp_get_passwd = $http_get_passwd } @@ -79,6 +83,20 @@ replace => false, } } + /^[A-Za-z]:/: { + if versioncmp($::puppetversion, '3.4.0') >= 0 { + file { $target_file: + source => $source, + replace => false, + source_permissions => ignore, + } + } else { + file { $target_file: + source => $source, + replace => false, + } + } + } /^puppet:\/\//: { file { $target_file: source => $source, @@ -107,8 +125,14 @@ command => $command, } } + /^s3:\/\//: { + $command = "aws s3 cp ${source} ${target_file}" + exec { $target_file: + command => $command, + } + } default: { - fail("stage::file: do not recognize source ${source}.") + fail("staging::file: do not recognize source ${source}.") } } diff --git a/staging/manifests/init.pp b/staging/manifests/init.pp index 19bb2da40..227e1ea3d 100644 --- a/staging/manifests/init.pp +++ b/staging/manifests/init.pp @@ -18,11 +18,14 @@ $exec_path = $staging::params::exec_path #: executable default path ) inherits staging::params { - file { $path: - ensure => directory, - owner => $owner, - group => $group, - mode => $mode, + # Resolve conflict with pe_staging + if !defined(File[$path]) { + file { $path: + ensure => directory, + owner => $owner, + group => $group, + mode => $mode, + } } } diff --git a/staging/manifests/params.pp b/staging/manifests/params.pp index 95ee0a134..0d2fba362 100644 --- a/staging/manifests/params.pp +++ b/staging/manifests/params.pp @@ -17,10 +17,17 @@ } 'windows': { $path = $::staging_windir - $owner = undef - $group = undef - $mode = '0755' + $owner = 'S-1-5-32-544' # Adminstrators + $group = 'S-1-5-18' # SYSTEM + $mode = '0660' $exec_path = $::path } + 'FreeBSD': { + $path = '/var/tmp/staging' + $owner = '0' + $group = '0' + $mode = '0755' + $exec_path = '/usr/local/bin:/usr/bin:/bin' + } } } diff --git a/staging/metadata.json b/staging/metadata.json new file mode 100644 index 000000000..eb5b2d866 --- /dev/null +++ b/staging/metadata.json @@ -0,0 +1,105 @@ +{ + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "OracleLinux", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "Scientific", + "operatingsystemrelease": [ + "4", + "5", + "6" + ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "11 SP1" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04" + ] + }, + { + "operatingsystem": "Solaris", + "operatingsystemrelease": [ + "10", + "11" + ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2003", + "Server 2003 R2", + "Server 2008", + "Server 2008 R2", + "Server 2012", + "Server 2012 R2", + "7", + "8" + ] + }, + { + "operatingsystem": "AIX", + "operatingsystemrelease": [ + "5.3", + "6.1", + "7.1" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.x" + }, + { + "name": "puppet", + "version_requirement": ">=2.7.0 <4.0.0" + } + ], + "name": "nanliu-staging", + "version": "1.0.4", + "source": "git://github.com/nanliu/puppet-staging", + "author": "Nan Liu", + "license": "Apache-2.0", + "summary": "Compressed file staging and deployment", + "description": "Manages compressed file staging and deployment.", + "project_page": "https://github.com/nanliu/puppet-staging", + "dependencies": [ + + ] +} diff --git a/staging/spec/defines/staging_deploy_spec.rb b/staging/spec/defines/staging_deploy_spec.rb index 66541d22f..2cfd33027 100644 --- a/staging/spec/defines/staging_deploy_spec.rb +++ b/staging/spec/defines/staging_deploy_spec.rb @@ -4,6 +4,7 @@ # forcing a more sane caller_module_name to match real usage. let(:facts) { { :caller_module_name => 'spec', :osfamily => 'RedHat', + :staging_http_get => 'curl', :path => '/usr/local/bin:/usr/bin:/bin', } } describe 'when deploying tar.gz' do diff --git a/staging/spec/defines/staging_extract_spec.rb b/staging/spec/defines/staging_extract_spec.rb index a3d742245..84186b997 100644 --- a/staging/spec/defines/staging_extract_spec.rb +++ b/staging/spec/defines/staging_extract_spec.rb @@ -21,6 +21,22 @@ } end + describe 'when deploying tar.gz with strip' do + let(:title) { 'sample.tar.gz' } + let(:params) { { :target => '/opt', + :strip => 1, } } + + it { + should contain_file('/opt/staging') + should contain_exec('extract sample.tar.gz').with({ + :command => 'tar xzf /opt/staging/spec/sample.tar.gz --strip=1', + :path => '/usr/local/bin:/usr/bin:/bin', + :cwd => '/opt', + :creates => '/opt/sample' + }) + } + end + describe 'when deploying zip' do let(:title) { 'sample.zip' } let(:params) { { :target => '/opt' } } @@ -35,6 +51,21 @@ } end + describe 'when deploying zip with strip (noop)' do + let(:title) { 'sample.zip' } + let(:params) { { :target => '/opt', + :strip => 1, } } + + it { should contain_file('/opt/staging') + should contain_exec('extract sample.zip').with({ + :command => 'unzip /opt/staging/spec/sample.zip', + :path => '/usr/local/bin:/usr/bin:/bin', + :cwd => '/opt', + :creates => '/opt/sample' + }) + } + end + describe 'when deploying war' do let(:title) { 'sample.war' } let(:params) { { :target => '/opt' } } @@ -49,6 +80,21 @@ } end + describe 'when deploying war with strip (noop)' do + let(:title) { 'sample.war' } + let(:params) { { :target => '/opt', + :strip => 1, } } + + it { should contain_file('/opt/staging') + should contain_exec('extract sample.war').with({ + :command => 'jar xf /opt/staging/spec/sample.war', + :path => '/usr/local/bin:/usr/bin:/bin', + :cwd => '/opt', + :creates => '/opt/sample' + }) + } + end + describe 'when deploying unknown' do let(:title) { 'sample.zzz'} let(:params) { { :target => '/opt' } } diff --git a/staging/spec/defines/staging_file_spec.rb b/staging/spec/defines/staging_file_spec.rb index ab1ee59e1..2eee396a1 100644 --- a/staging/spec/defines/staging_file_spec.rb +++ b/staging/spec/defines/staging_file_spec.rb @@ -2,7 +2,12 @@ describe 'staging::file', :type => :define do # forcing a more sane caller_module_name to match real usage. - let(:facts) { { :caller_module_name=> 'spec' } } + let(:facts) { { + :caller_module_name => 'spec', + :osfamily => 'RedHat', + :staging_http_get => 'curl', + :puppetversion => Puppet.version, + } } describe 'when deploying via puppet' do let(:title) { 'sample.tar.gz' } @@ -28,6 +33,20 @@ } end + describe 'when deploying via Windows local' do + let(:title) { 'sample.tar.gz' } + let(:params) { { + :source => 'S:/nfs/sample.tar.gz', + :target => '/usr/local/sample.tar.gz', + } } + + it { + should contain_file('/opt/staging') + should contain_file('/usr/local/sample.tar.gz') + should_not contain_exec('/opt/staging/spec/sample.tar.gz') + } + end + describe 'when deploying via http' do let(:title) { 'sample.tar.gz' } let(:params) { { :source => 'http://webserver/sample.tar.gz' } } @@ -35,7 +54,7 @@ it { should contain_file('/opt/staging') should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -f -L -o sample.tar.gz http://webserver/sample.tar.gz', + :command => 'curl -f -L -o /opt/staging/spec/sample.tar.gz http://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', @@ -55,7 +74,7 @@ it { should contain_file('/opt/staging') should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -b -f -L -o sample.tar.gz http://webserver/sample.tar.gz', + :command => 'curl -b -f -L -o /opt/staging/spec/sample.tar.gz http://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', @@ -68,16 +87,20 @@ describe 'when deploying via http with parameters' do let(:title) { 'sample.tar.gz' } let(:params) { { :source => 'http://webserver/sample.tar.gz', - :target => '/usr/local/sample.tar.gz', + :target => '/usr/local/sample.tar.gz', + :tries => '10', + :try_sleep => '6', } } it { should contain_file('/opt/staging') should contain_exec('/usr/local/sample.tar.gz').with( { - :command => 'curl -f -L -o sample.tar.gz http://webserver/sample.tar.gz', + :command => 'curl -f -L -o /usr/local/sample.tar.gz http://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/usr/local', :creates => '/usr/local/sample.tar.gz', + :tries => '10', + :try_sleep => '6', }) } end @@ -88,7 +111,7 @@ it { should contain_file('/opt/staging') } it { should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -f -L -o sample.tar.gz https://webserver/sample.tar.gz', + :command => 'curl -f -L -o /opt/staging/spec/sample.tar.gz https://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', @@ -107,7 +130,7 @@ it { should contain_file('/opt/staging') should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -f -L -o sample.tar.gz -u puppet:puppet https://webserver/sample.tar.gz', + :command => 'curl -f -L -o /opt/staging/spec/sample.tar.gz -u puppet:puppet https://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', @@ -124,7 +147,7 @@ it { should contain_file('/opt/staging') should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -o sample.tar.gz ftp://webserver/sample.tar.gz', + :command => 'curl -o /opt/staging/spec/sample.tar.gz ftp://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', @@ -144,7 +167,7 @@ it { should contain_file('/opt/staging') should contain_exec('/opt/staging/spec/sample.tar.gz').with( { - :command => 'curl -o sample.tar.gz -u puppet:puppet ftp://webserver/sample.tar.gz', + :command => 'curl -o /opt/staging/spec/sample.tar.gz -u puppet:puppet ftp://webserver/sample.tar.gz', :path => '/usr/local/bin:/usr/bin:/bin', :environment => nil, :cwd => '/opt/staging/spec', diff --git a/staging/spec/spec_helper.rb b/staging/spec/spec_helper.rb index dc7e9f4a0..ba15afe26 100644 --- a/staging/spec/spec_helper.rb +++ b/staging/spec/spec_helper.rb @@ -1,2 +1,29 @@ require 'rubygems' require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |c| + c.include PuppetlabsSpec::Files + + c.before :each do + # Ensure that we don't accidentally cache facts and environment + # between test cases. + Facter::Util::Loader.any_instance.stubs(:load_all) + Facter.clear + Facter.clear_messages + + # Store any environment variables away to be restored later + @old_env = {} + ENV.each_key {|k| @old_env[k] = ENV[k]} + + if Gem::Version.new(`puppet --version`) >= Gem::Version.new('3.5') + Puppet.settings[:strict_variables]=true + end + if ENV['PARSER'] + Puppet.settings[:parser]=ENV['PARSER'] + end + end + + c.after :each do + PuppetlabsSpec::Files.cleanup + end +end diff --git a/staging/spec/unit/puppet/parser/functions/staging_parse_spec.rb b/staging/spec/unit/puppet/parser/functions/staging_parse_spec.rb old mode 100755 new mode 100644