cheffish 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -0
  3. data/LICENSE +201 -201
  4. data/README.md +120 -120
  5. data/Rakefile +23 -23
  6. data/cheffish.gemspec +26 -0
  7. data/lib/chef/provider/chef_acl.rb +446 -439
  8. data/lib/chef/provider/chef_client.rb +53 -53
  9. data/lib/chef/provider/chef_container.rb +55 -55
  10. data/lib/chef/provider/chef_data_bag.rb +55 -55
  11. data/lib/chef/provider/chef_data_bag_item.rb +278 -278
  12. data/lib/chef/provider/chef_environment.rb +83 -83
  13. data/lib/chef/provider/chef_group.rb +83 -83
  14. data/lib/chef/provider/chef_mirror.rb +169 -169
  15. data/lib/chef/provider/chef_node.rb +87 -87
  16. data/lib/chef/provider/chef_organization.rb +155 -155
  17. data/lib/chef/provider/chef_resolved_cookbooks.rb +46 -46
  18. data/lib/chef/provider/chef_role.rb +84 -84
  19. data/lib/chef/provider/chef_user.rb +59 -59
  20. data/lib/chef/provider/private_key.rb +225 -225
  21. data/lib/chef/provider/public_key.rb +88 -88
  22. data/lib/chef/resource/chef_acl.rb +69 -69
  23. data/lib/chef/resource/chef_client.rb +48 -48
  24. data/lib/chef/resource/chef_container.rb +22 -22
  25. data/lib/chef/resource/chef_data_bag.rb +22 -22
  26. data/lib/chef/resource/chef_data_bag_item.rb +121 -121
  27. data/lib/chef/resource/chef_environment.rb +77 -77
  28. data/lib/chef/resource/chef_group.rb +53 -53
  29. data/lib/chef/resource/chef_mirror.rb +52 -52
  30. data/lib/chef/resource/chef_node.rb +22 -22
  31. data/lib/chef/resource/chef_organization.rb +69 -69
  32. data/lib/chef/resource/chef_resolved_cookbooks.rb +35 -35
  33. data/lib/chef/resource/chef_role.rb +110 -110
  34. data/lib/chef/resource/chef_user.rb +56 -56
  35. data/lib/chef/resource/private_key.rb +48 -48
  36. data/lib/chef/resource/public_key.rb +25 -25
  37. data/lib/cheffish.rb +235 -235
  38. data/lib/cheffish/actor_provider_base.rb +131 -131
  39. data/lib/cheffish/basic_chef_client.rb +184 -184
  40. data/lib/cheffish/chef_provider_base.rb +246 -246
  41. data/lib/cheffish/chef_run.rb +162 -162
  42. data/lib/cheffish/chef_run_data.rb +19 -19
  43. data/lib/cheffish/chef_run_listener.rb +30 -30
  44. data/lib/cheffish/key_formatter.rb +113 -113
  45. data/lib/cheffish/merged_config.rb +98 -94
  46. data/lib/cheffish/recipe_dsl.rb +157 -157
  47. data/lib/cheffish/rspec.rb +8 -8
  48. data/lib/cheffish/rspec/chef_run_support.rb +83 -83
  49. data/lib/cheffish/rspec/matchers.rb +4 -4
  50. data/lib/cheffish/rspec/matchers/be_idempotent.rb +16 -16
  51. data/lib/cheffish/rspec/matchers/emit_no_warnings_or_errors.rb +15 -15
  52. data/lib/cheffish/rspec/matchers/have_updated.rb +37 -37
  53. data/lib/cheffish/rspec/matchers/partially_match.rb +63 -63
  54. data/lib/cheffish/rspec/recipe_run_wrapper.rb +78 -78
  55. data/lib/cheffish/rspec/repository_support.rb +108 -108
  56. data/lib/cheffish/server_api.rb +52 -52
  57. data/lib/cheffish/version.rb +3 -3
  58. data/lib/cheffish/with_pattern.rb +21 -21
  59. data/spec/functional/fingerprint_spec.rb +64 -64
  60. data/spec/functional/merged_config_spec.rb +19 -19
  61. data/spec/functional/server_api_spec.rb +13 -13
  62. data/spec/integration/chef_acl_spec.rb +892 -879
  63. data/spec/integration/chef_client_spec.rb +105 -105
  64. data/spec/integration/chef_container_spec.rb +33 -33
  65. data/spec/integration/chef_group_spec.rb +309 -309
  66. data/spec/integration/chef_mirror_spec.rb +491 -491
  67. data/spec/integration/chef_node_spec.rb +786 -786
  68. data/spec/integration/chef_organization_spec.rb +226 -226
  69. data/spec/integration/chef_role_spec.rb +78 -78
  70. data/spec/integration/chef_user_spec.rb +85 -85
  71. data/spec/integration/private_key_spec.rb +399 -399
  72. data/spec/integration/recipe_dsl_spec.rb +28 -28
  73. data/spec/integration/rspec/converge_spec.rb +183 -183
  74. data/spec/support/key_support.rb +29 -29
  75. data/spec/support/spec_support.rb +15 -15
  76. data/spec/unit/get_private_key_spec.rb +131 -131
  77. data/spec/unit/recipe_run_wrapper_spec.rb +37 -37
  78. metadata +7 -5
