chef-zero-scheduled-task 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b5fa275005e105d18cb6b5ec89e06cea8a93182
4
+ data.tar.gz: 345aeadb9151ac547d05c26f76fbceecc54db322
5
+ SHA512:
6
+ metadata.gz: 3d033f71ec251ec5ea44952213b93a5073b32e6b6ac0461e8d3fd8b6f4f408803fbb7fc68c820b0c24890c7340777c8474b90b3cc8e424d8125a8b9c15a55a99
7
+ data.tar.gz: 63be65cde40949e44a9af397457f5886417b5c29c5b9371648fbe238f771e95542dec0b0964205034b30f6c0f22c8fc60bcfef89b0646a5ee393207f10911fc0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chef-zero-scheduled-task.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ [![Gem Version](https://badge.fury.io/rb/chef-zero-scheduled-task.svg)](http://badge.fury.io/rb/chef-zero-scheduled-task)
2
+ # Chef::Zero::Scheduled::Task
3
+
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'chef-zero-scheduled-task'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install chef-zero-scheduled-task
21
+
22
+ ## Usage
23
+
24
+ In the .kitchen.yml
25
+ ```
26
+ provisioner:
27
+ name: chef_zero_scheduled_task
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/[my-github-username]/chef-zero-scheduled-task/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+ Rake::TestTask.new(:unit) do |t|
7
+ t.libs.push "lib"
8
+ t.test_files = FileList["spec/**/*_spec.rb"]
9
+ t.verbose = true
10
+ end
11
+
12
+ desc "Run all test suites"
13
+ task :test => [:unit]
14
+
15
+ desc "Display LOC stats"
16
+ task :stats do
17
+ puts "\n## Production Code Stats"
18
+ sh "countloc -r lib"
19
+ puts "\n## Test Code Stats"
20
+ sh "countloc -r spec"
21
+ end
22
+
23
+ require "finstyle"
24
+ require "rubocop/rake_task"
25
+ RuboCop::RakeTask.new(:style) do |task|
26
+ task.options << "--display-cop-names"
27
+ task.options << "--lint"
28
+ task.options << '--config' << '.rubocop.yml'
29
+ task.patterns = ['lib/**/*.rb']
30
+ end
31
+
32
+ require "cane/rake_task"
33
+ desc "Run cane to check quality metrics"
34
+ Cane::RakeTask.new do |cane|
35
+ cane.canefile = "./.cane"
36
+ end
37
+
38
+ desc "Run all quality tasks"
39
+ task :quality => [:cane, :style, :stats]
40
+
41
+ require "yard"
42
+ YARD::Rake::YardocTask.new
43
+
44
+ desc "Generate gem dependency graph"
45
+ task :viz do
46
+ Bundler.with_clean_env do
47
+ sh "bundle viz --without test development guard " \
48
+ "--requirements --version"
49
+ end
50
+ end
51
+
52
+ task :default => [:test, :quality]
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chef/zero/scheduled/task/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chef-zero-scheduled-task"
8
+ spec.version = Chef::Zero::Scheduled::Task::VERSION
9
+ spec.authors = ["Steven Murawski"]
10
+ spec.email = ["steven.murawski@gmail.com"]
11
+ spec.summary = "Test-Kitchen Provisioner that runs Chef Zero in a Scheduled Task"
12
+ spec.description = "Test-Kitchen Provisioner that runs Chef Zero in a Scheduled Task"
13
+ spec.homepage = "https://github.com/smurawski/chef-zero-scheduled-task"
14
+ spec.license = "Apache 2"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "pry", "~> 0.10"
24
+
25
+ spec.add_dependency "test-kitchen", "~> 1.4"
26
+ end
@@ -0,0 +1,9 @@
1
+ module Chef
2
+ module Zero
3
+ module Scheduled
4
+ module Task
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,102 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Steven Murawski (<smurawski@chef.io>)
4
+ #
5
+ # Copyright (C) 2015, Chef Software
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require "kitchen/provisioner/chef_zero"
20
+
21
+ module Kitchen
22
+
23
+ module Provisioner
24
+
25
+ # Chef Zero provisioner to run in scheduled task on Windows
26
+ class ChefZeroScheduledTask < ChefZero
27
+
28
+ kitchen_provisioner_api_version 2
29
+
30
+ plugin_version Kitchen::VERSION
31
+
32
+ def create_sandbox
33
+ super
34
+ return unless windows_os?
35
+ prepare_client_zero_script
36
+ end
37
+
38
+ def init_command
39
+ wrap_shell_code( <<-EOH
40
+ $cmd_path = "#{remote_path_join(config[:root_path], "chef-client-script.ps1")}"
41
+ $cmd_line = $executioncontext.invokecommand.expandstring("powershell -executionpolicy unrestricted -File $cmd_path")
42
+ schtasks /create /tn "chef-tk" /ru #{@instance.transport[:username]} /rp #{@instance.transport[:password]} /sc daily /st 00:00 /f /tr "$cmd_line"
43
+ EOH
44
+ )
45
+ end
46
+
47
+ #assuming a version of Chef with local mode.
48
+ def prepare_command
49
+ return unless windows_os?
50
+ info('Creating a script to run chef client.')
51
+ cmd = <<-EOH
52
+ $pre_cmd = "`$env:temp = `"$env:temp`""
53
+ $cmd_path = "#{remote_path_join(config[:root_path], "chef-client-script.ps1")}"
54
+ $cmd_to_eval = gc $cmd_path | out-string
55
+ $cmd = $executioncontext.invokecommand.expandstring($cmd_to_eval)
56
+ $pre_cmd, $cmd | out-file $cmd_path
57
+ EOH
58
+ wrap_shell_code(cmd)
59
+ end
60
+
61
+ def run_command
62
+ wrap_shell_code( <<-EOH
63
+ if (test-path 'c:/chef/tk.log') {
64
+ remove-item c:/chef/tk.log -force
65
+ }
66
+ schtasks /run /tn "chef-tk"
67
+ $host.ui.WriteLine('Running scheduled task chef-tk.')
68
+ do {
69
+ $host.ui.WriteLine(' The task is still running.')
70
+ start-sleep -seconds 5
71
+ $state = schtasks /query /tn chef-tk /fo csv /v | convertfrom-csv
72
+ } while ($state.status -like 'Running')
73
+ $host.ui.WriteLine('')
74
+ get-content c:/chef/tk.log -readcount 0
75
+ EOH
76
+ )
77
+ end
78
+
79
+ private
80
+
81
+ def prepare_client_zero_script
82
+ cmd = [local_mode_command, *chef_client_args, '--logfile c:\chef\tk.log'].join(" ")
83
+ File.open(File.join(sandbox_path, 'chef-client-script.ps1'), 'w') do |file|
84
+ file.write(cmd)
85
+ end
86
+ end
87
+
88
+ def chef_client_args
89
+ level = config[:log_level] == :info ? :info : config[:log_level]
90
+ args = [
91
+ "--config #{remote_path_join(config[:root_path], "client.rb")}",
92
+ "--log_level #{level}",
93
+ "--force-formatter",
94
+ "--no-color"
95
+ ]
96
+ add_optional_chef_client_args!(args)
97
+
98
+ args
99
+ end
100
+ end
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-zero-scheduled-task
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Murawski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-kitchen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ description: Test-Kitchen Provisioner that runs Chef Zero in a Scheduled Task
70
+ email:
71
+ - steven.murawski@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - chef-zero-scheduled-task.gemspec
81
+ - lib/chef/zero/scheduled/task/version.rb
82
+ - lib/kitchen/provisioner/chef_zero_scheduled_task.rb
83
+ homepage: https://github.com/smurawski/chef-zero-scheduled-task
84
+ licenses:
85
+ - Apache 2
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.4
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Test-Kitchen Provisioner that runs Chef Zero in a Scheduled Task
107
+ test_files: []
108
+ has_rdoc: