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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -17,6 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/util/windows'
20
+ require 'chef/exceptions'
20
21
 
21
22
  #wrapper around a subset of the NetUser* APIs.
22
23
  #nothing Chef specific, but not complete enough to be its own gem, so util for now.
@@ -137,7 +138,9 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows
137
138
  ptr = 0.chr * PTR_SIZE
138
139
  rc = NetUserGetInfo.call(nil, @name, 3, ptr)
139
140
 
140
- if rc != NERR_Success
141
+ if rc == NERR_UserNotFound
142
+ raise Chef::Exceptions::UserIDNotFound, get_last_error(rc)
143
+ elsif rc != NERR_Success
141
144
  raise ArgumentError, get_last_error(rc)
142
145
  end
143
146
 
data/lib/chef/version.rb CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  class Chef
19
19
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
20
- VERSION = '12.0.0.alpha.1'
20
+ VERSION = '12.0.0.alpha.2'
21
21
  end
22
22
 
23
23
  #
@@ -459,11 +459,7 @@ BOOL WINAPI DeviceIoControl(
459
459
  # to be passed to the *W vesion of WinAPI File
460
460
  # functions
461
461
  def encode_path(path)
462
- (path_prepender << path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR)).to_wstring
463
- end
464
-
465
- def path_prepender
466
- "\\\\?\\"
462
+ Chef::Util::PathHelper.canonical_path(path).to_wstring
467
463
  end
468
464
 
469
465
  # retrieves a file search handle and passes it
@@ -33,6 +33,7 @@ class Chef
33
33
  MAX_PREFERRED_LENGTH = 0xFFFF
34
34
 
35
35
  NERR_Success = 0
36
+ NERR_UserNotFound = 2221
36
37
 
37
38
  ffi_lib "netapi32"
38
39
 
