madscience 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.madscience_gem_location +0 -0
- data/Cheffile +9 -0
- data/Cheffile.lock +34 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +9 -0
- data/README.md +126 -0
- data/Rakefile +1 -0
- data/TODO +17 -0
- data/bin/madscience +90 -0
- data/cookbooks/apt/CHANGELOG.md +183 -0
- data/cookbooks/apt/README.md +255 -0
- data/cookbooks/apt/attributes/default.rb +29 -0
- data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
- data/cookbooks/apt/libraries/helpers.rb +49 -0
- data/cookbooks/apt/libraries/matchers.rb +17 -0
- data/cookbooks/apt/libraries/network.rb +31 -0
- data/cookbooks/apt/metadata.json +54 -0
- data/cookbooks/apt/metadata.rb +34 -0
- data/cookbooks/apt/providers/preference.rb +63 -0
- data/cookbooks/apt/providers/repository.rb +150 -0
- data/cookbooks/apt/recipes/cacher-client.rb +81 -0
- data/cookbooks/apt/recipes/cacher-ng.rb +43 -0
- data/cookbooks/apt/recipes/default.rb +91 -0
- data/cookbooks/apt/resources/preference.rb +32 -0
- data/cookbooks/apt/resources/repository.rb +43 -0
- data/cookbooks/apt/templates/debian-6.0/acng.conf.erb +173 -0
- data/cookbooks/apt/templates/default/01proxy.erb +5 -0
- data/cookbooks/apt/templates/default/acng.conf.erb +275 -0
- data/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +269 -0
- data/cookbooks/chef_handler/CHANGELOG.md +44 -0
- data/cookbooks/chef_handler/README.md +103 -0
- data/cookbooks/chef_handler/attributes/default.rb +30 -0
- data/cookbooks/chef_handler/files/default/handlers/README +1 -0
- data/cookbooks/chef_handler/libraries/matchers.rb +29 -0
- data/cookbooks/chef_handler/metadata.json +29 -0
- data/cookbooks/chef_handler/metadata.rb +7 -0
- data/cookbooks/chef_handler/providers/default.rb +97 -0
- data/cookbooks/chef_handler/recipes/default.rb +33 -0
- data/cookbooks/chef_handler/recipes/json_file.rb +28 -0
- data/cookbooks/chef_handler/resources/default.rb +34 -0
- data/cookbooks/dmg/CHANGELOG.md +75 -0
- data/cookbooks/dmg/README.md +143 -0
- data/cookbooks/dmg/attributes/default.rb +20 -0
- data/cookbooks/dmg/metadata.json +30 -0
- data/cookbooks/dmg/metadata.rb +9 -0
- data/cookbooks/dmg/providers/package.rb +91 -0
- data/cookbooks/dmg/recipes/default.rb +18 -0
- data/cookbooks/dmg/resources/package.rb +37 -0
- data/cookbooks/vagrant/Berksfile +2 -0
- data/cookbooks/vagrant/CHANGELOG.md +7 -0
- data/cookbooks/vagrant/README.md +146 -0
- data/cookbooks/vagrant/TESTING.md +25 -0
- data/cookbooks/vagrant/attributes/default.rb +22 -0
- data/cookbooks/vagrant/metadata.rb +14 -0
- data/cookbooks/vagrant/providers/plugin.rb +50 -0
- data/cookbooks/vagrant/recipes/debian.rb +9 -0
- data/cookbooks/vagrant/recipes/default.rb +34 -0
- data/cookbooks/vagrant/recipes/fedora.rb +1 -0
- data/cookbooks/vagrant/recipes/mac_os_x.rb +7 -0
- data/cookbooks/vagrant/recipes/rhel.rb +9 -0
- data/cookbooks/vagrant/recipes/uninstall_gem.rb +7 -0
- data/cookbooks/vagrant/recipes/windows.rb +5 -0
- data/cookbooks/vagrant/resources/plugin.rb +8 -0
- data/cookbooks/virtualbox/README.md +167 -0
- data/cookbooks/virtualbox/attributes/default.rb +32 -0
- data/cookbooks/virtualbox/attributes/user.rb +22 -0
- data/cookbooks/virtualbox/attributes/webportal.rb +22 -0
- data/cookbooks/virtualbox/attributes/webservice.rb +24 -0
- data/cookbooks/virtualbox/files/ubuntu/machines_enabled +1 -0
- data/cookbooks/virtualbox/files/ubuntu/vboxcontrol +104 -0
- data/cookbooks/virtualbox/libraries/helpers.rb +30 -0
- data/cookbooks/virtualbox/metadata.rb +16 -0
- data/cookbooks/virtualbox/recipes/default.rb +70 -0
- data/cookbooks/virtualbox/recipes/systemservice.rb +56 -0
- data/cookbooks/virtualbox/recipes/user.rb +39 -0
- data/cookbooks/virtualbox/recipes/webportal.rb +58 -0
- data/cookbooks/virtualbox/recipes/webservice.rb +44 -0
- data/cookbooks/virtualbox/templates/ubuntu/config.erb +3 -0
- data/cookbooks/virtualbox/templates/ubuntu/config.php.erb +183 -0
- data/cookbooks/virtualbox/templates/ubuntu/vbox.cfg.erb +51 -0
- data/cookbooks/windows/CHANGELOG.md +268 -0
- data/cookbooks/windows/README.md +665 -0
- data/cookbooks/windows/attributes/default.rb +23 -0
- data/cookbooks/windows/files/default/handlers/windows_reboot_handler.rb +76 -0
- data/cookbooks/windows/libraries/feature_base.rb +59 -0
- data/cookbooks/windows/libraries/matchers.rb +450 -0
- data/cookbooks/windows/libraries/powershell_helper.rb +59 -0
- data/cookbooks/windows/libraries/powershell_out.rb +79 -0
- data/cookbooks/windows/libraries/registry_helper.rb +357 -0
- data/cookbooks/windows/libraries/version.rb +206 -0
- data/cookbooks/windows/libraries/windows_architecture_helper.rb +86 -0
- data/cookbooks/windows/libraries/windows_helper.rb +88 -0
- data/cookbooks/windows/libraries/windows_privileged.rb +94 -0
- data/cookbooks/windows/metadata.json +31 -0
- data/cookbooks/windows/metadata.rb +9 -0
- data/cookbooks/windows/providers/auto_run.rb +32 -0
- data/cookbooks/windows/providers/batch.rb +62 -0
- data/cookbooks/windows/providers/feature_dism.rb +64 -0
- data/cookbooks/windows/providers/feature_powershell.rb +38 -0
- data/cookbooks/windows/providers/feature_servermanagercmd.rb +47 -0
- data/cookbooks/windows/providers/package.rb +252 -0
- data/cookbooks/windows/providers/pagefile.rb +153 -0
- data/cookbooks/windows/providers/path.rb +35 -0
- data/cookbooks/windows/providers/printer.rb +100 -0
- data/cookbooks/windows/providers/printer_port.rb +102 -0
- data/cookbooks/windows/providers/reboot.rb +31 -0
- data/cookbooks/windows/providers/registry.rb +72 -0
- data/cookbooks/windows/providers/shortcut.rb +56 -0
- data/cookbooks/windows/providers/task.rb +128 -0
- data/cookbooks/windows/providers/zipfile.rb +91 -0
- data/cookbooks/windows/recipes/default.rb +34 -0
- data/cookbooks/windows/recipes/reboot_handler.rb +32 -0
- data/cookbooks/windows/resources/auto_run.rb +30 -0
- data/cookbooks/windows/resources/batch.rb +36 -0
- data/cookbooks/windows/resources/feature.rb +44 -0
- data/cookbooks/windows/resources/package.rb +46 -0
- data/cookbooks/windows/resources/pagefile.rb +29 -0
- data/cookbooks/windows/resources/path.rb +28 -0
- data/cookbooks/windows/resources/printer.rb +41 -0
- data/cookbooks/windows/resources/printer_port.rb +40 -0
- data/cookbooks/windows/resources/reboot.rb +29 -0
- data/cookbooks/windows/resources/registry.rb +34 -0
- data/cookbooks/windows/resources/shortcut.rb +35 -0
- data/cookbooks/windows/resources/task.rb +50 -0
- data/cookbooks/windows/resources/zipfile.rb +33 -0
- data/cookbooks/yum/CHANGELOG.md +212 -0
- data/cookbooks/yum/README.md +268 -0
- data/cookbooks/yum/attributes/main.rb +97 -0
- data/cookbooks/yum/libraries/matchers.rb +27 -0
- data/cookbooks/yum/metadata.json +34 -0
- data/cookbooks/yum/metadata.rb +13 -0
- data/cookbooks/yum/providers/globalconfig.rb +37 -0
- data/cookbooks/yum/providers/repository.rb +85 -0
- data/cookbooks/yum/recipes/default.rb +34 -0
- data/cookbooks/yum/resources/globalconfig.rb +105 -0
- data/cookbooks/yum/resources/repository.rb +63 -0
- data/cookbooks/yum/templates/default/main.erb +251 -0
- data/cookbooks/yum/templates/default/repo.erb +109 -0
- data/lib/madscience/version.rb +3 -0
- data/lib/madscience.rb +5 -0
- data/madscience.gemspec +44 -0
- data/new_gem_version.rb +6 -0
- data/node-data.json +3 -0
- data/site-cookbooks/madscience-vagrant-cookbook/CHANGELOG.md +13 -0
- data/site-cookbooks/madscience-vagrant-cookbook/README.md +53 -0
- data/site-cookbooks/madscience-vagrant-cookbook/metadata.rb +17 -0
- data/site-cookbooks/madscience-vagrant-cookbook/recipes/default.rb +87 -0
- data/solo.rb +6 -0
- metadata +337 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, 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
|
+
class WindowsRebootHandler < Chef::Handler
|
20
|
+
include Chef::Mixin::ShellOut
|
21
|
+
|
22
|
+
def initialize(allow_pending_reboots = true, timeout = 60, reason = "Opscode Chef initiated reboot")
|
23
|
+
@allow_pending_reboots = allow_pending_reboots
|
24
|
+
@timeout = timeout
|
25
|
+
@reason = reason
|
26
|
+
end
|
27
|
+
|
28
|
+
def report
|
29
|
+
log_message, reboot = begin
|
30
|
+
if reboot_requested?
|
31
|
+
["chef_handler[#{self.class}] requested reboot will occur in #{timeout} seconds", true]
|
32
|
+
elsif reboot_pending?
|
33
|
+
if @allow_pending_reboots
|
34
|
+
["chef_handler[#{self.class}] reboot pending - automatic reboot will occur in #{timeout} seconds", true]
|
35
|
+
else
|
36
|
+
["chef_handler[#{self.class}] reboot pending but handler not configured to act on pending reboots - please reboot node manually", false]
|
37
|
+
end
|
38
|
+
else
|
39
|
+
["chef_handler[#{self.class}] no reboot requested or pending", false]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Chef::Log.warn(log_message)
|
44
|
+
shell_out!("shutdown /r /t #{timeout} /c \"#{reason}\"") if reboot
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
# reboot cause CHEF says so:
|
49
|
+
# reboot explicitly requested in our cookbook code
|
50
|
+
def reboot_requested?
|
51
|
+
node.run_state[:reboot_requested] == true
|
52
|
+
end
|
53
|
+
|
54
|
+
# reboot cause WIN says so:
|
55
|
+
# reboot pending because of some configuration action we performed
|
56
|
+
def reboot_pending?
|
57
|
+
# Any files listed here means reboot needed
|
58
|
+
(Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations') &&
|
59
|
+
Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations').any?) ||
|
60
|
+
# 1 for any value means reboot pending
|
61
|
+
# "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1
|
62
|
+
(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') &&
|
63
|
+
Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired').select{|v| v[2] == 1 }.any?) ||
|
64
|
+
# 1 or 2 for 'Flags' value means reboot pending
|
65
|
+
(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
|
66
|
+
[1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags')))
|
67
|
+
end
|
68
|
+
|
69
|
+
def timeout
|
70
|
+
node.run_state[:reboot_timeout] || node['windows']['reboot_timeout'] || @timeout
|
71
|
+
end
|
72
|
+
|
73
|
+
def reason
|
74
|
+
node.run_state[:reboot_reason] || @reason
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Chef
|
2
|
+
class Provider
|
3
|
+
class WindowsFeature
|
4
|
+
module Base
|
5
|
+
|
6
|
+
def action_install
|
7
|
+
unless installed?
|
8
|
+
install_feature(@new_resource.feature_name)
|
9
|
+
@new_resource.updated_by_last_action(true)
|
10
|
+
Chef::Log.info("#{@new_resource} installed feature")
|
11
|
+
else
|
12
|
+
Chef::Log.debug("#{@new_resource} is already installed - nothing to do")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def action_remove
|
17
|
+
if installed?
|
18
|
+
remove_feature(@new_resource.feature_name)
|
19
|
+
@new_resource.updated_by_last_action(true)
|
20
|
+
Chef::Log.info("#{@new_resource} removed")
|
21
|
+
else
|
22
|
+
Chef::Log.debug("#{@new_resource} feature does not exist - nothing to do")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def action_delete
|
27
|
+
if available?
|
28
|
+
delete_feature(@new_resource.feature_name)
|
29
|
+
@new_resource.updated_by_last_action(true)
|
30
|
+
Chef::Log.info("#{@new_resource} deleted")
|
31
|
+
else
|
32
|
+
Chef::Log.debug("#{@new_resource} feature is not installed - nothing to do")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def install_feature(name)
|
37
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_feature(name)
|
41
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_feature(name)
|
45
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :delete"
|
46
|
+
end
|
47
|
+
|
48
|
+
def installed?
|
49
|
+
raise Chef::Exceptions::Override, "You must override installed? in #{self.to_s}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def available?
|
53
|
+
raise Chef::Exceptions::Override, "You must override available? in #{self.to_s}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,450 @@
|
|
1
|
+
if defined?(ChefSpec)
|
2
|
+
|
3
|
+
#
|
4
|
+
# Assert that a +windows_package+ resource exists in the Chef run with the
|
5
|
+
# action +:install+. Given a Chef Recipe that installs "Node.js" as a
|
6
|
+
# +windows_package+:
|
7
|
+
#
|
8
|
+
# windows_package 'Node.js' do
|
9
|
+
# source 'http://nodejs.org/dist/v0.10.26/x64/node-v0.10.26-x64.msi'
|
10
|
+
# action :install
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# The Examples section demonstrates the different ways to test a
|
14
|
+
# +windows_package+ resource with ChefSpec.
|
15
|
+
#
|
16
|
+
# @example Assert that a +windows_package+ was installed
|
17
|
+
# expect(chef_run).to install_windows_package('Node.js')
|
18
|
+
#
|
19
|
+
# @example Assert that a +windows_package+ was _not_ installed
|
20
|
+
# expect(chef_run).to_not install_windows_package('7-zip')
|
21
|
+
#
|
22
|
+
#
|
23
|
+
# @param [String, Regex] resource_name
|
24
|
+
# the name of the resource to match
|
25
|
+
#
|
26
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
27
|
+
#
|
28
|
+
def install_windows_package(resource_name)
|
29
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_package, :install, resource_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Assert that a +windows_package+ resource exists in the Chef run with the
|
34
|
+
# action +:remove+. Given a Chef Recipe that removes "Node.js" as a
|
35
|
+
# +windows_package+:
|
36
|
+
#
|
37
|
+
# windows_package 'Node.js' do
|
38
|
+
# action :remove
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# The Examples section demonstrates the different ways to test a
|
42
|
+
# +windows_package+ resource with ChefSpec.
|
43
|
+
#
|
44
|
+
# @example Assert that a +windows_package+ was installed
|
45
|
+
# expect(chef_run).to remove_windows_package('Node.js')
|
46
|
+
#
|
47
|
+
# @example Assert that a +windows_package+ was _not_ removed
|
48
|
+
# expect(chef_run).to_not remove_windows_package('7-zip')
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# @param [String, Regex] resource_name
|
52
|
+
# the name of the resource to match
|
53
|
+
#
|
54
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
55
|
+
#
|
56
|
+
def remove_windows_package(resource_name)
|
57
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_package, :remove, resource_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
#
|
63
|
+
# Assert that a +windows_feature+ resource exists in the Chef run with the
|
64
|
+
# action +:install+. Given a Chef Recipe that installs "NetFX3" as a
|
65
|
+
# +windows_feature+:
|
66
|
+
#
|
67
|
+
# windows_feature 'NetFX3' do
|
68
|
+
# action :install
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# The Examples section demonstrates the different ways to test a
|
72
|
+
# +windows_feature+ resource with ChefSpec.
|
73
|
+
#
|
74
|
+
# @example Assert that a +windows_feature+ was installed
|
75
|
+
# expect(chef_run).to install_windows_feature('NetFX3')
|
76
|
+
#
|
77
|
+
# @example Assert that a +windows_feature+ was _not_ installed
|
78
|
+
# expect(chef_run).to_not install_windows_feature('NetFX3')
|
79
|
+
#
|
80
|
+
#
|
81
|
+
# @param [String, Regex] resource_name
|
82
|
+
# the name of the resource to match
|
83
|
+
#
|
84
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
85
|
+
#
|
86
|
+
def install_windows_feature(resource_name)
|
87
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_feature, :install, resource_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Assert that a +windows_feature+ resource exists in the Chef run with the
|
92
|
+
# action +:remove+. Given a Chef Recipe that removes "NetFX3" as a
|
93
|
+
# +windows_feature+:
|
94
|
+
#
|
95
|
+
# windows_feature 'NetFX3' do
|
96
|
+
# action :remove
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# The Examples section demonstrates the different ways to test a
|
100
|
+
# +windows_feature+ resource with ChefSpec.
|
101
|
+
#
|
102
|
+
# @example Assert that a +windows_feature+ was removed
|
103
|
+
# expect(chef_run).to remove_windows_feature('NetFX3')
|
104
|
+
#
|
105
|
+
#
|
106
|
+
# @param [String, Regex] resource_name
|
107
|
+
# the name of the resource to match
|
108
|
+
#
|
109
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
110
|
+
#
|
111
|
+
def remove_windows_feature(resource_name)
|
112
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_feature, :remove, resource_name)
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# Assert that a +windows_feature+ resource exists in the Chef run with the
|
117
|
+
# action +:delete+. Given a Chef Recipe that deletes "NetFX3" as a
|
118
|
+
# +windows_feature+:
|
119
|
+
#
|
120
|
+
# windows_feature 'NetFX3' do
|
121
|
+
# action :delete
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# The Examples section demonstrates the different ways to test a
|
125
|
+
# +windows_feature+ resource with ChefSpec.
|
126
|
+
#
|
127
|
+
# @example Assert that a +windows_feature+ was deleted
|
128
|
+
# expect(chef_run).to delete_windows_feature('NetFX3')
|
129
|
+
#
|
130
|
+
#
|
131
|
+
# @param [String, Regex] resource_name
|
132
|
+
# the name of the resource to match
|
133
|
+
#
|
134
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
135
|
+
#
|
136
|
+
def delete_windows_feature(resource_name)
|
137
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_feature, :delete, resource_name)
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
#
|
143
|
+
# Assert that a +windows_task+ resource exists in the Chef run with the
|
144
|
+
# action +:create+. Given a Chef Recipe that creates "mytask" as a
|
145
|
+
# +windows_task+:
|
146
|
+
#
|
147
|
+
# windows_task 'mytask' do
|
148
|
+
# command 'mybatch.bat'
|
149
|
+
# action :create
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# The Examples section demonstrates the different ways to test a
|
153
|
+
# +windows_task+ resource with ChefSpec.
|
154
|
+
#
|
155
|
+
# @example Assert that a +windows_task+ was created
|
156
|
+
# expect(chef_run).to create_windows_task('mytask')
|
157
|
+
#
|
158
|
+
#
|
159
|
+
# @param [String, Regex] resource_name
|
160
|
+
# the name of the resource to match
|
161
|
+
#
|
162
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
163
|
+
#
|
164
|
+
def create_windows_task(resource_name)
|
165
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_task, :create, resource_name)
|
166
|
+
end
|
167
|
+
|
168
|
+
#
|
169
|
+
# Assert that a +windows_task+ resource exists in the Chef run with the
|
170
|
+
# action +:delete+. Given a Chef Recipe that deletes "mytask" as a
|
171
|
+
# +windows_task+:
|
172
|
+
#
|
173
|
+
# windows_task 'mytask' do
|
174
|
+
# action :delete
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# The Examples section demonstrates the different ways to test a
|
178
|
+
# +windows_task+ resource with ChefSpec.
|
179
|
+
#
|
180
|
+
# @example Assert that a +windows_task+ was deleted
|
181
|
+
# expect(chef_run).to delete_windows_task('mytask')
|
182
|
+
#
|
183
|
+
#
|
184
|
+
# @param [String, Regex] resource_name
|
185
|
+
# the name of the resource to match
|
186
|
+
#
|
187
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
188
|
+
#
|
189
|
+
def delete_windows_task(resource_name)
|
190
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_task, :delete, resource_name)
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# Assert that a +windows_task+ resource exists in the Chef run with the
|
195
|
+
# action +:run+. Given a Chef Recipe that runs "mytask" as a
|
196
|
+
# +windows_task+:
|
197
|
+
#
|
198
|
+
# windows_task 'mytask' do
|
199
|
+
# action :run
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# The Examples section demonstrates the different ways to test a
|
203
|
+
# +windows_task+ resource with ChefSpec.
|
204
|
+
#
|
205
|
+
# @example Assert that a +windows_task+ was run
|
206
|
+
# expect(chef_run).to run_windows_task('mytask')
|
207
|
+
#
|
208
|
+
#
|
209
|
+
# @param [String, Regex] resource_name
|
210
|
+
# the name of the resource to match
|
211
|
+
#
|
212
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
213
|
+
#
|
214
|
+
def run_windows_task(resource_name)
|
215
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_task, :run, resource_name)
|
216
|
+
end
|
217
|
+
|
218
|
+
#
|
219
|
+
# Assert that a +windows_task+ resource exists in the Chef run with the
|
220
|
+
# action +:change+. Given a Chef Recipe that changes "mytask" as a
|
221
|
+
# +windows_task+:
|
222
|
+
#
|
223
|
+
# windows_task 'mytask' do
|
224
|
+
# action :change
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# The Examples section demonstrates the different ways to test a
|
228
|
+
# +windows_task+ resource with ChefSpec.
|
229
|
+
#
|
230
|
+
# @example Assert that a +windows_task+ was changed
|
231
|
+
# expect(chef_run).to change_windows_task('mytask')
|
232
|
+
#
|
233
|
+
#
|
234
|
+
# @param [String, Regex] resource_name
|
235
|
+
# the name of the resource to match
|
236
|
+
#
|
237
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
238
|
+
#
|
239
|
+
def change_windows_task(resource_name)
|
240
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_task, :change, resource_name)
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
#
|
246
|
+
# Assert that a +windows_path+ resource exists in the Chef run with the
|
247
|
+
# action +:add+. Given a Chef Recipe that adds "C:\7-Zip" to the Windows
|
248
|
+
# PATH env var
|
249
|
+
#
|
250
|
+
# windows_path 'C:\7-Zip' do
|
251
|
+
# action :add
|
252
|
+
# end
|
253
|
+
#
|
254
|
+
# The Examples section demonstrates the different ways to test a
|
255
|
+
# +windows_path+ resource with ChefSpec.
|
256
|
+
#
|
257
|
+
# @example Assert that a +windows_path+ was added
|
258
|
+
# expect(chef_run).to add_windows_path('C:\7-Zip')
|
259
|
+
#
|
260
|
+
#
|
261
|
+
# @param [String, Regex] resource_name
|
262
|
+
# the name of the resource to match
|
263
|
+
#
|
264
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
265
|
+
#
|
266
|
+
def add_windows_path(resource_name)
|
267
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_path, :add, resource_name)
|
268
|
+
end
|
269
|
+
|
270
|
+
#
|
271
|
+
# Assert that a +windows_path+ resource exists in the Chef run with the
|
272
|
+
# action +:remove+. Given a Chef Recipe that removes "C:\7-Zip" from the
|
273
|
+
# Windows PATH env var
|
274
|
+
#
|
275
|
+
# windows_path 'C:\7-Zip' do
|
276
|
+
# action :remove
|
277
|
+
# end
|
278
|
+
#
|
279
|
+
# The Examples section demonstrates the different ways to test a
|
280
|
+
# +windows_path+ resource with ChefSpec.
|
281
|
+
#
|
282
|
+
# @example Assert that a +windows_path+ was removed
|
283
|
+
# expect(chef_run).to remove_windows_path('C:\7-Zip')
|
284
|
+
#
|
285
|
+
#
|
286
|
+
# @param [String, Regex] resource_name
|
287
|
+
# the name of the resource to match
|
288
|
+
#
|
289
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
290
|
+
#
|
291
|
+
def remove_windows_path(resource_name)
|
292
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_path, :remove, resource_name)
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
#
|
298
|
+
# Assert that a +windows_batch+ resource exists in the Chef run with the
|
299
|
+
# action +:run+. Given a Chef Recipe that runs a batch script
|
300
|
+
#
|
301
|
+
# windows_batch "unzip_and_move_ruby" do
|
302
|
+
# code <<-EOH
|
303
|
+
# 7z.exe x #{Chef::Config[:file_cache_path]}/ruby-1.8.7-p352-i386-mingw32.7z
|
304
|
+
# -oC:\\source -r -y
|
305
|
+
# xcopy C:\\source\\ruby-1.8.7-p352-i386-mingw32 C:\\ruby /e /y
|
306
|
+
# EOH
|
307
|
+
# end
|
308
|
+
#
|
309
|
+
# The Examples section demonstrates the different ways to test a
|
310
|
+
# +windows_path+ resource with ChefSpec.
|
311
|
+
#
|
312
|
+
# @example Assert that a +windows_path+ was removed
|
313
|
+
# expect(chef_run).to run_windows_batch('unzip_and_move_ruby')
|
314
|
+
#
|
315
|
+
#
|
316
|
+
# @param [String, Regex] resource_name
|
317
|
+
# the name of the resource to match
|
318
|
+
#
|
319
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
320
|
+
#
|
321
|
+
def run_windows_batch(resource_name)
|
322
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_batch, :run, resource_name)
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
#
|
328
|
+
# Assert that a +windows_pagefile+ resource exists in the Chef run with the
|
329
|
+
# action +:set+. Given a Chef Recipe that sets a pagefile
|
330
|
+
#
|
331
|
+
# windows_pagefile "pagefile" do
|
332
|
+
# system_managed true
|
333
|
+
# initial_size 1024
|
334
|
+
# maximum_size 4096
|
335
|
+
# end
|
336
|
+
#
|
337
|
+
# The Examples section demonstrates the different ways to test a
|
338
|
+
# +windows_pagefile+ resource with ChefSpec.
|
339
|
+
#
|
340
|
+
# @example Assert that a +windows_pagefile+ was set
|
341
|
+
# expect(chef_run).to set_windows_pagefile('pagefile').with(
|
342
|
+
# initial_size: 1024)
|
343
|
+
#
|
344
|
+
#
|
345
|
+
# @param [String, Regex] resource_name
|
346
|
+
# the name of the resource to match
|
347
|
+
#
|
348
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
349
|
+
#
|
350
|
+
def set_windows_pagefile(resource_name)
|
351
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_pagefile, :set, resource_name)
|
352
|
+
end
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
#
|
357
|
+
# Assert that a +windows_zipfile+ resource exists in the Chef run with the
|
358
|
+
# action +:unzip+. Given a Chef Recipe that extracts "SysinternalsSuite.zip"
|
359
|
+
# to c:/bin
|
360
|
+
#
|
361
|
+
# windows_zipfile "c:/bin" do
|
362
|
+
# source "http://download.sysinternals.com/Files/SysinternalsSuite.zip"
|
363
|
+
# action :unzip
|
364
|
+
# not_if {::File.exists?("c:/bin/PsExec.exe")}
|
365
|
+
# end
|
366
|
+
#
|
367
|
+
# The Examples section demonstrates the different ways to test a
|
368
|
+
# +windows_zipfile+ resource with ChefSpec.
|
369
|
+
#
|
370
|
+
# @example Assert that a +windows_zipfile+ was unzipped
|
371
|
+
# expect(chef_run).to unzip_windows_zipfile_to('c:/bin')
|
372
|
+
#
|
373
|
+
#
|
374
|
+
# @param [String, Regex] resource_name
|
375
|
+
# the name of the resource to match
|
376
|
+
#
|
377
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
378
|
+
#
|
379
|
+
def unzip_windows_zipfile_to(resource_name)
|
380
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_zipfile, :unzip, resource_name)
|
381
|
+
end
|
382
|
+
|
383
|
+
#
|
384
|
+
# Assert that a +windows_zipfile+ resource exists in the Chef run with the
|
385
|
+
# action +:zip+. Given a Chef Recipe that zips "c:/src"
|
386
|
+
# to c:/code.zip
|
387
|
+
#
|
388
|
+
# windows_zipfile "c:/code.zip" do
|
389
|
+
# source "c:/src"
|
390
|
+
# action :zip
|
391
|
+
# end
|
392
|
+
#
|
393
|
+
# The Examples section demonstrates the different ways to test a
|
394
|
+
# +windows_zipfile+ resource with ChefSpec.
|
395
|
+
#
|
396
|
+
# @example Assert that a +windows_zipfile+ was zipped
|
397
|
+
# expect(chef_run).to zip_windows_zipfile_to('c:/code.zip')
|
398
|
+
#
|
399
|
+
#
|
400
|
+
# @param [String, Regex] resource_name
|
401
|
+
# the name of the resource to match
|
402
|
+
#
|
403
|
+
# @return [ChefSpec::Matchers::ResourceMatcher]
|
404
|
+
#
|
405
|
+
def zip_windows_zipfile_to(resource_name)
|
406
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_zipfile, :zip, resource_name)
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
# All the other less commonly used LWRPs
|
411
|
+
def create_windows_shortcut(resource_name)
|
412
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_shortcut, :create, resource_name)
|
413
|
+
end
|
414
|
+
|
415
|
+
def create_windows_auto_run(resource_name)
|
416
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_auto_run, :create, resource_name)
|
417
|
+
end
|
418
|
+
|
419
|
+
def remove_windows_auto_run(resource_name)
|
420
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_auto_run, :remove, resource_name)
|
421
|
+
end
|
422
|
+
|
423
|
+
def create_windows_printer(resource_name)
|
424
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_printer, :create, resource_name)
|
425
|
+
end
|
426
|
+
|
427
|
+
def delete_windows_printer(resource_name)
|
428
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_printer, :delete, resource_name)
|
429
|
+
end
|
430
|
+
|
431
|
+
def create_windows_printer_port(resource_name)
|
432
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_printer_port, :create, resource_name)
|
433
|
+
end
|
434
|
+
|
435
|
+
def delete_windows_printer_port(resource_name)
|
436
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_printer_port, :delete, resource_name)
|
437
|
+
end
|
438
|
+
|
439
|
+
def request_windows_reboot(resource_name)
|
440
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_reboot, :request, resource_name)
|
441
|
+
end
|
442
|
+
|
443
|
+
def cancel_windows_reboot(resource_name)
|
444
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_reboot, :cancel, resource_name)
|
445
|
+
end
|
446
|
+
|
447
|
+
def create_windows_shortcut(resource_name)
|
448
|
+
ChefSpec::Matchers::ResourceMatcher.new(:windows_shortcut, :create, resource_name)
|
449
|
+
end
|
450
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Cookbook Name:: windows
|
4
|
+
# Library:: helper
|
5
|
+
#
|
6
|
+
# Copyright:: 2011, Opscode, Inc.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'chef/mixin/shell_out'
|
22
|
+
|
23
|
+
module Powershell
|
24
|
+
module Helper
|
25
|
+
include Chef::Mixin::ShellOut
|
26
|
+
|
27
|
+
def powershell_installed?
|
28
|
+
!powershell_version.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def interpreter
|
32
|
+
# force 64-bit powershell from 32-bit ruby process
|
33
|
+
if ::File.exist?("#{ENV['WINDIR']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
|
34
|
+
"#{ENV['WINDIR']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
|
35
|
+
elsif ::File.exist?("#{ENV['WINDIR']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
|
36
|
+
"#{ENV['WINDIR']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
|
37
|
+
else
|
38
|
+
"powershell.exe"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def powershell_version
|
43
|
+
begin
|
44
|
+
cmd = shell_out("#{interpreter} -InputFormat none -Command \"& echo $PSVersionTable.psversion.major\"")
|
45
|
+
if cmd.stdout.empty? # PowerShell 1.0 doesn't have a $PSVersionTable
|
46
|
+
1
|
47
|
+
else
|
48
|
+
if cmd.stdout =~ /^(\d+)/
|
49
|
+
$1.to_i
|
50
|
+
else
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
rescue Errno::ENOENT
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|