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

Fix issue where package provider override isn't working when specifying a package_source #18

Merged
merged 6 commits into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 3 additions & 2 deletions libraries/chef_server_ingredients_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ def whyrun_supported?
only_if { new_resource.package_source.nil? }
end

package new_resource.package_name do
package_resource = new_resource.package_source.nil? ? :package : local_package_resource

declare_resource package_resource, new_resource.package_name do
options new_resource.options
version new_resource.version
source new_resource.package_source
provider local_provider if new_resource.package_source
timeout new_resource.timeout
end
end
Expand Down
7 changes: 4 additions & 3 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def chef_server_ctl_command(pkg)
ctl_cmds[pkg]
end

def local_provider
return Chef::Provider::Package::Dpkg if node['platform_family'] == 'debian'
return Chef::Provider::Package::Rpm if node['platform_family'] == 'rhel'
def local_package_resource
return :dpkg_package if node['platform_family'] == 'debian'
return :rpm_package if node['platform_family'] == 'rhel'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably return :package here by default, or else raise if you don't want to try to guess that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, done

:package # fallback if there's no platform match
end

def ctl_command
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'chef-server-ingredient'
version '0.3.2'
version '0.3.3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not increment versions in PR's 🍰

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about that! fixed.

maintainer 'Chef Software, Inc.'
maintainer_email 'cookbooks@chef.io'
license 'Apache 2.0'
Expand Down
43 changes: 42 additions & 1 deletion spec/centos_65_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
cached(:centos_65) do
ChefSpec::SoloRunner.new(
platform: 'centos',
version: '6.5'
version: '6.5',
step_into: 'chef_server_ingredient'
) do |node|
node.set['chef-server-core']['version'] = nil
end.converge('test::repo')
end

context 'compiling the test recipe' do
it 'creates packagecloud_repo[chef/stable]' do
expect(centos_65).to create_packagecloud_repo('chef/stable')
end

it 'installs chef_server_ingredient[chef-server-core]' do
expect(centos_65).to install_chef_server_ingredient('chef-server-core')
end

it 'installs yum_package[chef-server-core]' do
expect(centos_65).to install_yum_package('chef-server-core')
end

it 'creates file[/tmp/chef-server-core.firstrun]' do
expect(centos_65).to create_file('/tmp/chef-server-core.firstrun')
end
Expand All @@ -23,8 +32,40 @@
expect(centos_65).to install_chef_server_ingredient('opscode-manage')
end

it 'installs yum_package[opscode-manage]' do
expect(centos_65).to install_yum_package('opscode-manage')
end

it 'creates file[/tmp/opscode-manage.firstrun]' do
expect(centos_65).to create_file('/tmp/opscode-manage.firstrun')
end
end
end


describe 'test::local' do
cached(:centos_65) do
ChefSpec::SoloRunner.new(
platform: 'centos',
version: '6.5',
step_into: 'chef_server_ingredient'
) do |node|
node.set['chef-server-core']['version'] = nil
end.converge('test::local')
end

context 'compiling the test recipe' do
it 'installs chef_server_ingredient[chef-server-core]' do
expect(centos_65).to install_chef_server_ingredient('chef-server-core')
end

it 'uses the rpm_package provider instead of yum_package' do
expect(centos_65).to install_rpm_package('chef-server-core')
expect(centos_65).to_not install_yum_package('chef-server-core')
end

it 'creates file[/tmp/chef-server-core.firstrun]' do
expect(centos_65).to create_file('/tmp/chef-server-core.firstrun')
end
end
end
42 changes: 41 additions & 1 deletion spec/ubuntu_1404_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
cached(:ubuntu_1404) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04'
version: '14.04',
step_into: 'chef_server_ingredient'
) do |node|
node.set['chef-server-core']['version'] = nil
end.converge('test::repo')
end

context 'compiling the test recipe' do
it 'creates packagecloud_repo[chef/stable]' do
expect(ubuntu_1404).to create_packagecloud_repo('chef/stable')
end

