chef 12.0.0.alpha.0-x86-mingw32 → 12.0.0.alpha.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -2,7 +2,7 @@ require 'support/shared/integration/integration_helper'
2
2
  require 'chef/mixin/shell_out'
3
3
 
4
4
  describe "LWRPs with inline resources" do
5
- extend IntegrationSupport
5
+ include IntegrationSupport
6
6
  include Chef::Mixin::ShellOut
7
7
 
8
8
  let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..", "bin") }
@@ -19,22 +19,23 @@ describe "LWRPs with inline resources" do
19
19
  let(:chef_client) { "ruby #{chef_dir}/chef-client" }
20
20
 
21
21
  when_the_repository "has a cookbook with a nested LWRP" do
22
- directory 'cookbooks/x' do
22
+ before do
23
+ directory 'cookbooks/x' do
23
24
 
24
- file 'resources/do_nothing.rb', <<EOM
25
+ file 'resources/do_nothing.rb', <<EOM
25
26
  actions :create, :nothing
26
27
  default_action :create
27
28
  EOM
28
- file 'providers/do_nothing.rb', <<EOM
29
+ file 'providers/do_nothing.rb', <<EOM
29
30
  action :create do
30
31
  end
31
32
  EOM
32
33
 
33
- file 'resources/my_machine.rb', <<EOM
34
+ file 'resources/my_machine.rb', <<EOM
34
35
  actions :create, :nothing
35
36
  default_action :create
36
37
  EOM
37
- file 'providers/my_machine.rb', <<EOM
38
+ file 'providers/my_machine.rb', <<EOM
38
39
  use_inline_resources
39
40
  action :create do
40
41
  x_do_nothing 'a'
@@ -42,12 +43,13 @@ action :create do
42
43
  end
43
44
  EOM
44
45
 
45
- file 'recipes/default.rb', <<EOM
46
+ file 'recipes/default.rb', <<EOM
46
47
  x_my_machine "me"
47
48
  x_my_machine "you"
48
49
  EOM
49
50
 
50
- end # directory 'cookbooks/x'
51
+ end # directory 'cookbooks/x'
52
+ end
51
53
 
52
54
  it "should complete with success" do
53
55
  file 'config/client.rb', <<EOM
@@ -6,14 +6,20 @@ require 'timeout'
6
6
  require 'fileutils'
7
7
 
8
8
  describe "chef-solo" do
9
- extend IntegrationSupport
9
+ include IntegrationSupport
10
10
  include Chef::Mixin::ShellOut
11
11
 
12
12
  let(:chef_dir) { File.join(File.dirname(__FILE__), "..", "..", "..") }
13
13
 
14
+ let(:cookbook_x_100_metadata_rb) { cb_metadata("x", "1.0.0") }
15
+
16
+ let(:cookbook_ancient_100_metadata_rb) { cb_metadata("ancient", "1.0.0") }
17
+
14
18
  when_the_repository "has a cookbook with a basic recipe" do
15
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
16
- file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
19
+ before do
20
+ file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb
21
+ file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
22
+ end
17
23
 
18
24
  it "should complete with success" do
19
25
  file 'config/solo.rb', <<EOM
@@ -43,11 +49,13 @@ E
43
49
  end
44
50
 
45
51
  when_the_repository "has a cookbook with an undeclared dependency" do
46
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
47
- file 'cookbooks/x/recipes/default.rb', 'include_recipe "ancient::aliens"'
52
+ before do
53
+ file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb
54
+ file 'cookbooks/x/recipes/default.rb', 'include_recipe "ancient::aliens"'
48
55
 
49
- file 'cookbooks/ancient/metadata.rb', 'version "1.0.0"'
50
- file 'cookbooks/ancient/recipes/aliens.rb', 'print "it was aliens"'
56
+ file 'cookbooks/ancient/metadata.rb', cookbook_ancient_100_metadata_rb
57
+ file 'cookbooks/ancient/recipes/aliens.rb', 'print "it was aliens"'
58
+ end
51
59
 
52
60
  it "should exit with an error" do
53
61
  file 'config/solo.rb', <<EOM
@@ -62,16 +70,19 @@ EOM
62
70
 
63
71
 
64
72
  when_the_repository "has a cookbook with a recipe with sleep" do
