cheffish 1.5.0 → 1.6.0

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.
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,8 +1,8 @@
1
- require 'cheffish/rspec/chef_run_support'
2
- require 'cheffish/rspec/repository_support'
3
- require 'cheffish/rspec/matchers'
4
-
5
- module Cheffish
6
- module RSpec
7
- end
8
- end
1
+ require 'cheffish/rspec/chef_run_support'
2
+ require 'cheffish/rspec/repository_support'
3
+ require 'cheffish/rspec/matchers'
4
+
5
+ module Cheffish
6
+ module RSpec
7
+ end
8
+ end
@@ -1,83 +1,83 @@
1
- require 'chef_zero/rspec'
2
- require 'chef/server_api'
3
- require 'cheffish/rspec/repository_support'
4
- require 'uri'
5
- require 'cheffish/chef_run'
6
- require 'cheffish/rspec/recipe_run_wrapper'
7
- require 'cheffish/rspec/matchers'
8
-
9
- module Cheffish
10
- module RSpec
11
- module ChefRunSupport
12
- include ChefZero::RSpec
13
- include RepositorySupport
14
-
15
- def self.extended(klass)
16
- klass.class_eval do
17
- include ChefRunSupportInstanceMethods
18
- end
19
- end
20
-
21
- def when_the_chef_12_server(*args, **options, &block)
22
- if Gem::Version.new(ChefZero::VERSION) >= Gem::Version.new('3.1')
23
- when_the_chef_server(*args, :osc_compat => false, :single_org => false, **options, &block)
24
- end
25
- end
26
-
27
- def with_converge(&recipe)
28
- before :each do
29
- r = recipe(&recipe)
30
- r.converge
31
- end
32
- end
33
-
34
- module ChefRunSupportInstanceMethods
35
- def rest
36
- ::Chef::ServerAPI.new
37
- end
38
-
39
- def get(path, *args)
40
- if path[0] == '/'
41
- path = URI.join(rest.url, path)
42
- end
43
- rest.get(path, *args)
44
- end
45
-
46
- def chef_config
47
- {}
48
- end
49
-
50
- def expect_recipe(str=nil, file=nil, line=nil, &recipe)
51
- r = recipe(str, file, line, &recipe)
52
- r.converge
53
- expect(r)
54
- end
55
-
56
- def expect_converge(str=nil, file=nil, line=nil, &recipe)
57
- expect { converge(str, file, line, &recipe) }
58
- end
59
-
60
- def recipe(str=nil, file=nil, line=nil, &recipe)
61
- if !recipe
62
- if file && line
63
- recipe = proc { eval(str, nil, file, line) }
64
- else
65
- recipe = proc { eval(str) }
66
- end
67
- end
68
- RecipeRunWrapper.new(chef_config, &recipe)
69
- end
70
-
71
- def converge(str=nil, file=nil, line=nil, &recipe)
72
- r = recipe(str, file, line, &recipe)
73
- r.converge
74
- r
75
- end
76
-
77
- def chef_client
78
- @chef_client ||= ChefRun.new(chef_config)
79
- end
80
- end
81
- end
82
- end
83
- end
1
+ require 'chef_zero/rspec'
2
+ require 'chef/server_api'
3
+ require 'cheffish/rspec/repository_support'
4
+ require 'uri'
5
+ require 'cheffish/chef_run'
6
+ require 'cheffish/rspec/recipe_run_wrapper'
7
+ require 'cheffish/rspec/matchers'
8
+
9
+ module Cheffish
10
+ module RSpec
11
+ module ChefRunSupport
12
+ include ChefZero::RSpec
13
+ include RepositorySupport
14
+
15
+ def self.extended(klass)
16
+ klass.class_eval do
17
+ include ChefRunSupportInstanceMethods
18
+ end
19
+ end
20
+
21
+ def when_the_chef_12_server(*args, **options, &block)
22
+ if Gem::Version.new(ChefZero::VERSION) >= Gem::Version.new('3.1')
23
+ when_the_chef_server(*args, :osc_compat => false, :single_org => false, **options, &block)
24
+ end
25
+ end
26
+
27
+ def with_converge(&recipe)
28
+ before :each do
29
+ r = recipe(&recipe)
30
+ r.converge
31
+ end
32
+ end
33
+
34
+ module ChefRunSupportInstanceMethods
35
+ def rest
36
+ ::Chef::ServerAPI.new
37
+ end
38
+
39
+ def get(path, *args)
40
+ if path[0] == '/'
41
+ path = URI.join(rest.url, path)
42
+ end
43
+ rest.get(path, *args)
44
+ end
45
+
46
+ def chef_config
47
+ {}
48
+ end
49
+
50
+ def expect_recipe(str=nil, file=nil, line=nil, &recipe)
51
+ r = recipe(str, file, line, &recipe)
52
+ r.converge
53
+ expect(r)
54
+ end
55
+
56
+ def expect_converge(str=nil, file=nil, line=nil, &recipe)
57
+ expect { converge(str, file, line, &recipe) }
58
+ end
59
+
60
+ def recipe(str=nil, file=nil, line=nil, &recipe)
61
+ if !recipe
62
+ if file && line
63
+ recipe = proc { eval(str, nil, file, line) }
64
+ else
65
+ recipe = proc { eval(str) }
66
+ end
67
+ end
68
+ RecipeRunWrapper.new(chef_config, &recipe)
69
+ end
70
+
71
+ def converge(str=nil, file=nil, line=nil, &recipe)
72
+ r = recipe(str, file, line, &recipe)
73
+ r.converge
74
+ r
75
+ end
76
+
77
+ def chef_client
78
+ @chef_client ||= ChefRun.new(chef_config)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,4 +1,4 @@
1
- require 'cheffish/rspec/matchers/have_updated'
2
- require 'cheffish/rspec/matchers/be_idempotent'
3
- require 'cheffish/rspec/matchers/partially_match'
4
- require 'cheffish/rspec/matchers/emit_no_warnings_or_errors'
1
+ require 'cheffish/rspec/matchers/have_updated'
2
+ require 'cheffish/rspec/matchers/be_idempotent'
3
+ require 'cheffish/rspec/matchers/partially_match'
4
+ require 'cheffish/rspec/matchers/emit_no_warnings_or_errors'
@@ -1,16 +1,16 @@
1
- require 'rspec/matchers'
2
-
3
- RSpec::Matchers.define :be_idempotent do
4
- match do |recipe|
5
- @recipe = recipe
6
- recipe.reset
7
- recipe.converge
8
- recipe.up_to_date?
9
- end
10
-
11
- failure_message {
12
- "#{@recipe} is not idempotent! Converging it a second time caused updates.\n#{@recipe.output_for_failure_message}"
13
- }
14
-
15
- supports_block_expectations
16
- end
1
+ require 'rspec/matchers'
2
+
3
+ RSpec::Matchers.define :be_idempotent do
4
+ match do |recipe|
5
+ @recipe = recipe
6
+ recipe.reset
7
+ recipe.converge
8
+ recipe.up_to_date?
9
+ end
10
+
11
+ failure_message {
12
+ "#{@recipe} is not idempotent! Converging it a second time caused updates.\n#{@recipe.output_for_failure_message}"
13
+ }
14
+
15
+ supports_block_expectations
16
+ end
@@ -1,15 +1,15 @@
1
- require 'rspec/matchers'
2
-
3
- RSpec::Matchers.define :emit_no_warnings_or_errors do
4
- match do |recipe|
5
- @recipe = recipe
6
- @warn_err = recipe.logs.lines.select { |l| l =~ /warn|err/i }.join("\n")
7
- @warn_err.empty?
8
- end
9
-
10
- failure_message {
11
- "#{@recipe} emitted warnings and errors!\n#{@warn_err}"
12
- }
13
-
14
- supports_block_expectations
15
- end
1
+ require 'rspec/matchers'
2
+
3
+ RSpec::Matchers.define :emit_no_warnings_or_errors do
4
+ match do |recipe|
5
+ @recipe = recipe
6
+ @warn_err = recipe.logs.lines.select { |l| l =~ /warn|err/i }.join("\n")
7
+ @warn_err.empty?
8
+ end
9
+
10
+ failure_message {
11
+ "#{@recipe} emitted warnings and errors!\n#{@warn_err}"
12
+ }
13
+
14
+ supports_block_expectations
15
+ end
@@ -1,37 +1,37 @@
1
- require 'rspec/matchers'
2
-
3
- RSpec::Matchers.define :have_updated do |resource_name, *expected_actions|
4
- match do |recipe|
5
- @recipe = recipe
6
- actual = @recipe.event_sink.events
7
- actual_actions = actual.select { |event, resource, action| event == :resource_updated && resource.to_s == resource_name }.
8
- map { |event, resource, action| action }
9
- expect(actual_actions).to eq(expected_actions)
10
- end
11
-
12
- failure_message do
13
- actual = @recipe.event_sink.events
14
- updates = actual.select { |event, resource, action| event == :resource_updated }.to_a
15
- result = "expected that the chef_run would #{expected_actions.join(',')} #{resource_name}."
16
- if updates.size > 0
17
- result << " Actual updates were #{updates.map { |event, resource, action| "#{resource.to_s} => #{action.inspect}" }.join(', ')}"
18
- else
19
- result << " Nothing was updated."
20
- end
21
- result
22
- end
23
-
24
- failure_message_when_negated do
25
- actual = @recipe.event_sink.events
26
- updates = actual.select { |event, resource, action| event == :resource_updated }.to_a
27
- result = "expected that the chef_run would not #{expected_actions.join(',')} #{resource_name}."
28
- if updates.size > 0
29
- result << " Actual updates were #{updates.map { |event, resource, action| "#{resource.to_s} => #{action.inspect}" }.join(', ')}"
30
- else
31
- result << " Nothing was updated."
32
- end
33
- result
34
- end
35
- end
36
-
37
- RSpec::Matchers.define_negated_matcher :not_have_updated, :have_updated
1
+ require 'rspec/matchers'
2
+
3
+ RSpec::Matchers.define :have_updated do |resource_name, *expected_actions|
4
+ match do |recipe|
5
+ @recipe = recipe
6
+ actual = @recipe.event_sink.events
7
+ actual_actions = actual.select { |event, resource, action| event == :resource_updated && resource.to_s == resource_name }.
8
+ map { |event, resource, action| action }
9
+ expect(actual_actions).to eq(expected_actions)
10
+ end
11
+
12
+ failure_message do
13
+ actual = @recipe.event_sink.events
14
+ updates = actual.select { |event, resource, action| event == :resource_updated }.to_a
15
+ result = "expected that the chef_run would #{expected_actions.join(',')} #{resource_name}."
16
+ if updates.size > 0
17
+ result << " Actual updates were #{updates.map { |event, resource, action| "#{resource.to_s} => #{action.inspect}" }.join(', ')}"
18
+ else
19
+ result << " Nothing was updated."
20
+ end
21
+ result
22
+ end
23
+
24
+ failure_message_when_negated do
25
+ actual = @recipe.event_sink.events
26
+ updates = actual.select { |event, resource, action| event == :resource_updated }.to_a
27
+ result = "expected that the chef_run would not #{expected_actions.join(',')} #{resource_name}."
28
+ if updates.size > 0
29
+ result << " Actual updates were #{updates.map { |event, resource, action| "#{resource.to_s} => #{action.inspect}" }.join(', ')}"
30
+ else
31
+ result << " Nothing was updated."
32
+ end
33
+ result
34
+ end
35
+ end
36
+
37
+ RSpec::Matchers.define_negated_matcher :not_have_updated, :have_updated
@@ -1,63 +1,63 @@
1
- module Cheffish
2
- module RSpec
3
- module Matchers
4
- class PartiallyMatch
5
- include ::RSpec::Matchers::Composable
6
-
7
- def initialize(example, expected)
8
- @example = example
9
- @expected = expected
10
- end
11
-
12
- def matches?(actual)
13
- @actual = actual
14
- partially_matches_values(@expected, actual)
15
- end
16
-
17
- def failure_message
18
- "expected #{@actual} to match #{@expected}"
19
- end
20
-
21
- def failure_message_when_negated
22
- "expected #{@actual} not to match #{@expected}"
23
- end
24
-
25
- protected
26
-
27
- def partially_matches_values(expected, actual)
28
- if Hash === actual
29
- return partially_matches_hashes(expected, actual) if Hash === expected || Array === expected
30
- elsif Array === expected && Enumerable === actual && !(Struct === actual)
31
- return partially_matches_arrays(expected, actual)
32
- end
33
-
34
- return true if actual == expected
35
-
36
- begin
37
- expected === actual
38
- rescue ArgumentError
39
- # Some objects, like 0-arg lambdas on 1.9+, raise
40
- # ArgumentError for `expected === actual`.
41
- false
42
- end
43
- end
44
-
45
- def partially_matches_hashes(expected, actual)
46
- expected.all? { |key, value| partially_matches_values(value, actual[key]) }
47
- end
48
-
49
- def partially_matches_arrays(expected, actual)
50
- expected.all? { |e| actual.any? { |a| partially_matches_values(e, a) } }
51
- end
52
- end
53
- end
54
- end
55
- end
56
-
57
- module RSpec
58
- module Matchers
59
- def partially_match(expected)
60
- Cheffish::RSpec::Matchers::PartiallyMatch.new(self, expected)
61
- end
62
- end
63
- end
1
+ module Cheffish
2
+ module RSpec
3
+ module Matchers
4
+ class PartiallyMatch
5
+ include ::RSpec::Matchers::Composable
6
+
7
+ def initialize(example, expected)
8
+ @example = example
9
+ @expected = expected
10
+ end
11
+
12
+ def matches?(actual)
13
+ @actual = actual
14
+ partially_matches_values(@expected, actual)
15
+ end
16
+
17
+ def failure_message
18
+ "expected #{@actual} to match #{@expected}"
19
+ end
20
+
21
+ def failure_message_when_negated
22
+ "expected #{@actual} not to match #{@expected}"
23
+ end
24
+
25
+ protected
26
+
27
+ def partially_matches_values(expected, actual)
28
+ if Hash === actual
29
+ return partially_matches_hashes(expected, actual) if Hash === expected || Array === expected
30
+ elsif Array === expected && Enumerable === actual && !(Struct === actual)
31
+ return partially_matches_arrays(expected, actual)
32
+ end
33
+
34
+ return true if actual == expected
35
+
36
+ begin
37
+ expected === actual
38
+ rescue ArgumentError
39
+ # Some objects, like 0-arg lambdas on 1.9+, raise
40
+ # ArgumentError for `expected === actual`.
41
+ false
42
+ end
43
+ end
44
+
45
+ def partially_matches_hashes(expected, actual)
46
+ expected.all? { |key, value| partially_matches_values(value, actual[key]) }
47
+ end
48
+
49
+ def partially_matches_arrays(expected, actual)
50
+ expected.all? { |e| actual.any? { |a| partially_matches_values(e, a) } }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ module RSpec
58
+ module Matchers
59
+ def partially_match(expected)
60
+ Cheffish::RSpec::Matchers::PartiallyMatch.new(self, expected)
61
+ end
62
+ end
63
+ end