chef 11.12.0.alpha.1 → 11.12.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/api_client/registration.rb +46 -9
- data/lib/chef/application.rb +1 -0
- data/lib/chef/application/client.rb +25 -24
- data/lib/chef/client.rb +34 -0
- data/lib/chef/config.rb +11 -0
- data/lib/chef/cookbook/chefignore.rb +10 -2
- data/lib/chef/cookbook/metadata.rb +31 -3
- data/lib/chef/cookbook/synchronizer.rb +2 -2
- data/lib/chef/cookbook/syntax_check.rb +4 -4
- data/lib/chef/encrypted_data_bag_item.rb +37 -1
- data/lib/chef/exceptions.rb +1 -0
- data/lib/chef/guard_interpreter/default_guard_interpreter.rb +42 -0
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +122 -0
- data/lib/chef/http.rb +0 -1
- data/lib/chef/http/decompressor.rb +7 -4
- data/lib/chef/http/simple.rb +5 -0
- data/lib/chef/http/validate_content_length.rb +28 -12
- data/lib/chef/knife.rb +1 -0
- data/lib/chef/knife/client_bulk_delete.rb +48 -9
- data/lib/chef/knife/client_delete.rb +4 -4
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_upload.rb +17 -7
- data/lib/chef/knife/core/bootstrap_context.rb +1 -1
- data/lib/chef/knife/core/ui.rb +42 -5
- data/lib/chef/knife/node_run_list_add.rb +31 -2
- data/lib/chef/knife/ssh.rb +44 -31
- data/lib/chef/knife/ssl_check.rb +213 -0
- data/lib/chef/knife/ssl_fetch.rb +145 -0
- data/lib/chef/mixin/deep_merge.rb +13 -5
- data/lib/chef/mixin/shell_out.rb +9 -3
- data/lib/chef/node.rb +23 -4
- data/lib/chef/node/immutable_collections.rb +32 -0
- data/lib/chef/platform/provider_mapping.rb +21 -18
- data/lib/chef/platform/query_helpers.rb +10 -2
- data/lib/chef/policy_builder/expand_node_object.rb +3 -6
- data/lib/chef/provider/cron.rb +25 -3
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package/dpkg.rb +2 -1
- data/lib/chef/provider/package/windows.rb +80 -0
- data/lib/chef/provider/package/windows/msi.rb +69 -0
- data/lib/chef/provider/powershell_script.rb +19 -6
- data/lib/chef/provider/service/solaris.rb +11 -7
- data/lib/chef/resource.rb +18 -5
- data/lib/chef/resource/conditional.rb +20 -7
- data/lib/chef/resource/cron.rb +18 -2
- data/lib/chef/resource/execute.rb +0 -2
- data/lib/chef/resource/powershell_script.rb +23 -1
- data/lib/chef/resource/script.rb +25 -0
- data/lib/chef/resource/subversion.rb +4 -0
- data/lib/chef/resource/windows_package.rb +79 -0
- data/lib/chef/resource/windows_script.rb +0 -5
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest.rb +6 -1
- data/lib/chef/run_context.rb +22 -2
- data/lib/chef/run_context/cookbook_compiler.rb +12 -0
- data/lib/chef/util/editor.rb +92 -0
- data/lib/chef/util/file_edit.rb +22 -54
- data/lib/chef/version.rb +2 -2
- data/lib/chef/win32/api/installer.rb +166 -0
- data/lib/chef/win32/version.rb +8 -0
- data/spec/data/standalone_cookbook/Gemfile +1 -0
- data/spec/data/standalone_cookbook/chefignore +9 -0
- data/spec/data/standalone_cookbook/recipes/default.rb +3 -0
- data/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb +1 -0
- data/spec/functional/resource/powershell_spec.rb +262 -1
- data/spec/functional/win32/versions_spec.rb +3 -3
- data/spec/integration/knife/chefignore_spec.rb +1 -2
- data/spec/integration/knife/raw_spec.rb +8 -13
- data/spec/integration/knife/redirection_spec.rb +6 -14
- data/spec/integration/solo/solo_spec.rb +19 -0
- data/spec/support/shared/functional/windows_script.rb +1 -1
- data/spec/support/shared/integration/app_server_support.rb +42 -0
- data/spec/support/shared/integration/integration_helper.rb +1 -0
- data/spec/support/shared/unit/script_resource.rb +38 -0
- data/spec/unit/api_client/registration_spec.rb +109 -38
- data/spec/unit/application/client_spec.rb +48 -1
- data/spec/unit/cookbook/chefignore_spec.rb +10 -0
- data/spec/unit/cookbook/metadata_spec.rb +45 -1
- data/spec/unit/cookbook/syntax_check_spec.rb +28 -0
- data/spec/unit/cookbook_spec.rb +0 -10
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +56 -0
- data/spec/unit/http/simple_spec.rb +32 -0
- data/spec/unit/http/validate_content_length_spec.rb +187 -0
- data/spec/unit/knife/bootstrap_spec.rb +13 -4
- data/spec/unit/knife/client_bulk_delete_spec.rb +123 -38
- data/spec/unit/knife/client_delete_spec.rb +4 -4
- data/spec/unit/knife/cookbook_upload_spec.rb +181 -88
- data/spec/unit/knife/core/bootstrap_context_spec.rb +11 -1
- data/spec/unit/knife/core/ui_spec.rb +109 -38
- data/spec/unit/knife/node_run_list_add_spec.rb +24 -1
- data/spec/unit/knife/ssh_spec.rb +17 -6
- data/spec/unit/knife/ssl_check_spec.rb +187 -0
- data/spec/unit/knife/ssl_fetch_spec.rb +151 -0
- data/spec/unit/mixin/deep_merge_spec.rb +17 -0
- data/spec/unit/node/immutable_collections_spec.rb +55 -0
- data/spec/unit/node_spec.rb +9 -0
- data/spec/unit/platform/query_helpers_spec.rb +32 -0
- data/spec/unit/platform_spec.rb +193 -175
- data/spec/unit/policy_builder/expand_node_object_spec.rb +1 -1
- data/spec/unit/provider/cron_spec.rb +175 -1
- data/spec/unit/provider/mount/mount_spec.rb +33 -3
- data/spec/unit/provider/package/dpkg_spec.rb +4 -0
- data/spec/unit/provider/package/windows/msi_spec.rb +60 -0
- data/spec/unit/provider/package/windows_spec.rb +80 -0
- data/spec/unit/provider/service/macosx_spec.rb +3 -3
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +35 -10
- data/spec/unit/pure_application_spec.rb +32 -0
- data/spec/unit/recipe_spec.rb +4 -0
- data/spec/unit/resource/conditional_spec.rb +13 -12
- data/spec/unit/resource/cron_spec.rb +7 -2
- data/spec/unit/resource/powershell_spec.rb +85 -2
- data/spec/unit/resource/subversion_spec.rb +5 -0
- data/spec/unit/resource/windows_package_spec.rb +74 -0
- data/spec/unit/resource_spec.rb +23 -1
- data/spec/unit/rest_spec.rb +15 -0
- data/spec/unit/run_context/cookbook_compiler_spec.rb +12 -0
- data/spec/unit/run_context_spec.rb +7 -0
- data/spec/unit/util/editor_spec.rb +152 -0
- data/spec/unit/util/file_edit_spec.rb +37 -1
- metadata +41 -30
data/lib/chef/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
#rc
|
2
2
|
# Author:: Daniel DeLeo (<dan@opscode.com>)
|
3
3
|
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
class Chef
|
19
19
|
CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
20
|
-
VERSION = '11.12.0.
|
20
|
+
VERSION = '11.12.0.rc.1'
|
21
21
|
end
|
22
22
|
|
23
23
|
# NOTE: the Chef::Version class is defined in version_class.rb
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan <btm@loftninjas.org>
|
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/exceptions'
|
20
|
+
require 'chef/win32/api'
|
21
|
+
require 'chef/win32/error'
|
22
|
+
require 'pathname'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
module ReservedNames::Win32
|
26
|
+
module API
|
27
|
+
module Installer
|
28
|
+
extend Chef::ReservedNames::Win32
|
29
|
+
extend Chef::ReservedNames::Win32::API
|
30
|
+
|
31
|
+
###############################################
|
32
|
+
# Win32 API Constants
|
33
|
+
###############################################
|
34
|
+
|
35
|
+
|
36
|
+
###############################################
|
37
|
+
# Win32 API Bindings
|
38
|
+
###############################################
|
39
|
+
|
40
|
+
ffi_lib 'msi'
|
41
|
+
|
42
|
+
=begin
|
43
|
+
UINT MsiOpenPackage(
|
44
|
+
_In_ LPCTSTR szPackagePath,
|
45
|
+
_Out_ MSIHANDLE *hProduct
|
46
|
+
);
|
47
|
+
=end
|
48
|
+
safe_attach_function :msi_open_package, :MsiOpenPackageExA, [ :string, :int, :pointer ], :int
|
49
|
+
|
50
|
+
=begin
|
51
|
+
UINT MsiGetProductProperty(
|
52
|
+
_In_ MSIHANDLE hProduct,
|
53
|
+
_In_ LPCTSTR szProperty,
|
54
|
+
_Out_ LPTSTR lpValueBuf,
|
55
|
+
_Inout_ DWORD *pcchValueBuf
|
56
|
+
);
|
57
|
+
=end
|
58
|
+
safe_attach_function :msi_get_product_property, :MsiGetProductPropertyA, [ :pointer, :pointer, :pointer, :pointer ], :int
|
59
|
+
|
60
|
+
=begin
|
61
|
+
UINT MsiGetProductInfo(
|
62
|
+
_In_ LPCTSTR szProduct,
|
63
|
+
_In_ LPCTSTR szProperty,
|
64
|
+
_Out_ LPTSTR lpValueBuf,
|
65
|
+
_Inout_ DWORD *pcchValueBuf
|
66
|
+
);
|
67
|
+
=end
|
68
|
+
safe_attach_function :msi_get_product_info, :MsiGetProductInfoA, [ :pointer, :pointer, :pointer, :pointer ], :int
|
69
|
+
|
70
|
+
=begin
|
71
|
+
UINT MsiCloseHandle(
|
72
|
+
_In_ MSIHANDLE hAny
|
73
|
+
);
|
74
|
+
=end
|
75
|
+
safe_attach_function :msi_close_handle, :MsiCloseHandle, [ :pointer ], :int
|
76
|
+
|
77
|
+
###############################################
|
78
|
+
# Helpers
|
79
|
+
###############################################
|
80
|
+
|
81
|
+
# Opens a Microsoft Installer (MSI) file from an absolute path and returns the specified property
|
82
|
+
def get_product_property(package_path, property_name)
|
83
|
+
pkg_ptr = open_package(package_path)
|
84
|
+
|
85
|
+
buffer = 0.chr
|
86
|
+
buffer_length = FFI::Buffer.new(:long).write_long(0)
|
87
|
+
|
88
|
+
# Fetch the length of the property
|
89
|
+
status = msi_get_product_property(pkg_ptr.read_pointer, property_name, buffer, buffer_length)
|
90
|
+
|
91
|
+
# We expect error ERROR_MORE_DATA (234) here because we passed a buffer length of 0
|
92
|
+
if status != 234
|
93
|
+
msg = "msi_get_product_property: returned unknown error #{status} when retrieving #{property_name}: "
|
94
|
+
msg << Chef::ReservedNames::Win32::Error.format_message(status)
|
95
|
+
raise Chef::Exceptions::Package, msg
|
96
|
+
end
|
97
|
+
|
98
|
+
buffer_length = FFI::Buffer.new(:long).write_long(buffer_length.read_long + 1)
|
99
|
+
buffer = 0.chr * buffer_length.read_long
|
100
|
+
|
101
|
+
# Fetch the property
|
102
|
+
status = msi_get_product_property(pkg_ptr.read_pointer, property_name, buffer, buffer_length)
|
103
|
+
|
104
|
+
if status != 0
|
105
|
+
msg = "msi_get_product_property: returned unknown error #{status} when retrieving #{property_name}: "
|
106
|
+
msg << Chef::ReservedNames::Win32::Error.format_message(status)
|
107
|
+
raise Chef::Exceptions::Package, msg
|
108
|
+
end
|
109
|
+
|
110
|
+
msi_close_handle(pkg_ptr.read_pointer)
|
111
|
+
return buffer
|
112
|
+
end
|
113
|
+
|
114
|
+
# Opens a Microsoft Installer (MSI) file from an absolute path and returns a pointer to a handle
|
115
|
+
# Remember to close the handle with msi_close_handle()
|
116
|
+
def open_package(package_path)
|
117
|
+
# MsiOpenPackage expects a perfect absolute Windows path to the MSI
|
118
|
+
raise ArgumentError, "Provided path '#{package_path}' must be an absolute path" unless Pathname.new(package_path).absolute?
|
119
|
+
|
120
|
+
pkg_ptr = FFI::MemoryPointer.new(:pointer, 4)
|
121
|
+
status = msi_open_package(package_path, 1, pkg_ptr)
|
122
|
+
case status
|
123
|
+
when 0
|
124
|
+
# success
|
125
|
+
else
|
126
|
+
raise Chef::Exceptions::Package, "msi_open_package: unexpected status #{status}: #{Chef::ReservedNames::Win32::Error.format_message(status)}"
|
127
|
+
end
|
128
|
+
return pkg_ptr
|
129
|
+
end
|
130
|
+
|
131
|
+
# All installed product_codes should have a VersionString
|
132
|
+
# Returns a version if installed, nil if not installed
|
133
|
+
def get_installed_version(product_code)
|
134
|
+
version = 0.chr
|
135
|
+
version_length = FFI::Buffer.new(:long).write_long(0)
|
136
|
+
|
137
|
+
status = msi_get_product_info(product_code, "VersionString", version, version_length)
|
138
|
+
|
139
|
+
return nil if status == 1605 # ERROR_UNKNOWN_PRODUCT (0x645)
|
140
|
+
|
141
|
+
# We expect error ERROR_MORE_DATA (234) here because we passed a buffer length of 0
|
142
|
+
if status != 234
|
143
|
+
msg = "msi_get_product_info: product code '#{product_code}' returned unknown error #{status} when retrieving VersionString: "
|
144
|
+
msg << Chef::ReservedNames::Win32::Error.format_message(status)
|
145
|
+
raise Chef::Exceptions::Package, msg
|
146
|
+
end
|
147
|
+
|
148
|
+
# We could fetch the product version now that we know the variable length, but we don't need it here.
|
149
|
+
|
150
|
+
version_length = FFI::Buffer.new(:long).write_long(version_length.read_long + 1)
|
151
|
+
version = 0.chr * version_length.read_long
|
152
|
+
|
153
|
+
status = msi_get_product_info(product_code, "VersionString", version, version_length)
|
154
|
+
|
155
|
+
if status != 0
|
156
|
+
msg = "msi_get_product_info: product code '#{product_code}' returned unknown error #{status} when retrieving VersionString: "
|
157
|
+
msg << Chef::ReservedNames::Win32::Error.format_message(status)
|
158
|
+
raise Chef::Exceptions::Package, msg
|
159
|
+
end
|
160
|
+
|
161
|
+
version
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/lib/chef/win32/version.rb
CHANGED
@@ -116,9 +116,17 @@ class Chef
|
|
116
116
|
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
|
117
117
|
require 'ruby-wmi'
|
118
118
|
|
119
|
+
# CHEF-4888: Work around ruby #2618, expected to be fixed in Ruby 2.1.0
|
120
|
+
# https://github.com/ruby/ruby/commit/588504b20f5cc880ad51827b93e571e32446e5db
|
121
|
+
# https://github.com/ruby/ruby/commit/27ed294c7134c0de582007af3c915a635a6506cd
|
122
|
+
|
123
|
+
WIN32OLE.ole_initialize
|
124
|
+
|
119
125
|
os_info = WMI::Win32_OperatingSystem.find(:first)
|
120
126
|
os_version = os_info.send('Version')
|
121
127
|
|
128
|
+
WIN32OLE.ole_uninitialize
|
129
|
+
|
122
130
|
# The operating system version is a string in the following form
|
123
131
|
# that can be split into components based on the '.' delimiter:
|
124
132
|
# MajorVersionNumber.MinorVersionNumber.BuildNumber
|
@@ -0,0 +1 @@
|
|
1
|
+
source "https://rubygems.org/"
|
data/spec/data/standalone_cookbook/vendor/bundle/ruby/2.0.0/gems/multi_json-1.9.0/lib/multi_json.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# This is a dummy ruby file
|
@@ -84,7 +84,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
84
84
|
# last line executed -- in this case, we return the status of the
|
85
85
|
# second to last line. This happens because Powershell gives no
|
86
86
|
# way for us to determine whether the last operation was a cmdlet
|
87
|
-
# or Windows process. Because the latter gives more
|
87
|
+
# or Windows process. Because the latter gives more specific
|
88
88
|
# errors than 0 or 1, we return that instead, which is acceptable
|
89
89
|
# since callers can test for nonzero rather than testing for 1.
|
90
90
|
it "returns 1 if the last command was a cmdlet that failed and was preceded by an unsuccessfully executed non-cmdlet Windows binary" do
|
@@ -111,6 +111,32 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
111
111
|
resource.run_action(:run)
|
112
112
|
end
|
113
113
|
|
114
|
+
it "returns 0 for $false as the last line of the script when convert_boolean_return is false" do
|
115
|
+
resource.code "$false"
|
116
|
+
resource.returns(0)
|
117
|
+
resource.run_action(:run)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "returns 0 for $true as the last line of the script when convert_boolean_return is false" do
|
121
|
+
resource.code "$true"
|
122
|
+
resource.returns(0)
|
123
|
+
resource.run_action(:run)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns 1 for $false as the last line of the script when convert_boolean_return is true" do
|
127
|
+
resource.convert_boolean_return true
|
128
|
+
resource.code "$false"
|
129
|
+
resource.returns(1)
|
130
|
+
resource.run_action(:run)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "returns 0 for $true as the last line of the script when convert_boolean_return is true" do
|
134
|
+
resource.convert_boolean_return true
|
135
|
+
resource.code "$true"
|
136
|
+
resource.returns(0)
|
137
|
+
resource.run_action(:run)
|
138
|
+
end
|
139
|
+
|
114
140
|
it "executes a script with a 64-bit process on a 64-bit OS, otherwise a 32-bit process" do
|
115
141
|
resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
|
116
142
|
resource.returns(0)
|
@@ -177,6 +203,241 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
177
203
|
end
|
178
204
|
end
|
179
205
|
|
206
|
+
describe "when executing guards" do
|
207
|
+
|
208
|
+
before(:each) do
|
209
|
+
resource.not_if.clear
|
210
|
+
resource.only_if.clear
|
211
|
+
resource.guard_interpreter :powershell_script
|
212
|
+
end
|
213
|
+
|
214
|
+
it "evaluates a succeeding not_if block using cmd.exe as false by default" do
|
215
|
+
resource.guard_interpreter :default
|
216
|
+
resource.not_if "exit /b 0"
|
217
|
+
resource.should_skip?(:run).should be_true
|
218
|
+
end
|
219
|
+
|
220
|
+
it "evaluates a failing not_if block using cmd.exe as true by default" do
|
221
|
+
resource.guard_interpreter :default
|
222
|
+
resource.not_if "exit /b 2"
|
223
|
+
resource.should_skip?(:run).should be_false
|
224
|
+
end
|
225
|
+
|
226
|
+
it "evaluates an succeeding only_if block using cmd.exe as true by default" do
|
227
|
+
resource.guard_interpreter :default
|
228
|
+
resource.only_if "exit /b 0"
|
229
|
+
resource.should_skip?(:run).should be_false
|
230
|
+
end
|
231
|
+
|
232
|
+
it "evaluates a failing only_if block using cmd.exe as false by default" do
|
233
|
+
resource.guard_interpreter :default
|
234
|
+
resource.only_if "exit /b 2"
|
235
|
+
resource.should_skip?(:run).should be_true
|
236
|
+
end
|
237
|
+
|
238
|
+
it "evaluates a powershell $false for a not_if block as true" do
|
239
|
+
resource.not_if "$false"
|
240
|
+
resource.should_skip?(:run).should be_false
|
241
|
+
end
|
242
|
+
|
243
|
+
it "evaluates a powershell $true for a not_if block as false" do
|
244
|
+
resource.not_if "$true"
|
245
|
+
resource.should_skip?(:run).should be_true
|
246
|
+
end
|
247
|
+
|
248
|
+
it "evaluates a powershell $false for an only_if block as false" do
|
249
|
+
resource.only_if "$false"
|
250
|
+
resource.should_skip?(:run).should be_true
|
251
|
+
end
|
252
|
+
|
253
|
+
it "evaluates a powershell $true for a only_if block as true" do
|
254
|
+
resource.only_if "$true"
|
255
|
+
resource.should_skip?(:run).should be_false
|
256
|
+
end
|
257
|
+
|
258
|
+
it "evaluates a not_if block using powershell.exe" do
|
259
|
+
resource.not_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
|
260
|
+
resource.should_skip?(:run).should be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "evaluates an only_if block using powershell.exe" do
|
264
|
+
resource.only_if "exit([int32](![System.Environment]::CommandLine.Contains('powershell.exe')))"
|
265
|
+
resource.should_skip?(:run).should be_false
|
266
|
+
end
|
267
|
+
|
268
|
+
it "evaluates a not_if block as false" do
|
269
|
+
resource.not_if { false }
|
270
|
+
resource.should_skip?(:run).should be_false
|
271
|
+
end
|
272
|
+
|
273
|
+
it "evaluates a not_if block as true" do
|
274
|
+
resource.not_if { true }
|
275
|
+
resource.should_skip?(:run).should be_true
|
276
|
+
end
|
277
|
+
|
278
|
+
it "evaluates an only_if block as false" do
|
279
|
+
resource.only_if { false }
|
280
|
+
resource.should_skip?(:run).should be_true
|
281
|
+
end
|
282
|
+
|
283
|
+
it "evaluates an only_if block as true" do
|
284
|
+
resource.only_if { true }
|
285
|
+
resource.should_skip?(:run).should be_false
|
286
|
+
end
|
287
|
+
|
288
|
+
it "evaluates a non-zero powershell exit status for not_if as true" do
|
289
|
+
resource.not_if "exit 37"
|
290
|
+
resource.should_skip?(:run).should be_false
|
291
|
+
end
|
292
|
+
|
293
|
+
it "evaluates a zero powershell exit status for not_if as false" do
|
294
|
+
resource.not_if "exit 0"
|
295
|
+
resource.should_skip?(:run).should be_true
|
296
|
+
end
|
297
|
+
|
298
|
+
it "evaluates a failed executable exit status for not_if as false" do
|
299
|
+
resource.not_if windows_process_exit_code_not_found_content
|
300
|
+
resource.should_skip?(:run).should be_false
|
301
|
+
end
|
302
|
+
|
303
|
+
it "evaluates a successful executable exit status for not_if as true" do
|
304
|
+
resource.not_if windows_process_exit_code_success_content
|
305
|
+
resource.should_skip?(:run).should be_true
|
306
|
+
end
|
307
|
+
|
308
|
+
it "evaluates a failed executable exit status for only_if as false" do
|
309
|
+
resource.only_if windows_process_exit_code_not_found_content
|
310
|
+
resource.should_skip?(:run).should be_true
|
311
|
+
end
|
312
|
+
|
313
|
+
it "evaluates a successful executable exit status for only_if as true" do
|
314
|
+
resource.only_if windows_process_exit_code_success_content
|
315
|
+
resource.should_skip?(:run).should be_false
|
316
|
+
end
|
317
|
+
|
318
|
+
it "evaluates a failed cmdlet exit status for not_if as true" do
|
319
|
+
resource.not_if "throw 'up'"
|
320
|
+
resource.should_skip?(:run).should be_false
|
321
|
+
end
|
322
|
+
|
323
|
+
it "evaluates a successful cmdlet exit status for not_if as true" do
|
324
|
+
resource.not_if "cd ."
|
325
|
+
resource.should_skip?(:run).should be_true
|
326
|
+
end
|
327
|
+
|
328
|
+
it "evaluates a failed cmdlet exit status for only_if as false" do
|
329
|
+
resource.only_if "throw 'up'"
|
330
|
+
resource.should_skip?(:run).should be_true
|
331
|
+
end
|
332
|
+
|
333
|
+
it "evaluates a successful cmdlet exit status for only_if as true" do
|
334
|
+
resource.only_if "cd ."
|
335
|
+
resource.should_skip?(:run).should be_false
|
336
|
+
end
|
337
|
+
|
338
|
+
it "evaluates a not_if block using the cwd guard parameter" do
|
339
|
+
custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
|
340
|
+
resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
|
341
|
+
resource.should_skip?(:run).should be_true
|
342
|
+
end
|
343
|
+
|
344
|
+
it "evaluates an only_if block using the cwd guard parameter" do
|
345
|
+
custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
|
346
|
+
resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", :cwd => custom_cwd
|
347
|
+
resource.should_skip?(:run).should be_false
|
348
|
+
end
|
349
|
+
|
350
|
+
it "inherits cwd from the parent resource for only_if" do
|
351
|
+
custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
|
352
|
+
resource.cwd custom_cwd
|
353
|
+
resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
|
354
|
+
resource.should_skip?(:run).should be_false
|
355
|
+
end
|
356
|
+
|
357
|
+
it "inherits cwd from the parent resource for not_if" do
|
358
|
+
custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc"
|
359
|
+
resource.cwd custom_cwd
|
360
|
+
resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')"
|
361
|
+
resource.should_skip?(:run).should be_true
|
362
|
+
end
|
363
|
+
|
364
|
+
it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean false as zero status code", :windows64_only do
|
365
|
+
resource.architecture :x86_64
|
366
|
+
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'AMD64')"
|
367
|
+
resource.should_skip?(:run).should be_false
|
368
|
+
end
|
369
|
+
|
370
|
+
it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do
|
371
|
+
resource.architecture :x86_64
|
372
|
+
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')"
|
373
|
+
resource.should_skip?(:run).should be_true
|
374
|
+
end
|
375
|
+
|
376
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do
|
377
|
+
resource.architecture :i386
|
378
|
+
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')"
|
379
|
+
resource.should_skip?(:run).should be_false
|
380
|
+
end
|
381
|
+
|
382
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do
|
383
|
+
resource.architecture :i386
|
384
|
+
resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')"
|
385
|
+
resource.should_skip?(:run).should be_true
|
386
|
+
end
|
387
|
+
|
388
|
+
it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do
|
389
|
+
resource.convert_boolean_return true
|
390
|
+
resource.only_if "$false"
|
391
|
+
resource.should_skip?(:run).should be_true
|
392
|
+
end
|
393
|
+
|
394
|
+
it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do
|
395
|
+
resource.convert_boolean_return true
|
396
|
+
resource.not_if "$false"
|
397
|
+
resource.should_skip?(:run).should be_false
|
398
|
+
end
|
399
|
+
|
400
|
+
it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for only_if" do
|
401
|
+
resource.convert_boolean_return true
|
402
|
+
resource.only_if "$true"
|
403
|
+
resource.should_skip?(:run).should be_false
|
404
|
+
end
|
405
|
+
|
406
|
+
it "evaluates a simple boolean true as 0 status code when convert_boolean_return is true for not_if" do
|
407
|
+
resource.convert_boolean_return true
|
408
|
+
resource.not_if "$true"
|
409
|
+
resource.should_skip?(:run).should be_true
|
410
|
+
end
|
411
|
+
|
412
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do
|
413
|
+
resource.convert_boolean_return true
|
414
|
+
resource.architecture :i386
|
415
|
+
resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
|
416
|
+
resource.should_skip?(:run).should be_false
|
417
|
+
end
|
418
|
+
|
419
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do
|
420
|
+
resource.convert_boolean_return true
|
421
|
+
resource.architecture :i386
|
422
|
+
resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
|
423
|
+
resource.should_skip?(:run).should be_false
|
424
|
+
end
|
425
|
+
|
426
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do
|
427
|
+
resource.convert_boolean_return true
|
428
|
+
resource.architecture :i386
|
429
|
+
resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
|
430
|
+
resource.should_skip?(:run).should be_true
|
431
|
+
end
|
432
|
+
|
433
|
+
it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do
|
434
|
+
resource.convert_boolean_return true
|
435
|
+
resource.architecture :i386
|
436
|
+
resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
|
437
|
+
resource.should_skip?(:run).should be_true
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
180
441
|
def get_script_output
|
181
442
|
script_output = File.read(script_output_path)
|
182
443
|
end
|