chef-rewind 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +17 -0
- data/Gemfile +42 -2
- data/README.md +2 -0
- data/chef-rewind.gemspec +1 -1
- data/lib/chef/rewind.rb +7 -0
- data/spec/data/cookbooks/angrybash/recipes/default.rb +8 -0
- data/spec/data/cookbooks/apache2/files/default/apache2_module_conf_generate.pl +2 -0
- data/spec/data/cookbooks/apache2/recipes/default.rb +3 -0
- data/spec/data/cookbooks/borken/recipes/default.rb +2 -0
- data/spec/data/cookbooks/borken/templates/default/borken.erb +2 -0
- data/spec/data/cookbooks/chefignore +6 -0
- data/spec/data/cookbooks/java/files/default/java.response +2 -0
- data/spec/data/cookbooks/openldap/attributes/default.rb +16 -0
- data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -0
- data/spec/data/cookbooks/openldap/definitions/client.rb +5 -0
- data/spec/data/cookbooks/openldap/definitions/server.rb +5 -0
- data/spec/data/cookbooks/openldap/files/default/.dotfile +1 -0
- data/spec/data/cookbooks/openldap/files/default/.ssh/id_rsa +1 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir +1 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file1.txt +3 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file2.txt +3 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/.a_dotfile +1 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file1.txt +3 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file2.txt +3 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/subdir_with_no_file_just_a_subsubdir/the_subsubdir/some_file.txt +3 -0
- data/spec/data/cookbooks/openldap/recipes/default.rb +3 -0
- data/spec/data/cookbooks/openldap/recipes/gigantor.rb +3 -0
- data/spec/data/cookbooks/openldap/recipes/one.rb +15 -0
- data/spec/data/cookbooks/openldap/templates/default/openldap_stuff.conf.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/openldap_variable_stuff.conf.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/test.erb +1 -0
- data/spec/rewind_recipe_spec.rb +62 -0
- data/spec/rewind_resource_spec.rb +34 -0
- data/spec/spec_helper.rb +81 -0
- data/spec/support/chef_helpers.rb +52 -0
- data/spec/support/lib/chef/provider/easy.rb +35 -0
- data/spec/support/lib/chef/provider/snakeoil.rb +40 -0
- data/spec/support/lib/chef/resource/cat.rb +41 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +43 -0
- data/spec/support/lib/chef/resource/zen_master.rb +46 -0
- data/spec/support/matchers/leak.rb +96 -0
- data/spec/support/mock/constant.rb +52 -0
- data/spec/support/mock/platform.rb +18 -0
- data/spec/support/platform_helpers.rb +31 -0
- data/spec/support/platforms/prof/gc.rb +54 -0
- data/spec/support/platforms/prof/win32.rb +46 -0
- data/spec/support/shared/functional/directory_resource.rb +85 -0
- data/spec/support/shared/functional/file_resource.rb +173 -0
- data/spec/support/shared/functional/knife.rb +37 -0
- data/spec/support/shared/functional/securable_resource.rb +394 -0
- data/spec/support/shared/unit/api_error_inspector.rb +192 -0
- data/spec/support/shared/unit/platform_introspector.rb +162 -0
- metadata +99 -4
data/CHANGELOG
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Peter Fern: Allow rewinding recipe_name
|
2
|
+
Peter Fern: Shef extensions have moved in 11.x, add compatible require
|
3
|
+
Peter Fern: Change deprecated Gemfile source `:rubygems` to `https://rubygems.org`
|
4
|
+
aabes: Update README.md
|
5
|
+
Bryan Berry: now with rspec tests using chef's spec_helper
|
6
|
+
Bryan Berry: rename to chef-rewind
|
7
|
+
Bryan Berry: use set_and_return for Chef::Resource.cookbook_name
|
8
|
+
Bryan Berry: update readme
|
9
|
+
Bryan Berry: revert earlier commit that sets cookbook_name
|
10
|
+
Bryan Berry: update readme
|
11
|
+
Bryan Berry: set cookbook_name to current cookbook at time of editing
|
12
|
+
Bryan Berry: don't create nonexistent resources
|
13
|
+
Nathen Harvey: Add recipe file name to the README
|
14
|
+
Bryan Berry: add note that need `chef_gem` to install it
|
15
|
+
Bryan Berry: update readme
|
16
|
+
Bryan Berry: set version #
|
17
|
+
Bryan Berry: initial commit
|
data/Gemfile
CHANGED
@@ -1,4 +1,44 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem "activesupport", :group => :compat_testing, :platform => "ruby"
|
6
|
+
gem "ronn"
|
7
|
+
gem "rspec"
|
8
|
+
gem "chef"
|
9
|
+
gem "pry"
|
10
|
+
|
11
|
+
group(:development, :test) do
|
12
|
+
gem 'rack'
|
13
|
+
gem 'thin'
|
14
|
+
|
15
|
+
# Eventmachine 1.0.0 is causing functional test failures on Solaris
|
16
|
+
# 9 SPARC. Pinning em to 0.12.10 solves this issue until we can
|
17
|
+
# replace thin with webrat or some other alternative.
|
18
|
+
gem 'eventmachine', '0.12.10', :platforms => :ruby
|
19
|
+
|
20
|
+
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(darwin|freebsd)/)
|
21
|
+
# gem 'awesome_print'
|
22
|
+
# gem 'pry'
|
23
|
+
end
|
24
|
+
|
25
|
+
platforms :mswin, :mingw do
|
26
|
+
gem "ffi", "1.0.9"
|
27
|
+
gem "rdp-ruby-wmi", "0.3.1"
|
28
|
+
gem "windows-api", "0.4.0"
|
29
|
+
gem "windows-pr", "1.2.1"
|
30
|
+
gem "win32-api", "1.4.8"
|
31
|
+
gem "win32-dir", "0.3.7"
|
32
|
+
gem "win32-event", "0.5.2"
|
33
|
+
gem "win32-mutex", "0.3.1"
|
34
|
+
gem "win32-process", "0.6.5"
|
35
|
+
gem "win32-service", "0.7.2"
|
36
|
+
end
|
37
|
+
|
38
|
+
platforms :mingw_18 do
|
39
|
+
gem "win32-open3", "0.3.2"
|
40
|
+
end
|
41
|
+
|
42
|
+
# If you want to load debugging tools into the bundle exec sandbox,
|
43
|
+
# add these additional dependencies into chef/Gemfile.local
|
44
|
+
eval(IO.read(__FILE__ + '.local'), binding) if File.exists?(__FILE__ + '.local')
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@ a Chef::Exceptions::ResourceNotFound exception will be raised.
|
|
6
6
|
|
7
7
|
This function is designed to assist the library cookbook pattern.
|
8
8
|
|
9
|
+
Effectively, the rewind resource allows you to monkeypatch a cookbook that you would rather not modify directly. It will modify some properties of a resource, during the complile phase, before chef-client actually starts the run phase.
|
10
|
+
|
9
11
|
## Installation
|
10
12
|
|
11
13
|
Add this line to your application's Gemfile:
|
data/chef-rewind.gemspec
CHANGED
data/lib/chef/rewind.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
chef_env ||= nil
|
2
|
+
case chef_env
|
3
|
+
when "prod"
|
4
|
+
default[:ldap_server] = "ops1prod"
|
5
|
+
default[:ldap_basedn] = "dc=hjksolutions,dc=com"
|
6
|
+
default[:ldap_replication_password] = "yes"
|
7
|
+
when "corp"
|
8
|
+
default[:ldap_server] = "ops1prod"
|
9
|
+
default[:ldap_basedn] = "dc=hjksolutions,dc=com"
|
10
|
+
default[:ldap_replication_password] = "yougotit"
|
11
|
+
else
|
12
|
+
|
13
|
+
default[:ldap_server] = "ops1prod"
|
14
|
+
default[:ldap_basedn] = "dc=hjksolutions,dc=com"
|
15
|
+
default[:ldap_replication_password] = "forsure"
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
default[:smokey] = "robinson"
|
@@ -0,0 +1 @@
|
|
1
|
+
I am here to test .dotfiles work in file directories.
|
@@ -0,0 +1 @@
|
|
1
|
+
FAKE KEY
|
@@ -0,0 +1 @@
|
|
1
|
+
this is a dotfile in a dotdir
|
@@ -0,0 +1 @@
|
|
1
|
+
this is a file with a name beginning with a . dot
|
@@ -0,0 +1,15 @@
|
|
1
|
+
##
|
2
|
+
# Nodes should have a unique name
|
3
|
+
##
|
4
|
+
name "test.example.com-default"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Nodes can set arbitrary arguments
|
8
|
+
##
|
9
|
+
sunshine "in"
|
10
|
+
something "else"
|
11
|
+
|
12
|
+
##
|
13
|
+
# Nodes should have recipes
|
14
|
+
##
|
15
|
+
recipes "operations-master", "operations-monitoring"
|
@@ -0,0 +1 @@
|
|
1
|
+
slappiness is <%= node[:slappiness] -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
super secret is <%= @secret -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
We could be diving for pearls!
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'chef/rewind'
|
4
|
+
|
5
|
+
describe Chef::Recipe do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
|
9
|
+
cl = Chef::CookbookLoader.new(@cookbook_repo)
|
10
|
+
cl.load_cookbooks
|
11
|
+
@cookbook_collection = Chef::CookbookCollection.new(cl)
|
12
|
+
@node = Chef::Node.new
|
13
|
+
@node.normal[:tags] = Array.new
|
14
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
15
|
+
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
|
16
|
+
@recipe = Chef::Recipe.new("hjk", "test", @run_context)
|
17
|
+
|
18
|
+
# Shell/ext.rb is on the run path, and it defines
|
19
|
+
# Chef::Recipe#resources to call pp, which we don't want when
|
20
|
+
# we're running tests.
|
21
|
+
@recipe.stub!(:pp)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe "rewind" do
|
26
|
+
it "rewind an existing resource rather than create a new one" do
|
27
|
+
|
28
|
+
@recipe.zen_master "foobar" do
|
29
|
+
peace false
|
30
|
+
end
|
31
|
+
|
32
|
+
@recipe.rewind "zen_master[foobar]" do
|
33
|
+
peace true
|
34
|
+
end
|
35
|
+
resources = @run_context.resource_collection.all_resources
|
36
|
+
resources.length.should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "change the value of an existing resource" do
|
40
|
+
@recipe.zen_master "foobar" do
|
41
|
+
peace false
|
42
|
+
end
|
43
|
+
|
44
|
+
@recipe.rewind "zen_master[foobar]" do
|
45
|
+
peace true
|
46
|
+
end
|
47
|
+
|
48
|
+
zen_master = @run_context.resource_collection.find("zen_master[foobar]")
|
49
|
+
peace_status = zen_master.instance_exec { @peace }
|
50
|
+
peace_status.should == true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "throw an error when rewinding a nonexistent resource" do
|
54
|
+
lambda do
|
55
|
+
@recipe.rewind "zen_master[foobar]" do
|
56
|
+
peace true
|
57
|
+
end
|
58
|
+
end.should raise_error(Chef::Exceptions::ResourceNotFound)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chef/rewind'
|
3
|
+
|
4
|
+
class ResourceTestHarness < Chef::Resource
|
5
|
+
provider_base Chef::Provider::Package
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Chef::Resource do
|
9
|
+
before(:each) do
|
10
|
+
@cookbook_repo_path = File.join(CHEF_SPEC_DATA, 'cookbooks')
|
11
|
+
@cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new(@cookbook_repo_path))
|
12
|
+
@node = Chef::Node.new
|
13
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
14
|
+
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
|
15
|
+
@resource = Chef::Resource.new("funk", @run_context)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "cookbook_name" do
|
19
|
+
it "cookbook_name sets @cookbook_name properly" do
|
20
|
+
@resource.cookbook_name "foobar"
|
21
|
+
@resource.cookbook_name.should == "foobar"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "recipe_name" do
|
27
|
+
it "recipe_name sets @recipe_name properly" do
|
28
|
+
@resource.recipe_name "foobar"
|
29
|
+
@resource.recipe_name.should == "foobar"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# If you need to add anything in here, don't.
|
19
|
+
# Add it to one of the files in spec/support
|
20
|
+
|
21
|
+
# Abuse ruby's constant lookup to avoid undefined constant errors
|
22
|
+
module Shef
|
23
|
+
JUST_TESTING_MOVE_ALONG = true unless defined? JUST_TESTING_MOVE_ALONG
|
24
|
+
IRB = nil unless defined? IRB
|
25
|
+
end
|
26
|
+
|
27
|
+
# Ruby 1.9 Compat
|
28
|
+
$:.unshift File.expand_path("../..", __FILE__)
|
29
|
+
|
30
|
+
require 'rubygems'
|
31
|
+
require 'rspec/mocks'
|
32
|
+
|
33
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
34
|
+
$:.unshift(File.expand_path("../lib", __FILE__))
|
35
|
+
$:.unshift(File.dirname(__FILE__))
|
36
|
+
|
37
|
+
require 'chef'
|
38
|
+
require 'chef/knife'
|
39
|
+
Chef::Knife.load_commands
|
40
|
+
require 'chef/mixins'
|
41
|
+
require 'chef/application'
|
42
|
+
require 'chef/applications'
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'chef/shef'
|
46
|
+
rescue LoadError
|
47
|
+
require 'chef/shef/ext'
|
48
|
+
end
|
49
|
+
require 'chef/util/file_edit'
|
50
|
+
|
51
|
+
# If you want to load anything into the testing environment
|
52
|
+
# without versioning it, add it to spec/support/local_gems.rb
|
53
|
+
require 'spec/support/local_gems.rb' if File.exists?(File.join(File.dirname(__FILE__), 'support', 'local_gems.rb'))
|
54
|
+
|
55
|
+
# Explicitly require spec helpers that need to load first
|
56
|
+
require 'spec/support/platform_helpers'
|
57
|
+
|
58
|
+
# Autoloads support files
|
59
|
+
# Excludes support/platforms by default
|
60
|
+
# Do not change the gsub.
|
61
|
+
Dir["spec/support/**/*.rb"].
|
62
|
+
reject { |f| f =~ %r{^spec/support/platforms} }.
|
63
|
+
map { |f| f.gsub(%r{.rb$}, '') }.
|
64
|
+
each { |f| require f }
|
65
|
+
|
66
|
+
RSpec.configure do |config|
|
67
|
+
config.include(Matchers)
|
68
|
+
config.filter_run :focus => true
|
69
|
+
config.filter_run_excluding :external => true
|
70
|
+
|
71
|
+
# Add jruby filters here
|
72
|
+
config.filter_run_excluding :windows_only => true unless windows?
|
73
|
+
config.filter_run_excluding :unix_only => true unless unix?
|
74
|
+
config.filter_run_excluding :ruby_18_only => true unless ruby_18?
|
75
|
+
config.filter_run_excluding :ruby_19_only => true unless ruby_19?
|
76
|
+
config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
|
77
|
+
config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'
|
78
|
+
|
79
|
+
config.run_all_when_everything_filtered = true
|
80
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
81
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
CHEF_SPEC_DATA = File.expand_path(File.dirname(__FILE__) + "/../data/")
|
17
|
+
CHEF_SPEC_BACKUP_PATH = File.join(Dir.tmpdir, 'test-backup-path')
|
18
|
+
|
19
|
+
Chef::Config[:log_level] = :fatal
|
20
|
+
Chef::Config[:cache_type] = "Memory"
|
21
|
+
Chef::Config[:cache_options] = { }
|
22
|
+
Chef::Config[:persistent_queue] = false
|
23
|
+
Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
|
24
|
+
|
25
|
+
Chef::Log.level(Chef::Config.log_level)
|
26
|
+
Chef::Config.solo(false)
|
27
|
+
|
28
|
+
Chef::Log.logger = Logger.new(StringIO.new)
|
29
|
+
|
30
|
+
def sha256_checksum(path)
|
31
|
+
Digest::SHA256.hexdigest(File.read(path))
|
32
|
+
end
|
33
|
+
|
34
|
+
# From Ruby 1.9.2+
|
35
|
+
# Here for backwards compatibility with Ruby 1.8.7
|
36
|
+
# http://rubydoc.info/stdlib/tmpdir/1.9.2/Dir/Tmpname
|
37
|
+
def make_tmpname(prefix_suffix, n)
|
38
|
+
case prefix_suffix
|
39
|
+
when String
|
40
|
+
prefix = prefix_suffix
|
41
|
+
suffix = ""
|
42
|
+
when Array
|
43
|
+
prefix = prefix_suffix[0]
|
44
|
+
suffix = prefix_suffix[1]
|
45
|
+
else
|
46
|
+
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
47
|
+
end
|
48
|
+
t = Time.now.strftime("%Y%m%d")
|
49
|
+
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
50
|
+
path << "-#{n}" if n
|
51
|
+
path << suffix
|
52
|
+
end
|