chef-zero-scheduled-task 0.0.7.dev → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8117747c819d4f31c7f77aae4963ce74c8725f8f
4
- data.tar.gz: f5720d725bf9275e5c15d1e7b788f278b7d60c57
3
+ metadata.gz: 17ecbdf7cc8a7a59ae9454dc63226bc799d8b1e6
4
+ data.tar.gz: de917b0ac0899172edb3f4ef04ceceb467f39574
5
5
  SHA512:
6
- metadata.gz: 206da575b7737e8cb185748a06b19f87fcdc909ce9f41b5d5bf066058792af20788f863c0c62182b2372b0fcab78b8d353fb0d3c6f214539005b4dd8f6e97210
7
- data.tar.gz: c1b6fff9b97504421e484cffc1e92995f66aab0e5f0846f299fdd24ed6e8e0170399e0d4ed25b1508a7241ab57f6a0ddae868bfe9fc94b9e137a21160439a7ae
6
+ metadata.gz: feab4427f9e635d6462a85793379e59119d1993b9970a6479f12f369412e98ab0ac1a4c1c5d7ae112269d89152852495c76e60ce58c217ae8f78a414626fb162
7
+ data.tar.gz: 1b6da04813e2b102727e78ba07dcf612029edfbfbd404aa418aa15056a2dea4a189c97906aa86f74611de988978ca70c3678dd2b4f8daf2ac72cef5444050633
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ Cucumber::Rake::Task.new(:features) do |t|
16
16
  end
17
17
 
18
18
  desc "Run all test suites"
19
- task :test => [:unit] #[:unit, :features]
19
+ task :test => [:unit] # [:unit, :features]
20
20
 
21
21
  desc "Display LOC stats"
22
22
  task :stats do
@@ -2,7 +2,7 @@ module Chef
2
2
  module Zero
3
3
  module Scheduled
4
4
  module Task
5
- VERSION = "0.0.7.dev"
5
+ VERSION = "0.0.7"
6
6
  end
7
7
  end
8
8
  end
@@ -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 init_command
40
- resolve_username_and_password
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
- # assuming a version of Chef with local mode.
45
- def prepare_command
46
- return unless windows_os?
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
- def resolve_username
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 resolve_password
70
+
71
+ def task_password
73
72
  unless config[:task_password]
74
73
  if local_state_file.key?(:password)
75
- local_state_file[:password]
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
- schtasks_cmd = 'schtasks /create /tn "chef-tk"'
112
- schtasks_user = "/ru '#{@task_username}'" /
113
- " /rp '#{@task_password}'"
114
- schtasks_timing = "/sc daily /st 00:00 /f"
115
- <<-EOH
116
- $cmd_path = "#{remote_path_join(config[:root_path], "chef-client-script.ps1")}"
117
- $cmd_line = $executioncontext.invokecommand.expandstring(
118
- "powershell -executionpolicy unrestricted -File $cmd_path")
119
- #{schtasks_cmd} #{schtasks_user} #{schtasks_timing} /tr "$cmd_line"
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 scheduled_task_command
127
+ def scheduled_task_command_script
124
128
  <<-EOH
125
- $pre_cmd = '$env:temp = "' + $env:temp + '"' + ";"
126
- $pre_cmd += 'start-sleep -seconds 5;'
127
- $pre_cmd += '$npipeClient = new-object System.IO.Pipes.NamedPipeClientStream('
128
- $pre_cmd += '$env:ComputerName,"task", [System.IO.Pipes.PipeDirection]::Out);'
129
- $pre_cmd += '$npipeclient.connect();'
130
- $pre_cmd += '$pipeWriter = new-object System.IO.StreamWriter($npipeClient);'
131
- $pre_cmd += '$pipeWriter.AutoFlush = $true'
132
- $cmd_path = "#{remote_path_join(config[:root_path], "chef-client-script.ps1")}"
133
- $cmd_to_eval = gc $cmd_path -readcount 0 | out-string
134
- $cmd = $executioncontext.invokecommand.expandstring($cmd_to_eval) -replace '\r\n'
135
- $cmd = "$cmd | " +
136
- '% {} {$pipewriter.writeline($_)} {$pipewriter.writeline("SCHEDULED_TASK_DONE:' +
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(cmd)
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 'pry'
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) { StringIO.new }
10
- let(:logger) { Logger.new(logged_output) }
11
- let(:platform) { stub(:os_type => "windows",
12
- :shell_type => "powershell") }
13
- let(:suite) { stub(:name => "fries") }
14
- let(:transport) { { :username => "Administrator",
15
- :password => "P@ssw0rd" } }
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", :kitchen_root => "/r", :log_level => :info }
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 => { :state_file => {:hostname => "Blah"} }
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 'when username is not provided by the driver or task_username' do
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
- it 'is resolved from the transport' do
48
- provisioner.resolve_username.must_match "Administrator"
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
- describe 'when password is not provided by the driver or task_password' do
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.dev
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-09-10 00:00:00.000000000 Z
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: 1.3.1
259
+ version: '0'
260
260
  requirements: []
261
261
  rubyforge_project:
262
- rubygems_version: 2.4.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