cheffish 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/README.md +120 -120
  4. data/Rakefile +23 -23
  5. data/lib/chef/provider/chef_acl.rb +439 -439
  6. data/lib/chef/provider/chef_client.rb +53 -53
  7. data/lib/chef/provider/chef_container.rb +55 -55
  8. data/lib/chef/provider/chef_data_bag.rb +55 -55
  9. data/lib/chef/provider/chef_data_bag_item.rb +278 -278
  10. data/lib/chef/provider/chef_environment.rb +83 -83
  11. data/lib/chef/provider/chef_group.rb +83 -83
  12. data/lib/chef/provider/chef_mirror.rb +169 -169
  13. data/lib/chef/provider/chef_node.rb +87 -87
  14. data/lib/chef/provider/chef_organization.rb +155 -155
  15. data/lib/chef/provider/chef_resolved_cookbooks.rb +46 -46
  16. data/lib/chef/provider/chef_role.rb +84 -84
  17. data/lib/chef/provider/chef_user.rb +59 -59
  18. data/lib/chef/provider/private_key.rb +225 -225
  19. data/lib/chef/provider/public_key.rb +88 -88
  20. data/lib/chef/resource/chef_acl.rb +69 -69
  21. data/lib/chef/resource/chef_client.rb +48 -48
  22. data/lib/chef/resource/chef_container.rb +22 -22
  23. data/lib/chef/resource/chef_data_bag.rb +22 -22
  24. data/lib/chef/resource/chef_data_bag_item.rb +121 -121
  25. data/lib/chef/resource/chef_environment.rb +77 -77
  26. data/lib/chef/resource/chef_group.rb +53 -53
  27. data/lib/chef/resource/chef_mirror.rb +52 -52
  28. data/lib/chef/resource/chef_node.rb +22 -22
  29. data/lib/chef/resource/chef_organization.rb +69 -69
  30. data/lib/chef/resource/chef_resolved_cookbooks.rb +35 -35
  31. data/lib/chef/resource/chef_role.rb +110 -110
  32. data/lib/chef/resource/chef_user.rb +56 -56
  33. data/lib/chef/resource/private_key.rb +48 -48
  34. data/lib/chef/resource/public_key.rb +25 -25
  35. data/lib/cheffish.rb +235 -235
  36. data/lib/cheffish/actor_provider_base.rb +131 -131
  37. data/lib/cheffish/basic_chef_client.rb +184 -184
  38. data/lib/cheffish/chef_provider_base.rb +246 -246
  39. data/lib/cheffish/chef_run.rb +162 -162
  40. data/lib/cheffish/chef_run_data.rb +19 -19
  41. data/lib/cheffish/chef_run_listener.rb +30 -30
  42. data/lib/cheffish/key_formatter.rb +113 -113
  43. data/lib/cheffish/merged_config.rb +94 -94
  44. data/lib/cheffish/recipe_dsl.rb +157 -157
  45. data/lib/cheffish/rspec.rb +8 -8
  46. data/lib/cheffish/rspec/chef_run_support.rb +83 -83
  47. data/lib/cheffish/rspec/matchers.rb +4 -4
  48. data/lib/cheffish/rspec/matchers/be_idempotent.rb +16 -16
  49. data/lib/cheffish/rspec/matchers/emit_no_warnings_or_errors.rb +15 -15
  50. data/lib/cheffish/rspec/matchers/have_updated.rb +37 -37
  51. data/lib/cheffish/rspec/matchers/partially_match.rb +63 -63
  52. data/lib/cheffish/rspec/recipe_run_wrapper.rb +59 -59
  53. data/lib/cheffish/rspec/repository_support.rb +108 -108
  54. data/lib/cheffish/server_api.rb +52 -52
  55. data/lib/cheffish/version.rb +3 -3
  56. data/lib/cheffish/with_pattern.rb +21 -21
  57. data/spec/functional/fingerprint_spec.rb +64 -64
  58. data/spec/functional/merged_config_spec.rb +19 -19
  59. data/spec/functional/server_api_spec.rb +13 -13
  60. data/spec/integration/chef_acl_spec.rb +879 -879
  61. data/spec/integration/chef_client_spec.rb +105 -105
  62. data/spec/integration/chef_container_spec.rb +33 -33
  63. data/spec/integration/chef_group_spec.rb +309 -309
  64. data/spec/integration/chef_mirror_spec.rb +491 -491
  65. data/spec/integration/chef_node_spec.rb +786 -786
  66. data/spec/integration/chef_organization_spec.rb +226 -226
  67. data/spec/integration/chef_role_spec.rb +78 -78
  68. data/spec/integration/chef_user_spec.rb +85 -85
  69. data/spec/integration/private_key_spec.rb +399 -399
  70. data/spec/integration/recipe_dsl_spec.rb +28 -28
  71. data/spec/integration/rspec/converge_spec.rb +183 -183
  72. data/spec/support/key_support.rb +29 -29
  73. data/spec/support/spec_support.rb +15 -15
  74. data/spec/unit/get_private_key_spec.rb +131 -131
  75. data/spec/unit/recipe_run_wrapper_spec.rb +37 -37
  76. metadata +3 -4
