ridley-connectors 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/ridley-connectors/command_context.rb +1 -16
- data/lib/ridley-connectors/command_context/unix_update_omnibus.rb +60 -0
- data/lib/ridley-connectors/command_context/windows_update_omnibus.rb +144 -0
- data/lib/ridley-connectors/host_commander.rb +27 -0
- data/lib/ridley-connectors/host_connector/ssh.rb +31 -0
- data/lib/ridley-connectors/host_connector/winrm.rb +5 -0
- data/lib/ridley-connectors/resources/node_resource.rb +29 -0
- data/lib/ridley-connectors/version.rb +1 -1
- data/scripts/unix_update_omnibus.erb +78 -0
- data/scripts/windows_update_omnibus.erb +30 -0
- data/spec/unit/ridley-connectors/command_context/unix_uninstall_spec.rb +37 -0
- data/spec/unit/ridley-connectors/command_context/unix_update_omnibus_spec.rb +98 -0
- data/spec/unit/ridley-connectors/command_context/windows>update_omnibus_spec.rb +92 -0
- data/spec/unit/ridley-connectors/command_context_spec.rb +0 -23
- data/spec/unit/ridley-connectors/host_connector/ssh_spec.rb +28 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75a45b3d5ebe84723f39a4eab4449f2d62232a7e
|
4
|
+
data.tar.gz: c35e78280d736f252028d9a167092d8bdfe85b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d55c6296fc29e58250b15c4d80dc01eda0efd20014c8beb2e5ca707145cc8824251a0350e6fb470b319dbc1e05d65f2404ec0a2ff56dc98984cfb8d0bab36e85
|
7
|
+
data.tar.gz: c7bbc2ae0143b1db7c5c6bc52a4fc5b8c848fe8b753a3853098f6f7d851324e25cd485791ecb4b7b5c9eed452cc0053ee2263820f7e1ce9cdf09990f85ce94ef
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## v.2.2.0
|
2
|
+
|
3
|
+
* [#27](https://github.com/RiotGames/ridley-connectors/pull/27) New upgrade_omnibus feature for updating a node's Omnibus installation of Chef
|
4
|
+
|
1
5
|
## v.2.1.2
|
2
6
|
|
3
7
|
* [#25](https://github.com/RiotGames/ridley-connectors/pull/25) Fix an edge case in the connector_for logic from #22
|
@@ -49,22 +49,7 @@ module Ridley
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# A command context for Unix based OSes
|
52
|
-
class Unix < Base
|
53
|
-
# @return [Boolean]
|
54
|
-
attr_reader :sudo
|
55
|
-
|
56
|
-
# @option options [Boolean] :sudo (true)
|
57
|
-
# bootstrap with sudo (default: true)
|
58
|
-
def initialize(options = {})
|
59
|
-
options = options.reverse_merge(sudo: true)
|
60
|
-
@sudo = options[:sudo]
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [String]
|
64
|
-
def command
|
65
|
-
sudo ? "sudo #{super}" : super
|
66
|
-
end
|
67
|
-
end
|
52
|
+
class Unix < Base; end
|
68
53
|
|
69
54
|
# A command context for Windows based OSes
|
70
55
|
class Windows < Base; end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Ridley
|
2
|
+
module CommandContext
|
3
|
+
# Context class for generating an upgrade command for an Omnibus Chef installation on Unix based OSes
|
4
|
+
class UnixUpdateOmnibus < CommandContext::Unix
|
5
|
+
template_file 'unix_update_omnibus'
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :chef_version
|
9
|
+
|
10
|
+
# @return [Boolean]
|
11
|
+
attr_reader :prerelease
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :direct_url
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
super(options)
|
18
|
+
options = options.reverse_merge(chef_version: "latest", prerelease: false)
|
19
|
+
@chef_version = options[:chef_version]
|
20
|
+
@prerelease = options[:prerelease]
|
21
|
+
@direct_url = options[:direct_url]
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def update_dir
|
26
|
+
"/tmp"
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
def recipe_path
|
31
|
+
File.join(update_dir, "default.rb")
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
def upgrade_solo_rb_path
|
36
|
+
File.join(update_dir, "upgrade_solo.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
def tmp_cookbook_path
|
41
|
+
File.join(update_dir, "cookbooks")
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def tmp_cookbook
|
46
|
+
File.join(tmp_cookbook_path, "upgrade_omnibus")
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String]
|
50
|
+
def chef_solo_command
|
51
|
+
"chef-solo -c #{upgrade_solo_rb_path} -o upgrade_omnibus"
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
def chef_apply_command
|
56
|
+
"chef-apply #{recipe_path}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module Ridley
|
2
|
+
module CommandContext
|
3
|
+
# Context class for generating an upgrade command for an Omnibus Chef installation on Windows based OSes
|
4
|
+
class WindowsUpdateOmnibus < CommandContext::Windows
|
5
|
+
template_file 'windows_update_omnibus'
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :chef_version
|
9
|
+
|
10
|
+
# @return [Boolean]
|
11
|
+
attr_reader :prerelease
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :direct_url
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
super(options)
|
18
|
+
options = options.reverse_merge(chef_version: "latest", prerelease: false)
|
19
|
+
@chef_version = options[:chef_version]
|
20
|
+
@prerelease = options[:prerelease]
|
21
|
+
@direct_url = options[:direct_url]
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String]
|
25
|
+
def update_dir
|
26
|
+
"C:\\chef\\update"
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
def recipe_path
|
31
|
+
"#{update_dir}\\default.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
def tmp_cookbook_path
|
36
|
+
"#{update_dir}\\cookbooks\\upgrade_omnibus"
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
def tmp_recipes_path
|
41
|
+
"#{tmp_cookbook_path}\\recipes"
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def upgrade_solo_rb_path
|
46
|
+
"#{update_dir}\\upgrade_solo.rb"
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String]
|
50
|
+
def chef_solo_command
|
51
|
+
"chef-solo -c #{upgrade_solo_rb_path} -o upgrade_omnibus"
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
def chef_apply_command
|
56
|
+
"chef-apply #{recipe_path}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Writes a recipe that uses remote_file to download the appropriate
|
60
|
+
# Chef MSI file
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
def recipe_code
|
64
|
+
code = <<-RECIPE_CODE
|
65
|
+
chef_version = '#{chef_version}'
|
66
|
+
prerelease = #{prerelease}
|
67
|
+
|
68
|
+
platform = node[:platform]
|
69
|
+
platform_version = if node[:product_type] == 1 # Not server
|
70
|
+
case node[:platform_version]
|
71
|
+
when /6\.1\./
|
72
|
+
"7"
|
73
|
+
when /6\.2\./
|
74
|
+
"8"
|
75
|
+
end
|
76
|
+
else # server
|
77
|
+
case node[:platform_version]
|
78
|
+
when /5\.2\.3/
|
79
|
+
"2003r2"
|
80
|
+
when /6\.0\./
|
81
|
+
"2008"
|
82
|
+
when /6\.1\./
|
83
|
+
"2008r2"
|
84
|
+
when /6\.2\./
|
85
|
+
"2012"
|
86
|
+
when /6\.3\./
|
87
|
+
"2012r2"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
machine = node[:kernel][:machine]
|
92
|
+
nightlies = false
|
93
|
+
|
94
|
+
url = 'http://www.opscode.com/chef/download'
|
95
|
+
url_args = [ "p=\#{platform}", "pv=\#{platform_version}", "m=\#{machine}", "v=\#{chef_version}", "prerelease=\#{prerelease}", "nightlies=\#{nightlies}" ]
|
96
|
+
|
97
|
+
composed_url = "\#{url}?\#{url_args.join '&'}"
|
98
|
+
|
99
|
+
#{direct_url.nil? ? "full_url = composed_url" : "full_url = \"#{direct_url}\""}
|
100
|
+
request = Chef::REST::RESTRequest.new(:head, URI.parse(full_url), nil)
|
101
|
+
result = request.call
|
102
|
+
|
103
|
+
if result.kind_of?(Net::HTTPRedirection)
|
104
|
+
full_url = result['location']
|
105
|
+
end
|
106
|
+
|
107
|
+
file_name = ::File.basename(full_url)
|
108
|
+
file_download_path = "C:\\\\chef\\\\update\\\\\#{file_name}"
|
109
|
+
|
110
|
+
remote_file file_download_path do
|
111
|
+
source full_url
|
112
|
+
backup false
|
113
|
+
action :create_if_missing
|
114
|
+
end
|
115
|
+
|
116
|
+
file_extension = ::File.extname(file_name)
|
117
|
+
|
118
|
+
RECIPE_CODE
|
119
|
+
escape_and_echo(code)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Uses powershell to find a Chef installation and uninstalls it
|
123
|
+
#
|
124
|
+
# @return [String]
|
125
|
+
def uninstall_chef
|
126
|
+
win_uninstall_chef = <<-UNIN_PS
|
127
|
+
$productName = "Chef"
|
128
|
+
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match $productName }
|
129
|
+
If ($app) { $app.Uninstall() }
|
130
|
+
UNIN_PS
|
131
|
+
|
132
|
+
escape_and_echo(win_uninstall_chef)
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
# escape WIN BATCH special chars and prefixes each line with an
|
138
|
+
# echo
|
139
|
+
def escape_and_echo(file_contents)
|
140
|
+
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -194,6 +194,33 @@ module Ridley
|
|
194
194
|
execute(__method__, host, options)
|
195
195
|
end
|
196
196
|
|
197
|
+
# Update a node's Omnibus installation of Chef
|
198
|
+
#
|
199
|
+
# @param [String] host
|
200
|
+
# the host to perform the action on
|
201
|
+
#
|
202
|
+
# @option options [String] :chef_version
|
203
|
+
# the version of Chef to install on the node
|
204
|
+
# @option options [Boolean] :prerelease
|
205
|
+
# install a prerelease version of Chef
|
206
|
+
# @option options [String] :direct_url
|
207
|
+
# a url pointing directly to a Chef package to install
|
208
|
+
# @option options [Hash] :ssh
|
209
|
+
# * :user (String) a shell user that will login to each node and perform the bootstrap command on
|
210
|
+
# * :password (String) the password for the shell user that will perform the bootstrap
|
211
|
+
# * :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password
|
212
|
+
# * :timeout (Float) timeout value for SSH bootstrap (5.0)
|
213
|
+
# * :sudo (Boolean) run as sudo (true)
|
214
|
+
# @option options [Hash] :winrm
|
215
|
+
# * :user (String) a user that will login to each node and perform the bootstrap command on
|
216
|
+
# * :password (String) the password for the user that will perform the bootstrap (required)
|
217
|
+
# * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
|
218
|
+
#
|
219
|
+
# @return [HostConnector::Response]
|
220
|
+
def update_omnibus(host, options = {})
|
221
|
+
execute(__method__, host, options)
|
222
|
+
end
|
223
|
+
|
197
224
|
# Finds and returns the best HostConnector for a given host
|
198
225
|
#
|
199
226
|
# @param [String] host
|
@@ -194,6 +194,37 @@ module Ridley
|
|
194
194
|
run(host, CommandContext::UnixUninstall.command(options), options)
|
195
195
|
end
|
196
196
|
|
197
|
+
# Update a node's Omnibus installation of Chef
|
198
|
+
#
|
199
|
+
# @param [String] host
|
200
|
+
# the host to perform the action on
|
201
|
+
#
|
202
|
+
# @option options [String] :chef_version
|
203
|
+
# the version of Chef to install on the node
|
204
|
+
# @option options [Boolean] :prerelease
|
205
|
+
# install a prerelease version of Chef
|
206
|
+
# @option options [String] :direct_url
|
207
|
+
# a url pointing directly to a Chef package to install
|
208
|
+
# @option options [Hash] :ssh
|
209
|
+
# * :user (String) a shell user that will login to each node and perform the bootstrap command on
|
210
|
+
# * :password (String) the password for the shell user that will perform the bootstrap
|
211
|
+
# * :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password
|
212
|
+
# * :timeout (Float) timeout value for SSH bootstrap (5.0)
|
213
|
+
# * :sudo (Boolean) run as sudo (true)
|
214
|
+
# @option options [Hash] :winrm
|
215
|
+
# * :user (String) a user that will login to each node and perform the bootstrap command on
|
216
|
+
# * :password (String) the password for the user that will perform the bootstrap (required)
|
217
|
+
# * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
|
218
|
+
#
|
219
|
+
# @return [HostConnector::Response]
|
220
|
+
def update_omnibus(host, options = {})
|
221
|
+
options = options.reverse_merge(ssh: Hash.new)
|
222
|
+
options[:ssh].reverse_merge!(sudo: true, timeout: 5.0)
|
223
|
+
|
224
|
+
log.info "Updating Omnibus installation on host: #{host}"
|
225
|
+
run(host, CommandContext::UnixUpdateOmnibus.command(options), options)
|
226
|
+
end
|
227
|
+
|
197
228
|
private
|
198
229
|
|
199
230
|
def channel_exec(channel, command, host, response)
|
@@ -213,6 +213,11 @@ module Ridley
|
|
213
213
|
run(host, CommandContext::WindowsUninstall.command(options), options)
|
214
214
|
end
|
215
215
|
|
216
|
+
def update_omnibus(host, options = {})
|
217
|
+
log.info "Updating Omnibus installation on host: #{host}"
|
218
|
+
run(host, CommandContext::WindowsUpdateOmnibus.command(options), options)
|
219
|
+
end
|
220
|
+
|
216
221
|
private
|
217
222
|
|
218
223
|
# @param [String] host
|
@@ -192,6 +192,35 @@ module Ridley
|
|
192
192
|
host_commander.uninstall_chef(host, options)
|
193
193
|
end
|
194
194
|
|
195
|
+
|
196
|
+
# Update a node's Omnibus installation of Chef
|
197
|
+
#
|
198
|
+
# @param [String] host
|
199
|
+
# the host to perform the action on
|
200
|
+
#
|
201
|
+
# @option options [String] :chef_version
|
202
|
+
# the version of Chef to install on the node
|
203
|
+
# @option options [Boolean] :prerelease
|
204
|
+
# install a prerelease version of Chef
|
205
|
+
# @option options [String] :direct_url
|
206
|
+
# a url pointing directly to a Chef package to install
|
207
|
+
# @option options [Hash] :ssh
|
208
|
+
# * :user (String) a shell user that will login to each node and perform the bootstrap command on
|
209
|
+
# * :password (String) the password for the shell user that will perform the bootstrap
|
210
|
+
# * :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password
|
211
|
+
# * :timeout (Float) timeout value for SSH bootstrap (5.0)
|
212
|
+
# * :sudo (Boolean) run as sudo (true)
|
213
|
+
# @option options [Hash] :winrm
|
214
|
+
# * :user (String) a user that will login to each node and perform the bootstrap command on
|
215
|
+
# * :password (String) the password for the user that will perform the bootstrap (required)
|
216
|
+
# * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)
|
217
|
+
#
|
218
|
+
# @return [HostConnector::Response]
|
219
|
+
def update_omnibus(host, options = {})
|
220
|
+
options = options.reverse_merge(ssh: ssh, winrm: winrm)
|
221
|
+
host_commander.update_omnibus(host, options)
|
222
|
+
end
|
223
|
+
|
195
224
|
private
|
196
225
|
|
197
226
|
# @return [Ridley::HostCommander]
|
@@ -0,0 +1,78 @@
|
|
1
|
+
cat << EOP > <%= recipe_path %>
|
2
|
+
|
3
|
+
# Set Variables
|
4
|
+
|
5
|
+
chef_version = '<%= chef_version %>'
|
6
|
+
prerelease = <%= prerelease %>
|
7
|
+
|
8
|
+
platform = node[:platform]
|
9
|
+
platform_version = node[:platform_version]
|
10
|
+
machine = node[:kernel][:machine]
|
11
|
+
nightlies = false
|
12
|
+
|
13
|
+
# Compose Chef download URL
|
14
|
+
|
15
|
+
url = 'http://www.opscode.com/chef/download'
|
16
|
+
url_args = [ "p=#{platform}", "pv=#{platform_version}", "m=#{machine}", "v=#{chef_version}", "prerelease=#{prerelease}", "nightlies=#{nightlies}" ]
|
17
|
+
|
18
|
+
composed_url = "#{url}?#{url_args.join('&')}"
|
19
|
+
|
20
|
+
# Download the Chef file
|
21
|
+
|
22
|
+
<% if direct_url.nil? -%>
|
23
|
+
full_url = composed_url
|
24
|
+
<% else -%>
|
25
|
+
full_url = <%= direct_url %>
|
26
|
+
<% end -%>
|
27
|
+
request = Chef::REST::RESTRequest.new(:head, URI.parse(full_url), nil)
|
28
|
+
result = request.call
|
29
|
+
|
30
|
+
if result.kind_of?(Net::HTTPRedirection)
|
31
|
+
full_url = result['location']
|
32
|
+
end
|
33
|
+
|
34
|
+
file_name = ::File.basename(full_url)
|
35
|
+
file_download_path = ::File.join("<%= update_dir %>", file_name)
|
36
|
+
|
37
|
+
remote_file file_download_path do
|
38
|
+
source full_url
|
39
|
+
backup false
|
40
|
+
action :create_if_missing
|
41
|
+
end
|
42
|
+
|
43
|
+
# Install the Chef file
|
44
|
+
|
45
|
+
file_extension = ::File.extname(file_name)
|
46
|
+
|
47
|
+
execute "Install the Omnibus package: #{file_download_path}" do
|
48
|
+
case file_extension
|
49
|
+
when '.rpm'
|
50
|
+
command "rpm -Uvh --oldpackage --replacepkgs #{file_download_path}"
|
51
|
+
when '.deb'
|
52
|
+
command "dpkg -i #{file_download_path}"
|
53
|
+
else
|
54
|
+
raise 'Unknown package type encountered!'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
EOP
|
59
|
+
|
60
|
+
# Install the Chef package using the resources above and chef-solo / chef-apply
|
61
|
+
|
62
|
+
installed_major_chef_version=`chef-client -v | awk '{print $2}' | awk -F \. '{print $1}'`
|
63
|
+
|
64
|
+
if [ $installed_major_chef_version -lt 11 ]; then
|
65
|
+
mkdir -p <%= File.join(tmp_cookbook_path, "upgrade_omnibus/recipes/") %>
|
66
|
+
cp <%= recipe_path %> <%= File.join(tmp_cookbook, "recipes") %>
|
67
|
+
echo 'cookbook_path "/tmp/cookbooks"' > <%= upgrade_solo_rb_path %>
|
68
|
+
<%= chef_solo_command %>
|
69
|
+
else
|
70
|
+
<%= chef_apply_command %>
|
71
|
+
fi
|
72
|
+
|
73
|
+
# Cleanup
|
74
|
+
|
75
|
+
rm -f <%= upgrade_solo_rb_path %>
|
76
|
+
rm -rf <%= tmp_cookbook_path %>
|
77
|
+
rm -f <%= recipe_path %>
|
78
|
+
rm -rf <%= update_dir %>/*.rpm
|
@@ -0,0 +1,30 @@
|
|
1
|
+
mkdir <%= update_dir %>
|
2
|
+
|
3
|
+
> <%= recipe_path %> (
|
4
|
+
<%= recipe_code %>
|
5
|
+
)
|
6
|
+
|
7
|
+
chef-client -v | awk '{print $2}' | awk -F \. '{print $1}' > <%= update_dir %>\major_version.txt
|
8
|
+
SET /p installed_major_chef_version=<<%= update_dir %>\major_version.txt
|
9
|
+
|
10
|
+
IF %installed_major_chef_version% LSS 11 (
|
11
|
+
mkdir <%= tmp_cookbook_path %>
|
12
|
+
mkdir <%= tmp_recipes_path %>
|
13
|
+
cp <%= recipe_path %> <%= tmp_recipes_path %>
|
14
|
+
echo cookbook_path 'C:\chef\update\cookbooks' > <%= upgrade_solo_rb_path %>
|
15
|
+
call <%= chef_solo_command %>
|
16
|
+
) else (
|
17
|
+
call <%= chef_apply_command %>
|
18
|
+
)
|
19
|
+
|
20
|
+
> <%= update_dir %>\uninstall_chef.ps1 (
|
21
|
+
<%= uninstall_chef %>
|
22
|
+
)
|
23
|
+
|
24
|
+
ls <%= update_dir %> | grep "chef-client" > <%= update_dir %>\msi_name.txt
|
25
|
+
SET /p msi_name=<<%= update_dir %>\msi_name.txt
|
26
|
+
powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive <%= update_dir %>\uninstall_chef.ps1
|
27
|
+
|
28
|
+
msiexec /qb /norestart /i "<%= update_dir %>\%msi_name%"
|
29
|
+
|
30
|
+
rm -rf <%= update_dir %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ridley::CommandContext::UnixUninstall do
|
4
|
+
let(:unix_uninstall) { described_class.new }
|
5
|
+
|
6
|
+
describe "::new" do
|
7
|
+
context "when skip_chef is not provided" do
|
8
|
+
it "sets skip_chef to false" do
|
9
|
+
expect(unix_uninstall.skip_chef).to be_false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#command" do
|
15
|
+
it "returns a string" do
|
16
|
+
expect(unix_uninstall.command).to be_a(String)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#config_directory" do
|
21
|
+
it "returns a string" do
|
22
|
+
expect(unix_uninstall.config_directory).to be_a(String)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#data_directory" do
|
27
|
+
it "returns a string" do
|
28
|
+
expect(unix_uninstall.data_directory).to be_a(String)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#install_directory" do
|
33
|
+
it "returns a string" do
|
34
|
+
expect(unix_uninstall.install_directory).to be_a(String)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ridley::CommandContext::UnixUpdateOmnibus do
|
4
|
+
let(:unix_update_omnibus) { described_class.new }
|
5
|
+
|
6
|
+
describe "::new" do
|
7
|
+
context "when a chef_version is not given" do
|
8
|
+
it "chef_version is set to latest" do
|
9
|
+
expect(unix_update_omnibus.chef_version).to eql("latest")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when prerelease is not given" do
|
14
|
+
it "prerelease is set to false" do
|
15
|
+
expect(unix_update_omnibus.prerelease).to be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when options are set" do
|
20
|
+
let(:unix_update_omnibus) { described_class.new(options) }
|
21
|
+
let(:options) do
|
22
|
+
{
|
23
|
+
chef_version: "1.2.3",
|
24
|
+
prerelease: true,
|
25
|
+
direct_url: "http://my.package.com/"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets chef_version" do
|
30
|
+
expect(unix_update_omnibus.chef_version).to eql("1.2.3")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets prerelease" do
|
34
|
+
expect(unix_update_omnibus.prerelease).to be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets direct_url" do
|
38
|
+
expect(unix_update_omnibus.direct_url).to eql("http://my.package.com/")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#command" do
|
44
|
+
it "returns a string" do
|
45
|
+
expect(unix_update_omnibus.command).to be_a(String)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#update_dir" do
|
50
|
+
it "returns a string" do
|
51
|
+
expect(unix_update_omnibus.update_dir).to be_a(String)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#upgrade_solo_rb_path" do
|
56
|
+
it "returns a string" do
|
57
|
+
expect(unix_update_omnibus.upgrade_solo_rb_path).to be_a(String)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#recipe_path" do
|
62
|
+
it "returns a string" do
|
63
|
+
expect(unix_update_omnibus.recipe_path).to be_a(String)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#tmp_cookbook_path" do
|
68
|
+
it "returns a string" do
|
69
|
+
expect(unix_update_omnibus.tmp_cookbook_path).to be_a(String)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#tmp_cookbook" do
|
74
|
+
it "returns a string" do
|
75
|
+
expect(unix_update_omnibus.tmp_cookbook).to be_a(String)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#chef_solo_command" do
|
80
|
+
it "returns a string" do
|
81
|
+
expect(unix_update_omnibus.chef_solo_command).to be_a(String)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "calls chef-solo" do
|
85
|
+
expect(unix_update_omnibus.chef_solo_command).to start_with("chef-solo")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#chef_apply_command" do
|
90
|
+
it "returns a string" do
|
91
|
+
expect(unix_update_omnibus.chef_apply_command).to be_a(String)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "calls chef-apply" do
|
95
|
+
expect(unix_update_omnibus.chef_apply_command).to start_with("chef-apply")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ridley::CommandContext::WindowsUpdateOmnibus do
|
4
|
+
let(:windows_update_omnibus) { described_class.new }
|
5
|
+
|
6
|
+
describe "::new" do
|
7
|
+
context "when a chef_version is not given" do
|
8
|
+
it "chef_version is set to latest" do
|
9
|
+
expect(windows_update_omnibus.chef_version).to eql("latest")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when prerelease is not given" do
|
14
|
+
it "prerelease is set to false" do
|
15
|
+
expect(windows_update_omnibus.prerelease).to be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when options are set" do
|
20
|
+
let(:windows_update_omnibus) { described_class.new(options) }
|
21
|
+
let(:options) do
|
22
|
+
{
|
23
|
+
chef_version: "1.2.3",
|
24
|
+
prerelease: true,
|
25
|
+
direct_url: "http://my.package.com/"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets chef_version" do
|
30
|
+
expect(windows_update_omnibus.chef_version).to eql("1.2.3")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets prerelease" do
|
34
|
+
expect(windows_update_omnibus.prerelease).to be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets direct_url" do
|
38
|
+
expect(windows_update_omnibus.direct_url).to eql("http://my.package.com/")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#command" do
|
44
|
+
it "returns a string" do
|
45
|
+
expect(windows_update_omnibus.command).to be_a(String)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#update_dir" do
|
50
|
+
it "returns a string" do
|
51
|
+
expect(windows_update_omnibus.update_dir).to be_a(String)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#upgrade_solo_rb_path" do
|
56
|
+
it "returns a string" do
|
57
|
+
expect(windows_update_omnibus.upgrade_solo_rb_path).to be_a(String)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#recipe_path" do
|
62
|
+
it "returns a string" do
|
63
|
+
expect(windows_update_omnibus.recipe_path).to be_a(String)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#tmp_cookbook_path" do
|
68
|
+
it "returns a string" do
|
69
|
+
expect(windows_update_omnibus.tmp_cookbook_path).to be_a(String)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#chef_solo_command" do
|
74
|
+
it "returns a string" do
|
75
|
+
expect(windows_update_omnibus.chef_solo_command).to be_a(String)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "calls chef-solo" do
|
79
|
+
expect(windows_update_omnibus.chef_solo_command).to start_with("chef-solo")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#chef_apply_command" do
|
84
|
+
it "returns a string" do
|
85
|
+
expect(windows_update_omnibus.chef_apply_command).to be_a(String)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "calls chef-apply" do
|
89
|
+
expect(windows_update_omnibus.chef_apply_command).to start_with("chef-apply")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -31,26 +31,3 @@ describe Ridley::CommandContext::Base do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
describe Ridley::CommandContext::Unix do
|
36
|
-
let(:unix) { described_class.new(options) }
|
37
|
-
|
38
|
-
describe "#command" do
|
39
|
-
context "when sudo is true" do
|
40
|
-
let(:command) { unix.command }
|
41
|
-
let(:template) { double(:evaluate => command_string) }
|
42
|
-
let(:options) do
|
43
|
-
{sudo: true}
|
44
|
-
end
|
45
|
-
let(:command_string) { "echo 'hi'" }
|
46
|
-
|
47
|
-
before do
|
48
|
-
unix.stub(:template).and_return(template)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "prepends sudo to the command" do
|
52
|
-
expect(command).to eql("sudo echo 'hi'")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -66,4 +66,32 @@ describe Ridley::HostConnector::SSH do
|
|
66
66
|
connector.ruby_script(host, command_lines, options)
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe "#uninstall_chef" do
|
71
|
+
let(:command) { "uninstall chef" }
|
72
|
+
|
73
|
+
before do
|
74
|
+
Ridley::CommandContext::UnixUninstall.stub(:command).and_return(command)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "receives a run command to uninstall chef" do
|
78
|
+
connector.should_receive(:run).with(host, command, options)
|
79
|
+
|
80
|
+
connector.uninstall_chef(host, options)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#update_omnibus" do
|
85
|
+
let(:command) { "update omnibus" }
|
86
|
+
|
87
|
+
before do
|
88
|
+
Ridley::CommandContext::UnixUpdateOmnibus.stub(:command).and_return(command)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "receives a run command to update omnibus" do
|
92
|
+
connector.should_receive(:run).with(host, command, options)
|
93
|
+
|
94
|
+
connector.update_omnibus(host, options)
|
95
|
+
end
|
96
|
+
end
|
69
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley-connectors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
@@ -136,7 +136,9 @@ files:
|
|
136
136
|
- lib/ridley-connectors/client.rb
|
137
137
|
- lib/ridley-connectors/command_context.rb
|
138
138
|
- lib/ridley-connectors/command_context/unix_uninstall.rb
|
139
|
+
- lib/ridley-connectors/command_context/unix_update_omnibus.rb
|
139
140
|
- lib/ridley-connectors/command_context/windows_uninstall.rb
|
141
|
+
- lib/ridley-connectors/command_context/windows_update_omnibus.rb
|
140
142
|
- lib/ridley-connectors/errors.rb
|
141
143
|
- lib/ridley-connectors/host_commander.rb
|
142
144
|
- lib/ridley-connectors/host_connector.rb
|
@@ -148,7 +150,9 @@ files:
|
|
148
150
|
- lib/ridley-connectors/version.rb
|
149
151
|
- ridley-connectors.gemspec
|
150
152
|
- scripts/unix_uninstall_omnibus.erb
|
153
|
+
- scripts/unix_update_omnibus.erb
|
151
154
|
- scripts/windows_uninstall_omnibus.erb
|
155
|
+
- scripts/windows_update_omnibus.erb
|
152
156
|
- spec/fixtures/encrypted_data_bag_secret
|
153
157
|
- spec/fixtures/my-fake.pem
|
154
158
|
- spec/spec_helper.rb
|
@@ -160,6 +164,9 @@ files:
|
|
160
164
|
- spec/unit/ridley-connectors/bootstrap_context_spec.rb
|
161
165
|
- spec/unit/ridley-connectors/chef_objects/node_object_spec.rb
|
162
166
|
- spec/unit/ridley-connectors/client_spec.rb
|
167
|
+
- spec/unit/ridley-connectors/command_context/unix_uninstall_spec.rb
|
168
|
+
- spec/unit/ridley-connectors/command_context/unix_update_omnibus_spec.rb
|
169
|
+
- spec/unit/ridley-connectors/command_context/windows>update_omnibus_spec.rb
|
163
170
|
- spec/unit/ridley-connectors/command_context_spec.rb
|
164
171
|
- spec/unit/ridley-connectors/host_commander_spec.rb
|
165
172
|
- spec/unit/ridley-connectors/host_connector/ssh_spec.rb
|
@@ -203,6 +210,9 @@ test_files:
|
|
203
210
|
- spec/unit/ridley-connectors/bootstrap_context_spec.rb
|
204
211
|
- spec/unit/ridley-connectors/chef_objects/node_object_spec.rb
|
205
212
|
- spec/unit/ridley-connectors/client_spec.rb
|
213
|
+
- spec/unit/ridley-connectors/command_context/unix_uninstall_spec.rb
|
214
|
+
- spec/unit/ridley-connectors/command_context/unix_update_omnibus_spec.rb
|
215
|
+
- spec/unit/ridley-connectors/command_context/windows>update_omnibus_spec.rb
|
206
216
|
- spec/unit/ridley-connectors/command_context_spec.rb
|
207
217
|
- spec/unit/ridley-connectors/host_commander_spec.rb
|
208
218
|
- spec/unit/ridley-connectors/host_connector/ssh_spec.rb
|