Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

Commit

Permalink
Merge pull request #125 from chef-cookbooks/hard_fail
Browse files Browse the repository at this point in the history
Hard fail on unsupported platforms
  • Loading branch information
tas50 authored Aug 20, 2016
2 parents 3d3ed00 + 6f16ee4 commit ee2793d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ platforms:
- name: centos-7.2
- name: debian-7.11
- name: debian-8.5
- name: freebsd-9.3
- name: freebsd-10.3
- name: fedora-24
- name: opensuse-13.2
- name: opensuse-leap-42.1
- name: ubuntu-12.04
- name: ubuntu-14.04
- name: ubuntu-16.04
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ This cookbook allows you to upgrade the omnibus based Chef install package via C

### Platforms

- redhat
- centos
- amazon
- scientific
- oracle
- debian
- ubuntu
- mac_os_x
- solaris
- windows
- Debian / Ubuntu
- Mac OS X
- RHEL (redhat, centos, amazon, scientific, oracle)
- Solaris
- SLES / openSUSE
- Windows

### Chef

Expand Down
4 changes: 4 additions & 0 deletions libraries/omnitrucker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def collect_attributes(node, args = {})
@attrs = { platform: 'el', platform_version: set['platform_version'].to_i }
elsif set['platform'] == 'debian'
@attrs = { platform: set['platform'], platform_version: set['platform_version'].to_i }
elsif set['platform'] =~ /opensuse/
@attrs = { platform: 'suse', platform_version: 13 }
elsif set['platform_family'] == 'suse'
@attrs = { platform: 'sles', platform_version: 12 }
elsif set['platform_family'] == 'mac_os_x'
major, minor, _patch = set['platform_version'].split('.').map { |v| String(v) }
@attrs = { platform: set['platform_family'], platform_version: [[major, minor].join('.'), '10.7'].min }
Expand Down
8 changes: 6 additions & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
# limitations under the License.
#

# fail hard if we're on an unsupported platform
# feel free to open PRs to add additional platforms
unless platform_family?('debian', 'fedora', 'mac_os_x', 'rhel', 'solaris2', 'windows', 'suse')
Chef::Application.fatal! "Omnibus updater does not support the #{node['platform']} platform"
end

if node['omnibus_updater']['disabled']
Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute'
elsif node['platform'] == 'raspbian'
Chef::Log.warn 'Omnibus updater does not support Raspbian'
else
include_recipe 'omnibus_updater::downloader'
include_recipe 'omnibus_updater::installer'
Expand Down
47 changes: 42 additions & 5 deletions spec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
require 'spec_helper'

describe 'omnibus_updater::default' do
let(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'redhat', version: '7.0') do |node, server|
end.converge(described_recipe)
describe 'omnibus_updater::default on unsupported platform' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'freebsd', version: '10.3').converge('omnibus_updater::default')
end

it 'logs a warning that the platform is unsupported' do
expect { chef_run }.to raise_error
end
end

describe 'omnibus_updater::default with no attributes set' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04').converge('omnibus_updater::default')
end

it 'should complie without any errors' do
it 'compiles without any errors' do
expect { chef_run }.to_not raise_error
end

it 'includes the downloader recipe' do
expect(chef_run).to include_recipe('omnibus_updater::downloader')
end

it 'includes the installer recipe' do
expect(chef_run).to include_recipe('omnibus_updater::installer')
end

it 'includes the old_package_cleaner recipe' do
expect(chef_run).to include_recipe('omnibus_updater::old_package_cleaner')
end

it 'does not include the remove_chef_system_gem recipe' do
expect(chef_run).to_not include_recipe('omnibus_updater::remove_chef_system_gem')
end
end

describe 'omnibus_updater::default with remove_chef_system_gem set' do
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04') do |node|
node.normal['omnibus_updater']['remove_chef_system_gem'] = true
end.converge('omnibus_updater::default')

it 'includes the remove_chef_system_gem recipe' do
expect(chef_run).to include_recipe('omnibus_updater::remove_chef_system_gem')
end
end
end

0 comments on commit ee2793d

Please sign in to comment.