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

Replace lwrps and recipes with libraries #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ platforms:
- name: ubuntu-12.04
run_list:
- recipe[apt]
- name: centos-6.4
- name: ubuntu-14.04
run_list:
- recipe[apt]
- name: centos-6.6
run_list:
- recipe[yum]

suites:
# Test the installation of holland leveraging the library
- name: default
run_list:
- recipe[hollandbackup::default]
- recipe[hollandbackup::mysqldump]
- recipe[hollandbackup::main]
- recipe[hollandbackup::backupsets]
attributes:
- recipe[test-cookbook::default]

# Test the installation and then removal of holland leveraging the library
- name: uninstall
run_list:
- recipe[test-cookbook::install_uninstall]
15 changes: 14 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ UselessAssignment:
Enabled: false

MethodLength:
Enabled: false
Enabled: false

Style/Documentation:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Metrics/AbcSize:
Enabled: false

AllCops:
Exclude:
- '.kitchen/*'
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby

rvm:
- 1.9.3
- 2.0.0
- 2.1.0

Expand All @@ -17,4 +16,4 @@ branches:

notifications:
email:
- dev@escapestudios.com
- dev@escapestudios.com
2 changes: 2 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://supermarket.getchef.com'

metadata

cookbook 'test-cookbook', :path => 'test/fixtures/cookbooks/test-cookbook'
21 changes: 12 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ source 'https://rubygems.org'
gem 'rake'

group :lint do
gem 'rubocop', '~> 0.18'
gem 'foodcritic', '~> 3.0'
gem 'rubocop'
gem 'foodcritic'
end

group :unit, :integration do
gem 'berkshelf', '~> 3.0'
gem 'berkshelf'
end

group :unit do
gem 'chefspec', '~> 3.1'
gem 'rspec-expectations', '~> 2.14.0'
gem 'chefspec'
gem 'rspec-expectations'
end

group :integration do
gem 'test-kitchen', '~> 1.2'
gem 'kitchen-vagrant', '~> 0.11'
gem 'serverspec', '~> 1.0'
group :kitchen_common do
gem 'test-kitchen'
end

group :kitchen_vagrant do
gem 'kitchen-vagrant'
gem 'vagrant-wrapper'
end
8 changes: 0 additions & 8 deletions attributes/backupsets.rb

This file was deleted.

14 changes: 0 additions & 14 deletions attributes/main.rb

This file was deleted.

39 changes: 0 additions & 39 deletions attributes/mysqldump.rb

This file was deleted.

8 changes: 0 additions & 8 deletions attributes/repository.rb

This file was deleted.

37 changes: 37 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module HollandBackupCookbook
module Helpers
include Chef::DSL::IncludeRecipe

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def distro
return new_resource.repo_name if new_resource.repo_name
return 'RHEL_7' if node['platform'] == 'redhat' && node['platform_version'].to_i == 7
return 'RedHat_RHEL-6' if node['platform'] == 'redhat' && node['platform_version'].to_i == 6
return 'RedHat_RHEL-5' if node['platform'] == 'redhat' && node['platform_version'].to_i == 5
return 'RedHat_RHEL-4' if node['platform'] == 'redhat' && node['platform_version'].to_i == 4

return 'CentOS_7' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 7
return 'CentOS_CentOS-6' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 6
return 'CentOS_CentOS-5' if node['platform_family'] == 'rhel' && node['platform_version'].to_i == 5

return 'Debian_7.0' if node['platform'] == 'debian' && node['platform_version'].to_i == 7
return 'Debian_6.0' if node['platform'] == 'debian' && node['platform_version'].to_i == 6

return 'xUbuntu_10.04' if node['platform_family'] == 'debian' && node['platform_version'] == '10.04'
return 'xUbuntu_12.04' if node['platform_family'] == 'debian' && node['platform_version'] == '12.04'
return 'xUbuntu_13.04' if node['platform_family'] == 'debian' && node['platform_version'] == '13.04'
return 'xUbuntu_13.10' if node['platform_family'] == 'debian' && node['platform_version'] == '13.10'
return 'xUbuntu_14.04' if node['platform_family'] == 'debian' && node['platform_version'] == '14.04'
end

def repo_url
return new_resource.repo_url if new_resource.repo_url
"http://download.opensuse.org/repositories/home:/holland-backup/#{distro}/"
end

