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

Support all platforms that have packages #5

Merged
merged 8 commits into from Dec 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions .kitchen.yml
Expand Up @@ -6,7 +6,14 @@ provisioner:
name: chef_zero

platforms:
- name: ubuntu-15.10
driver:
box: boxcutter/ubuntu1510
- name: ubuntu-14.04
- name: ubuntu-12.04
- name: ubuntu-10.04
- name: centos-7.1
- name: centos-6.7
- name: ubuntu-14.04-chef-11
driver:
box: bento/ubuntu-14.04
Expand All @@ -17,6 +24,6 @@ suites:
- name: default
run_list:
- recipe[snoopy_test]
- name: uninstall
- name: remove
run_list:
- recipe[snoopy_test::uninstall]
- recipe[snoopy_test::remove]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,8 @@ Snoopy Cookbook CHANGELOG

v?.?.? (????-??-??)
-------------------
- Start testing against Ubuntus 15.10 and 10.04
- Add RHEL and RHEL-alike support

v1.0.2 (2015-10-29)
-------------------
Expand Down
20 changes: 11 additions & 9 deletions README.md
@@ -1,14 +1,14 @@
Snoopy Cookbook
===============
[![Cookbook Version](https://img.shields.io/cookbook/v/snoopy.svg)][cookbook]
[![Build Status](https://img.shields.io/travis/socrata-cookbooks/chef-snoopy.svg)][travis]
[![Code Climate](https://img.shields.io/codeclimate/github/socrata-cookbooks/chef-snoopy.svg)][codeclimate]
[![Coverage Status](https://img.shields.io/coveralls/socrata-cookbooks/chef-snoopy.svg)][coveralls]
[![Build Status](https://img.shields.io/travis/socrata-cookbooks/snoopy.svg)][travis]
[![Code Climate](https://img.shields.io/codeclimate/github/socrata-cookbooks/snoopy.svg)][codeclimate]
[![Coverage Status](https://img.shields.io/coveralls/socrata-cookbooks/snoopy.svg)][coveralls]

[cookbook]: https://supermarket.chef.io/cookbooks/snoopy
[travis]: https://travis-ci.org/socrata-cookbooks/chef-snoopy
[codeclimate]: https://codeclimate.com/github/socrata-cookbooks/chef-snoopy
[coveralls]: https://coveralls.io/r/socrata-cookbooks/chef-snoopy
[travis]: https://travis-ci.org/socrata-cookbooks/snoopy
[codeclimate]: https://codeclimate.com/github/socrata-cookbooks/snoopy
[coveralls]: https://coveralls.io/r/socrata-cookbooks/snoopy

A Chef cookbook for [Snoopy Logger](https://github.com/a2o/snoopy).

Expand All @@ -20,9 +20,11 @@ in PackageCloud.io.
Requirements
============

This cookbook currently supports Ubuntu only. It intentionally maintains
backward compatibility with Chef 11, at the expense of some minor additional
complexity.
This cookbook is currently compatible with and tested against Ubuntu 10.04,
12.04, 14.04, and 15.10; and RHEL (or CentOS, etc.) 7 and 6.

It intentionally maintains backward compatibility with Chef 11, at the expense
of some minor additional complexity.

Usage
=====
Expand Down
14 changes: 12 additions & 2 deletions libraries/provider_mapping.rb
Expand Up @@ -22,16 +22,26 @@
require 'chef/platform/provider_mapping'
require_relative 'provider_snoopy'
require_relative 'provider_snoopy_app'
require_relative 'provider_snoopy_app_debian'
require_relative 'provider_snoopy_app_rhel'
require_relative 'provider_snoopy_config'
require_relative 'provider_snoopy_service'

if Gem::Version.new(Chef::VERSION) < Gem::Version.new('12')
{
ubuntu: Chef::Provider::SnoopyApp::Debian,
debian: Chef::Provider::SnoopyApp::Debian,
redhat: Chef::Provider::SnoopyApp::Rhel,
centos: Chef::Provider::SnoopyApp::Rhel,
scientific: Chef::Provider::SnoopyApp::Rhel
}.each do |f, p|
Chef::Platform.set(platform: f, resource: :snoopy_app, provider: p)
end
{
snoopy: Chef::Provider::Snoopy,
snoopy_app: Chef::Provider::SnoopyApp,
snoopy_config: Chef::Provider::SnoopyConfig,
snoopy_service: Chef::Provider::SnoopyService
}.each do |r, p|
Chef::Platform.set(platform: :ubuntu, resource: r, provider: p)
Chef::Platform.set(resource: r, provider: p)
end
end
32 changes: 20 additions & 12 deletions libraries/provider_snoopy_app.rb
Expand Up @@ -23,14 +23,13 @@

class Chef
class Provider
# A Chef provider for the Snoopy Logger application packages.
# A parent Chef provider for the Snoopy app for platform-specific providers
# to inherit from.
#
# @author Jonathan Hartman <jonathan.hartman@socrata.com>
class SnoopyApp < LWRPBase
use_inline_resources

provides(:snoopy_app, platform: 'ubuntu') if defined?(provides)

#
# WhyRun is supported by this provider
#
Expand All @@ -41,24 +40,33 @@ def whyrun_supported?
end

#
# Install the Snoopy Logger and set it up in the linker config.
# Set up an install action.
#
action :install do
unless new_resource.source
packagecloud_repo('socrata-platform/snoopy') { type 'deb' }
end
install!
end

#
# Set up a :remove action.
#
action :remove do
remove!
end

private

#
# Install the Snoopy Logger.
#
def install!
package(new_resource.source || 'snoopy')
end

#
# Uninstall the Snoopy Logger.
#
action :remove do
def remove!
package('snoopy') { action :remove }
# For lack of a :remove action in the packagecloud cookbook
file('/etc/apt/sources.list.d/socrata-platform_snoopy.list') do
action :delete
end
end
end
end
Expand Down
61 changes: 61 additions & 0 deletions libraries/provider_snoopy_app_debian.rb
@@ -0,0 +1,61 @@
# Encoding: UTF-8
#
# Cookbook Name:: snoopy
# Library:: provider_snoopy_app_debian
#
# Copyright 2015 Socrata, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/exceptions'
require 'chef/provider/lwrp_base'
require_relative 'provider_snoopy_app'

class Chef
class Provider
class SnoopyApp < LWRPBase
# A Chef provider for the Snoopy Logger application packages for Debian.
#
# @author Jonathan Hartman <jonathan.hartman@socrata.com>
class Debian < SnoopyApp
provides(:snoopy_app, platform_family: 'debian') if defined?(provides)

#
# Set up the PackageCloud .deb repo before trying to install Snoopy.
#
# (see Chef::Provider::SnoopyApp#install!)
#
def install!
unless new_resource.source
packagecloud_repo('socrata-platform/snoopy') { type 'deb' }
end
super
end

#
# Remove the PackageCloud .deb repo after uninstalling Snoopy.
#
# (see Chef::Provider::SnoopyApp#remove!)
#
def remove!
super
# For lack of a :remove action in the packagecloud cookbook
file('/etc/apt/sources.list.d/socrata-platform_snoopy.list') do
action :delete
end
end
end
end
end
end
61 changes: 61 additions & 0 deletions libraries/provider_snoopy_app_rhel.rb
@@ -0,0 +1,61 @@
# Encoding: UTF-8
#
# Cookbook Name:: snoopy
# Library:: provider_snoopy_app_rhel
#
# Copyright 2015 Socrata, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/exceptions'
require 'chef/provider/lwrp_base'
require_relative 'provider_snoopy_app'

class Chef
class Provider
class SnoopyApp < LWRPBase
# A Chef provider for the Snoopy Logger application packages for RHEL.
#
# @author Jonathan Hartman <jonathan.hartman@socrata.com>
class Rhel < SnoopyApp
provides(:snoopy_app, platform_family: 'rhel') if defined?(provides)

#
# Set up the PackageCloud .rpm repo before trying to install Snoopy.
#
# (see Chef::Provider::SnoopyApp#install!)
#
def install!
unless new_resource.source
packagecloud_repo('socrata-platform/snoopy') { type 'rpm' }
end
super
end

#
# Remove the PackageCloud .rpm repo after uninstalling Snoopy.
#
# (see Chef::Provider::SnoopyApp#remove!)
#
def remove!
super
# For lack of a :remove action in the packagecloud cookbook
file('/etc/yum.repos.d/socrata-platform_snoopy.repo') do
action :delete
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion libraries/provider_snoopy_config.rb
Expand Up @@ -31,7 +31,7 @@ class SnoopyConfig < LWRPBase

use_inline_resources

provides(:snoopy_config, platform: 'ubuntu') if defined?(provides)
provides(:snoopy_config) if defined?(provides)

#
# WhyRun is supported by this provider
Expand Down
2 changes: 1 addition & 1 deletion libraries/provider_snoopy_service.rb
Expand Up @@ -29,7 +29,7 @@ class Provider
class SnoopyService < LWRPBase
use_inline_resources

provides(:snoopy_service, platform: 'ubuntu') if defined?(provides)
provides(:snoopy_service) if defined?(provides)

#
# WhyRun is supported by this provider
Expand Down
3 changes: 3 additions & 0 deletions metadata.rb
Expand Up @@ -12,4 +12,7 @@
depends 'packagecloud'

supports 'ubuntu'
supports 'redhat'
supports 'centos'
supports 'scientific'
# rubocop:enable SingleSpaceBeforeFirstArg
28 changes: 27 additions & 1 deletion spec/libraries/provider_mapping_spec.rb
Expand Up @@ -67,7 +67,33 @@
load(File.expand_path('../../../libraries/provider_mapping.rb',
__FILE__))
expect(provider).to eq(Chef::Provider::Snoopy)
expect(app_provider).to eq(Chef::Provider::SnoopyApp)
expect(app_provider).to eq(Chef::Provider::SnoopyApp::Debian)
expect(config_provider).to eq(Chef::Provider::SnoopyConfig)
expect(service_provider).to eq(Chef::Provider::SnoopyService)
end
end
end

context 'CentOS' do
let(:platform) { { platform: 'CentOS', version: '7.0' } }

context 'Chef 12' do
let(:chef_version) { '12.4.1' }

it_behaves_like 'Chef 12'
end

context 'Chef 11' do
let(:chef_version) { '11.16.4' }

it 'sets up old-style provider mappings' do
allow(Chef::Log).to receive(:warn)
expect(Chef::Platform).to receive(:set).at_least(1).times
.and_call_original
load(File.expand_path('../../../libraries/provider_mapping.rb',
__FILE__))
expect(provider).to eq(Chef::Provider::Snoopy)
expect(app_provider).to eq(Chef::Provider::SnoopyApp::Rhel)
expect(config_provider).to eq(Chef::Provider::SnoopyConfig)
expect(service_provider).to eq(Chef::Provider::SnoopyService)
end
Expand Down