it 'installs chef_server_ingredient[chef-server-core]' do
expect(ubuntu_1404).to install_chef_server_ingredient('chef-server-core')
end

it 'installs apt_package[chef-server-core]' do
expect(ubuntu_1404).to install_apt_package('chef-server-core')
end

it 'creates file[/tmp/chef-server-core.firstrun]' do
expect(ubuntu_1404).to create_file('/tmp/chef-server-core.firstrun')
end
Expand All @@ -23,8 +32,39 @@
expect(ubuntu_1404).to install_chef_server_ingredient('opscode-manage')
end

it 'installs apt_package[opscode-manage]' do
expect(ubuntu_1404).to install_apt_package('opscode-manage')
end

it 'creates file[/tmp/opscode-manage.firstrun]' do
expect(ubuntu_1404).to create_file('/tmp/opscode-manage.firstrun')
end
end
end

describe 'test::local' do
cached(:ubuntu_1404) do
ChefSpec::SoloRunner.new(
platform: 'ubuntu',
version: '14.04',
step_into: 'chef_server_ingredient'
) do |node|
node.set['chef-server-core']['version'] = nil
end.converge('test::local')
end

context 'compiling the test recipe' do
it 'installs chef_server_ingredient[chef-server-core]' do
expect(ubuntu_1404).to install_chef_server_ingredient('chef-server-core')
end

it 'uses the rpm_package provider instead of yum_package' do
expect(ubuntu_1404).to install_dpkg_package('chef-server-core')
expect(ubuntu_1404).to_not install_apt_package('chef-server-core')
end

it 'creates file[/tmp/chef-server-core.firstrun]' do
expect(ubuntu_1404).to create_file('/tmp/chef-server-core.firstrun')
end
end
end
16 changes: 16 additions & 0 deletions test/fixtures/cookbooks/test/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
default['test']['chef-server-core']['version'] = nil
default['test']['source_url'] = case node['platform_family']
when 'debian'
if node['platform_version'].to_f == 14.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_12.0.5-1_amd64.deb'
elsif node['platform_version'].to_f == 12.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/precise/chef-server-core_12.0.5-1_amd64.deb'
elsif node['platform_version'].to_f == 10.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/lucid/chef-server-core_12.0.5-1_amd64.deb'
end
when 'rhel'
if node['platform_version'].to_i == 6
'https://web-dl.packagecloud.io/chef/stable/packages/el/6/chef-server-core-12.0.5-1.el6.x86_64.rpm'
elsif node['platform_version'].to_i == 5
'https://web-dl.packagecloud.io/chef/stable/packages/el/5/chef-server-core-12.0.5-1.el5.x86_64.rpm'
end
end
32 changes: 3 additions & 29 deletions test/fixtures/cookbooks/test/recipes/local.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
# helper methods for recipe clariy

# TODO: create yum-chef and apt-chef cookbooks and move these
# locations to node attributes. see yum-epel, yum-centos, etc for examples.
def source_url
case node['platform_family']
when 'debian'
if node['platform_version'].to_f == 14.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_12.0.5-1_amd64.deb'
elsif node['platform_version'].to_f == 12.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/precise/chef-server-core_12.0.5-1_amd64.deb'
elsif node['platform_version'].to_f == 10.04
'https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/lucid/chef-server-core_12.0.5-1_amd64.deb'
end
when 'rhel'
if node['platform_version'].to_i == 6
'https://web-dl.packagecloud.io/chef/stable/packages/el/6/chef-server-core-12.0.5-1.el6.x86_64.rpm'
elsif node['platform_version'].to_i == 5
'https://web-dl.packagecloud.io/chef/stable/packages/el/5/chef-server-core-12.0.5-1.el5.x86_64.rpm'
end
end
end

def pkgname
::File.basename(source_url)
end

def cache_path
Chef::Config[:file_cache_path]
end
pkgname = ::File.basename(node['test']['source_url'])
cache_path = Chef::Config[:file_cache_path]

# recipe
remote_file "#{cache_path}/#{pkgname}" do
source "#{source_url}"
source node['test']['source_url']
mode '0644'
end

Expand Down