cucumber-chef 2.1.0.rc.11 → 2.1.0.rc.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cucumber-chef +10 -24
- data/chef_repo/cookbooks/cucumber-chef/recipes/lxc.rb +1 -65
- data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +1 -41
- data/cucumber-chef.gemspec +1 -2
- data/lib/cucumber/chef/client.rb +50 -60
- data/lib/cucumber/chef/containers.rb +519 -0
- data/lib/cucumber/chef/providers/aws.rb +0 -2
- data/lib/cucumber/chef/providers/vagrant.rb +1 -1
- data/lib/cucumber/chef/steps/provision_steps.rb +11 -13
- data/lib/cucumber/chef/test_lab.rb +15 -40
- data/lib/cucumber/chef/version.rb +1 -1
- data/lib/cucumber/chef.rb +1 -4
- metadata +4 -17
- data/bin/cc-push +0 -49
- data/bin/cc-server +0 -84
- data/chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb +0 -10
- data/lib/cucumber/chef/helpers/chef_client.rb +0 -167
- data/lib/cucumber/chef/helpers/chef_server.rb +0 -42
- data/lib/cucumber/chef/helpers/command.rb +0 -60
- data/lib/cucumber/chef/helpers/container.rb +0 -187
- data/lib/cucumber/chef/helpers/minitest.rb +0 -35
- data/lib/cucumber/chef/helpers/server.rb +0 -115
- data/lib/cucumber/chef/helpers/test_lab.rb +0 -52
- data/lib/cucumber/chef/helpers/utility.rb +0 -71
- data/lib/cucumber/chef/helpers.rb +0 -50
@@ -25,7 +25,7 @@ module Cucumber
|
|
25
25
|
class TestLabError < Error; end
|
26
26
|
|
27
27
|
class TestLab
|
28
|
-
attr_accessor :provider
|
28
|
+
attr_accessor :provider, :containers
|
29
29
|
|
30
30
|
################################################################################
|
31
31
|
|
@@ -33,31 +33,28 @@ module Cucumber
|
|
33
33
|
@ui = ui
|
34
34
|
|
35
35
|
@provider = Cucumber::Chef::Provider.new(@ui)
|
36
|
+
@containers = Cucumber::Chef::Containers.new(@ui, self)
|
36
37
|
end
|
37
38
|
|
38
39
|
################################################################################
|
39
40
|
|
40
|
-
def bootstrap_ssh
|
41
|
-
|
41
|
+
def bootstrap_ssh(options={})
|
42
|
+
if (!defined?(@bootstrap_ssh) || @bootstrap_ssh.nil?)
|
43
|
+
@bootstrap_ssh ||= ZTK::SSH.new({:ui => @ui, :timeout => Cucumber::Chef::Config.command_timeout}.merge(options))
|
42
44
|
|
43
|
-
|
44
|
-
@
|
45
|
-
|
46
|
-
@
|
47
|
-
@ssh.config.port = self.port
|
48
|
-
@ssh.config.user = Cucumber::Chef.bootstrap_user
|
49
|
-
@ssh.config.keys = Cucumber::Chef.bootstrap_identity
|
45
|
+
@bootstrap_ssh.config.host_name = self.ip
|
46
|
+
@bootstrap_ssh.config.port = self.port
|
47
|
+
@bootstrap_ssh.config.user = Cucumber::Chef.bootstrap_user
|
48
|
+
@bootstrap_ssh.config.keys = Cucumber::Chef.bootstrap_identity
|
50
49
|
end
|
51
|
-
@
|
50
|
+
@bootstrap_ssh
|
52
51
|
end
|
53
52
|
|
54
53
|
################################################################################
|
55
54
|
|
56
|
-
def ssh
|
57
|
-
dead? and raise TestLabError, "The test lab must be running in order to start an SSH session!"
|
58
|
-
|
55
|
+
def ssh(options={})
|
59
56
|
if (!defined?(@ssh) || @ssh.nil?)
|
60
|
-
@ssh ||= ZTK::SSH.new(:ui => @ui, :timeout => Cucumber::Chef::Config.command_timeout)
|
57
|
+
@ssh ||= ZTK::SSH.new({:ui => @ui, :timeout => Cucumber::Chef::Config.command_timeout}.merge(options))
|
61
58
|
|
62
59
|
@ssh.config.host_name = self.ip
|
63
60
|
@ssh.config.port = self.port
|
@@ -69,13 +66,11 @@ module Cucumber
|
|
69
66
|
|
70
67
|
################################################################################
|
71
68
|
|
72
|
-
def proxy_ssh(container)
|
73
|
-
dead? and raise TestLabError, "The test lab must be running in order to start a proxy SSH session!"
|
74
|
-
|
69
|
+
def proxy_ssh(container, options={})
|
75
70
|
container = container.to_sym
|
76
71
|
@proxy_ssh ||= Hash.new
|
77
72
|
if (!defined?(@proxy_ssh[container]) || @proxy_ssh[container].nil?)
|
78
|
-
@proxy_ssh[container] ||= ZTK::SSH.new(:ui => @ui, :timeout => Cucumber::Chef::Config.command_timeout)
|
73
|
+
@proxy_ssh[container] ||= ZTK::SSH.new({:ui => @ui, :timeout => Cucumber::Chef::Config.command_timeout}.merge(options))
|
79
74
|
|
80
75
|
@proxy_ssh[container].config.proxy_host_name = self.ip
|
81
76
|
@proxy_ssh[container].config.proxy_port = self.port
|
@@ -89,38 +84,18 @@ module Cucumber
|
|
89
84
|
@proxy_ssh[container]
|
90
85
|
end
|
91
86
|
|
92
|
-
################################################################################
|
93
|
-
|
94
|
-
def cc_client
|
95
|
-
dead? and raise TestLabError, "The test lab must be running in order to start the cc-server/client session!"
|
96
|
-
|
97
|
-
@cc_client ||= Cucumber::Chef::Client.new(self, @ui)
|
98
|
-
@cc_client
|
99
|
-
end
|
100
|
-
|
101
|
-
################################################################################
|
102
|
-
|
103
|
-
def drb
|
104
|
-
dead? and raise TestLabError, "The test lab must be running in order to start a Drb session!"
|
105
|
-
|
106
|
-
self.cc_client.drb
|
107
|
-
end
|
108
|
-
|
109
87
|
################################################################################
|
110
88
|
|
111
89
|
def knife_cli(args, options={})
|
112
90
|
options = {:silence => true}.merge(options)
|
113
91
|
|
114
|
-
extracted_options = options.select{ |k,v| [:silence, :expected_exit_code].include?(k) }
|
115
|
-
options.reject!{ |k,v| [:silence, :expected_exit_code].include?(k) }
|
116
|
-
|
117
92
|
arguments = Array.new
|
118
93
|
arguments << "--user #{Cucumber::Chef::Config.user}"
|
119
94
|
arguments << "--server-url #{self.chef_server_api}"
|
120
95
|
arguments << "--config #{Cucumber::Chef.knife_rb}" if File.exists?(Cucumber::Chef.knife_rb)
|
121
96
|
|
122
97
|
command = Cucumber::Chef.build_command("knife", args, arguments)
|
123
|
-
ZTK::Command.new
|
98
|
+
ZTK::Command.new.exec(command, options)
|
124
99
|
end
|
125
100
|
|
126
101
|
################################################################################
|
@@ -24,7 +24,7 @@ module Cucumber
|
|
24
24
|
|
25
25
|
################################################################################
|
26
26
|
|
27
|
-
VERSION = "2.1.0.rc.
|
27
|
+
VERSION = "2.1.0.rc.12" unless const_defined?(:VERSION)
|
28
28
|
|
29
29
|
################################################################################
|
30
30
|
|
data/lib/cucumber/chef.rb
CHANGED
@@ -19,10 +19,6 @@
|
|
19
19
|
#
|
20
20
|
################################################################################
|
21
21
|
|
22
|
-
require 'drb'
|
23
|
-
require 'readline'
|
24
|
-
require 'socket'
|
25
|
-
require 'stringio'
|
26
22
|
require 'benchmark'
|
27
23
|
|
28
24
|
################################################################################
|
@@ -48,6 +44,7 @@ module Cucumber
|
|
48
44
|
|
49
45
|
autoload :Client, 'cucumber/chef/client'
|
50
46
|
autoload :Config, 'cucumber/chef/config'
|
47
|
+
autoload :Containers, 'cucumber/chef/containers'
|
51
48
|
autoload :Provider, 'cucumber/chef/provider'
|
52
49
|
autoload :Provisioner, 'cucumber/chef/provisioner'
|
53
50
|
autoload :TestLab, 'cucumber/chef/test_lab'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0.rc.
|
4
|
+
version: 2.1.0.rc.12
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -147,7 +147,7 @@ dependencies:
|
|
147
147
|
requirements:
|
148
148
|
- - ! '>='
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: 1.0.
|
150
|
+
version: 1.0.1
|
151
151
|
type: :runtime
|
152
152
|
prerelease: false
|
153
153
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -155,7 +155,7 @@ dependencies:
|
|
155
155
|
requirements:
|
156
156
|
- - ! '>='
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version: 1.0.
|
158
|
+
version: 1.0.1
|
159
159
|
- !ruby/object:Gem::Dependency
|
160
160
|
name: simplecov
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,8 +227,6 @@ email:
|
|
227
227
|
executables:
|
228
228
|
- cc-console
|
229
229
|
- cc-knife
|
230
|
-
- cc-push
|
231
|
-
- cc-server
|
232
230
|
- cucumber-chef
|
233
231
|
extensions: []
|
234
232
|
extra_rdoc_files: []
|
@@ -245,8 +243,6 @@ files:
|
|
245
243
|
- TODO.md
|
246
244
|
- bin/cc-console
|
247
245
|
- bin/cc-knife
|
248
|
-
- bin/cc-push
|
249
|
-
- bin/cc-server
|
250
246
|
- bin/cucumber-chef
|
251
247
|
- chef_repo/cookbooks/cucumber-chef/LICENSE
|
252
248
|
- chef_repo/cookbooks/cucumber-chef/README.md
|
@@ -258,7 +254,6 @@ files:
|
|
258
254
|
- chef_repo/cookbooks/cucumber-chef/templates/default/db-168-192.erb
|
259
255
|
- chef_repo/cookbooks/cucumber-chef/templates/default/db-test-lab.erb
|
260
256
|
- chef_repo/cookbooks/cucumber-chef/templates/default/dhcpd-conf.erb
|
261
|
-
- chef_repo/cookbooks/cucumber-chef/templates/default/gemrc.erb
|
262
257
|
- chef_repo/cookbooks/cucumber-chef/templates/default/lxc-initializer-config.erb
|
263
258
|
- chef_repo/cookbooks/cucumber-chef/templates/default/lxc-install-chef.erb
|
264
259
|
- chef_repo/cookbooks/cucumber-chef/templates/default/motd.erb
|
@@ -284,15 +279,7 @@ files:
|
|
284
279
|
- lib/cucumber/chef.rb
|
285
280
|
- lib/cucumber/chef/client.rb
|
286
281
|
- lib/cucumber/chef/config.rb
|
287
|
-
- lib/cucumber/chef/
|
288
|
-
- lib/cucumber/chef/helpers/chef_client.rb
|
289
|
-
- lib/cucumber/chef/helpers/chef_server.rb
|
290
|
-
- lib/cucumber/chef/helpers/command.rb
|
291
|
-
- lib/cucumber/chef/helpers/container.rb
|
292
|
-
- lib/cucumber/chef/helpers/minitest.rb
|
293
|
-
- lib/cucumber/chef/helpers/server.rb
|
294
|
-
- lib/cucumber/chef/helpers/test_lab.rb
|
295
|
-
- lib/cucumber/chef/helpers/utility.rb
|
282
|
+
- lib/cucumber/chef/containers.rb
|
296
283
|
- lib/cucumber/chef/provider.rb
|
297
284
|
- lib/cucumber/chef/providers/aws.rb
|
298
285
|
- lib/cucumber/chef/providers/vagrant.rb
|
data/bin/cc-push
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'cucumber-chef'
|
3
|
-
|
4
|
-
tag = Cucumber::Chef.tag("cc-push")
|
5
|
-
puts(tag)
|
6
|
-
Cucumber::Chef.boot(tag)
|
7
|
-
|
8
|
-
ui = ZTK::UI.new(:logger => Cucumber::Chef.logger)
|
9
|
-
if (test_lab = Cucumber::Chef::TestLab.new(ui)) && test_lab.alive?
|
10
|
-
gem_name = "cucumber-chef-#{Cucumber::Chef::VERSION}.gem"
|
11
|
-
gem_path = File.join(Cucumber::Chef.root_dir, gem_name)
|
12
|
-
|
13
|
-
ui.logger.info { "gem_name == '#{gem_name}'" }
|
14
|
-
ui.logger.info { "gem_path == '#{gem_path}'" }
|
15
|
-
|
16
|
-
if !File.exists?(gem_path)
|
17
|
-
puts
|
18
|
-
puts("To build cucumber-chef and install the gem in to the test lab, execute:")
|
19
|
-
puts
|
20
|
-
puts [ "cd #{Cucumber::Chef.root_dir}", "gem build cucumber-chef.gemspec", "cd #{Dir.pwd}", "bundle exec cc-push" ].join(" ; ")
|
21
|
-
puts
|
22
|
-
else
|
23
|
-
local_file = File.join(Cucumber::Chef.root_dir, gem_name)
|
24
|
-
remote_file = File.join("/", "home", test_lab.bootstrap_ssh.config.user, gem_name)
|
25
|
-
ui.logger.info { "#{local_file} -> #{test_lab.bootstrap_ssh.config.user}@#{test_lab.ip}:#{remote_file}" }
|
26
|
-
|
27
|
-
test_lab.bootstrap_ssh.upload(local_file, remote_file)
|
28
|
-
FileUtils.rm_f(File.join(Cucumber::Chef.root_dir, "*.gem"))
|
29
|
-
|
30
|
-
test_lab.bootstrap_ssh.exec(<<-EOH
|
31
|
-
sudo /bin/bash -c '
|
32
|
-
pkill -9 cc-server
|
33
|
-
cd #{File.dirname(remote_file)}
|
34
|
-
ls -la | grep 'cucumber-chef-'
|
35
|
-
gem uninstall cucumber-chef ztk --all --ignore-dependencies --executables --backtrace
|
36
|
-
rm -fv /usr/lib/ruby/gems/1.8/cache/#{gem_name}
|
37
|
-
gem cleanup cucumber-chef --backtrace
|
38
|
-
gem install #{remote_file} --backtrace
|
39
|
-
rm -fv /home/#{test_lab.bootstrap_ssh.config.user}/*.gem
|
40
|
-
exit 0'
|
41
|
-
EOH
|
42
|
-
)
|
43
|
-
File.exists?(gem_path) and File.delete(gem_path)
|
44
|
-
end
|
45
|
-
|
46
|
-
else
|
47
|
-
puts("No running cucumber-chef test labs to connect to!")
|
48
|
-
exit(1)
|
49
|
-
end
|
data/bin/cc-server
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
if !ENV['BACKGROUND'].nil?
|
3
|
-
if RUBY_VERSION < "1.9"
|
4
|
-
exit if fork
|
5
|
-
Process.setsid
|
6
|
-
exit if fork
|
7
|
-
Dir.chdir "/"
|
8
|
-
STDIN.reopen "/dev/null"
|
9
|
-
STDOUT.reopen "/dev/null", "a"
|
10
|
-
STDERR.reopen "/dev/null", "a"
|
11
|
-
else
|
12
|
-
Process.daemon
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'drb/drb'
|
17
|
-
require 'drb/acl'
|
18
|
-
require 'cucumber-chef'
|
19
|
-
require 'cucumber/chef/helpers'
|
20
|
-
|
21
|
-
tag = Cucumber::Chef.tag("cc-server")
|
22
|
-
puts(" * #{tag}")
|
23
|
-
Cucumber::Chef.boot(tag)
|
24
|
-
$logger = Cucumber::Chef.logger
|
25
|
-
Dir.chdir(File.join("/home", Cucumber::Chef.lab_user))
|
26
|
-
|
27
|
-
class FrontObject
|
28
|
-
attr_accessor :containers
|
29
|
-
|
30
|
-
include Cucumber::Chef
|
31
|
-
include Cucumber::Chef::Helpers
|
32
|
-
|
33
|
-
################################################################################
|
34
|
-
|
35
|
-
def initialize
|
36
|
-
logger.info { "DRB=#{DRb.config.inspect}" }
|
37
|
-
|
38
|
-
if ENV['PURGE'] == 'YES'
|
39
|
-
Cucumber::Chef.logger.warn { "PURGING CONTAINERS! Container attributes will be reset!" }
|
40
|
-
load_containers
|
41
|
-
containers.each do |name, value|
|
42
|
-
server_destroy(name)
|
43
|
-
end
|
44
|
-
|
45
|
-
File.exists?(Cucumber::Chef.containers_bin) && File.delete(Cucumber::Chef.containers_bin)
|
46
|
-
load_containers
|
47
|
-
else
|
48
|
-
Cucumber::Chef.logger.info { "Allowing existing containers to persist." }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
################################################################################
|
53
|
-
|
54
|
-
def shutdown
|
55
|
-
logger.fatal { "Shutting down." }
|
56
|
-
DRb.stop_service
|
57
|
-
exit(0)
|
58
|
-
end
|
59
|
-
|
60
|
-
################################################################################
|
61
|
-
|
62
|
-
def logger
|
63
|
-
$logger
|
64
|
-
end
|
65
|
-
|
66
|
-
################################################################################
|
67
|
-
|
68
|
-
def ping
|
69
|
-
"pong"
|
70
|
-
end
|
71
|
-
|
72
|
-
################################################################################
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
list = %w(deny all)
|
77
|
-
ARGV[0] and (list += [ 'allow', ARGV[0] ])
|
78
|
-
acl = ACL.new(list)
|
79
|
-
|
80
|
-
# This will break everything:
|
81
|
-
# $SAFE = 1
|
82
|
-
|
83
|
-
DRb.start_service("druby://:8787", FrontObject.new)
|
84
|
-
DRb.thread.join
|
@@ -1,167 +0,0 @@
|
|
1
|
-
################################################################################
|
2
|
-
#
|
3
|
-
# Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
|
4
|
-
# Author: Zachary Patten <zachary@jovelabs.com>
|
5
|
-
# Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
|
6
|
-
# License: Apache License, Version 2.0
|
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
|
-
|
22
|
-
module Cucumber::Chef::Helpers::ChefClient
|
23
|
-
|
24
|
-
################################################################################
|
25
|
-
|
26
|
-
# call this in a Before hook
|
27
|
-
def chef_set_client_config(config={})
|
28
|
-
@chef_client_config = (@chef_client_config || {
|
29
|
-
:log_level => :info,
|
30
|
-
:log_location => "/var/log/chef/client.log",
|
31
|
-
:chef_server_url => "https://api.opscode.com/organizations/#{config[:orgname]}",
|
32
|
-
:validation_client_name => "#{config[:orgname]}-validator",
|
33
|
-
:ssl_verify_mode => :verify_none,
|
34
|
-
:environment => nil # use default; i.e. set no value
|
35
|
-
}).merge(config)
|
36
|
-
logger.info { "Setting chef client config '#{@chef_client_config.inspect}'." }
|
37
|
-
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
################################################################################
|
42
|
-
|
43
|
-
# call this before chef_run_client
|
44
|
-
def chef_set_client_attributes(name, attributes={})
|
45
|
-
@containers[name] ||= Hash.new
|
46
|
-
@containers[name][:chef_client] = (@containers[name][:chef_client] || {}).merge(attributes) { |k,o,n| (k = (o + n).uniq) }
|
47
|
-
logger.info { "Setting chef client attributes to '#{@containers[name][:chef_client].inspect}' for container '#{name}'." }
|
48
|
-
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
52
|
-
################################################################################
|
53
|
-
|
54
|
-
def chef_run_client(name, *args)
|
55
|
-
chef_config_client(name)
|
56
|
-
|
57
|
-
logger.info { "Removing artifacts #{Cucumber::Chef::Config[:artifacts].values.collect{|z| "'#{z}'" }.join(' ')}." }
|
58
|
-
(command_run_remote(name, "/bin/rm -fv #{Cucumber::Chef::Config[:artifacts].values.join(' ')}") rescue nil)
|
59
|
-
|
60
|
-
logger.info { "Running chef client on container '#{name}'." }
|
61
|
-
|
62
|
-
arguments = {
|
63
|
-
"--node-name" => name,
|
64
|
-
"--json-attributes" => File.join("/etc", "chef", "attributes.json").to_s,
|
65
|
-
"--log_level" => @chef_client_config[:log_level],
|
66
|
-
"--logfile" => @chef_client_config[:log_location],
|
67
|
-
"--server" => @chef_client_config[:chef_server_url],
|
68
|
-
"--environment" => @chef_client_config[:environment]
|
69
|
-
}.reject{ |k,v| v.nil? }.sort
|
70
|
-
|
71
|
-
output = nil
|
72
|
-
bm = ::Benchmark.realtime do
|
73
|
-
output = command_run_remote(name, ["/usr/bin/chef-client", arguments, args, "--once"].flatten.join(" "))
|
74
|
-
end
|
75
|
-
logger.info { "Chef client run on container '#{name}' took %0.4f seconds." % bm }
|
76
|
-
|
77
|
-
output
|
78
|
-
end
|
79
|
-
|
80
|
-
################################################################################
|
81
|
-
|
82
|
-
def chef_config_client(name)
|
83
|
-
# make sure our configuration location is there
|
84
|
-
client_rb = File.join("/", container_root(name), "etc/chef/client.rb")
|
85
|
-
FileUtils.mkdir_p(File.dirname(client_rb))
|
86
|
-
|
87
|
-
# render the chef-client client.rb if we are configured to
|
88
|
-
if Cucumber::Chef::Config.chef[:render_client_rb]
|
89
|
-
File.exists?(client_rb) && File.delete(client_rb)
|
90
|
-
|
91
|
-
max_key_size = @chef_client_config.keys.collect{ |z| z.to_s.size }.max
|
92
|
-
|
93
|
-
File.open(client_rb, 'w') do |f|
|
94
|
-
f.puts(Cucumber::Chef.generate_do_not_edit_warning("Chef Client Configuration"))
|
95
|
-
f.puts
|
96
|
-
@chef_client_config.merge(:node_name => name).each do |(key,value)|
|
97
|
-
next if value.nil?
|
98
|
-
f.puts("%-#{max_key_size}s %s" % [key, value.inspect])
|
99
|
-
end
|
100
|
-
f.puts
|
101
|
-
f.puts("Mixlib::Log::Formatter.show_time = true")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
attributes_json = File.join("/", container_root(name), "etc", "chef", "attributes.json")
|
106
|
-
FileUtils.mkdir_p(File.dirname(attributes_json))
|
107
|
-
File.open(attributes_json, 'w') do |f|
|
108
|
-
f.puts((@containers[name][:chef_client] || {}).to_json)
|
109
|
-
end
|
110
|
-
|
111
|
-
# make sure our log location is there
|
112
|
-
log_location = File.join("/", container_root(name), @chef_client_config[:log_location])
|
113
|
-
FileUtils.mkdir_p(File.dirname(log_location))
|
114
|
-
|
115
|
-
command_run_local("cp /etc/chef/validation.pem #{container_root(name)}/etc/chef/ 2>&1")
|
116
|
-
|
117
|
-
true
|
118
|
-
end
|
119
|
-
|
120
|
-
################################################################################
|
121
|
-
|
122
|
-
def chef_client_artifacts(name)
|
123
|
-
# this is messy and needs to be refactored into a more configurable
|
124
|
-
# solution; but for now this should do the trick
|
125
|
-
|
126
|
-
ssh = $test_lab.proxy_ssh(name)
|
127
|
-
|
128
|
-
feature_file = $scenario.file_colon_line.split(":").first
|
129
|
-
feature_line = $scenario.file_colon_line.split(":").last
|
130
|
-
scenario_tag = $scenario.name.gsub(" ", "_")
|
131
|
-
|
132
|
-
feature_name = File.basename(feature_file, ".feature")
|
133
|
-
feature_dir = feature_file.split("/")[-2]
|
134
|
-
|
135
|
-
Cucumber::Chef::Config[:artifacts].each do |label, remote_path|
|
136
|
-
result = ssh.exec("/bin/bash -c '[[ -f #{remote_path} ]] ; echo $?'", :silence => true)
|
137
|
-
if (result.output =~ /0/)
|
138
|
-
logger.info { "Retrieving artifact '#{remote_path}' from container '#{name}'." }
|
139
|
-
|
140
|
-
local_path = File.join(Cucumber::Chef.artifacts_dir, feature_dir, "#{feature_name}.txt")
|
141
|
-
tmp_path = File.join("/tmp", label)
|
142
|
-
|
143
|
-
FileUtils.mkdir_p(File.dirname(local_path))
|
144
|
-
ssh.download(remote_path, tmp_path)
|
145
|
-
data = IO.read(tmp_path).chomp
|
146
|
-
|
147
|
-
message = "#{$scenario.name} (#{File.basename(feature_file)}:#{feature_line}:#{label})"
|
148
|
-
header = ("-" * message.length)
|
149
|
-
|
150
|
-
f = File.open(local_path, "a")
|
151
|
-
f.write("#{header}\n")
|
152
|
-
f.write("#{message}\n")
|
153
|
-
f.write("#{header}\n")
|
154
|
-
f.write("#{data}\n")
|
155
|
-
|
156
|
-
File.chmod(0644, local_path)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
true
|
161
|
-
end
|
162
|
-
|
163
|
-
################################################################################
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
################################################################################
|
@@ -1,42 +0,0 @@
|
|
1
|
-
################################################################################
|
2
|
-
#
|
3
|
-
# Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
|
4
|
-
# Author: Zachary Patten <zachary@jovelabs.com>
|
5
|
-
# Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
|
6
|
-
# License: Apache License, Version 2.0
|
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
|
-
|
22
|
-
module Cucumber::Chef::Helpers::ChefServer
|
23
|
-
|
24
|
-
################################################################################
|
25
|
-
|
26
|
-
def chef_server_node_destroy(name)
|
27
|
-
(::Chef::Node.load(name).destroy rescue nil)
|
28
|
-
logger.info { "Destroyed chef node '#{name}'." }
|
29
|
-
end
|
30
|
-
|
31
|
-
################################################################################
|
32
|
-
|
33
|
-
def chef_server_client_destroy(name)
|
34
|
-
(::Chef::ApiClient.load(name).destroy rescue nil)
|
35
|
-
logger.info { "Destroyed chef client '#{name}'." }
|
36
|
-
end
|
37
|
-
|
38
|
-
################################################################################
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
################################################################################
|
@@ -1,60 +0,0 @@
|
|
1
|
-
################################################################################
|
2
|
-
#
|
3
|
-
# Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
|
4
|
-
# Author: Zachary Patten <zachary@jovelabs.com>
|
5
|
-
# Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
|
6
|
-
# License: Apache License, Version 2.0
|
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
|
-
|
22
|
-
module Cucumber::Chef::Helpers::Command
|
23
|
-
|
24
|
-
################################################################################
|
25
|
-
|
26
|
-
def command_run_remote(name, command, options={})
|
27
|
-
expected_exit_code = (options[:expected_exit_code] || 0)
|
28
|
-
options.reject!{ |k,v| k == :expected_exit_code }
|
29
|
-
|
30
|
-
identity_file = File.join(Cucumber::Chef.lab_user_home_dir, ".ssh", "id_rsa")
|
31
|
-
|
32
|
-
command = %W(/usr/bin/ssh #{ENV['LOG_LEVEL'] == 'DEBUG' ? "-v" : nil} -i #{identity_file} #{name} #{command})
|
33
|
-
::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command.compact.join(" "), :silence => true, :exit_code => expected_exit_code)
|
34
|
-
end
|
35
|
-
|
36
|
-
################################################################################
|
37
|
-
|
38
|
-
def command_run_chroot(name, command, options={})
|
39
|
-
expected_exit_code = (options[:expected_exit_code] || 0)
|
40
|
-
options.reject!{ |k,v| k == :expected_exit_code }
|
41
|
-
|
42
|
-
command = %Q(/usr/sbin/chroot #{container_root(name)} /bin/bash -c '#{command.gsub("'", '"')}')
|
43
|
-
::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command, :silence => true, :exit_code => expected_exit_code)
|
44
|
-
end
|
45
|
-
|
46
|
-
################################################################################
|
47
|
-
|
48
|
-
def command_run_local(command, options={})
|
49
|
-
expected_exit_code = (options[:expected_exit_code] || 0)
|
50
|
-
options.reject!{ |k,v| k == :expected_exit_code }
|
51
|
-
|
52
|
-
command = %Q(/bin/bash -c '#{command.gsub("'", '"')}')
|
53
|
-
::ZTK::Command.new({:timeout => Cucumber::Chef::Config.command_timeout}.merge(options)).exec(command, :silence => true, :exit_code => expected_exit_code)
|
54
|
-
end
|
55
|
-
|
56
|
-
################################################################################
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
################################################################################
|