@@ -0,0 +1,177 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, 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/config_fetcher'
20
+ require 'chef/config'
21
+ require 'chef/null_logger'
22
+
23
+ class Chef
24
+
25
+ class WorkstationConfigLoader
26
+
27
+ # Path to a config file requested by user, (e.g., via command line option). Can be nil
28
+ attr_reader :explicit_config_file
29
+
30
+ # TODO: initialize this with a logger for Chef and Knife
31
+ def initialize(explicit_config_file, logger=nil)
32
+ @explicit_config_file = explicit_config_file
33
+ @config_location = nil
34
+ @logger = logger || NullLogger.new
35
+ end
36
+
37
+ def no_config_found?
38
+ config_location.nil?
39
+ end
40
+
41
+ def config_location
42
+ @config_location ||= (explicit_config_file || locate_local_config)
43
+ end
44
+
45
+ def chef_config_dir
46
+ if @chef_config_dir.nil?
47
+ @chef_config_dir = false
48
+ full_path = working_directory.split(File::SEPARATOR)
49
+ (full_path.length - 1).downto(0) do |i|
50
+ candidate_directory = File.join(full_path[0..i] + [".chef" ])
51
+ if File.exist?(candidate_directory) && File.directory?(candidate_directory)
52
+ @chef_config_dir = candidate_directory
53
+ break
54
+ end
55
+ end
56
+ end
57
+ @chef_config_dir
58
+ end
59
+
60
+ def load
61
+ # Ignore it if there's no explicit_config_file and can't find one at a
62
+ # default path.
63
+ return false if config_location.nil?
64
+
65
+ if explicit_config_file && !path_exists?(config_location)
66
+ raise Exceptions::ConfigurationError, "Specified config file #{config_location} does not exist"
67
+ end
68
+
69
+ # Have to set Chef::Config.config_file b/c other config is derived from it.
70
+ Chef::Config.config_file = config_location
71
+ read_config(IO.read(config_location), config_location)
72
+ end
73
+
74
+ # (Private API, public for test purposes)
75
+ def env
76
+ ENV
77
+ end
78
+
79
+ # (Private API, public for test purposes)
80
+ def path_exists?(path)
81
+ Pathname.new(path).expand_path.exist?
82
+ end
83
+
84
+ private
85
+
86
+ def have_config?(path)
87
+ if path_exists?(path)
88
+ logger.info("Using config at #{path}")
89
+ true
90
+ else
91
+ logger.debug("Config not found at #{path}, trying next option")
92
+ false
93
+ end
94
+ end
95
+
96
+ def locate_local_config
97
+ candidate_configs = []
98
+
99
+ # Look for $KNIFE_HOME/knife.rb (allow multiple knives config on same machine)
100
+ if env['KNIFE_HOME']
101
+ candidate_configs << File.join(env['KNIFE_HOME'], 'config.rb')
102
+ candidate_configs << File.join(env['KNIFE_HOME'], 'knife.rb')
103
+ end
104
+ # Look for $PWD/knife.rb
105
+ if Dir.pwd
106
+ candidate_configs << File.join(Dir.pwd, 'config.rb')
107
+ candidate_configs << File.join(Dir.pwd, 'knife.rb')
108
+ end
109
+ # Look for $UPWARD/.chef/knife.rb
110
+ if chef_config_dir
111
+ candidate_configs << File.join(chef_config_dir, 'config.rb')
112
+ candidate_configs << File.join(chef_config_dir, 'knife.rb')
113
+ end
114
+ # Look for $HOME/.chef/knife.rb
115
+ if env['HOME']
116
+ candidate_configs << File.join(env['HOME'], '.chef', 'config.rb')
117
+ candidate_configs << File.join(env['HOME'], '.chef', 'knife.rb')
118
+ end
119
+
120
+ candidate_configs.find do | candidate_config |
121
+ have_config?(candidate_config)
122
+ end
123
+ end
124
+
125
+ def working_directory
126
+ a = if Chef::Platform.windows?
127
+ env['CD']
128
+ else
129
+ env['PWD']
130
+ end || Dir.pwd
131
+
132
+ a
133
+ end
134
+
135
+ def read_config(config_content, config_file_path)
136
+ Chef::Config.from_string(config_content, config_file_path)
137
+ rescue SignalException
138
+ raise
139
+ rescue SyntaxError => e
140
+ message = ""
141
+ message << "You have invalid ruby syntax in your config file #{config_file_path}\n\n"
142
+ message << "#{e.class.name}: #{e.message}\n"
143
+ if file_line = e.message[/#{Regexp.escape(config_file_path)}:[\d]+/]
144
+ line = file_line[/:([\d]+)$/, 1].to_i
145
+ message << highlight_config_error(config_file_path, line)
146
+ end
147
+ raise Exceptions::ConfigurationError, message
148
+ rescue Exception => e
149
+ message = "You have an error in your config file #{config_file_path}\n\n"
150
+ message << "#{e.class.name}: #{e.message}\n"
151
+ filtered_trace = e.backtrace.grep(/#{Regexp.escape(config_file_path)}/)
152
+ filtered_trace.each {|bt_line| message << " " << bt_line << "\n" }
153
+ if !filtered_trace.empty?
154
+ line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:([\d]+)/, 1]
155
+ message << highlight_config_error(config_file_path, line_nr.to_i)
156
+ end
157
+ raise Exceptions::ConfigurationError, message
158
+ end
159
+
160
+
161
+ def highlight_config_error(file, line)
162
+ config_file_lines = []
163
+ IO.readlines(file).each_with_index {|l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}"}
164
+ if line == 1
165
+ lines = config_file_lines[0..3]
166
+ else
167
+ lines = config_file_lines[Range.new(line - 2, line)]
168
+ end
169
+ "Relevant file content:\n" + lines.join("\n") + "\n"
170
+ end
171
+
172
+ def logger
173
+ @logger
174
+ end
175
+
176
+ end
177
+ end
@@ -80,5 +80,61 @@ describe Chef::HTTP::Simple do
80
80
  end
81
81
 
82
82
  it_behaves_like "downloading all the things"
83
- end
84
83
 
84
+ context "when Chef::Log.level = :debug" do
85
+ before do
86
+ Chef::Log.level = :debug
87
+ @debug_log = ''
88
+ Chef::Log.stub(:debug) { |str| @debug_log << str }
89
+ end
90
+
91
+ let(:source) { 'http://localhost:9000' }
92
+
93
+ it "Logs the request and response for 200's but not the body" do
94
+ http_client.get('http://localhost:9000/nyan_cat.png')
95
+ expect(@debug_log).to match(/200/)
96
+ expect(@debug_log).to match(/HTTP Request Header Data/)
97
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
98
+ expect(@debug_log).not_to match(/HTTP Request Body/)
99
+ expect(@debug_log).not_to match(/HTTP Response Body/)
100
+ expect(@debug_log).not_to match(/Your request is just terrible./)
101
+ end
102
+
103
+ it "Logs the request and response for 200 POST, but not the body" do
104
+ http_client.post('http://localhost:9000/posty', 'hithere')
105
+ expect(@debug_log).to match(/200/)
106
+ expect(@debug_log).to match(/HTTP Request Header Data/)
107
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
108
+ expect(@debug_log).not_to match(/HTTP Request Body/)
109
+ expect(@debug_log).not_to match(/hithere/)
110
+ expect(@debug_log).not_to match(/HTTP Response Body/)
111
+ expect(@debug_log).not_to match(/Your request is just terrible./)
112
+ end
113
+
114
+ it "Logs the request and response and bodies for 400 response" do
115
+ expect do
116
+ http_client.get('http://localhost:9000/bad_request')
117
+ end.to raise_error(Net::HTTPServerException)
118
+ expect(@debug_log).to match(/400/)
119
+ expect(@debug_log).to match(/HTTP Request Header Data/)
120
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
121
+ expect(@debug_log).not_to match(/HTTP Request Body/)
122
+ expect(@debug_log).not_to match(/hithere/)
123
+ expect(@debug_log).to match(/HTTP Response Body/)
124
+ expect(@debug_log).to match(/Your request is just terrible./)
125
+ end
126
+
127
+ it "Logs the request and response and bodies for 400 POST response" do
128
+ expect do
129
+ http_client.post('http://localhost:9000/bad_request', 'hithere')
130
+ end.to raise_error(Net::HTTPServerException)
131
+ expect(@debug_log).to match(/400/)
132
+ expect(@debug_log).to match(/HTTP Request Header Data/)
133
+ expect(@debug_log).to match(/HTTP Status and Header Data/)
134
+ expect(@debug_log).to match(/HTTP Request Body/)
135
+ expect(@debug_log).to match(/hithere/)
136
+ expect(@debug_log).to match(/HTTP Response Body/)
137
+ expect(@debug_log).to match(/Your request is just terrible./)
138
+ end
139
+ end
140
+ end
@@ -29,7 +29,7 @@ describe Chef::Mixin::ShellOut do
29
29
  shell_out_with_systems_locale('echo $LC_ALL')
30
30
  end
31
31
 
32
- cmd.stdout.chomp.should match_environment_variable('LC_ALL')
32
+ expect(cmd.stdout.chomp).to match_environment_variable('LC_ALL')
33
33
  end
34
34
  end
35
35
 
@@ -41,7 +41,7 @@ describe Chef::Mixin::ShellOut do
41
41
  shell_out_with_systems_locale('echo $LC_ALL', :environment => {'LC_ALL' => 'POSIX'})
42
42
  end
43
43
 
44
- cmd.stdout.chomp.should eq 'POSIX'
44
+ expect(cmd.stdout.chomp).to eq 'POSIX'
45
45
  end
46
46
  end
47
47
  end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Serdar Sutay (<serdar@opscode.com>)
3
+ # Copyright:: Copyright (c) 2014 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 'spec_helper'
20
+
21
+ describe Chef::Resource::WhyrunSafeRubyBlock do
22
+ let(:node) { Chef::Node.new }
23
+
24
+ let(:run_context) {
25
+ events = Chef::EventDispatch::Dispatcher.new
26
+ Chef::RunContext.new(node, {}, events)
27
+ }
28
+
29
+ before do
30
+ $evil_global_evil_laugh = :wahwah
31
+ Chef::Config[:why_run] = true
32
+ end
33
+
34
+ after do
35
+ Chef::Config[:why_run] = false
36
+ end
37
+
38
+ describe "when testing the resource" do
39
+ let(:new_resource) do
40
+ r = Chef::Resource::WhyrunSafeRubyBlock.new("reload all", run_context)
41
+ r.block { $evil_global_evil_laugh = :mwahahaha }
42
+ r
43
+ end
44
+
45
+ it "updates the evil laugh, even in why-run mode" do
46
+ new_resource.run_action(new_resource.action)
47
+ $evil_global_evil_laugh.should == :mwahahaha
48
+ new_resource.should be_updated
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,105 @@
1
+ #
2
+ # Author:: Chris Doherty <cdoherty@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef, 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 'spec_helper'
20
+
21
+ describe Chef::Platform::Rebooter do
22
+
23
+ let(:reboot_info) do
24
+ {
25
+ :delay_mins => 5,
26
+ :requested_by => "reboot resource functional test",
27
+ :reason => "rebooter spec test"
28
+ }
29
+ end
30
+
31
+ def create_resource
32
+ resource = Chef::Resource::Reboot.new(expected[:requested_by], run_context)
33
+ resource.delay_mins(expected[:delay_mins])
34
+ resource.reason(expected[:reason])
35
+ resource
36
+ end
37
+
38
+ let(:run_context) do
39
+ node = Chef::Node.new
40
+ events = Chef::EventDispatch::Dispatcher.new
41
+ Chef::RunContext.new(node, {}, events)
42
+ end
43
+
44
+ let(:expected) do
45
+ {
46
+ :windows => 'shutdown /r /t 5 /c "rebooter spec test"',
47
+ :linux => 'shutdown -r +5 "rebooter spec test"'
48
+ }
49
+ end
50
+
51
+ let(:rebooter) { Chef::Platform::Rebooter }
52
+
53
+ describe '#reboot_if_needed!' do
54
+
55
+ it 'should not call #shell_out! when reboot has not been requested' do
56
+ expect(rebooter).to receive(:shell_out!).exactly(0).times
57
+ expect(rebooter).to receive(:reboot_if_needed!).once.and_call_original
58
+ rebooter.reboot_if_needed!(run_context.node)
59
+ end
60
+
61
+ describe 'calling #shell_out! to reboot' do
62
+
63
+ before(:each) do
64
+ run_context.request_reboot(reboot_info)
65
+ end
66
+
67
+ after(:each) do
68
+ run_context.cancel_reboot
69
+ end
70
+
71
+ shared_context 'test a reboot method' do
72
+ def test_rebooter_method(method_sym, is_windows, expected_reboot_str)
73
+ Chef::Platform.stub(:windows?).and_return(is_windows)
74
+ expect(rebooter).to receive(:shell_out!).once.with(expected_reboot_str)
75
+ expect(rebooter).to receive(method_sym).once.and_call_original
76
+ rebooter.send(method_sym, run_context.node)
77
+ end
78
+ end
79
+
80
+ describe 'when using #reboot_if_needed!' do
81
+ include_context 'test a reboot method'
82
+
83
+ it 'should produce the correct string on Windows' do
84
+ test_rebooter_method(:reboot_if_needed!, true, expected[:windows])
85
+ end
86
+
87
+ it 'should produce the correct (Linux-specific) string on non-Windows' do
88
+ test_rebooter_method(:reboot_if_needed!, false, expected[:linux])
89
+ end
90
+ end
91
+
92
+ describe 'when using #reboot!' do
93
+ include_context 'test a reboot method'
94
+
95
+ it 'should produce the correct string on Windows' do
96
+ test_rebooter_method(:reboot!, true, expected[:windows])
97
+ end
98
+
99
+ it 'should produce the correct (Linux-specific) string on non-Windows' do
100
+ test_rebooter_method(:reboot!, false, expected[:linux])
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end