@@ -1,59 +1,59 @@
1
- require 'cheffish/chef_run'
2
-
3
- module Cheffish
4
- module RSpec
5
- class RecipeRunWrapper < ChefRun
6
- def initialize(chef_config, example: nil, &recipe)
7
- super(chef_config)
8
- @recipe = recipe
9
- @example = example || recipe.binding.eval('self')
10
- end
11
-
12
- attr_reader :recipe
13
- attr_reader :example
14
-
15
- def client
16
- if !@client
17
- super
18
- example = self.example
19
-
20
- # Call into the rspec example's let variables and other methods
21
- @client.define_singleton_method(:method_missing) do |name, *args, &block|
22
- # the elimination of a bunch of metaprogramming in 12.4 changed how Chef DSL is defined in code,
23
- # requiring a slight contortion for earlier versions.
24
- if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('12.4') # incompatibility introduced at 2b364df
25
- if example.respond_to?(name)
26
- example.public_send(name, *args, &block)
27
- end
28
- else
29
- begin
30
- super(name, *args, &block)
31
- rescue NameError
32
- if example.respond_to?(name)
33
- example.public_send(name, *args, &block)
34
- else
35
- raise
36
- end
37
- end
38
- end
39
- end
40
- # This is called by respond_to?, and is required to make sure the
41
- # resource knows that we will in fact call the given method.
42
- @client.define_singleton_method(:respond_to_missing?) do |name, include_private = false|
43
- example.respond_to?(name) || super(name, include_private)
44
- end
45
- # Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource
46
- # will hook resources up to the example let variables as well (via
47
- # enclosing_provider).
48
- # Please don't hurt me
49
- @client.define_singleton_method(:is_a?) do |klass|
50
- klass == Chef::Provider || super(klass)
51
- end
52
-
53
- @client.load_block(&recipe)
54
- end
55
- @client
56
- end
57
- end
58
- end
59
- end
1
+ require 'cheffish/chef_run'
2
+
3
+ module Cheffish
4
+ module RSpec
5
+ class RecipeRunWrapper < ChefRun
6
+ def initialize(chef_config, example: nil, &recipe)
7
+ super(chef_config)
8
+ @recipe = recipe
9
+ @example = example || recipe.binding.eval('self')
10
+ end
11
+
12
+ attr_reader :recipe
13
+ attr_reader :example
14
+
15
+ def client
16
+ if !@client
17
+ super
18
+ example = self.example
19
+
20
+ # Call into the rspec example's let variables and other methods
21
+ @client.define_singleton_method(:method_missing) do |name, *args, &block|
22
+ # the elimination of a bunch of metaprogramming in 12.4 changed how Chef DSL is defined in code,
23
+ # requiring a slight contortion for earlier versions.
24
+ if Gem::Version.new(Chef::VERSION) >= Gem::Version.new('12.4') # incompatibility introduced at 2b364df
25
+ if example.respond_to?(name)
26
+ example.public_send(name, *args, &block)
27
+ end
28
+ else
29
+ begin
30
+ super(name, *args, &block)
31
+ rescue NameError
32
+ if example.respond_to?(name)
33
+ example.public_send(name, *args, &block)
34
+ else
35
+ raise
36
+ end
37
+ end
38
+ end
39
+ end
40
+ # This is called by respond_to?, and is required to make sure the
41
+ # resource knows that we will in fact call the given method.
42
+ @client.define_singleton_method(:respond_to_missing?) do |name, include_private = false|
43
+ example.respond_to?(name) || super(name, include_private)
44
+ end
45
+ # Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource
46
+ # will hook resources up to the example let variables as well (via
47
+ # enclosing_provider).
48
+ # Please don't hurt me
49
+ @client.define_singleton_method(:is_a?) do |klass|
50
+ klass == Chef::Provider || super(klass)
51
+ end
52
+
53
+ @client.load_block(&recipe)
54
+ end
55
+ @client
56
+ end
57
+ end
58
+ end
59
+ 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
@@ -1,3 +1,3 @@
1
- module Cheffish
2
- VERSION = '1.4.0'
3
- end
1
+ module Cheffish
2
+ VERSION = '1.4.1'
3
+ end
@@ -1,21 +1,21 @@
1
- module Cheffish
2
- module WithPattern
3
- def with(symbol)
4
- class_eval <<EOM
5
- attr_accessor :current_#{symbol}
6
-
7
- def with_#{symbol}(value)
8
- old_value = self.current_#{symbol}
9
- self.current_#{symbol} = value
10
- if block_given?
11
- begin
12
- yield
13
- ensure
14
- self.current_#{symbol} = old_value
15
- end
16
- end
17
- end
18
- EOM
19
- end
20
- end
21
- end
1
+ module Cheffish
2
+ module WithPattern
3
+ def with(symbol)
4
+ class_eval <<EOM
5
+ attr_accessor :current_#{symbol}
6
+
7
+ def with_#{symbol}(value)
8
+ old_value = self.current_#{symbol}
9
+ self.current_#{symbol} = value
10
+ if block_given?
11
+ begin
12
+ yield
13
+ ensure
14
+ self.current_#{symbol} = old_value
15
+ end
16
+ end
17
+ end
18
+ EOM
19
+ end
20
+ end
21
+ end