65
- directory 'logs'
66
- file 'logs/runs.log', ''
67
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
68
- file 'cookbooks/x/recipes/default.rb', <<EOM
73
+ before do
74
+ directory 'logs'
75
+ file 'logs/runs.log', ''
76
+ file 'cookbooks/x/metadata.rb', cookbook_x_100_metadata_rb
77
+ file 'cookbooks/x/recipes/default.rb', <<EOM
69
78
  ruby_block "sleeping" do
70
79
  block do
71
80
  sleep 5
72
81
  end
73
82
  end
74
83
  EOM
84
+ end
85
+
75
86
  # Ruby 1.8.7 doesn't have Process.spawn :(
76
87
  it "while running solo concurrently", :ruby_gte_19_only => true do
77
88
  file 'config/solo.rb', <<EOM
@@ -124,6 +124,9 @@ RSpec.configure do |config|
124
124
  config.filter_run_excluding :requires_root_or_running_windows => true unless (root? || windows?)
125
125
  config.filter_run_excluding :requires_unprivileged_user => true if root?
126
126
  config.filter_run_excluding :uses_diff => true unless has_diff?
127
+ config.filter_run_excluding :ruby_gte_20_and_openssl_gte_101 => true unless (ruby_gte_20? && openssl_gte_101?)
128
+ config.filter_run_excluding :openssl_lt_101 => true unless openssl_lt_101?
129
+ config.filter_run_excluding :ruby_lt_20 => true unless ruby_lt_20?
127
130
 
128
131
  running_platform_arch = `uname -m`.strip
129
132
 
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/knife'
19
+ require 'chef/json_compat'
20
+
21
+ class Chef
22
+ class Resource
23
+ class ZenFollower < Chef::Resource
24
+ attr_accessor :created_as_type
25
+
26
+ provides :follower, :on_platforms => ["zen"]
27
+
28
+ def initialize(name, run_context=nil)
29
+ @resource_name = :zen_follower
30
+ @created_as_type = "zen_follower"
31
+ super
32
+ end
33
+
34
+ def to_s
35
+ "#{created_as_type}[#{name}]"
36
+ end
37
+
38
+ def master(arg=nil)
39
+ if !arg.nil?
40
+ @master = arg
41
+ end
42
+ @master
43
+ end
44
+ end
45
+ end
46
+ end
@@ -7,6 +7,10 @@ def ruby_gte_20?
7
7
  RUBY_VERSION.to_f >= 2.0
8
8
  end
9
9
 
10
+ def ruby_lt_20?
11
+ !ruby_gte_20?
12
+ end
13
+
10
14
  def ruby_gte_19?
11
15
  RUBY_VERSION.to_f >= 1.9
12
16
  end
@@ -129,3 +133,11 @@ def root?
129
133
  return false if windows?
130
134
  Process.euid == 0
131
135
  end
136
+
137
+ def openssl_gte_101?
138
+ OpenSSL::OPENSSL_VERSION_NUMBER >= 10001000
139
+ end
140
+
141
+ def openssl_lt_101?
142
+ !openssl_gte_101?
143
+ end
@@ -96,6 +96,16 @@ shared_examples_for "a file with the wrong content" do
96
96
  selinux_security_context_restored?(path).should be_true
97
97
  end
98
98
  end
99
+
100
+ context "with a checksum that does not match the content to deploy" do
101
+ before do
102
+ resource.checksum("aAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaAaA")
103
+ end
104
+
105
+ it "raises an exception" do
106
+ expect{ resource.run_action(:create) }.to raise_error(Chef::Exceptions::ChecksumMismatch)
107
+ end
108
+ end
99
109
  end
100
110
 
101
111
  describe "when running action :create_if_missing" do
