-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quite a few changes to incorporate rubocop
- Loading branch information
Showing
12 changed files
with
136 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
AllCops: | ||
Includes: | ||
- ./**/*.rb | ||
Excludes: | ||
- vendor/** | ||
|
||
Encoding: | ||
Exclude: | ||
- metadata.rb | ||
- Gemfile | ||
|
||
WordArray: | ||
MinSize: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
source "https://rubygems.org" | ||
source 'https://rubygems.org' | ||
|
||
gem "rake" | ||
gem "chef", "~> 11.10" | ||
gem "berkshelf", "~> 2.0" | ||
gem "chefspec", "~> 3.2" | ||
gem "foodcritic", "~> 3.0" | ||
gem 'berkshelf', '~> 2.0' | ||
gem 'chef', '~> 11.10' | ||
gem 'chefspec', '~> 3.2' | ||
gem 'foodcritic', '~> 3.0' | ||
gem 'rake', '~> 10.1' | ||
gem 'rubocop', '~> 0.18' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
class Reboot < ::Chef::Handler | ||
# encoding: UTF-8 | ||
|
||
# A Chef handler to manage reboots. | ||
class Reboot < Chef::Handler | ||
def initialize | ||
end | ||
|
||
def report | ||
### If Chef ran successfully. | ||
if run_status.success? | ||
### AND node is in the booted role. | ||
if node.roles.include? node['reboot-handler']['enabled_role'] | ||
### AND node has the reboot flag. | ||
if node.run_state['reboot'] | ||
### THEN reset run_list if necessary. | ||
unless node['reboot-handler']['post_boot_runlist'].empty? | ||
node.run_list.reset! node['reboot-handler']['post_boot_runlist'] | ||
node.save | ||
end | ||
|
||
### AND reboot node. | ||
::Mixlib::ShellOut.new(node['reboot-handler']['reboot_command']).run_command | ||
end | ||
return unless run_status.success? | ||
return unless node.roles.include? node['reboot-handler']['enabled_role'] | ||
if node.run_state['reboot'] | ||
unless node['reboot-handler']['post_boot_runlist'].empty? | ||
node.run_list.reset! node['reboot-handler']['post_boot_runlist'] | ||
node.save | ||
end | ||
|
||
Mixlib::ShellOut.new(node['reboot-handler']['command']).run_command | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
name "reboot-handler" | ||
maintainer "John Dewey" | ||
maintainer_email "[email protected]" | ||
license "Apache 2.0" | ||
description "Installs/Configures reboot-handler" | ||
name 'reboot-handler' | ||
maintainer 'John Dewey' | ||
maintainer_email '[email protected]' | ||
license 'Apache 2.0' | ||
description 'Installs/Configures reboot-handler' | ||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) | ||
version "0.2.2" | ||
version '1.0.0' | ||
|
||
recipe "reboot-handler", "Installs/Configures reboot-handler" | ||
recipe 'reboot-handler', 'Installs/Configures reboot-handler' | ||
|
||
%w{ debian ubuntu }.each do |os| | ||
supports os | ||
end | ||
|
||
depends "chef_handler" | ||
depends 'chef_handler' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
require_relative "spec_helper" | ||
# encoding: UTF-8 | ||
|
||
describe "reboot-handler::default" do | ||
require_relative 'spec_helper' | ||
|
||
describe 'reboot-handler::default' do | ||
before do | ||
Chef::Recipe.any_instance.stub(:require). | ||
with("/var/chef/handlers/reboot") | ||
@chef_run = ::ChefSpec::Runner.new | ||
Chef::Recipe.any_instance.stub(:require) | ||
.with('/var/chef/handlers/reboot') | ||
@chef_run = ChefSpec::Runner.new | ||
end | ||
|
||
it "includes chef_handler" do | ||
Chef::Recipe.any_instance.should_receive(:include_recipe). | ||
with("chef_handler") | ||
it 'includes chef_handler' do | ||
Chef::Recipe.any_instance.should_receive(:include_recipe) | ||
.with('chef_handler') | ||
|
||
@chef_run.converge "reboot-handler::default" | ||
@chef_run.converge 'reboot-handler::default' | ||
end | ||
|
||
it "installs the handler" do | ||
@chef_run.converge "reboot-handler::default" | ||
it 'installs the handler' do | ||
@chef_run.converge 'reboot-handler::default' | ||
|
||
@chef_run.should create_cookbook_file "/var/chef/handlers/reboot.rb" | ||
@chef_run.should create_cookbook_file '/var/chef/handlers/reboot.rb' | ||
end | ||
|
||
it "doesn't log" do | ||
@chef_run.converge "reboot-handler::default" | ||
@chef_run.converge 'reboot-handler::default' | ||
|
||
@chef_run.should_not write_log "Unable to require the reboot handler!" | ||
@chef_run.should_not write_log 'Unable to require the reboot handler!' | ||
end | ||
|
||
it "logs when handler is missing" do | ||
Chef::Recipe.any_instance.should_receive(:require). | ||
with("/var/chef/handlers/reboot"). | ||
and_raise ::LoadError.new | ||
@chef_run.converge "reboot-handler::default" | ||
it 'logs when handler is missing' do | ||
Chef::Recipe.any_instance.should_receive(:require) | ||
.with('/var/chef/handlers/reboot') | ||
.and_raise LoadError.new | ||
@chef_run.converge 'reboot-handler::default' | ||
|
||
@chef_run.should write_log "Unable to require the reboot handler!" | ||
@chef_run.should write_log 'Unable to require the reboot handler!' | ||
end | ||
|
||
it "chef_handler lwrp" do | ||
pending "No idea how to test this" | ||
it 'chef_handler lwrp' do | ||
pending 'No idea how to test this' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,68 @@ | ||
require_relative "spec_helper" | ||
require ::File.join ::File.dirname(__FILE__), "..", "files", "default", "reboot" | ||
# encoding: UTF-8 | ||
|
||
require_relative 'spec_helper' | ||
require File.join File.dirname(__FILE__), '..', 'files', 'default', 'reboot' | ||
|
||
describe Reboot do | ||
::Mixlib::ShellOut.class_eval do | ||
Mixlib::ShellOut.class_eval do | ||
def run_command | ||
true | ||
end | ||
end | ||
|
||
before do | ||
@handler = ::Reboot.new | ||
@node = ::ChefSpec::Runner.new.converge("reboot-handler::default").node | ||
@handler = Reboot.new | ||
@node = ChefSpec::Runner.new.converge('reboot-handler::default').node | ||
@node.stub :save | ||
@run_status = ::Chef::RunStatus.new @node, ::Chef::EventDispatch::Dispatcher.new | ||
@status = Chef::RunStatus.new @node, Chef::EventDispatch::Dispatcher.new | ||
end | ||
|
||
it "doesn't reboot if the run failed" do | ||
@run_status.exception = ::Exception.new | ||
@status.exception = Exception.new | ||
|
||
@handler.run_report_unsafe(@run_status).should_not be_true | ||
@handler.run_report_unsafe(@status).should_not be_true | ||
end | ||
|
||
it "doesn't reboot if the node does not have the enabled_role" do | ||
@handler.run_report_unsafe(@run_status).should_not be_true | ||
@handler.run_report_unsafe(@status).should_not be_true | ||
end | ||
|
||
it "doesn't reboot if the node has the enabled_role, but missing the reboot flag" do | ||
@node.stub(:roles).and_return ["booted"] | ||
it "doesn't reboot if the node has the enabled_role, but missing the reboot flag" do # rubocop:disable LineLength | ||
@node.stub(:roles).and_return ['booted'] | ||
|
||
@handler.run_report_unsafe(@run_status).should_not be_true | ||
@handler.run_report_unsafe(@status).should_not be_true | ||
end | ||
|
||
describe "with enabled_role and reboot flag" do | ||
describe 'with enabled_role and reboot flag' do | ||
before do | ||
@node.stub(:roles).and_return ["booted"] | ||
@node.stub(:roles).and_return ['booted'] | ||
@node.run_state['reboot'] = true | ||
end | ||
|
||
it "reboots" do | ||
@handler.run_report_unsafe(@run_status).should be_true | ||
it 'reboots' do | ||
@handler.run_report_unsafe(@status).should be_true | ||
end | ||
|
||
it "issues correct reboot_command" do | ||
it 'issues correct command' do | ||
obj = double | ||
obj.stub(:run_command) { true } | ||
::Mixlib::ShellOut.should_receive(:new). | ||
with("sync; sync; shutdown -r +1&"). | ||
and_return(obj) | ||
@handler.run_report_unsafe(@run_status) | ||
Mixlib::ShellOut.should_receive(:new) | ||
.with('sync; sync; shutdown -r +1&') | ||
.and_return(obj) | ||
@handler.run_report_unsafe(@status) | ||
end | ||
|
||
it "resets run_list if node has a post_boot_runlist attribute" do | ||
node = ::ChefSpec::Runner.new do |n| | ||
n.set['reboot-handler']['post_boot_runlist'] = ["role[foo]"] | ||
end.converge("reboot-handler::default").node | ||
it 'resets run_list if node has a post_boot_runlist attribute' do | ||
node = ChefSpec::Runner.new do |n| | ||
n.set['reboot-handler']['post_boot_runlist'] = ['role[foo]'] | ||
end.converge('reboot-handler::default').node | ||
node.stub :save | ||
run_status = ::Chef::RunStatus.new node, ::Chef::EventDispatch::Dispatcher.new | ||
node.stub(:roles).and_return ["booted"] | ||
status = Chef::RunStatus.new node, Chef::EventDispatch::Dispatcher.new | ||
node.stub(:roles).and_return ['booted'] | ||
node.run_state['reboot'] = true | ||
@handler.run_report_unsafe(run_status) | ||
@handler.run_report_unsafe(status) | ||
|
||
node.run_list.to_s.should eq("role[foo]") | ||
node.run_list.to_s.should eq('role[foo]') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
require "chef" | ||
require "chefspec" | ||
require "chefspec/berkshelf" | ||
require "chefspec/deprecations" | ||
# encoding: UTF-8 | ||
|
||
require 'chef' | ||
require 'chefspec' | ||
require 'chefspec/berkshelf' | ||
require 'chefspec/deprecations' |