Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove seperate resources for handling plugin extension #389

Merged
merged 1 commit into from
Oct 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
) {
include ::jenkins::params

$plugin = "${name}.hpi"
$plugin_parent_dir = inline_template('<%= @plugin_dir.split(\'/\')[0..-2].join(\'/\') %>')
validate_bool($manage_config)
validate_bool($enabled)
Expand All @@ -58,6 +57,15 @@
$search = "${name} "
}

# if $source is specified, it overrides any other URL construction
$download_url = $source ? {
undef => "${base_url}${name}.hpi",
default => $source,
}

$plugin_ext = regsubst($download_url, '^.*\.(hpi|jpi)$', '\1')
$plugin = "${name}.${plugin_ext}"

if (!defined(File[$plugin_dir])) {
if (!defined(File[$plugin_parent_dir])) {
# ensure ownership only when it's home directory for the new user
Expand Down Expand Up @@ -123,31 +131,9 @@
notify => Service['jenkins'],
}

# Create disabled file for jpi extensions too.
file { "${plugin_dir}/${name}.jpi.disabled":
ensure => $enabled_ensure,
file { "${plugin_dir}/${plugin}.pinned":
owner => $username,
mode => '0644',
require => File["${plugin_dir}/${plugin}"],
notify => Service['jenkins'],
}

# create a pinned file if the plugin has a .jpi extension
# to override the builtin module versions
exec { "create-pinnedfile-${name}" :
command => "touch ${plugin_dir}/${name}.jpi.pinned",
cwd => $plugin_dir,
require => File[$plugin_dir],
path => ['/usr/bin', '/usr/sbin', '/bin'],
onlyif => "test -f ${plugin_dir}/${name}.jpi -a ! -f ${plugin_dir}/${name}.jpi.pinned",
before => Archive::Download[$plugin],
user => $username,
}

# if $source is specified, it overrides any other URL construction
$download_url = $source ? {
undef => "${base_url}${plugin}",
default => $source,
require => Archive::Download[$plugin],
}

if $digest_string == '' {
Expand Down
30 changes: 22 additions & 8 deletions spec/defines/jenkins_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
:ensure => 'present',
:owner => 'jenkins',
})}
it { should contain_file('/var/lib/jenkins/plugins/myplug.jpi.disabled').with({
:ensure => 'present',
:owner => 'jenkins',
})}
end

describe 'with enabled is true' do
Expand All @@ -85,10 +81,6 @@
:ensure => 'absent',
:owner => 'jenkins',
})}
it { should contain_file('/var/lib/jenkins/plugins/myplug.jpi.disabled').with({
:ensure => 'absent',
:owner => 'jenkins',
})}
end

describe 'with proxy' do
Expand Down Expand Up @@ -216,4 +208,26 @@
end
end # validate_string
end # source

context 'pinned file' do
let(:title) { 'foo' }

context 'default params' do
it do
should contain_file('/var/lib/jenkins/plugins/foo.hpi.pinned').with(
:owner => 'jenkins',
).that_requires('Archive::Download[foo.hpi]')
end
end

context 'with source param' do
let(:params) {{ :source => 'foo.jpi' }}

it do
should contain_file('/var/lib/jenkins/plugins/foo.jpi.pinned').with(
:owner => 'jenkins',
).that_requires('Archive::Download[foo.jpi]')
end
end
end # pinned file extension name
end