chef-zero-scheduled-task 0.0.7.dev → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17ecbdf7cc8a7a59ae9454dc63226bc799d8b1e6
|
4
|
+
data.tar.gz: de917b0ac0899172edb3f4ef04ceceb467f39574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feab4427f9e635d6462a85793379e59119d1993b9970a6479f12f369412e98ab0ac1a4c1c5d7ae112269d89152852495c76e60ce58c217ae8f78a414626fb162
|
7
|
+
data.tar.gz: 1b6da04813e2b102727e78ba07dcf612029edfbfbd404aa418aa15056a2dea4a189c97906aa86f74611de988978ca70c3678dd2b4f8daf2ac72cef5444050633
|
data/Rakefile
CHANGED
@@ -33,31 +33,30 @@ module Kitchen
|
|
33
33
|
def create_sandbox
|
34
34
|
super
|
35
35
|
return unless windows_os?
|
36
|
+
info("Creating a script to run chef client.")
|
36
37
|
prepare_client_zero_script
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
-
|
41
|
-
wrap_shell_code(setup_scheduled_task_command)
|
40
|
+
def prepare_command
|
41
|
+
wrap_shell_code('$env:temp = "$env:temp"')
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
info("Creating a script to run chef client.")
|
48
|
-
wrap_shell_code(scheduled_task_command)
|
44
|
+
def init_command
|
45
|
+
info("Creating the scheduled task.")
|
46
|
+
wrap_shell_code(setup_scheduled_task_command)
|
49
47
|
end
|
50
48
|
|
51
49
|
def run_command
|
52
50
|
wrap_shell_code(run_scheduled_task_command)
|
53
51
|
end
|
54
52
|
|
55
|
-
#private
|
53
|
+
# private
|
56
54
|
|
57
|
-
def local_state_file
|
55
|
+
def local_state_file
|
58
56
|
@local_state_file ||= @instance.diagnose[:state_file]
|
59
57
|
end
|
60
|
-
|
58
|
+
|
59
|
+
def task_username
|
61
60
|
if config[:task_username]
|
62
61
|
config[:task_username]
|
63
62
|
else
|
@@ -68,22 +67,17 @@ module Kitchen
|
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
71
|
-
|
72
|
-
def
|
70
|
+
|
71
|
+
def task_password
|
73
72
|
unless config[:task_password]
|
74
73
|
if local_state_file.key?(:password)
|
75
|
-
|
74
|
+
local_state_file[:password]
|
76
75
|
else
|
77
76
|
@instance.transport[:password]
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
|
-
def resolve_username_and_password
|
83
|
-
@task_username = resolve_username
|
84
|
-
@task_password = resolve_password
|
85
|
-
end
|
86
|
-
|
87
81
|
def run_scheduled_task_command
|
88
82
|
<<-EOH
|
89
83
|
try {
|
@@ -107,45 +101,56 @@ module Kitchen
|
|
107
101
|
EOH
|
108
102
|
end
|
109
103
|
|
104
|
+
def new_scheduled_task_command
|
105
|
+
"schtasks /create /tn 'chef-tk' " \
|
106
|
+
"/ru '#{task_username}' /rp '#{task_password}' " \
|
107
|
+
"/sc daily /st 00:00 /f "
|
108
|
+
end
|
109
|
+
|
110
|
+
def new_scheduled_task_command_line_ps
|
111
|
+
"/tr $executioncontext.invokecommand.expandstring(" \
|
112
|
+
'"powershell -executionpolicy unrestricted -File '
|
113
|
+
end
|
114
|
+
|
110
115
|
def setup_scheduled_task_command
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
EOH
|
116
|
+
new_scheduled_task_command +
|
117
|
+
new_scheduled_task_command_line_ps +
|
118
|
+
remote_chef_client_script +
|
119
|
+
'")'
|
120
|
+
end
|
121
|
+
|
122
|
+
def remote_chef_client_script
|
123
|
+
@remote_script_path ||= remote_path_join(
|
124
|
+
config[:root_path], "chef-client-script.ps1")
|
121
125
|
end
|
122
126
|
|
123
|
-
def
|
127
|
+
def scheduled_task_command_script
|
124
128
|
<<-EOH
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
'$LastExitCode");$pipewriter.dispose();$npipeclient.dispose()}'
|
138
|
-
$pre_cmd, $cmd | out-file $cmd_path
|
129
|
+
start-sleep -seconds 5;
|
130
|
+
$npipeClient = new-object System.IO.Pipes.NamedPipeClientStream(
|
131
|
+
$env:ComputerName, 'task', [System.IO.Pipes.PipeDirection]::Out);
|
132
|
+
$npipeclient.connect();
|
133
|
+
$pipeWriter = new-object System.IO.StreamWriter($npipeClient);
|
134
|
+
$pipeWriter.AutoFlush = $true;
|
135
|
+
#{client_zero_command} |
|
136
|
+
foreach-object {} {$pipewriter.writeline($_)} {
|
137
|
+
$pipewriter.writeline("SCHEDULED_TASK_DONE: $LastExitCode");
|
138
|
+
$pipewriter.dispose();
|
139
|
+
$npipeclient.dispose()
|
140
|
+
}
|
139
141
|
EOH
|
140
142
|
end
|
141
143
|
|
142
144
|
def prepare_client_zero_script
|
143
|
-
cmd = [local_mode_command, *chef_client_args].join(" ")
|
144
145
|
File.open(File.join(sandbox_path, "chef-client-script.ps1"), "w") do |file|
|
145
|
-
file.write(
|
146
|
+
file.write(Util.outdent!(scheduled_task_command_script))
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
150
|
+
def client_zero_command
|
151
|
+
[local_mode_command, *chef_client_args].join(" ")
|
152
|
+
end
|
153
|
+
|
149
154
|
def chef_client_args
|
150
155
|
level = config[:log_level] == :info ? :info : config[:log_level]
|
151
156
|
args = [
|
@@ -1,21 +1,27 @@
|
|
1
1
|
require_relative "../../spec_helper"
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pry"
|
4
4
|
require "kitchen"
|
5
5
|
require "kitchen/provisioner/chef_zero_scheduled_task"
|
6
6
|
|
7
7
|
describe Kitchen::Provisioner::ChefZeroScheduledTask do
|
8
8
|
|
9
|
-
let(:logged_output)
|
10
|
-
let(:logger)
|
11
|
-
let(:platform)
|
12
|
-
|
13
|
-
|
14
|
-
let(:
|
15
|
-
|
9
|
+
let(:logged_output) { StringIO.new }
|
10
|
+
let(:logger) { Logger.new(logged_output) }
|
11
|
+
let(:platform) do
|
12
|
+
stub(:os_type => "windows", :shell_type => "powershell")
|
13
|
+
end
|
14
|
+
let(:suite) { stub(:name => "fries") }
|
15
|
+
let(:transport) do
|
16
|
+
{ :username => "Administrator", :password => "P@ssw0rd" }
|
17
|
+
end
|
18
|
+
let(:diagnose) { { :state_file => { :hostname => "Blah" } } }
|
16
19
|
|
17
20
|
let(:config) do
|
18
|
-
{ :test_base_path => "/b",
|
21
|
+
{ :test_base_path => "/b",
|
22
|
+
:kitchen_root => "/r",
|
23
|
+
:log_level => :info,
|
24
|
+
:root_path => "c:\\" }
|
19
25
|
end
|
20
26
|
|
21
27
|
let(:instance) do
|
@@ -25,11 +31,10 @@ describe Kitchen::Provisioner::ChefZeroScheduledTask do
|
|
25
31
|
:suite => suite,
|
26
32
|
:platform => platform,
|
27
33
|
:transport => transport,
|
28
|
-
:diagnose =>
|
34
|
+
:diagnose => diagnose
|
29
35
|
)
|
30
36
|
end
|
31
37
|
|
32
|
-
|
33
38
|
let(:provisioner) do
|
34
39
|
Kitchen::Provisioner::ChefZeroScheduledTask.new(config).finalize_config!(instance)
|
35
40
|
end
|
@@ -42,17 +47,42 @@ describe Kitchen::Provisioner::ChefZeroScheduledTask do
|
|
42
47
|
provisioner.diagnose_plugin[:version].must_equal Kitchen::VERSION
|
43
48
|
end
|
44
49
|
|
45
|
-
describe
|
50
|
+
describe "when username is not provided by the driver or task_username" do
|
51
|
+
it "is resolved from the transport" do
|
52
|
+
provisioner.task_username.must_match "Administrator"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "when password is not provided by the driver or task_password" do
|
57
|
+
it "is resolved from the transport" do
|
58
|
+
provisioner.task_password.must_match "P@ssw0rd"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "new_scheduled_task_command" do
|
63
|
+
it "returns a valid command line" do
|
64
|
+
provisioner.
|
65
|
+
new_scheduled_task_command.
|
66
|
+
must_match("schtasks /create /tn 'chef-tk' /ru " \
|
67
|
+
"'Administrator' /rp 'P@ssw0rd' /sc daily /st 00:00 /f ")
|
68
|
+
end
|
69
|
+
end
|
46
70
|
|
47
|
-
|
48
|
-
|
71
|
+
describe "new_scheduled_task_command_line_ps" do
|
72
|
+
it "returns a valid task to execute" do
|
73
|
+
provisioner.
|
74
|
+
new_scheduled_task_command_line_ps.
|
75
|
+
must_match("/tr $executioncontext.invokecommand.expandstring(" \
|
76
|
+
'"powershell -executionpolicy unrestricted -File ')
|
49
77
|
end
|
78
|
+
end
|
50
79
|
|
80
|
+
describe "remote_chef_client_script" do
|
81
|
+
it "returns a valid path to the script to execute" do
|
82
|
+
provisioner.
|
83
|
+
remote_chef_client_script.
|
84
|
+
must_match("c:\\chef-client-script.ps1")
|
85
|
+
end
|
51
86
|
end
|
52
|
-
|
53
|
-
# before { transport
|
54
|
-
it 'is resolved from the transport' do
|
55
|
-
provisioner.resolve_password.must_match "P@ssw0rd"
|
56
|
-
end
|
57
|
-
end
|
87
|
+
|
58
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero-scheduled-task
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Murawski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -254,12 +254,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
256
|
requirements:
|
257
|
-
- - "
|
257
|
+
- - ">="
|
258
258
|
- !ruby/object:Gem::Version
|
259
|
-
version:
|
259
|
+
version: '0'
|
260
260
|
requirements: []
|
261
261
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.4.
|
262
|
+
rubygems_version: 2.4.8
|
263
263
|
signing_key:
|
264
264
|
specification_version: 4
|
265
265
|
summary: Test-Kitchen Provisioner that runs Chef Zero in a Scheduled Task
|