chef 12.1.2-x86-mingw32 → 12.2.0.rc.1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/chef/application/client.rb +2 -2
- data/lib/chef/audit/audit_reporter.rb +1 -1
- data/lib/chef/audit/runner.rb +15 -2
- data/lib/chef/client.rb +1 -1
- data/lib/chef/config.rb +6 -4
- data/lib/chef/dsl/powershell.rb +29 -0
- data/lib/chef/exceptions.rb +18 -3
- data/lib/chef/formatters/doc.rb +2 -2
- data/lib/chef/knife/bootstrap.rb +2 -1
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +13 -5
- data/lib/chef/knife/exec.rb +2 -1
- data/lib/chef/knife/ssh.rb +12 -2
- data/lib/chef/mixin/params_validate.rb +42 -19
- data/lib/chef/mixin/powershell_type_coercions.rb +82 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +8 -0
- data/lib/chef/node.rb +1 -1
- data/lib/chef/platform/provider_mapping.rb +0 -107
- data/lib/chef/platform/query_helpers.rb +7 -0
- data/lib/chef/provider/batch.rb +2 -0
- data/lib/chef/provider/cron.rb +2 -0
- data/lib/chef/provider/cron/aix.rb +2 -0
- data/lib/chef/provider/cron/unix.rb +2 -0
- data/lib/chef/provider/deploy.rb +104 -87
- data/lib/chef/provider/dsc_resource.rb +157 -0
- data/lib/chef/provider/env.rb +2 -0
- data/lib/chef/provider/env/windows.rb +2 -0
- data/lib/chef/provider/git.rb +4 -0
- data/lib/chef/provider/group.rb +5 -5
- data/lib/chef/provider/group/dscl.rb +2 -0
- data/lib/chef/provider/group/groupmod.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +2 -0
- data/lib/chef/provider/group/windows.rb +2 -0
- data/lib/chef/provider/mdadm.rb +2 -0
- data/lib/chef/provider/mount/windows.rb +2 -0
- data/lib/chef/provider/package/homebrew.rb +1 -1
- data/lib/chef/provider/package/openbsd.rb +49 -18
- data/lib/chef/provider/package/rubygems.rb +7 -2
- data/lib/chef/provider/powershell_script.rb +2 -0
- data/lib/chef/provider/service/macosx.rb +1 -2
- data/lib/chef/provider/user/dscl.rb +7 -1
- data/lib/chef/provider/user/windows.rb +2 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/recipe.rb +2 -0
- data/lib/chef/resource.rb +9 -0
- data/lib/chef/resource/batch.rb +2 -0
- data/lib/chef/resource/cron.rb +3 -3
- data/lib/chef/resource/deploy.rb +52 -217
- data/lib/chef/resource/dsc_resource.rb +83 -0
- data/lib/chef/resource/env.rb +2 -0
- data/lib/chef/resource/git.rb +1 -1
- data/lib/chef/resource/group.rb +2 -0
- data/lib/chef/resource/homebrew_package.rb +1 -1
- data/lib/chef/resource/lwrp_base.rb +0 -8
- data/lib/chef/resource/mdadm.rb +2 -0
- data/lib/chef/resource/mount.rb +2 -0
- data/lib/chef/resource/powershell_script.rb +2 -0
- data/lib/chef/resource/user.rb +2 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/run_context.rb +1 -1
- data/lib/chef/shell.rb +7 -5
- data/lib/chef/util/dsc/resource_store.rb +110 -0
- data/lib/chef/util/path_helper.rb +76 -0
- data/lib/chef/util/powershell/cmdlet.rb +41 -7
- data/lib/chef/util/powershell/cmdlet_result.rb +18 -3
- data/lib/chef/util/powershell/ps_credential.rb +38 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +2 -0
- data/lib/chef/win32/api/crypto.rb +63 -0
- data/lib/chef/win32/api/installer.rb +1 -1
- data/lib/chef/win32/crypto.rb +49 -0
- data/lib/chef/workstation_config_loader.rb +4 -3
- data/spec/functional/file_content_management/deploy_strategies_spec.rb +1 -1
- data/spec/functional/resource/cookbook_file_spec.rb +1 -1
- data/spec/functional/resource/deploy_revision_spec.rb +35 -0
- data/spec/functional/resource/directory_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +93 -0
- data/spec/functional/resource/env_spec.rb +4 -3
- data/spec/functional/resource/file_spec.rb +1 -1
- data/spec/functional/resource/powershell_spec.rb +2 -1
- data/spec/functional/resource/remote_directory_spec.rb +1 -1
- data/spec/functional/resource/remote_file_spec.rb +1 -1
- data/spec/functional/resource/template_spec.rb +1 -1
- data/spec/functional/resource/user/dscl_spec.rb +1 -2
- data/spec/functional/resource/user/useradd_spec.rb +27 -13
- data/spec/functional/util/powershell/cmdlet_spec.rb +3 -3
- data/spec/functional/win32/crypto_spec.rb +57 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/platform_helpers.rb +14 -0
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +5 -5
- data/spec/unit/application/client_spec.rb +4 -4
- data/spec/unit/audit/audit_reporter_spec.rb +1 -1
- data/spec/unit/audit/runner_spec.rb +10 -0
- data/spec/unit/config_spec.rb +2 -8
- data/spec/unit/knife/bootstrap_spec.rb +20 -8
- data/spec/unit/knife/core/subcommand_loader_spec.rb +29 -29
- data/spec/unit/mixin/params_validate_spec.rb +75 -61
- data/spec/unit/mixin/powershell_type_coercions_spec.rb +72 -0
- data/spec/unit/platform/query_helpers_spec.rb +22 -0
- data/spec/unit/platform_spec.rb +0 -5
- data/spec/unit/provider/dsc_resource_spec.rb +84 -0
- data/spec/unit/provider/package/openbsd_spec.rb +105 -17
- data/spec/unit/provider/service/macosx_spec.rb +3 -3
- data/spec/unit/provider_resolver_spec.rb +132 -0
- data/spec/unit/recipe_spec.rb +4 -0
- data/spec/unit/resource/deploy_spec.rb +27 -0
- data/spec/unit/resource/dsc_resource_spec.rb +85 -0
- data/spec/unit/shell_spec.rb +1 -1
- data/spec/unit/util/dsc/resource_store.rb +76 -0
- data/spec/unit/util/powershell/ps_credential_spec.rb +37 -0
- data/spec/unit/workstation_config_loader_spec.rb +1 -1
- metadata +175 -226
@@ -18,22 +18,35 @@
|
|
18
18
|
|
19
19
|
require 'chef/json_compat'
|
20
20
|
|
21
|
-
class Chef
|
21
|
+
class Chef
|
22
|
+
class Util
|
23
|
+
class Powershell
|
22
24
|
class CmdletResult
|
23
25
|
attr_reader :output_format
|
24
26
|
|
25
|
-
def initialize(status, output_format)
|
27
|
+
def initialize(status, streams, output_format)
|
26
28
|
@status = status
|
27
29
|
@output_format = output_format
|
30
|
+
@streams = streams
|
28
31
|
end
|
29
32
|
|
33
|
+
def stdout
|
34
|
+
@status.stdout
|
35
|
+
end
|
36
|
+
|
30
37
|
def stderr
|
31
38
|
@status.stderr
|
32
39
|
end
|
33
40
|
|
41
|
+
def stream(name)
|
42
|
+
@streams[name].read
|
43
|
+
end
|
44
|
+
|
34
45
|
def return_value
|
35
46
|
if output_format == :object
|
36
|
-
Chef::JSONCompat.parse(
|
47
|
+
Chef::JSONCompat.parse(stream(:json))
|
48
|
+
elsif output_format == :json
|
49
|
+
stream(:json)
|
37
50
|
else
|
38
51
|
@status.stdout
|
39
52
|
end
|
@@ -44,3 +57,5 @@ class Chef::Util::Powershell
|
|
44
57
|
end
|
45
58
|
end
|
46
59
|
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jay Mundrawala (<jdm@chef.io>)
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
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/win32/crypto' if Chef::Platform.windows?
|
20
|
+
|
21
|
+
class Chef::Util::Powershell
|
22
|
+
class PSCredential
|
23
|
+
def initialize(username, password)
|
24
|
+
@username = username
|
25
|
+
@password = password
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_psobject
|
29
|
+
"New-Object System.Management.Automation.PSCredential('#{@username}',('#{encrypt(@password)}' | ConvertTo-SecureString))"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def encrypt(str)
|
35
|
+
Chef::ReservedNames::Win32::Crypto.encrypt(str)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/chef/version.rb
CHANGED
data/lib/chef/win32/api.rb
CHANGED
@@ -184,6 +184,8 @@ class Chef
|
|
184
184
|
host.typedef :pointer, :PSTR # Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
|
185
185
|
host.typedef :pointer, :PTBYTE # Pointer to a TBYTE.
|
186
186
|
host.typedef :pointer, :PTCHAR # Pointer to a TCHAR.
|
187
|
+
host.typedef :pointer, :PCRYPTPROTECT_PROMPTSTRUCT # Pointer to a CRYPTOPROTECT_PROMPTSTRUCT.
|
188
|
+
host.typedef :pointer, :PDATA_BLOB # Pointer to a DATA_BLOB.
|
187
189
|
host.typedef :pointer, :PTSTR # A PWSTR if UNICODE is defined, a PSTR otherwise.
|
188
190
|
host.typedef :pointer, :PUCHAR # Pointer to a UCHAR.
|
189
191
|
host.typedef :pointer, :PUHALF_PTR # Pointer to a UHALF_PTR.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jay Mundrawala (<jdm@chef.io>)
|
3
|
+
# Copyright:: Copyright 2015 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/win32/api'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
module ReservedNames::Win32
|
23
|
+
module API
|
24
|
+
module Crypto
|
25
|
+
extend Chef::ReservedNames::Win32::API
|
26
|
+
|
27
|
+
###############################################
|
28
|
+
# Win32 API Bindings
|
29
|
+
###############################################
|
30
|
+
|
31
|
+
ffi_lib 'Crypt32'
|
32
|
+
|
33
|
+
CRYPTPROTECT_UI_FORBIDDEN = 0x1
|
34
|
+
CRYPTPROTECT_LOCAL_MACHINE = 0x4
|
35
|
+
CRYPTPROTECT_AUDIT = 0x10
|
36
|
+
|
37
|
+
class CRYPT_INTEGER_BLOB < FFI::Struct
|
38
|
+
layout :cbData, :DWORD, # Count, in bytes, of data
|
39
|
+
:pbData, :pointer # Pointer to data buffer
|
40
|
+
def initialize(str=nil)
|
41
|
+
super(nil)
|
42
|
+
if str
|
43
|
+
self[:pbData] = FFI::MemoryPointer.from_string(str)
|
44
|
+
self[:cbData] = str.bytesize
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
safe_attach_function :CryptProtectData, [
|
51
|
+
:PDATA_BLOB,
|
52
|
+
:LPCWSTR,
|
53
|
+
:PDATA_BLOB,
|
54
|
+
:pointer,
|
55
|
+
:PCRYPTPROTECT_PROMPTSTRUCT,
|
56
|
+
:DWORD,
|
57
|
+
:PDATA_BLOB
|
58
|
+
], :BOOL
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jay Mundrawala (<jdm@chef.io>)
|
3
|
+
# Copyright:: Copyright 2015 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/win32/error'
|
20
|
+
require 'chef/win32/api/memory'
|
21
|
+
require 'chef/win32/api/crypto'
|
22
|
+
require 'digest'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
module ReservedNames::Win32
|
26
|
+
class Crypto
|
27
|
+
include Chef::ReservedNames::Win32::API::Crypto
|
28
|
+
extend Chef::ReservedNames::Win32::API::Crypto
|
29
|
+
|
30
|
+
def self.encrypt(str, &block)
|
31
|
+
data_blob = CRYPT_INTEGER_BLOB.new
|
32
|
+
unless CryptProtectData(CRYPT_INTEGER_BLOB.new(str.to_wstring), nil, nil, nil, nil, 0, data_blob)
|
33
|
+
Chef::ReservedNames::Win32::Error.raise!
|
34
|
+
end
|
35
|
+
bytes = data_blob[:pbData].get_bytes(0, data_blob[:cbData])
|
36
|
+
if block
|
37
|
+
block.call(bytes)
|
38
|
+
else
|
39
|
+
Digest.hexencode(bytes)
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
unless data_blob[:pbData].null?
|
43
|
+
Chef::ReservedNames::Win32::Memory.local_free(data_blob[:pbData])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -19,6 +19,7 @@
|
|
19
19
|
require 'chef/config_fetcher'
|
20
20
|
require 'chef/config'
|
21
21
|
require 'chef/null_logger'
|
22
|
+
require 'chef/util/path_helper'
|
22
23
|
|
23
24
|
class Chef
|
24
25
|
|
@@ -112,9 +113,9 @@ class Chef
|
|
112
113
|
candidate_configs << File.join(chef_config_dir, 'knife.rb')
|
113
114
|
end
|
114
115
|
# Look for $HOME/.chef/knife.rb
|
115
|
-
|
116
|
-
candidate_configs << File.join(
|
117
|
-
candidate_configs << File.join(
|
116
|
+
Chef::Util::PathHelper.home('.chef') do |dot_chef_dir|
|
117
|
+
candidate_configs << File.join(dot_chef_dir, 'config.rb')
|
118
|
+
candidate_configs << File.join(dot_chef_dir, 'knife.rb')
|
118
119
|
end
|
119
120
|
|
120
121
|
candidate_configs.find do | candidate_config |
|
@@ -43,7 +43,7 @@ shared_examples_for "a content deploy strategy" do
|
|
43
43
|
|
44
44
|
##
|
45
45
|
# UNIX Context
|
46
|
-
let(:default_mode) { normalize_mode(
|
46
|
+
let(:default_mode) { normalize_mode(0666 & ~File.umask) }
|
47
47
|
|
48
48
|
it "touches the file to create it (UNIX)", :unix_only do
|
49
49
|
content_deployer.create(target_file_path)
|
@@ -201,6 +201,41 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
+
describe "setting default parameters to nil" do
|
205
|
+
before do
|
206
|
+
FileUtils.mkdir_p(rel_path("releases"))
|
207
|
+
FileUtils.mkdir_p(rel_path("shared"))
|
208
|
+
end
|
209
|
+
|
210
|
+
it "supports setting symlink_before_migrate to nil" do
|
211
|
+
deploy_to_latest_rev.symlink_before_migrate(nil)
|
212
|
+
expect(deploy_to_latest_rev.symlink_before_migrate).to eql(nil)
|
213
|
+
deploy_to_latest_rev.run_action(:deploy)
|
214
|
+
expect(deploy_to_latest_rev).to be_updated_by_last_action
|
215
|
+
end
|
216
|
+
|
217
|
+
it "supports setting symlinks to nil" do
|
218
|
+
deploy_to_latest_rev.symlinks(nil)
|
219
|
+
expect(deploy_to_latest_rev.symlinks).to eql(nil)
|
220
|
+
deploy_to_latest_rev.run_action(:deploy)
|
221
|
+
expect(deploy_to_latest_rev).to be_updated_by_last_action
|
222
|
+
end
|
223
|
+
|
224
|
+
it "supports setting purge_before_symlink to nil" do
|
225
|
+
deploy_to_latest_rev.purge_before_symlink(nil)
|
226
|
+
expect(deploy_to_latest_rev.purge_before_symlink).to eql(nil)
|
227
|
+
deploy_to_latest_rev.run_action(:deploy)
|
228
|
+
expect(deploy_to_latest_rev).to be_updated_by_last_action
|
229
|
+
end
|
230
|
+
|
231
|
+
it "supports setting create_dirs_before_symlink to nil" do
|
232
|
+
deploy_to_latest_rev.create_dirs_before_symlink(nil)
|
233
|
+
expect(deploy_to_latest_rev.create_dirs_before_symlink).to eql(nil)
|
234
|
+
deploy_to_latest_rev.run_action(:deploy)
|
235
|
+
expect(deploy_to_latest_rev).to be_updated_by_last_action
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
204
239
|
describe "back to a previously deployed revision, with the directory structure precreated" do
|
205
240
|
before do
|
206
241
|
FileUtils.mkdir_p(rel_path("releases"))
|
@@ -23,7 +23,7 @@ describe Chef::Resource::Directory do
|
|
23
23
|
|
24
24
|
let(:directory_base) { "directory_spec" }
|
25
25
|
|
26
|
-
let(:default_mode) { (
|
26
|
+
let(:default_mode) { (0777 & ~File.umask).to_s(8) }
|
27
27
|
|
28
28
|
def create_resource
|
29
29
|
events = Chef::EventDispatch::Dispatcher.new
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jay Mundrawala (<jdm@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 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 'spec_helper'
|
20
|
+
|
21
|
+
describe Chef::Resource::DscResource, :windows_powershell_dsc_only do
|
22
|
+
before(:all) do
|
23
|
+
@ohai = Ohai::System.new
|
24
|
+
@ohai.all_plugins(['platform', 'os', 'languages/powershell'])
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:event_dispatch) { Chef::EventDispatch::Dispatcher.new }
|
28
|
+
|
29
|
+
let(:node) {
|
30
|
+
Chef::Node.new.tap do |n|
|
31
|
+
n.consume_external_attrs(@ohai.data, {})
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
let(:run_context) { Chef::RunContext.new(node, {}, event_dispatch) }
|
36
|
+
|
37
|
+
let(:new_resource) {
|
38
|
+
Chef::Resource::DscResource.new("dsc_resource_test", run_context)
|
39
|
+
}
|
40
|
+
|
41
|
+
context 'when Powershell does not support Invoke-DscResource'
|
42
|
+
context 'when Powershell supports Invoke-DscResource' do
|
43
|
+
before do
|
44
|
+
if !Chef::Platform.supports_dsc_invoke_resource?(node)
|
45
|
+
skip 'Requires Powershell >= 5.0.10018.0'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context 'with an invalid dsc resource' do
|
49
|
+
it 'raises an exception if the resource is not found' do
|
50
|
+
new_resource.resource 'thisdoesnotexist'
|
51
|
+
expect { new_resource.run_action(:run) }.to raise_error(
|
52
|
+
Chef::Exceptions::ResourceNotFound)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with a valid dsc resource' do
|
57
|
+
let(:tmp_file_name) { Dir::Tmpname.create('tmpfile') {} }
|
58
|
+
let(:test_text) { "'\"!@#$%^&*)(}{][\u2713~n"}
|
59
|
+
|
60
|
+
before do
|
61
|
+
new_resource.resource :File
|
62
|
+
new_resource.property :Contents, test_text
|
63
|
+
new_resource.property :DestinationPath, tmp_file_name
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
File.delete(tmp_file_name) if File.exists? tmp_file_name
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'converges the resource if it is not converged' do
|
71
|
+
new_resource.run_action(:run)
|
72
|
+
contents = File.open(tmp_file_name, 'rb:bom|UTF-16LE') do |f|
|
73
|
+
f.read.encode('UTF-8')
|
74
|
+
end
|
75
|
+
expect(contents).to eq(test_text)
|
76
|
+
expect(new_resource).to be_updated
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'does not converge the resource if it is already converged' do
|
80
|
+
new_resource.run_action(:run)
|
81
|
+
expect(new_resource).to be_updated
|
82
|
+
reresource =
|
83
|
+
Chef::Resource::DscResource.new("dsc_resource_retest", run_context)
|
84
|
+
reresource.resource :File
|
85
|
+
reresource.property :Contents, test_text
|
86
|
+
reresource.property :DestinationPath, tmp_file_name
|
87
|
+
reresource.run_action(:run)
|
88
|
+
expect(reresource).not_to be_updated
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -29,14 +29,15 @@ describe Chef::Resource::Env, :windows_only do
|
|
29
29
|
let(:env_value_expandable) { '%SystemRoot%' }
|
30
30
|
let(:test_run_context) {
|
31
31
|
node = Chef::Node.new
|
32
|
+
node.default['os'] = 'windows'
|
32
33
|
node.default['platform'] = 'windows'
|
33
34
|
node.default['platform_version'] = '6.1'
|
34
35
|
empty_events = Chef::EventDispatch::Dispatcher.new
|
35
36
|
Chef::RunContext.new(node, {}, empty_events)
|
36
37
|
}
|
37
|
-
let(:test_resource) {
|
38
|
-
Chef::Resource::Env.new('unknown', test_run_context)
|
39
|
-
}
|
38
|
+
let(:test_resource) {
|
39
|
+
Chef::Resource::Env.new('unknown', test_run_context)
|
40
|
+
}
|
40
41
|
|
41
42
|
before(:each) do
|
42
43
|
resource_lower = Chef::Resource::Env.new(chef_env_test_lower_case, test_run_context)
|
@@ -56,7 +56,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
56
56
|
resource.run_action(:run)
|
57
57
|
end
|
58
58
|
|
59
|
-
it "returns the -27 for a powershell script that exits with -27" do
|
59
|
+
it "returns the -27 for a powershell script that exits with -27", :windows_powershell_dsc_only do
|
60
|
+
# This is broken on Powershell < 4.0
|
60
61
|
file = Tempfile.new(['foo', '.ps1'])
|
61
62
|
begin
|
62
63
|
file.write "exit -27"
|