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

Use declare_resource for local package install #40

Merged
merged 2 commits into from
Sep 13, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ cookbook doesn't support installing from networked package managers

## Requirements

Chef 11.10.0+ for `declare_resource`.

### Platforms

This cookbook uses Test Kitchen to do cross-platform convergence and
Expand Down
18 changes: 8 additions & 10 deletions definitions/splunk_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@
end
end

package params[:name] do
local_package_resource = case node['platform_family']
when 'rhel' then :rpm_package
when 'debian' then :dpkg_package
when 'omnios' then :solaris_package
end

declare_resource local_package_resource, params[:name] do
source cached_package.gsub(/\.Z/, '')
case node['platform_family']
when 'rhel'
provider Chef::Provider::Package::Rpm
when 'debian'
provider Chef::Provider::Package::Dpkg
when 'omnios'
provider Chef::Provider::Package::Solaris
options pkgopts.join(' ')
end
options pkgopts.join(' ') if platform?('omnios')
end
end
6 changes: 3 additions & 3 deletions spec/recipes/install_forwarder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunkforwarder').with(
expect(chef_run).to install_dpkg_package('splunkforwarder').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.deb"
)
end
Expand All @@ -39,7 +39,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunkforwarder').with(
expect(chef_run).to install_rpm_package('splunkforwarder').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.rpm"
)
end
Expand Down Expand Up @@ -79,7 +79,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunkforwarder').with(
expect(chef_run).to install_solaris_package('splunkforwarder').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.pkg",
'options' => "-a #{Chef::Config[:file_cache_path]}/splunkforwarder-nocheck -r #{Chef::Config[:file_cache_path]}/splunk-response"
)
Expand Down
6 changes: 3 additions & 3 deletions spec/recipes/install_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunk').with(
expect(chef_run).to install_dpkg_package('splunk').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.deb"
)
end
Expand All @@ -39,7 +39,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunk').with(
expect(chef_run).to install_rpm_package('splunk').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.rpm"
)
end
Expand Down Expand Up @@ -79,7 +79,7 @@
end

it 'installs the package with the downloaded file' do
expect(chef_run).to install_package('splunk').with(
expect(chef_run).to install_solaris_package('splunk').with(
'source' => "#{Chef::Config[:file_cache_path]}/package.pkg",
'options' => "-a #{Chef::Config[:file_cache_path]}/splunk-nocheck -r #{Chef::Config[:file_cache_path]}/splunk-response"
)
Expand Down
2 changes: 1 addition & 1 deletion spec/recipes/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

it 'installs the package with splunk_installer' do
expect(chef_run).to install_package('splunkforwarder')
expect(chef_run).to install_dpkg_package('splunkforwarder')
end

it 'runs an unattended upgrade (starts splunk)' do
Expand Down