cuken 0.1.13 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +61 -0
- data/Gemfile +17 -15
- data/Gemfile.lock +55 -63
- data/VERSION +1 -1
- data/cuken.gems +46 -0
- data/cuken.gemspec +85 -31
- data/features/about.md +4 -0
- data/features/avagrant_steps/vagrant_steps.feature +13 -0
- data/features/chef_examples/cookbooks_cookbook.feature +1 -1
- data/features/chef_examples/cookbooks_metadata.feature +5 -5
- data/features/chef_examples/cookbooks_repo.feature +1 -1
- data/features/chef_examples/knife_admin_client.feature +12 -12
- data/features/chef_examples/knife_client_create.feature +1 -1
- data/features/chef_examples/zenoss_example/01_chef_server_setup.feature +1 -1
- data/features/chef_examples/zenoss_example/02_monitor_vm_setup.feature +1 -1
- data/features/chef_steps/cookbook_steps.feature +6 -16
- data/features/command_examples/commands.feature +3 -3
- data/features/command_examples/exit_statuses.feature +49 -0
- data/features/command_examples/file_system_commands.feature +128 -0
- data/features/command_examples/flushing.feature +24 -0
- data/features/command_examples/interactive.feature +57 -0
- data/features/command_examples/no_clobber.feature +41 -0
- data/features/command_examples/output.feature +205 -0
- data/features/command_steps/command_steps.feature +49 -42
- data/features/file_examples/files.feature +5 -5
- data/features/git_examples/git_clone.feature +33 -0
- data/features/ssh_examples/ssh.feature +11 -2
- data/features/step_definitions/cuken_steps.rb +3 -2
- data/features/support/env.rb +2 -1
- data/lib/cuken/all.rb +1 -0
- data/lib/cuken/api/aruba/api.rb +342 -0
- data/lib/cuken/api/aruba/hooks.rb +63 -0
- data/lib/cuken/api/aruba/process.rb +74 -0
- data/lib/cuken/api/aruba.rb +5 -0
- data/lib/cuken/api/chef/common.rb +8 -1
- data/lib/cuken/api/chef/cookbook.rb +31 -5
- data/lib/cuken/api/chef/knife.rb +3 -3
- data/lib/cuken/api/chef/role.rb +3 -3
- data/lib/cuken/api/chef.rb +98 -9
- data/lib/cuken/api/cmd.rb +8 -8
- data/lib/cuken/api/common.rb +11 -23
- data/lib/cuken/api/file.rb +38 -38
- data/lib/cuken/api/git/clone.rb +25 -0
- data/lib/cuken/api/git/common.rb +37 -0
- data/lib/cuken/api/git/remote.rb +16 -0
- data/lib/cuken/api/git/repository.rb +62 -0
- data/lib/cuken/api/git.rb +69 -0
- data/lib/cuken/api/rvm/common.rb +10 -0
- data/lib/cuken/api/rvm/gemsets.rb +33 -0
- data/lib/cuken/api/rvm/wip.rb +554 -0
- data/lib/cuken/api/rvm.rb +25 -479
- data/lib/cuken/api/ssh.rb +85 -4
- data/lib/cuken/api/vagrant/common.rb +7 -4
- data/lib/cuken/api/vagrant/v_m.rb +2 -2
- data/lib/cuken/api/vagrant.rb +3 -3
- data/lib/cuken/common.rb +3 -1
- data/lib/cuken/cucumber/chef/common.rb +3 -3
- data/lib/cuken/cucumber/chef/cookbook/action.rb +81 -0
- data/lib/cuken/cucumber/chef/cookbook/local.rb +71 -0
- data/lib/cuken/cucumber/chef/cookbook/remote.rb +37 -0
- data/lib/cuken/cucumber/chef/cookbook.rb +3 -140
- data/lib/cuken/cucumber/chef/cookbook_steps.rb +1 -1
- data/lib/cuken/cucumber/chef/deploy_steps.rb +1 -1
- data/lib/cuken/cucumber/chef/done_directory_steps.rb +2 -2
- data/lib/cuken/cucumber/chef/done_file_steps.rb +5 -5
- data/lib/cuken/cucumber/chef/knife.rb +1 -1
- data/lib/cuken/cucumber/chef.rb +1 -1
- data/lib/cuken/cucumber/cmd/execution.rb +34 -0
- data/lib/cuken/cucumber/cmd/exit_status.rb +30 -0
- data/lib/cuken/cucumber/cmd.rb +2 -36
- data/lib/cuken/cucumber/common.rb +42 -6
- data/lib/cuken/cucumber/file.rb +42 -37
- data/lib/cuken/cucumber/git/clone.rb +51 -0
- data/lib/cuken/cucumber/git/common.rb +36 -0
- data/lib/cuken/cucumber/git/local.rb +19 -0
- data/lib/cuken/cucumber/git/remote.rb +22 -0
- data/lib/cuken/cucumber/git.rb +26 -0
- data/lib/cuken/cucumber/output/all.rb +41 -0
- data/lib/cuken/cucumber/output/cmd.rb +46 -0
- data/lib/cuken/cucumber/output/stderr.rb +33 -0
- data/lib/cuken/cucumber/output/stdout.rb +34 -0
- data/lib/cuken/cucumber/rvm/common.rb +0 -0
- data/lib/cuken/cucumber/rvm/gemsets.rb +32 -0
- data/lib/cuken/cucumber/rvm/hooks.rb +0 -0
- data/lib/cuken/cucumber/rvm.rb +3 -1
- data/lib/cuken/cucumber/ssh/common.rb +51 -0
- data/lib/cuken/cucumber/ssh.rb +3 -35
- data/lib/cuken/cucumber/vagrant.rb +1 -1
- data/lib/cuken/git.rb +21 -0
- data/spec/api/rvm/gemsets/api_spec.rb +41 -0
- data/spec/api/rvm/gemsets/helper_spec.rb +19 -0
- data/spec/api/rvm_spec.rb +63 -15
- data/spec/api/vagrant/v_m/Vagrantfile +82 -0
- data/spec/api/vagrant/v_m/api_spec.rb +37 -0
- data/spec/spec_helper.rb +39 -0
- metadata +123 -45
- data/spec/cuken_spec.rb +0 -7
data/lib/cuken/api/rvm.rb
CHANGED
@@ -1,501 +1,47 @@
|
|
1
|
+
require 'rvm'
|
2
|
+
require 'cuken/api/common'
|
3
|
+
require 'cuken/api/rvm/common'
|
4
|
+
require 'cuken/api/rvm/gemsets'
|
5
|
+
|
1
6
|
module ::Cuken
|
2
7
|
module Api
|
3
8
|
module Rvm
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(path)
|
10
|
-
@root_path = ::File.directory?(path) ? path : File.dirname(path)
|
11
|
-
rvmrc_read(path)
|
12
|
-
end
|
13
|
-
|
14
|
-
# read the .rvmrc file contents into @rvmrc
|
15
|
-
def rvmrc_read(path)
|
16
|
-
fn = ::File.directory?(path) ? path + '/.rvmrc' : path
|
17
|
-
@rvmrc = ::File.new(fn).read
|
18
|
-
return true if @rvmrc.size > 0
|
19
|
-
end
|
20
|
-
|
21
|
-
# return the .rvmrc file contents
|
22
|
-
def rvmrc
|
23
|
-
@rvmrc
|
24
|
-
end
|
25
|
-
|
26
|
-
# return ruby name parsed from .rvmrc file contents
|
27
|
-
def rvmrc_ruby_name
|
28
|
-
extract_rubie(rvmrc)
|
29
|
-
end
|
30
|
-
|
31
|
-
# return gemset name parsed from .rvmrc file contents
|
32
|
-
def rvmrc_gemset_name
|
33
|
-
extract_gemset(rvmrc)
|
34
|
-
end
|
35
|
-
|
36
|
-
# return concatenated string of rvmrc_ruby@rvmrc_gemset
|
37
|
-
def rvmrc_ruby_gemset(rvmrc)
|
38
|
-
"#{extract_rubie(rvmrc)}@#{extract_gemset(rvmrc)}"
|
39
|
-
end
|
40
|
-
|
41
|
-
# return an array of .rvmrc file paths found beneath a root folder
|
42
|
-
def find_rvmrc_files(rvmrc_root)
|
43
|
-
Dir.glob(rvmrc_root + '/**' + '/.rvmrc')
|
44
|
-
end
|
45
|
-
|
46
|
-
# return an arry of paths containing .rvmrc files
|
47
|
-
def find_rvmrc_paths(rvmrc_root)
|
48
|
-
root = File.directory?(rvmrc_root) ? rvmrc_root : File.dirname(rvmrc_root)
|
49
|
-
dirs = []
|
50
|
-
find_rvmrc_files(root).each do |path|
|
51
|
-
dirs << File.dirname(File.expand_path(path)) if File.file?(path)
|
52
|
-
end
|
53
|
-
dirs
|
54
|
-
end
|
55
|
-
|
56
|
-
#return an array of *.gems file paths found beneath a root folder
|
57
|
-
def find_gems_files(rvmrc_root)
|
58
|
-
Dir.glob(rvmrc_root + '/**' + '/*.gems')
|
59
|
-
end
|
60
|
-
|
61
|
-
# returns rubies and gemsets from .rvmrc files glob'ed below
|
62
|
-
# a root folder.
|
63
|
-
def all_rubies_gemsets(root_path=@root_path)
|
64
|
-
@all_rubies_gemsets = Hash.new([])
|
65
|
-
arry=find_rvmrc_paths(root_path)
|
66
|
-
arry.each do |dir|
|
67
|
-
Dir.glob(dir + '/*.gems').each do |fn|
|
68
|
-
gsn = File.basename(fn,'.gems').to_s
|
69
|
-
rvmrc_read(dir + '/.rvmrc')
|
70
|
-
rube = rvmrc_ruby_name
|
71
|
-
egsn = rvmrc_gemset_name
|
72
|
-
@all_rubies_gemsets[rube] = [] unless @all_rubies_gemsets.key? rube
|
73
|
-
if gsn == egsn
|
74
|
-
@all_rubies_gemsets[rube] << {:ruby_alias => "cuken_#{rube}",:gemset_alias => "cuken_#{gsn}", :gemset_name => gsn, :gemset_path => fn}
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
@all_rubies_gemsets
|
79
|
-
end
|
10
|
+
extend ::RVM
|
11
|
+
include ::Cuken::Api::Rvm::Common
|
12
|
+
include ::Cuken::Api::Aruba::Api
|
80
13
|
|
81
|
-
|
82
|
-
def all_gemsets(root_path=@root_path)
|
83
|
-
default = Hash.new{|hsh,ky| hsh[ky] = {:ruby_alias => "cuken_#{ky}"}}
|
84
|
-
@all_rubies_gemsets ||= all_rubies_gemsets(root_path)
|
85
|
-
@all_gemsets = @all_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
|
86
|
-
end
|
87
|
-
|
88
|
-
# returns array of all rubies in all .rvmrc files beneath a root folder
|
89
|
-
def all_rubies(root_path=@root_path)
|
90
|
-
@all_rubies_gemsets ||= all_rubies_gemsets(root_path)
|
91
|
-
@all_rubies = @all_rubies_gemsets.keys
|
92
|
-
end
|
14
|
+
class RvmHelper
|
93
15
|
|
94
|
-
|
95
|
-
# and return current Ruby string even if the given block raises
|
96
|
-
def each_ruby
|
97
|
-
begin
|
98
|
-
all_rubies(@root_path).each do |rubie|
|
99
|
-
RVM.use(rubie)
|
100
|
-
yield rubie
|
101
|
-
end
|
102
|
-
rescue
|
103
|
-
ensure
|
104
|
-
RVM.reset_current!
|
105
|
-
end
|
106
|
-
end
|
16
|
+
attr_reader :environment
|
107
17
|
|
108
|
-
|
109
|
-
|
110
|
-
each_ruby do |rubie|
|
111
|
-
all_gemsets(@root_path)[rubie][:gemsets].each do |hsh|
|
112
|
-
::RVM.gemset.create([hsh[:gemset_name]])
|
113
|
-
end
|
114
|
-
end
|
18
|
+
def init
|
19
|
+
RVM::Environment
|
115
20
|
end
|
116
21
|
|
117
|
-
|
118
|
-
|
119
|
-
def gemspecs_to_install
|
120
|
-
@gemspecs_to_install ||= [['bundler', '1.0.10']]
|
22
|
+
def current
|
23
|
+
@current = RVM.current
|
121
24
|
end
|
122
25
|
|
123
|
-
|
124
|
-
|
125
|
-
def gems_install
|
126
|
-
create_gemsets
|
127
|
-
each_ruby do |rubie|
|
128
|
-
gemspecs_to_install.each { |spec| install_gem(rubie, spec) }
|
26
|
+
def environment_name
|
27
|
+
current.environment_name
|
129
28
|
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# return the options string for Ruby's `gem install...` CLI
|
133
|
-
def gem_install_options
|
134
|
-
@gem_install_options ||= ['no_ri', 'no_rdoc']
|
135
|
-
"--" + @gem_install_options.join(' --')
|
136
|
-
end
|
137
29
|
|
138
|
-
|
139
|
-
|
140
|
-
gem, version = spec
|
141
|
-
all_gemsets.each do |rubie, hsh|
|
142
|
-
hsh[:gemsets].each do |h|
|
143
|
-
if gem_available?(spec)
|
144
|
-
puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
|
145
|
-
else
|
146
|
-
puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
|
147
|
-
RVM.gemset.use(h[:gemset_alias])
|
148
|
-
RVM.run("rvm --create use #{h[:gemset_alias]}; gem install #{gem} -v#{version} #{gem_install_options}")
|
149
|
-
end
|
150
|
-
end
|
30
|
+
def gemset
|
31
|
+
current.gemset
|
151
32
|
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# return the parsed .rvmrc info for the current ruby
|
155
|
-
def current_ruby_info(rubie)
|
156
|
-
@all_rubies_gemsets ||= all_rubies_gemsets
|
157
|
-
@all_rubies_gemsets[rubie]
|
158
|
-
end
|
159
33
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
# Does not install existing RVM rubies that are listed in the .rvmrc files
|
165
|
-
# raise an error if RVM's install root does not exist
|
166
|
-
def setup_rubies
|
167
|
-
rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
|
168
|
-
@all_rubies_gemsets ||= all_rubies_gemsets(@root_path)
|
169
|
-
@all_rubies_gemsets.keys.each do |rubie|
|
170
|
-
if RVM.list_strings.include?(rubie)
|
171
|
-
puts "info: Rubie #{rubie} already installed."
|
172
|
-
else
|
173
|
-
with_rvm_environment_vars do
|
174
|
-
install_rubie(rubie)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
RVM.alias_create(current_ruby_info(rubie)[0][:ruby_alias], "#{rubie}") unless rubie == current_ruby_info(rubie)[0][:ruby_alias]
|
34
|
+
def environment(gemset, options={})
|
35
|
+
@environemnt = self.new(gemset, options)
|
36
|
+
yield @environemnt if block_given?
|
37
|
+
@environemnt
|
178
38
|
end
|
179
39
|
end
|
180
40
|
|
181
|
-
|
182
|
-
|
183
|
-
rvmrc[/ruby_id=\"(.*)\"/, 1]
|
184
|
-
end
|
185
|
-
def extract_gemset(rvmrc)
|
186
|
-
rvmrc[/gemset_id=\"(.*)\"/, 1]
|
187
|
-
end
|
188
|
-
def gem_available?(spec)
|
189
|
-
gem, version = spec
|
190
|
-
RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
|
191
|
-
end
|
192
|
-
def rvm_current_name
|
193
|
-
RVM.current.expanded_name
|
194
|
-
end
|
195
|
-
|
196
|
-
def rvm_loaded?
|
197
|
-
@rvm_setup = defined?(RVM) ? true : false
|
198
|
-
return(true) if @rvm_setup
|
199
|
-
rvm_lib_path = rvm_path + "lib" rescue return
|
200
|
-
$LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
|
201
|
-
require 'rvm'
|
202
|
-
@rvm_setup = defined?(RVM) ? true : false
|
203
|
-
end
|
204
|
-
|
205
|
-
def install_rubie(rubie)
|
206
|
-
std_msg = "info: Rubie #{rubie} installed."
|
207
|
-
err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
|
208
|
-
puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
|
209
|
-
RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
|
210
|
-
end
|
211
|
-
|
212
|
-
def rvm_install_options
|
213
|
-
{ }
|
214
|
-
end
|
215
|
-
|
216
|
-
def with_rvm_environment_vars
|
217
|
-
my_vars = rvm_environment_vars
|
218
|
-
current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
|
219
|
-
set_environment_vars(my_vars)
|
220
|
-
yield
|
221
|
-
ensure
|
222
|
-
set_environment_vars(current_vars)
|
223
|
-
end
|
224
|
-
|
225
|
-
def set_environment_vars(vars)
|
226
|
-
vars.each { |k,v| ENV[k] = v }
|
227
|
-
end
|
228
|
-
|
229
|
-
def rvm_environment_vars
|
230
|
-
if rvm_for_macports?
|
231
|
-
{'CC' => '/usr/bin/gcc-4.2',
|
232
|
-
'CFLAGS' => '-O2 -arch x86_64',
|
233
|
-
'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
|
234
|
-
'CPPFLAGS' => '-I/opt/local/include'}
|
235
|
-
else
|
236
|
-
{}
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def rvm_for_macports?
|
241
|
-
`uname`.strip == 'Darwin' && `which port`.present?
|
242
|
-
end
|
243
|
-
|
244
|
-
end # class RvmrcProcessor
|
245
|
-
|
246
|
-
module_function
|
247
|
-
class << self
|
248
|
-
attr_accessor :rvm_install_rubies, :rvm_install_gem_specs,
|
249
|
-
:rvm_gem_install_options
|
250
|
-
end
|
251
|
-
|
252
|
-
def rvmrc(path)
|
253
|
-
@rvmrc ||= RvmrcProcessor.new(path)
|
254
|
-
end
|
255
|
-
|
256
|
-
def rvm_current_name
|
257
|
-
RVM.current.expanded_name
|
258
|
-
end
|
259
|
-
|
260
|
-
def rvm_gem_install_options
|
261
|
-
@rvm_gem_install_options ||= ['no_ri', 'no_rdoc']
|
262
|
-
"--" + @rvm_gem_install_options.join(' --')
|
263
|
-
end
|
264
|
-
|
265
|
-
def rvm_install_rubies
|
266
|
-
@rvm_install_rubies ||= []
|
41
|
+
def rvm
|
42
|
+
@rvm ||= RvmHelper.new
|
267
43
|
end
|
268
|
-
|
269
|
-
def rvm_install_gemspecs
|
270
|
-
@rvm_install_gemspecs ||= [['bundler', '1.0.10']]
|
271
|
-
end
|
272
|
-
|
273
|
-
def rvm_create_gemsets
|
274
|
-
@rvm_create_gemsets ||= []
|
275
|
-
end
|
276
|
-
|
277
|
-
def rvm_requested_gemset(gemset)
|
278
|
-
@rvm_requested_gemset = gemset
|
279
|
-
end
|
280
|
-
|
281
|
-
def rvm_requested_gemset
|
282
|
-
@rvm_requested_gemset ||='vagrant'
|
283
|
-
end
|
284
|
-
#wip
|
285
|
-
def rvm_path
|
286
|
-
pn = Pathname.new(File.expand_path(ENV['rvm_path'] || '~/.rvm'))
|
287
|
-
pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller)
|
288
|
-
end
|
289
|
-
|
290
|
-
def rvm_local_install?
|
291
|
-
rvm_path.dirname.realpath.directory?
|
292
|
-
end
|
293
|
-
# done
|
294
|
-
def rvm_loaded?
|
295
|
-
_rvm_load
|
296
|
-
end
|
297
|
-
|
298
|
-
def rvm_gemset_paths(root_path='/usr/src/cuken')
|
299
|
-
rpn = Pathname(root_path)
|
300
|
-
rvmrc_dirs = []
|
301
|
-
Dir.glob((rpn + '**' + '.rvmrc').to_s).each do |d|
|
302
|
-
dn = File.dirname(d)
|
303
|
-
rvmrc_dirs << dn if File.directory?(dn)
|
304
|
-
end
|
305
|
-
rvmrc_dirs
|
306
|
-
end
|
307
|
-
|
308
|
-
# done
|
309
|
-
def rvmrc_rubies_gemsets(root_path='/usr/src/cuken')
|
310
|
-
@rvmrc_rubies_gemsets = Hash.new([])
|
311
|
-
arry=rvm_gemset_paths(root_path)
|
312
|
-
arry.each do |dir|
|
313
|
-
Dir.glob(dir + '/*.gems').each do |fn|
|
314
|
-
gsn = File.basename(fn,'.gems').to_s
|
315
|
-
rvmrc = File.new(File.dirname(fn) + '/.rvmrc').read
|
316
|
-
rube = rvmrc_extract_ruby(rvmrc)
|
317
|
-
egsn = rvmrc_extract_gemset(rvmrc)
|
318
|
-
@rvmrc_rubies_gemsets[rube] = [] unless @rvmrc_rubies_gemsets.key? rube
|
319
|
-
@rvmrc_rubies_gemsets[rube] << gsn if gsn == egsn
|
320
|
-
end
|
321
|
-
end
|
322
|
-
@rvmrc_rubies_gemsets
|
323
|
-
end
|
324
|
-
# done
|
325
|
-
def rvmrc_rubies
|
326
|
-
@rvmrc_rubies ||= _rvmrc_rubies #.keys.map{ |rubie| "#{rubie}@#{rvm_requested_gemset}" }
|
327
|
-
end
|
328
|
-
#wip
|
329
|
-
def rvm_rubies_setup(root_path='/usr/src/cuken')
|
330
|
-
rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
|
331
|
-
@rvmrc_rubies_gemsets ? true : rvmrc_rubies_gemsets(root_path)
|
332
|
-
@rvmrc_rubies_gemsets.keys.each do |rubie|
|
333
|
-
if RVM.list_strings.include?(rubie)
|
334
|
-
puts "info: Rubie #{rubie} already installed."
|
335
|
-
else
|
336
|
-
with_rvm_environment_vars do
|
337
|
-
_rvm_install_rubie(rubie)
|
338
|
-
end
|
339
|
-
end
|
340
|
-
RVM.alias_create(rvmrc_rubies[rubie][:alias], "#{rubie}@#{rvm_requested_gemset}") unless rubie == rvmrc_rubies[rubie][:alias]
|
341
|
-
end
|
342
|
-
end
|
343
|
-
#done
|
344
|
-
def rvm_current_rubie_info
|
345
|
-
rvmrc_rubies[_rvm_current_rubie_name]
|
346
|
-
end
|
347
|
-
|
348
|
-
# Install @rvm_install_gemspecs gemspec using rubies and gemsets
|
349
|
-
# found in .rvmrc files.
|
350
|
-
# done
|
351
|
-
def rvmrc_gems_install(root_path)
|
352
|
-
@rvmrc_root_path = root_path
|
353
|
-
_rvmrc_create_gemsets
|
354
|
-
_each_rvmrc_rubie do |rubie|
|
355
|
-
rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
def rvmrc_gemsets_install(root_path)
|
360
|
-
@rvmrc_root_path = root_path
|
361
|
-
_each_rvmrc_rubie do |rubie|
|
362
|
-
rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
protected
|
367
|
-
#done
|
368
|
-
def _rvm_load
|
369
|
-
@rvm_setup = false
|
370
|
-
rvm_lib_path = rvm_path + "lib" rescue return
|
371
|
-
$LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
|
372
|
-
require 'rvm'
|
373
|
-
@rvm_setup = defined?(RVM) ? true : false
|
374
|
-
end
|
375
|
-
module_function :_rvm_load
|
376
|
-
#done
|
377
|
-
def _rvm_install_rubie(rubie)
|
378
|
-
std_msg = "info: Rubie #{rubie} installed."
|
379
|
-
err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
|
380
|
-
puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
|
381
|
-
RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
|
382
|
-
end
|
383
|
-
module_function :_rvm_install_rubie
|
384
|
-
|
385
|
-
#done
|
386
|
-
def rvmrc_extract_ruby_gemset(rvmrc)
|
387
|
-
"#{rvmrc_extract_ruby(rvmrc)}@#{rvmrc_extract_gemset(rvmrc)}"
|
388
|
-
end
|
389
|
-
module_function :rvmrc_extract_ruby_gemset
|
390
|
-
#done
|
391
|
-
def rvmrc_extract_ruby(rvmrc)
|
392
|
-
rvmrc[/ruby_id=\"(.*)\"/, 1]
|
393
|
-
end
|
394
|
-
module_function :rvmrc_extract_ruby
|
395
|
-
#done
|
396
|
-
def rvmrc_extract_gemset(rvmrc)
|
397
|
-
rvmrc[/gemset_id=\"(.*)\"/, 1]
|
398
|
-
end
|
399
|
-
module_function :rvmrc_extract_gemset
|
400
|
-
#done
|
401
|
-
def _rvmrc_rubies
|
402
|
-
default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
|
403
|
-
@rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
|
404
|
-
@rvmrc_rubies = @rvmrc_rubies_gemsets.keys.inject(default){|h,(k,v)| h[k]; h }
|
405
|
-
end
|
406
|
-
module_function :_rvmrc_rubies
|
407
|
-
#done
|
408
|
-
def _rvmrc_gemsets
|
409
|
-
default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
|
410
|
-
@rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
|
411
|
-
@rvmrc_gemsets = @rvmrc_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
|
412
|
-
end
|
413
|
-
module_function :_rvmrc_gemsets
|
414
|
-
# done
|
415
|
-
def _each_rvmrc_rubie
|
416
|
-
_rvmrc_rubies.each do |ary|
|
417
|
-
RVM.use(ary[0])
|
418
|
-
yield ary[0]
|
419
|
-
end
|
420
|
-
ensure
|
421
|
-
RVM.reset_current!
|
422
|
-
end
|
423
|
-
module_function :_each_rvmrc_rubie
|
424
|
-
# done
|
425
|
-
def _rvmrc_create_gemsets
|
426
|
-
_rvmrc_gemsets.each do |hsh|
|
427
|
-
RVM.use hsh[0]
|
428
|
-
hsh[1][:gemsets].each do |gmst|
|
429
|
-
# TODO: Post refactor
|
430
|
-
#RVM.gemset.create([gmst])
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end
|
434
|
-
module_function :_rvmrc_create_gemsets
|
435
|
-
#done
|
436
|
-
def _rvmrc_install_gem(rubie, spec)
|
437
|
-
gem, version = spec
|
438
|
-
_rvmrc_gemsets.each do |hsh|
|
439
|
-
rubie = hsh[0]
|
440
|
-
hsh[1][:gemsets].each do |gmst|
|
441
|
-
#RVM.gemset.create([gmst])
|
442
|
-
RVM.gemset.use(gmst)
|
443
|
-
if _rvm_gem_available?(spec)
|
444
|
-
puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
|
445
|
-
else
|
446
|
-
puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
|
447
|
-
RVM.run("rvm --create use #{rubie}@#{gmst}; gem install #{gem} -v#{version} #{rvm_gem_install_options}")
|
448
|
-
end
|
449
|
-
end
|
450
|
-
end
|
451
|
-
end
|
452
|
-
module_function :_rvmrc_install_gem
|
453
|
-
|
454
|
-
# done
|
455
|
-
def set_environment_vars(vars)
|
456
|
-
vars.each { |k,v| ENV[k] = v }
|
457
|
-
end
|
458
|
-
module_function :set_environment_vars
|
459
|
-
#done
|
460
|
-
def with_rvm_environment_vars
|
461
|
-
my_vars = rvm_environment_vars
|
462
|
-
puts my_vars
|
463
|
-
current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
|
464
|
-
puts current_vars
|
465
|
-
set_environment_vars(my_vars)
|
466
|
-
yield
|
467
|
-
ensure
|
468
|
-
set_environment_vars(current_vars)
|
469
|
-
end
|
470
|
-
module_function :with_rvm_environment_vars
|
471
|
-
#done
|
472
|
-
def rvm_environment_vars
|
473
|
-
if rvm_for_macports?
|
474
|
-
{'CC' => '/usr/bin/gcc-4.2',
|
475
|
-
'CFLAGS' => '-O2 -arch x86_64',
|
476
|
-
'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
|
477
|
-
'CPPFLAGS' => '-I/opt/local/include'}
|
478
|
-
else
|
479
|
-
{}
|
480
|
-
end
|
481
|
-
end
|
482
|
-
module_function :rvm_environment_vars
|
483
|
-
#done
|
484
|
-
def rvm_for_macports?
|
485
|
-
`uname`.strip == 'Darwin' && `which port`.present?
|
486
|
-
end
|
487
|
-
module_function :rvm_for_macports?
|
488
|
-
# done
|
489
|
-
def rvm_install_options
|
490
|
-
{ }
|
491
|
-
end
|
492
|
-
module_function :rvm_install_options
|
493
|
-
#done
|
494
|
-
def _rvm_gem_available?(spec)
|
495
|
-
gem, version = spec
|
496
|
-
RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
|
497
|
-
end
|
498
|
-
module_function :_rvm_gem_available?
|
499
44
|
end
|
500
45
|
end
|
501
46
|
end
|
47
|
+
|
data/lib/cuken/api/ssh.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'aruba/api' unless defined? Aruba::Api
|
1
|
+
#require 'aruba/api' unless defined? Aruba::Api
|
2
2
|
require 'cuken/api/ssh-forever' unless defined? SecureShellForever
|
3
3
|
|
4
4
|
module Cuken
|
@@ -6,12 +6,48 @@ module Cuken
|
|
6
6
|
module Ssh
|
7
7
|
|
8
8
|
def ssh_init_password_less
|
9
|
-
@
|
10
|
-
cmd =
|
11
|
-
|
9
|
+
@ssh_options ||= ssh_default_options
|
10
|
+
cmd = ssh_cmd(@ssh_options)
|
11
|
+
announce_or_puts(unescape(cmd))
|
12
12
|
end
|
13
13
|
|
14
14
|
def ssh_init_password_less_batch(table=nil)
|
15
|
+
if table == :default
|
16
|
+
return @ssh_options = ssh_default_options
|
17
|
+
elsif table.nil?
|
18
|
+
return @ssh_options ||={}
|
19
|
+
end
|
20
|
+
@ssh_options ||={}
|
21
|
+
table.hashes.each do |hash|
|
22
|
+
hsh = parse_ssh_options(hash)
|
23
|
+
cmd = ssh_cmd(hsh)
|
24
|
+
ssh_run(cmd)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def ssh_init_password_less_interactive(table=nil)
|
29
|
+
if table == :default
|
30
|
+
return @ssh_options = ssh_default_options
|
31
|
+
elsif table.nil?
|
32
|
+
return @ssh_options ||={}
|
33
|
+
end
|
34
|
+
@ssh_options ||={}
|
35
|
+
table.hashes.each do |hash|
|
36
|
+
hsh = parse_ssh_options(hash)
|
37
|
+
cmd = ssh_cmd(hsh)
|
38
|
+
ssh_login_interactive(cmd)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def ssh_run(cmd)
|
43
|
+
run_simple(unescape(cmd))
|
44
|
+
end
|
45
|
+
|
46
|
+
def ssh_login_interactive(cmd)
|
47
|
+
run_interactive(unescape(cmd))
|
48
|
+
end
|
49
|
+
|
50
|
+
def ssh_forever_init_password_less_batch(table=nil)
|
15
51
|
if table == :default
|
16
52
|
return @ssh_forever_options = ssh_forever_default_options
|
17
53
|
elsif table.nil?
|
@@ -59,6 +95,26 @@ module Cuken
|
|
59
95
|
"ssh-forever #{hsh[:user]}@#{hsh[:hostname]} -p #{hsh[:port]} -i ~/.ssh/id_rsa_cuken -n #{hsh[:name]} -b"
|
60
96
|
end
|
61
97
|
|
98
|
+
def ssh_cmd(hsh)
|
99
|
+
if hsh[:alias]
|
100
|
+
#append_ssh_config unless existing_ssh_config?
|
101
|
+
login_command = "ssh #{hsh[:alias]} #{ssh_args(hsh)}"
|
102
|
+
else
|
103
|
+
login_command = "ssh #{hsh[:user]}@#{hsh[:hostname]}#{ssh_args(hsh)}"
|
104
|
+
end
|
105
|
+
login_command
|
106
|
+
end
|
107
|
+
|
108
|
+
def ssh_args(hsh)
|
109
|
+
[ ' ',
|
110
|
+
("-i #{hsh[:identity_file]}" if hsh[:identity_file]),
|
111
|
+
("-F #{hsh[:config_file]}" if hsh[:config_file]),
|
112
|
+
("-p #{hsh[:port]}" if hsh[:port] =~ /^\d+$/),
|
113
|
+
(hsh[:stricthostkeychecking] == 'yes' ? "-o stricthostkeychecking=yes" : "-o stricthostkeychecking=no"),
|
114
|
+
(hsh[:debug] ? "-vvv" : "-q")
|
115
|
+
].compact.join(' ')
|
116
|
+
end
|
117
|
+
|
62
118
|
def parse_ssh_forever_options(hsh)
|
63
119
|
new_hsh = hsh.inject({}) { |h, (k, v)| h[k.intern] = v; h }
|
64
120
|
ssh_forever_default_options.merge(new_hsh).inject({}) do |h, (k, v)|
|
@@ -78,11 +134,36 @@ module Cuken
|
|
78
134
|
end
|
79
135
|
end
|
80
136
|
|
137
|
+
def parse_ssh_options(hsh)
|
138
|
+
new_hsh = hsh.inject({}) { |h, (k, v)| h[k.intern] = v; h }
|
139
|
+
ssh_default_options.merge(new_hsh).inject({}) do |h, (k, v)|
|
140
|
+
v=v.to_s
|
141
|
+
if v[/\:default/]
|
142
|
+
v = ssh_default_options[k.to_sym]
|
143
|
+
h[k]=v
|
144
|
+
next h
|
145
|
+
end
|
146
|
+
if v[/`(.*)`/]
|
147
|
+
cmd=v.gsub(/`/,'')
|
148
|
+
run_simple(unescape(cmd))
|
149
|
+
v = output_from(cmd).strip
|
150
|
+
end
|
151
|
+
h[k]=v
|
152
|
+
h
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
81
156
|
def ssh_forever_default_options
|
82
157
|
{:user => ssh_client_username, :hostname => ssh_client_hostname,
|
83
158
|
:port => 22, :name => 'cuken', :identity_file => '~/.ssh/id_rsa_cuken',
|
84
159
|
:auto => true, :intense => true, :quiet => true }
|
85
160
|
end
|
161
|
+
|
162
|
+
def ssh_default_options
|
163
|
+
{:user => ssh_client_username, :hostname => ssh_client_hostname,
|
164
|
+
:port => 22, :identity_file => '~/.ssh/id_rsa',
|
165
|
+
:quiet => true }
|
166
|
+
end
|
86
167
|
end
|
87
168
|
end
|
88
169
|
end
|
@@ -20,7 +20,8 @@ module ::Cuken
|
|
20
20
|
module Common
|
21
21
|
|
22
22
|
def establish_vm_interactive_ssh(boxname)
|
23
|
-
|
23
|
+
name = vagrant.vm.key?(:primary) ? :primary : boxname.to_sym
|
24
|
+
cmd = vagrant.vm[name].ssh.ssh_connect_command
|
24
25
|
run_interactive(unescape(cmd))
|
25
26
|
end
|
26
27
|
|
@@ -41,7 +42,7 @@ module ::Cuken
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
else
|
44
|
-
|
45
|
+
in_dir do
|
45
46
|
if expect_presence
|
46
47
|
load_vagrant_file(path)
|
47
48
|
end
|
@@ -68,10 +69,12 @@ module ::Cuken
|
|
68
69
|
def check_vm_state(name, state, expect_state = true )
|
69
70
|
in_chef_root do
|
70
71
|
if expect_state
|
72
|
+
# puts vagrant.status(name).inspect
|
71
73
|
vagrant.vm[name.to_sym].vm.state.should == state
|
72
74
|
else
|
73
|
-
vagrant.
|
74
|
-
|
75
|
+
puts vagrant.status(name).inspect
|
76
|
+
vagrant.status(name).include?(state).should be_false
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
@@ -37,7 +37,7 @@ module ::Cuken
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def vms
|
40
|
-
@vms = environment.
|
40
|
+
@vms = environment.vms
|
41
41
|
end
|
42
42
|
|
43
43
|
# def name
|
@@ -80,7 +80,7 @@ module ::Cuken
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def state(name)
|
83
|
-
vm[name.to_sym].vm.state
|
83
|
+
vms[name.to_sym].vm ? vms[name.to_sym].vm.state : nil
|
84
84
|
end
|
85
85
|
|
86
86
|
def run_vagrant_cli(cmd, vm_name)
|