Skip to content

Commit

Permalink
Merge pull request voxpupuli#83 from mkrakowitzer/unzip_opts
Browse files Browse the repository at this point in the history
Add support for unzip options
  • Loading branch information
nanliu committed Oct 14, 2015
2 parents 9cfcdd3 + e77fc10 commit b262534
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
2 changes: 2 additions & 0 deletions manifests/deploy.pp
Expand Up @@ -8,6 +8,7 @@
$password = undef, #: https or ftp user password or https certificate password
$environment = undef, #: environment variable for settings such as http_proxy
$strip = undef, #: extract file with the --strip=X option. Only works with GNU tar.
$unzip_opts = '', #: additional options to pass the unzip command.
$timeout = undef, #: the time to wait for the file transfer to complete
$user = undef, #: extract file as this user
$group = undef, #: extract group as this group
Expand All @@ -34,6 +35,7 @@
group => $group,
environment => $environment,
strip => $strip,
unzip_opts => $unzip_opts,
subdir => $caller_module_name,
creates => $creates,
unless => $unless,
Expand Down
3 changes: 2 additions & 1 deletion manifests/extract.pp
Expand Up @@ -9,6 +9,7 @@
$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.
$unzip_opts = '', #: additional options to pass the unzip command.
$subdir = $caller_module_name #: subdir per module in staging directory.
) {

Expand Down Expand Up @@ -91,7 +92,7 @@
}

/.zip$/: {
$command = "unzip ${source_path}"
$command = "unzip ${unzip_opts} ${source_path}"
}

/(.war|.jar)$/: {
Expand Down
21 changes: 20 additions & 1 deletion spec/defines/staging_deploy_spec.rb
Expand Up @@ -31,7 +31,7 @@
let(:title) { 'sample.tar.gz' }
let(:params) {{
:source => 'puppet:///modules/staging/sample.tar.gz',
:target => '/usr/local' ,
:target => '/usr/local',
:strip => 1
}}

Expand All @@ -47,4 +47,23 @@
}
end

describe 'when deploying zip file with unzip_opts' do
let(:title) { 'sample.zip' }
let(:params) do
{ :source => 'puppet:///modules/staging/sample.tar.gz',
:target => '/usr/local',
:unzip_opts => '-o -f'
}
end
it { should contain_file('/opt/staging') }
it { should contain_file('/opt/staging//sample.zip') }
it do
should contain_exec('extract sample.zip').with({
:command => 'unzip -o -f /opt/staging//sample.zip',
:path => '/usr/local/bin:/usr/bin:/bin',
:cwd => '/usr/local',
:creates => '/usr/local/sample'
})
end
end
end
33 changes: 26 additions & 7 deletions spec/defines/staging_extract_spec.rb
Expand Up @@ -59,7 +59,24 @@

it { should contain_file('/opt/staging')
should contain_exec('extract sample.zip').with({
:command => 'unzip /opt/staging//sample.zip',
:command => 'unzip /opt/staging//sample.zip',
:path => '/usr/local/bin:/usr/bin:/bin',
:cwd => '/opt',
:creates => '/opt/sample'
})
}
end

describe 'when deploying zip with unzip_opts' do
let(:title) { 'sample.zip' }
let(:params) do
{ :target => '/opt',
:unzip_opts => '-o -f',
}
end
it { should contain_file('/opt/staging')
should contain_exec('extract sample.zip').with({
:command => 'unzip -o -f /opt/staging//sample.zip',
:path => '/usr/local/bin:/usr/bin:/bin',
:cwd => '/opt',
:creates => '/opt/sample'
Expand All @@ -74,7 +91,7 @@

it { should contain_file('/opt/staging')
should contain_exec('extract sample.zip').with({
:command => 'unzip /opt/staging//sample.zip',
:command => 'unzip /opt/staging//sample.zip',
:path => '/usr/local/bin:/usr/bin:/bin',
:cwd => '/opt',
:creates => '/opt/sample'
Expand All @@ -85,7 +102,6 @@
describe 'when deploying war' do
let(:title) { 'sample.war' }
let(:params) { { :target => '/opt' } }

it { should contain_file('/opt/staging')
should contain_exec('extract sample.war').with({
:command => 'jar xf /opt/staging//sample.war',
Expand All @@ -96,11 +112,14 @@
}
end

describe 'when deploying war with strip (noop)' do
describe 'when deploying war with strip (noop) and unzip_opts (noop)' do
let(:title) { 'sample.war' }
let(:params) { { :target => '/opt',
:strip => 1, } }

let(:params) do
{ :target => '/opt',
:strip => 1,
:unzip_opts => '-o -f'
}
end
it { should contain_file('/opt/staging')
should contain_exec('extract sample.war').with({
:command => 'jar xf /opt/staging//sample.war',
Expand Down

0 comments on commit b262534

Please sign in to comment.