@@ -0,0 +1,130 @@
1
+ require 'tempfile'
2
+ require 'chef_zero/server'
3
+ require 'chef_zero/rest_request'
4
+
5
+ # This is a copy of chef_zero/rspec, modified to implement contextual
6
+ # helpers as instance_methods rather than class methods. This makes it
7
+ # possible to use them with let bindings and other RSpec code reuse
8
+ # mechanisms.
9
+ #
10
+ # Unfortunately, at the time of this writing, chef-zero master doesn't
11
+ # work for our rspec tests, so in the interests of making forward
12
+ # progress, we're using a modified version of the chef_zero/rspec code
13
+ # here.
14
+ #
15
+ # This file should be entirely replaced by chef_zero/rspec once these
16
+ # issues are fixed.
17
+ module ChefZeroSupport
18
+ module Server
19
+
20
+ def self.server
21
+ @server
22
+ end
23
+ def self.server=(value)
24
+ @server = value
25
+ end
26
+ def self.client_key
27
+ @client_key
28
+ end
29
+ def self.client_key=(value)
30
+ @client_key = value
31
+ end
32
+ def self.request_log
33
+ @request_log ||= []
34
+ end
35
+ def self.clear_request_log
36
+ @request_log = []
37
+ end
38
+
39
+ end
40
+
41
+ def client(name, client)
42
+ ChefZeroSupport::Server.server.load_data({ 'clients' => { name => client }})
43
+ end
44
+
45
+ def cookbook(name, version, cookbook = {}, options = {})
46
+
47
+ auto_metadata = "name '#{name}'; version '#{version}'"
48
+
49
+ cookbook["metadata.rb"] ||= auto_metadata
50
+
51
+ ChefZeroSupport::Server.server.load_data({ 'cookbooks' => { "#{name}-#{version}" => cookbook.merge(options) }})
52
+ end
53
+
54
+ def data_bag(name, data_bag)
55
+ ChefZeroSupport::Server.server.load_data({ 'data' => { name => data_bag }})
56
+ end
57
+
58
+ def environment(name, environment)
59
+ ChefZeroSupport::Server.server.load_data({ 'environments' => { name => environment }})
60
+ end
61
+
62
+ def node(name, node)
63
+ ChefZeroSupport::Server.server.load_data({ 'nodes' => { name => node }})
64
+ end
65
+
66
+ def role(name, role)
67
+ ChefZeroSupport::Server.server.load_data({ 'roles' => { name => role }})
68
+ end
69
+
70
+ def user(name, user)
71
+ ChefZeroSupport::Server.server.load_data({ 'users' => { name => user }})
72
+ end
73
+
74
+ RSpec.shared_context "With chef-zero running" do
75
+ before :each do
76
+
77
+ default_opts = {:port => 8900, :signals => false, :log_requests => true}
78
+ server_opts = if self.respond_to?(:chef_zero_opts)
79
+ default_opts.merge(chef_zero_opts)
80
+ else
81
+ default_opts
82
+ end
83
+
84
+ if ChefZeroSupport::Server.server && server_opts.any? { |opt, value| ChefZeroSupport::Server.server.options[opt] != value }
85
+ ChefZeroSupport::Server.server.stop
86
+ ChefZeroSupport::Server.server = nil
87
+ end
88
+
89
+ unless ChefZeroSupport::Server.server
90
+ # TODO: can this be logged easily?
91
+ # pp :zero_opts => server_opts
92
+
93
+ # Set up configuration so that clients will point to the server
94
+ ChefZeroSupport::Server.server = ChefZero::Server.new(server_opts)
95
+ ChefZeroSupport::Server.client_key = Tempfile.new(['chef_zero_client_key', '.pem'])
96
+ ChefZeroSupport::Server.client_key.write(ChefZero::PRIVATE_KEY)
97
+ ChefZeroSupport::Server.client_key.close
98
+ # Start the server
99
+ ChefZeroSupport::Server.server.start_background
100
+ ChefZeroSupport::Server.server.on_response do |request, response|
101
+ ChefZeroSupport::Server.request_log << [ request, response ]
102
+ end
103
+ else
104
+ ChefZeroSupport::Server.server.clear_data
105
+ end
106
+ ChefZeroSupport::Server.clear_request_log
107
+
108
+ if defined?(Chef::Config)
109
+ @old_chef_server_url = Chef::Config.chef_server_url
110
+ @old_node_name = Chef::Config.node_name
111
+ @old_client_key = Chef::Config.client_key
112
+ Chef::Config.chef_server_url = ChefZeroSupport::Server.server.url
113
+ Chef::Config.node_name = 'admin'
114
+ Chef::Config.client_key = ChefZeroSupport::Server.client_key.path
115
+ Chef::Config.http_retry_count = 0
116
+ end
117
+ end
118
+
119
+ if defined?(Chef::Config)
120
+ after :each do
121
+ Chef::Config.chef_server_url = @old_chef_server_url
122
+ Chef::Config.node_name = @old_node_name
123
+ Chef::Config.client_key = @old_client_key
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+
@@ -20,131 +20,133 @@
20
20
  require 'tmpdir'
21
21
  require 'fileutils'
22
22
  require 'chef/config'
23
- require 'chef_zero/rspec'
24
- require 'json'
23
+
24
+ # Temporarily use our own copy of chef-zero rspec integration.
25
+ # See support/shared/integration/chef_zero_support for details
26
+ #require 'chef_zero/rspec'
27
+ require 'support/shared/integration/chef_zero_support'
28
+
29
+ require 'chef/json_compat'
25
30
  require 'support/shared/integration/knife_support'
26
31
  require 'support/shared/integration/app_server_support'
27
32
  require 'spec_helper'
28
33
 
29
34
  module IntegrationSupport
30
- include ChefZero::RSpec
31
-
32
- def when_the_repository(description, *args, &block)
33
- context "When the local repository #{description}", *args do
34
- before :each do
35
- raise "Can only create one directory per test" if @repository_dir
36
- @repository_dir = Dir.mktmpdir('chef_repo')
37
- Chef::Config.chef_repo_path = @repository_dir
38
- %w(client cookbook data_bag environment node role user).each do |object_name|
39
- Chef::Config.delete("#{object_name}_path".to_sym)
40
- end
41
- end
35
+ include ChefZeroSupport
42
36
 
43
- after :each do
44
- if @repository_dir
45
- begin
46
- %w(client cookbook data_bag environment node role user).each do |object_name|
47
- Chef::Config.delete("#{object_name}_path".to_sym)
48
- end
49
- Chef::Config.delete(:chef_repo_path)
50
- FileUtils.remove_entry_secure(@repository_dir)
51
- ensure
52
- @repository_dir = nil
53
- end
54
- end
55
- end
37
+ module ClassMethods
56
38
 
57
- def directory(relative_path, &block)
58
- old_parent_path = @parent_path
59
- @parent_path = path_to(relative_path)
60
- FileUtils.mkdir_p(@parent_path)
61
- instance_eval(&block) if block
62
- @parent_path = old_parent_path
39
+ def when_the_chef_server(desc, *tags, &block)
40
+ context("when the chef server #{desc}", *tags) do
41
+ #include ChefZero::RSpec::Fixtures
42
+ include_context "With chef-zero running"
43
+ module_eval(&block)
63
44
  end
45
+ end
64
46
 
65
- def file(relative_path, contents)
66
- filename = path_to(relative_path)
67
- dir = File.dirname(filename)
68
- FileUtils.mkdir_p(dir) unless dir == '.'
69
- File.open(filename, 'w') do |file|
70
- raw = case contents
71
- when Hash
72
- JSON.pretty_generate(contents)
73
- when Array
74
- contents.join("\n")
75
- else
76
- contents
77
- end
78
- file.write(raw)
79
- end
47
+ def when_the_repository(desc, *tags, &block)
48
+ context("when the chef repo #{desc}", *tags) do
49
+ include_context "with a chef repo"
50
+ module_eval(&block)
80
51
  end
52
+ end
81
53
 
82
- def symlink(relative_path, relative_dest)
83
- filename = path_to(relative_path)
84
- dir = File.dirname(filename)
85
- FileUtils.mkdir_p(dir) unless dir == '.'
86
- dest_filename = path_to(relative_dest)
87
- File.symlink(dest_filename, filename)
54
+ def with_versioned_cookbooks(&block)
55
+ context("with versioned cookbooks") do
56
+ include_context "with versioned cookbooks"
57
+ module_eval(&block)
88
58
  end
59
+ end
60
+ end
89
61
 
90
- def path_to(relative_path)
91
- File.expand_path(relative_path, (@parent_path || @repository_dir))
92
- end
62
+ def self.included(includer_class)
63
+ includer_class.extend(ClassMethods)
64
+ end
93
65
 
94
- def self.path_to(relative_path)
95
- File.expand_path(relative_path, (@parent_path || @repository_dir))
96
- end
66
+ def directory(relative_path, &block)
67
+ old_parent_path = @parent_path
68
+ @parent_path = path_to(relative_path)
69
+ FileUtils.mkdir_p(@parent_path)
70
+ instance_eval(&block) if block
71
+ @parent_path = old_parent_path
72
+ end
97
73
 