def gpg_key_url
return new_resource.gpg_key_url if new_resource.gpg_key_url
"http://download.opensuse.org/repositories/home:/holland-backup/#{distro}/Release.key"
end
end
end
17 changes: 17 additions & 0 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if defined?(ChefSpec)
def install_hollandbackup(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:hollandbackup, :install, resource_name)
end

def configure_hollandbackup_conf(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:hollandbackup_conf, :configure, resource_name)
end

def configure_hollandbackup_mysqldump(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:hollandbackup_mysqldump, :configure, resource_name)
end

def configure_hollandbackup_backupset(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:hollandbackup_backupset, :configure, resource_name)
end
end
72 changes: 72 additions & 0 deletions libraries/provider_hollandbackup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require_relative 'helpers'

class Chef
class Provider::Hollandbackup < Provider
include Poise
include HollandBackupCookbook::Helpers

use_inline_resources if defined?(use_inline_resources)

def action_install
case node['platform_family']
when 'debian'
file '/etc/apt/sources.list.d/holland.list' do
owner 'root'
group 'root'
mode 0644
content "deb #{repo_url} ./"
notifies 'run', 'execute[holland-apt-get-update]', 'immediately'
action 'create_if_missing'
end

remote_file "#{Chef::Config[:file_cache_path]}/hollandkey" do
source gpg_key_url
end

execute 'holland-add-gpg-key' do
command "apt-key add #{Chef::Config[:file_cache_path]}/hollandkey"
notifies 'run', 'execute[holland-apt-get-update]', 'immediately'
not_if "apt-key list | grep #{distro}"
end

execute 'holland-apt-get-update' do
command 'apt-get update'
action :nothing
end
when 'rhel'
include_recipe('yum-epel')
end

package 'holland' do
package_name new_resource.package_name if new_resource.package_name
version new_resource.package_version if new_resource.package_version
options new_resource.package_manager_flags if new_resource.package_manager_flags
end

new_resource.additional_packages.each do |package_name|
package "additional holland package #{package_name}" do
package_name package_name
end
end
end

def action_uninstall
package 'holland' do
package_name new_resource.package_name if new_resource.package_name
action :remove
end

new_resource.additional_packages.each do |package_name|
package "additional holland package #{package_name}" do
package_name package_name
action :remove
end
end

file '/etc/apt/sources.list.d/holland.list' do
action :delete
only_if { node['platform_family'] == 'debian' }
end
end
end
end
20 changes: 20 additions & 0 deletions libraries/provider_hollandbackup_backupset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Chef
class Provider::HollandbackupBackupset < Provider
include Poise

def action_configure
converge_by('backupset conf file for holland') do
template new_resource.path do
source new_resource.source
owner new_resource.owner
group new_resource.group
mode new_resource.mode
cookbook new_resource.cookbook
variables(
:conf => new_resource.conf
)
end
end
end
end
end
20 changes: 20 additions & 0 deletions libraries/provider_hollandbackup_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Chef
class Provider::HollandbackupConf < Provider
include Poise

def action_configure
converge_by('configure conf file for holland') do
template new_resource.path do
source new_resource.source
owner new_resource.owner
group new_resource.group
mode new_resource.mode
cookbook new_resource.cookbook
variables(
:conf => new_resource.conf
)
end
end
end
end
end
20 changes: 20 additions & 0 deletions libraries/provider_hollandbackup_mysqldump.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Chef
class Provider::HollandbackupMysqldump < Provider
include Poise

def action_configure
converge_by('mysqldump conf file for holland') do
template new_resource.path do
source new_resource.source
owner new_resource.owner
group new_resource.group
mode new_resource.mode
cookbook new_resource.cookbook
variables(
:conf => new_resource.conf
)
end
end
end
end
end
20 changes: 20 additions & 0 deletions libraries/resource_hollandbackup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'chef/resource/lwrp_base'

class Chef
class Resource
class Hollandbackup < Chef::Resource::LWRPBase
self.resource_name = :hollandbackup
actions :install, :uninstall
default_action :install

# install attributes
attribute :repo_name, :kind_of => String
attribute :package_version, :kind_of => String
attribute :package_name, :kind_of => String
attribute :repo_url, :kind_of => String
attribute :gpg_key_url, :kind_of => String
attribute :additional_packages, :kind_of => Array, :default => []
attribute :package_manager_flags, :kind_of => String
end
end
end
Loading