@@ -1,78 +1,78 @@
1
- require 'cheffish/chef_run'
2
- require 'forwardable'
3
-
4
- module Cheffish
5
- module RSpec
6
- class RecipeRunWrapper < ChefRun
7
- def initialize(chef_config, example: nil, &recipe)
8
- super(chef_config)
9
- @recipe = recipe
10
- @example = example || recipe.binding.eval('self')
11
- end
12
-
13
- attr_reader :recipe
14
- attr_reader :example
15
-
16
- def client
17
- if !@client
18
- super
19
- example = self.example
20
-
21
- #
22
- # Support for both resources and rspec example's let variables:
23
- #
24
- # In 12.4, the elimination of a bunch of metaprogramming in 12.4
25
- # changed how Chef DSL is defined in code: resource methods are now
26
- # explicitly defined in `Chef::DSL::Recipe`. In 12.3, no actual
27
- # methods were defined and `respond_to?(:file)` would return false.
28
- # If we reach `method_missing` here, it means that we either have a
29
- # 12.3-ish resource or we want to call a `let` variable.
30
- #
31
- @client.instance_eval { @rspec_example = example }
32
- def @client.method_missing(name, *args, &block)
33
- # If there is a let variable, call it. This is because in 12.4,
34
- # the parent class is going to call respond_to?(name) to find out
35
- # if someone was doing weird things, and then call send(). This
36
- # would result in an infinite loop, coming right. Back. Here.
37
- # A fix to chef is incoming, but we still need this if we want to
38
- # work with Chef 12.4.
39
- if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('12.4')
40
- if @rspec_example.respond_to?(name)
41
- return @rspec_example.public_send(name, *args, &block)
42
- end
43
- end
44
-
45
- # In 12.3 or below, method_missing was the only way to call
46
- # resources. If we are in 12.4, we still need to call the crazy
47
- # method_missing metaprogramming because backcompat.
48
- begin
49
- super
50
- rescue NameError
51
- if @rspec_example.respond_to?(name)
52
- @rspec_example.public_send(name, *args, &block)
53
- else
54
- raise
55
- end
56
- end
57
- end
58
- # This is called by respond_to?, and is required to make sure the
59
- # resource knows that we will in fact call the given method.
60
- def @client.respond_to_missing?(name, include_private = false)
61
- @rspec_example.respond_to?(name, include_private) || super
62
- end
63
-
64
- # Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource
65
- # will hook resources up to the example let variables as well (via
66
- # enclosing_provider).
67
- # Please don't hurt me
68
- def @client.is_a?(klass)
69
- klass == Chef::Provider || super(klass)
70
- end
71
-
72
- @client.load_block(&recipe)
73
- end
74
- @client
75
- end
76
- end
77
- end
78
- end
1
+ require 'cheffish/chef_run'
2
+ require 'forwardable'
3
+
4
+ module Cheffish
5
+ module RSpec
6
+ class RecipeRunWrapper < ChefRun
7
+ def initialize(chef_config, example: nil, &recipe)
8
+ super(chef_config)
9
+ @recipe = recipe
10
+ @example = example || recipe.binding.eval('self')
11
+ end
12
+
13
+ attr_reader :recipe
14
+ attr_reader :example
15
+
16
+ def client
17
+ if !@client
18
+ super
19
+ example = self.example
20
+
21
+ #
22
+ # Support for both resources and rspec example's let variables:
23
+ #
24
+ # In 12.4, the elimination of a bunch of metaprogramming in 12.4
25
+ # changed how Chef DSL is defined in code: resource methods are now
26
+ # explicitly defined in `Chef::DSL::Recipe`. In 12.3, no actual
27
+ # methods were defined and `respond_to?(:file)` would return false.
28
+ # If we reach `method_missing` here, it means that we either have a
29
+ # 12.3-ish resource or we want to call a `let` variable.
30
+ #
31
+ @client.instance_eval { @rspec_example = example }
32
+ def @client.method_missing(name, *args, &block)
33
+ # If there is a let variable, call it. This is because in 12.4,
34
+ # the parent class is going to call respond_to?(name) to find out
35
+ # if someone was doing weird things, and then call send(). This
36
+ # would result in an infinite loop, coming right. Back. Here.
37
+ # A fix to chef is incoming, but we still need this if we want to
38
+ # work with Chef 12.4.
39
+ if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('12.4')
40
+ if @rspec_example.respond_to?(name)
41
+ return @rspec_example.public_send(name, *args, &block)
42
+ end
43
+ end
44
+
45
+ # In 12.3 or below, method_missing was the only way to call
46
+ # resources. If we are in 12.4, we still need to call the crazy
47
+ # method_missing metaprogramming because backcompat.
48
+ begin
49
+ super
50
+ rescue NameError
51
+ if @rspec_example.respond_to?(name)
52
+ @rspec_example.public_send(name, *args, &block)
53
+ else
54
+ raise
55
+ end
56
+ end
57
+ end
58
+ # This is called by respond_to?, and is required to make sure the
59
+ # resource knows that we will in fact call the given method.
60
+ def @client.respond_to_missing?(name, include_private = false)
61
+ @rspec_example.respond_to?(name, include_private) || super
62
+ end
63
+
64
+ # Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource
65
+ # will hook resources up to the example let variables as well (via
66
+ # enclosing_provider).
67
+ # Please don't hurt me
68
+ def @client.is_a?(klass)
69
+ klass == Chef::Provider || super(klass)
70
+ end
71
+
72
+ @client.load_block(&recipe)
73
+ end
74
+ @client
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,108 +1,108 @@
1
- module Cheffish
2
- module RSpec
3
- module RepositorySupport
4
- def when_the_repository(desc, *tags, &block)
5
- context("when the chef repo #{desc}", *tags) do
6
- include_context "with a chef repo"
7
- extend WhenTheRepositoryClassMethods
8
- module_eval(&block)
9
- end
10
- end
11
-
12
- ::RSpec.shared_context "with a chef repo" do
13
- before :each do
14
- raise "Can only create one directory per test" if @repository_dir
15
- @repository_dir = Dir.mktmpdir('chef_repo')
16
- Chef::Config.chef_repo_path = @repository_dir
17
- %w(client cookbook data_bag environment node role user).each do |object_name|
18
- Chef::Config.delete("#{object_name}_path".to_sym)
19
- end
20
- end
21
-
22
- after :each do
23
- if @repository_dir
24
- begin
25
- %w(client cookbook data_bag environment node role user).each do |object_name|
26
- Chef::Config.delete("#{object_name}_path".to_sym)
27
- end
28
- Chef::Config.delete(:chef_repo_path)
29
- FileUtils.remove_entry_secure(@repository_dir)
30
- ensure
31
- @repository_dir = nil
32
- end
33
- end
34
- Dir.chdir(@old_cwd) if @old_cwd
35
- end
36
-
37
- def directory(relative_path, &block)
38
- old_parent_path = @parent_path
39
- @parent_path = path_to(relative_path)
40
- FileUtils.mkdir_p(@parent_path)
41
- instance_eval(&block) if block
42
- @parent_path = old_parent_path
43
- end
44
-
45
- def file(relative_path, contents)
46
- filename = path_to(relative_path)
47
- dir = File.dirname(filename)
48
- FileUtils.mkdir_p(dir) unless dir == '.'
49
- File.open(filename, 'w') do |file|
50
- raw = case contents
51
- when Hash
52
- JSON.pretty_generate(contents)
53
- when Array
54
- contents.join("\n")
55
- else
56
- contents
57
- end
58
- file.write(raw)
59
- end
60
- end
61
-
62
- def symlink(relative_path, relative_dest)
63
- filename = path_to(relative_path)
64
- dir = File.dirname(filename)
65
- FileUtils.mkdir_p(dir) unless dir == '.'
66
- dest_filename = path_to(relative_dest)
67
- File.symlink(dest_filename, filename)
68
- end
69
-
70
- def path_to(relative_path)
71
- File.expand_path(relative_path, (@parent_path || @repository_dir))
72
- end
73
-
74
- def cwd(relative_path)
75
- @old_cwd = Dir.pwd
76
- Dir.chdir(path_to(relative_path))
77
- end
78
-
79
- module WhenTheRepositoryClassMethods
80
- def directory(*args, &block)
81
- before :each do
82
- directory(*args, &block)
83
- end
84
- end
85
-
86
- def file(*args, &block)
87
- before :each do
88
- file(*args, &block)
89
- end
90
- end
91
-
92
- def symlink(*args, &block)
93
- before :each do
94
- symlink(*args, &block)
95
- end
96
- end
97
-
98
- def path_to(*args, &block)
99
- before :each do
100
- file(*args, &block)
101
- end
102
- end
103
- end
104
- end
105
- end
106
-
107
- end
108
- end
1
+ module Cheffish
2
+ module RSpec
3
+ module RepositorySupport
4
+ def when_the_repository(desc, *tags, &block)
5
+ context("when the chef repo #{desc}", *tags) do
6
+ include_context "with a chef repo"
7
+ extend WhenTheRepositoryClassMethods
8
+ module_eval(&block)
9
+ end
10
+ end
11
+
12
+ ::RSpec.shared_context "with a chef repo" do
13
+ before :each do
14
+ raise "Can only create one directory per test" if @repository_dir
15
+ @repository_dir = Dir.mktmpdir('chef_repo')
16
+ Chef::Config.chef_repo_path = @repository_dir
17
+ %w(client cookbook data_bag environment node role user).each do |object_name|
18
+ Chef::Config.delete("#{object_name}_path".to_sym)
19
+ end
20
+ end
21
+
22
+ after :each do
23
+ if @repository_dir
24
+ begin
25
+ %w(client cookbook data_bag environment node role user).each do |object_name|
26
+ Chef::Config.delete("#{object_name}_path".to_sym)
27
+ end
28
+ Chef::Config.delete(:chef_repo_path)
29
+ FileUtils.remove_entry_secure(@repository_dir)
30
+ ensure
31
+ @repository_dir = nil
32
+ end
33
+ end
34
+ Dir.chdir(@old_cwd) if @old_cwd
35
+ end
36
+
37
+ def directory(relative_path, &block)
38
+ old_parent_path = @parent_path
39
+ @parent_path = path_to(relative_path)
40
+ FileUtils.mkdir_p(@parent_path)
41
+ instance_eval(&block) if block
42
+ @parent_path = old_parent_path
43
+ end
44
+
45
+ def file(relative_path, contents)
46
+ filename = path_to(relative_path)
47
+ dir = File.dirname(filename)
48
+ FileUtils.mkdir_p(dir) unless dir == '.'
49
+ File.open(filename, 'w') do |file|
50
+ raw = case contents
51
+ when Hash
52
+ JSON.pretty_generate(contents)
53
+ when Array
54
+ contents.join("\n")
55
+ else
56
+ contents
57
+ end
58
+ file.write(raw)
59
+ end
60
+ end
61
+
62
+ def symlink(relative_path, relative_dest)
63
+ filename = path_to(relative_path)
64
+ dir = File.dirname(filename)
65
+ FileUtils.mkdir_p(dir) unless dir == '.'
66
+ dest_filename = path_to(relative_dest)
67
+ File.symlink(dest_filename, filename)
68
+ end
69
+
70
+ def path_to(relative_path)
71
+ File.expand_path(relative_path, (@parent_path || @repository_dir))
72
+ end
73
+
74
+ def cwd(relative_path)
75
+ @old_cwd = Dir.pwd
76
+ Dir.chdir(path_to(relative_path))
77
+ end
78
+
79
+ module WhenTheRepositoryClassMethods
80
+ def directory(*args, &block)
81
+ before :each do
82
+ directory(*args, &block)
83
+ end
84
+ end
85
+
86
+ def file(*args, &block)
87
+ before :each do
88
+ file(*args, &block)
89
+ end
90
+ end
91
+
92
+ def symlink(*args, &block)
93
+ before :each do
94
+ symlink(*args, &block)
95
+ end
96
+ end
97
+
98
+ def path_to(*args, &block)
99
+ before :each do
100
+ file(*args, &block)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -1,52 +1,52 @@
1
- #
2
- # Author:: John Keiser (<jkeiser@opscode.com>)
3
- # Copyright:: Copyright (c) 2012 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
-
19
- require 'chef/version'
20
- require 'chef/http'
21
- require 'chef/http/authenticator'
22
- require 'chef/http/cookie_manager'
23
- require 'chef/http/decompressor'
24
- require 'chef/http/json_input'
25
- require 'chef/http/json_output'
26
- if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.12')
27
- require 'chef/http/remote_request_id'
28
- end
29
-
30
- module Cheffish
31
- # Exactly like Chef::ServerAPI, but requires you to pass in what keys you want (no defaults)
32
- class ServerAPI < Chef::HTTP
33
-
34
- def initialize(url, options = {})
35
- super(url, options)
36
- root_url = URI.parse(url)
37
- root_url.path = ''
38
- @root_url = root_url.to_s
39
- end
40
-
41
- attr_reader :root_url
42
-
43
- use Chef::HTTP::JSONInput
44
- use Chef::HTTP::JSONOutput
45
- use Chef::HTTP::CookieManager
46
- use Chef::HTTP::Decompressor
47
- use Chef::HTTP::Authenticator
48
- if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.12')
49
- use Chef::HTTP::RemoteRequestID
50
- end
51
- end
52
- end
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 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
+
19
+ require 'chef/version'
20
+ require 'chef/http'
21
+ require 'chef/http/authenticator'
22
+ require 'chef/http/cookie_manager'
23
+ require 'chef/http/decompressor'
24
+ require 'chef/http/json_input'
25
+ require 'chef/http/json_output'
26
+ if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.12')
27
+ require 'chef/http/remote_request_id'
28
+ end
29
+
30
+ module Cheffish
31
+ # Exactly like Chef::ServerAPI, but requires you to pass in what keys you want (no defaults)
32
+ class ServerAPI < Chef::HTTP
33
+
34
+ def initialize(url, options = {})
35
+ super(url, options)
36
+ root_url = URI.parse(url)
37
+ root_url.path = ''
38
+ @root_url = root_url.to_s
39
+ end
40
+
41
+ attr_reader :root_url
42
+
43
+ use Chef::HTTP::JSONInput
44
+ use Chef::HTTP::JSONOutput
45
+ use Chef::HTTP::CookieManager
46
+ use Chef::HTTP::Decompressor
47
+ use Chef::HTTP::Authenticator
48
+ if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('11.12')
49
+ use Chef::HTTP::RemoteRequestID
50
+ end
51
+ end
52
+ end