98
- def self.directory(relative_path, &block)
99
- before :each do
100
- directory(relative_path, &block)
101
- end
102
- end
74
+ def file(relative_path, contents)
75
+ filename = path_to(relative_path)
76
+ dir = File.dirname(filename)
77
+ FileUtils.mkdir_p(dir) unless dir == '.'
78
+ File.open(filename, 'w') do |file|
79
+ raw = case contents
80
+ when Hash
81
+ JSON.pretty_generate(contents)
82
+ when Array
83
+ contents.join("\n")
84
+ else
85
+ contents
86
+ end
87
+ file.write(raw)
88
+ end
89
+ end
103
90
 
104
- def self.file(relative_path, contents)
105
- before :each do
106
- file(relative_path, contents)
107
- end
108
- end
91
+ def symlink(relative_path, relative_dest)
92
+ filename = path_to(relative_path)
93
+ dir = File.dirname(filename)
94
+ FileUtils.mkdir_p(dir) unless dir == '.'
95
+ dest_filename = path_to(relative_dest)
96
+ File.symlink(dest_filename, filename)
97
+ end
109
98
 
110
- def self.symlink(relative_path, relative_dest)
111
- before :each do
112
- symlink(relative_path, relative_dest)
113
- end
99
+ def path_to(relative_path)
100
+ File.expand_path(relative_path, (@parent_path || @repository_dir))
101
+ end
102
+
103
+ def cb_metadata(name, version, extra_text="")
104
+ "name '#{name}'; version '#{version}'#{extra_text}"
105
+ end
106
+
107
+ def cwd(relative_path)
108
+ @old_cwd = Dir.pwd
109
+ Dir.chdir(path_to(relative_path))
110
+ end
111
+
112
+ RSpec.shared_context "with a chef repo" do
113
+ before :each do
114
+ raise "Can only create one directory per test" if @repository_dir
115
+ @repository_dir = Dir.mktmpdir('chef_repo')
116
+ Chef::Config.chef_repo_path = @repository_dir
117
+ %w(client cookbook data_bag environment node role user).each do |object_name|
118
+ Chef::Config.delete("#{object_name}_path".to_sym)
114
119
  end
120
+ end
115
121
 
116
- def self.cwd(relative_path)
117
- before :each do
118
- @old_cwd = Dir.pwd
119
- Dir.chdir(path_to(relative_path))
120
- end
121
- after :each do
122
- Dir.chdir(@old_cwd)
122
+ after :each do
123
+ if @repository_dir
124
+ begin
125
+ %w(client cookbook data_bag environment node role user).each do |object_name|
126
+ Chef::Config.delete("#{object_name}_path".to_sym)
127
+ end
128
+ Chef::Config.delete(:chef_repo_path)
129
+ FileUtils.remove_entry_secure(@repository_dir)
130
+ ensure
131
+ @repository_dir = nil
123
132
  end
124
133
  end
125
-
126
- instance_eval(&block)
134
+ Dir.chdir(@old_cwd) if @old_cwd
127
135
  end
136
+
128
137
  end
129
138
 
130
139
  # Versioned cookbooks
131
140
 
132
- def with_versioned_cookbooks(_metadata = {}, &block)
133
- _m = { :versioned_cookbooks => true }.merge(_metadata)
134
- context 'with versioned cookbooks', _m do
135
- before(:each) { Chef::Config[:versioned_cookbooks] = true }
136
- after(:each) { Chef::Config.delete(:versioned_cookbooks) }
137
- instance_eval(&block)
138
- end
141
+ RSpec.shared_context 'with versioned cookbooks', :versioned_cookbooks => true do
142
+ before(:each) { Chef::Config[:versioned_cookbooks] = true }
143
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
139
144
  end
140
145
 
141
- def without_versioned_cookbooks(_metadata = {}, &block)
142
- _m = { :versioned_cookbooks => false }.merge(_metadata)
143
- context 'with versioned cookbooks', _m do
144
- # Just make sure this goes back to default
145
- before(:each) { Chef::Config[:versioned_cookbooks] = false }
146
- after(:each) { Chef::Config.delete(:versioned_cookbooks) }
147
- instance_eval(&block)
148
- end
146
+ RSpec.shared_context "without versioned cookbooks", :versioned_cookbooks => false do
147
+ # Just make sure this goes back to default
148
+ before(:each) { Chef::Config[:versioned_cookbooks] = false }
149
+ after(:each) { Chef::Config.delete(:versioned_cookbooks) }
149
150
  end
151
+
150
152
  end