cucumber-chef 2.1.0.rc.1 → 2.1.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cc-knife +1 -1
- data/bin/cc-push +9 -14
- data/bin/cc-server +2 -3
- data/bin/cucumber-chef +111 -47
- data/chef_repo/cookbooks/cucumber-chef/recipes/test_lab.rb +2 -1
- data/cucumber-chef.gemspec +12 -4
- data/lib/cucumber/chef/bootstrap.rb +4 -3
- data/lib/cucumber/chef/config.rb +32 -17
- data/lib/cucumber/chef/helpers/chef_client.rb +6 -9
- data/lib/cucumber/chef/helpers/command.rb +1 -1
- data/lib/cucumber/chef/helpers/container.rb +5 -12
- data/lib/cucumber/chef/provider.rb +102 -0
- data/lib/cucumber/chef/providers/aws.rb +294 -0
- data/lib/cucumber/chef/providers/vagrant.rb +121 -0
- data/lib/cucumber/chef/provisioner.rb +32 -29
- data/lib/cucumber/chef/server.rb +133 -0
- data/lib/cucumber/chef/steps/ssh_steps.rb +23 -8
- data/lib/cucumber/chef/templates/bootstrap/ubuntu-precise-test-lab.erb +1 -1
- data/lib/cucumber/chef/templates/cucumber/cc-hooks.rb +8 -68
- data/lib/cucumber/chef/test_lab.rb +20 -309
- data/lib/cucumber/chef/utility.rb +109 -41
- data/lib/cucumber/chef/version.rb +1 -1
- data/lib/cucumber/chef.rb +5 -0
- metadata +42 -22
@@ -0,0 +1,133 @@
|
|
1
|
+
################################################################################
|
2
|
+
#
|
3
|
+
# Author: Zachary Patten <zachary@jovelabs.com>
|
4
|
+
# Copyright: Copyright (c) 2011-2013 Atalanta Systems Ltd
|
5
|
+
# License: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
################################################################################
|
20
|
+
|
21
|
+
module Cucumber
|
22
|
+
module Chef
|
23
|
+
|
24
|
+
class ServerError < Error; end
|
25
|
+
|
26
|
+
class Server
|
27
|
+
attr_accessor :test_lab, :stdout, :stderr, :stdin, :logger
|
28
|
+
|
29
|
+
################################################################################
|
30
|
+
|
31
|
+
def initialize(test_lab, stdout=STDOUT, stderr=STDERR, stdin=STDIN, logger=$logger)
|
32
|
+
@stdout, @stderr, @stdin, @logger = stdout, stderr, stdin, logger
|
33
|
+
@stdout.sync = true if @stdout.respond_to?(:sync=)
|
34
|
+
|
35
|
+
@test_lab = test_lab
|
36
|
+
end
|
37
|
+
|
38
|
+
################################################################################
|
39
|
+
|
40
|
+
def up
|
41
|
+
user = Cucumber::Chef.lab_user
|
42
|
+
home_dir = Cucumber::Chef.lab_user_home_dir
|
43
|
+
provider = Cucumber::Chef::Config[:provider].to_s
|
44
|
+
@test_lab.ssh.exec("sudo mkdir -p #{File.join(home_dir, ".cucumber-chef", provider)}")
|
45
|
+
@test_lab.ssh.exec("sudo cp -f #{File.join(home_dir, ".chef", "knife.rb")} #{File.join(home_dir, ".cucumber-chef", provider, "knife.rb")}")
|
46
|
+
@test_lab.ssh.exec("sudo chown -R #{user}:#{user} #{File.join(home_dir, ".cucumber-chef")}")
|
47
|
+
|
48
|
+
local_file = Cucumber::Chef.config_rb
|
49
|
+
remote_file = File.join(home_dir, ".cucumber-chef", "config.rb")
|
50
|
+
@test_lab.ssh.upload(local_file, remote_file)
|
51
|
+
|
52
|
+
@server_thread = Thread.new do
|
53
|
+
@test_lab.ssh.exec("sudo pkill -9 -f cc-server")
|
54
|
+
|
55
|
+
destroy = (ENV['DESTROY'] == '1' ? "DESTROY='1'" : nil)
|
56
|
+
verbose = (ENV['VERBOSE'] == '1' ? "VERBOSE='1'" : nil)
|
57
|
+
log_level = ((!ENV['LOG_LEVEL'].nil? && !ENV['LOG_LEVEL'].empty?) ? "LOG_LEVEL=#{ENV['LOG_LEVEL'].inspect}" : nil)
|
58
|
+
command = ["sudo", destroy, verbose, log_level, "cc-server", Cucumber::Chef.external_ip].compact.join(" ")
|
59
|
+
@test_lab.ssh.exec(command, :silence => false)
|
60
|
+
|
61
|
+
Kernel.at_exit do
|
62
|
+
@test_lab.ssh.close
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
sleep(3)
|
67
|
+
ZTK::TCPSocketCheck.new(:host => @test_lab.ip, :port => 8787, :data => "\n\n").wait
|
68
|
+
|
69
|
+
artifacts = File.join(Cucumber::Chef.home_dir, "artifacts")
|
70
|
+
File.exists?(artifacts) && FileUtils.rm_rf(artifacts)
|
71
|
+
|
72
|
+
@server_thread
|
73
|
+
end
|
74
|
+
|
75
|
+
################################################################################
|
76
|
+
|
77
|
+
def down
|
78
|
+
end
|
79
|
+
|
80
|
+
################################################################################
|
81
|
+
|
82
|
+
def before(scenario)
|
83
|
+
# store the current scenario here; espcially since I don't know a better way to get at this information
|
84
|
+
# we use various aspects of the scenario to name our artifacts
|
85
|
+
$scenario = scenario
|
86
|
+
|
87
|
+
# cleanup previous lxc containers if asked
|
88
|
+
if ENV['DESTROY']
|
89
|
+
Cucumber::Chef.logger.info("'containers' are being destroyed")
|
90
|
+
@test_lab.drb.servers.each do |name, value|
|
91
|
+
@test_lab.drb.server_destroy(name)
|
92
|
+
end
|
93
|
+
File.exists?(Cucumber::Chef.servers_bin) && File.delete(Cucumber::Chef.servers_bin)
|
94
|
+
else
|
95
|
+
Cucumber::Chef.logger.info("'containers' are being persisted")
|
96
|
+
end
|
97
|
+
|
98
|
+
if File.exists?(Cucumber::Chef.servers_bin)
|
99
|
+
@test_lab.drb.servers = (Marshal.load(IO.read(Cucumber::Chef.servers_bin)) rescue Hash.new(nil))
|
100
|
+
end
|
101
|
+
|
102
|
+
@test_lab.drb.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
|
103
|
+
:validation_client_name => "chef-validator")
|
104
|
+
end
|
105
|
+
|
106
|
+
################################################################################
|
107
|
+
|
108
|
+
def after(scenario)
|
109
|
+
File.open(Cucumber::Chef.servers_bin, 'w') do |f|
|
110
|
+
f.puts(Marshal.dump(@test_lab.drb.servers))
|
111
|
+
end
|
112
|
+
|
113
|
+
# cleanup non-persistent lxc containers between tests
|
114
|
+
@test_lab.drb.servers.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
|
115
|
+
@test_lab.drb.server_destroy(name)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
################################################################################
|
120
|
+
|
121
|
+
def at_exit
|
122
|
+
@test_lab.drb.shutdown
|
123
|
+
@server_thread.kill
|
124
|
+
end
|
125
|
+
|
126
|
+
################################################################################
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
################################################################################
|
@@ -11,9 +11,9 @@ When /^I have the following SSH sessions:$/ do |table|
|
|
11
11
|
@ssh_sessions[id] and !@ssh_sessions[id].closed? and @ssh_sessions[id].close
|
12
12
|
@ssh_sessions[id] = ZTK::SSH.new
|
13
13
|
|
14
|
-
@ssh_sessions[id].config.proxy_host_name = $test_lab.
|
15
|
-
@ssh_sessions[id].config.proxy_user =
|
16
|
-
@ssh_sessions[id].config.proxy_keys = Cucumber::Chef.
|
14
|
+
@ssh_sessions[id].config.proxy_host_name = $test_lab.ip
|
15
|
+
@ssh_sessions[id].config.proxy_user = Cucumber::Chef.lab_user
|
16
|
+
@ssh_sessions[id].config.proxy_keys = Cucumber::Chef.lab_identity
|
17
17
|
|
18
18
|
hash['hostname'] and (@ssh_sessions[id].config.host_name = hash['hostname'])
|
19
19
|
hash['username'] and (@ssh_sessions[id].config.user = hash['username'])
|
@@ -32,14 +32,29 @@ When /^I ssh to "([^\"]*)" with the following credentials:$/ do |hostname, table
|
|
32
32
|
@connection and !@connection.ssh.closed? and @connection.ssh.close
|
33
33
|
@connection = ZTK::SSH.new
|
34
34
|
|
35
|
-
@connection.config.proxy_host_name = $test_lab.
|
36
|
-
@connection.config.
|
37
|
-
@connection.config.
|
35
|
+
@connection.config.proxy_host_name = $test_lab.ip
|
36
|
+
@connection.config.proxy_port = $test_lab.port
|
37
|
+
@connection.config.proxy_user = Cucumber::Chef.lab_user
|
38
|
+
@connection.config.proxy_keys = Cucumber::Chef.lab_identity
|
38
39
|
|
39
40
|
hostname and (@connection.config.host_name = hostname)
|
40
|
-
session["username"] and (@connection.config.user = session["username"])
|
41
41
|
session["password"] and (@connection.config.password = session["password"])
|
42
|
-
|
42
|
+
|
43
|
+
if username = session["username"]
|
44
|
+
if username == "$lxc$"
|
45
|
+
@connection.config.user = Cucumber::Chef.lxc_user
|
46
|
+
else
|
47
|
+
@connection.config.user = username
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if keyfile = session["keyfile"]
|
52
|
+
if keyfile == "$lxc$"
|
53
|
+
@connection.config.keys = Cucumber::Chef.lxc_identity
|
54
|
+
else
|
55
|
+
@connection.config.keys = keyfile
|
56
|
+
end
|
57
|
+
end
|
43
58
|
|
44
59
|
}.should_not raise_error
|
45
60
|
end
|
@@ -4,7 +4,7 @@ CUCUMBER_CHEF_BOOTSTRAP_DONE="/.cucumber-chef-bootstrap-finished"
|
|
4
4
|
|
5
5
|
export DEBIAN_FRONTEND=noninteractive
|
6
6
|
|
7
|
-
|
7
|
+
echo "127.0.0.1 <%= @hostname %>" | tee -a /etc/hosts
|
8
8
|
echo "<%= @hostname %>" | tee /etc/hostname
|
9
9
|
hostname <%= @hostname %>
|
10
10
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
################################################################################
|
2
2
|
#
|
3
3
|
# Author: Zachary Patten <zachary@jovelabs.com>
|
4
|
-
# Copyright: Copyright (c) 2011-
|
4
|
+
# Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
|
5
5
|
# License: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,33 +20,11 @@
|
|
20
20
|
|
21
21
|
tag = Cucumber::Chef.tag("cucumber-chef")
|
22
22
|
puts(" * #{tag}")
|
23
|
-
Cucumber::Chef.
|
23
|
+
Cucumber::Chef.boot(tag)
|
24
24
|
|
25
25
|
if ($test_lab = Cucumber::Chef::TestLab.new) && ($test_lab.labs_running.count > 0)
|
26
|
-
$
|
27
|
-
$
|
28
|
-
$test_lab.ssh.exec("sudo chown -R #{$test_lab.ssh.config.user}:#{$test_lab.ssh.config.user} /home/#{$test_lab.ssh.config.user}/.cucumber-chef")
|
29
|
-
|
30
|
-
local_file = Cucumber::Chef.config_rb
|
31
|
-
remote_file = File.join("/", "home", $test_lab.ssh.config.user, ".cucumber-chef", "config.rb")
|
32
|
-
$test_lab.ssh.upload(local_file, remote_file)
|
33
|
-
|
34
|
-
$cc_server_thread = Thread.new do
|
35
|
-
$test_lab.ssh.exec("sudo pkill -9 -f cc-server")
|
36
|
-
|
37
|
-
destroy = (ENV['DESTROY'] == '1' ? 'DESTROY="1"' : nil)
|
38
|
-
verbose = (ENV['VERBOSE'] == '1' ? 'VERBOSE="1"' : nil)
|
39
|
-
command = ["sudo", destroy, verbose, "cc-server", Cucumber::Chef.external_ip].compact.join(" ")
|
40
|
-
$test_lab.ssh.exec(command, :silence => false)
|
41
|
-
|
42
|
-
Kernel.at_exit do
|
43
|
-
$test_lab.ssh.close
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
ZTK::TCPSocketCheck.new(:host => $test_lab.labs_running.first.public_ip_address, :port => 8787, :data => "\n\n").wait
|
48
|
-
|
49
|
-
FileUtils.rm_rf(File.join(Cucumber::Chef.locate(:directory, ".cucumber-chef"), "artifacts"))
|
26
|
+
$cc_server = Cucumber::Chef::Server.new($test_lab)
|
27
|
+
$cc_server.up
|
50
28
|
else
|
51
29
|
message = "No running cucumber-chef test labs to connect to!"
|
52
30
|
Cucumber::Chef.logger.fatal { message }
|
@@ -55,57 +33,19 @@ end
|
|
55
33
|
|
56
34
|
|
57
35
|
################################################################################
|
58
|
-
#
|
36
|
+
# HOOKS
|
59
37
|
################################################################################
|
60
38
|
|
61
39
|
Before do |scenario|
|
62
|
-
|
63
|
-
# we use various aspects of the scenario to name our artifacts
|
64
|
-
$scenario = scenario
|
65
|
-
|
66
|
-
# cleanup previous lxc containers if asked
|
67
|
-
if ENV['DESTROY']
|
68
|
-
log("$containers$ are being destroyed")
|
69
|
-
$test_lab.drb.servers.each do |name, value|
|
70
|
-
$test_lab.drb.server_destroy(name)
|
71
|
-
end
|
72
|
-
File.exists?(Cucumber::Chef.servers_bin) && File.delete(Cucumber::Chef.servers_bin)
|
73
|
-
else
|
74
|
-
log("$containers$ are being persisted")
|
75
|
-
end
|
76
|
-
|
77
|
-
if File.exists?(Cucumber::Chef.servers_bin)
|
78
|
-
$test_lab.drb.servers = (Marshal.load(IO.read(Cucumber::Chef.servers_bin)) rescue Hash.new(nil))
|
79
|
-
end
|
80
|
-
|
81
|
-
$test_lab.drb.chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
|
82
|
-
:validation_client_name => "chef-validator")
|
40
|
+
$cc_server.before(scenario)
|
83
41
|
end
|
84
42
|
|
85
|
-
|
86
|
-
################################################################################
|
87
|
-
# AFTER HOOK
|
88
|
-
################################################################################
|
89
|
-
|
90
43
|
After do |scenario|
|
91
|
-
|
92
|
-
f.puts(Marshal.dump($test_lab.drb.servers))
|
93
|
-
end
|
94
|
-
|
95
|
-
# cleanup non-persistent lxc containers between tests
|
96
|
-
$test_lab.drb.servers.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
|
97
|
-
$test_lab.drb.server_destroy(name)
|
98
|
-
end
|
44
|
+
$cc_server.after(scenario)
|
99
45
|
end
|
100
46
|
|
101
|
-
|
102
|
-
################################################################################
|
103
|
-
# EXIT HOOK
|
104
|
-
################################################################################
|
105
|
-
|
106
47
|
Kernel.at_exit do
|
107
|
-
$
|
108
|
-
$cc_server_thread.kill
|
48
|
+
$cc_server.at_exit
|
109
49
|
end
|
110
50
|
|
111
51
|
################################################################################
|
@@ -25,40 +25,27 @@ module Cucumber
|
|
25
25
|
class TestLabError < Error; end
|
26
26
|
|
27
27
|
class TestLab
|
28
|
-
|
29
|
-
attr_accessor :stdout, :stderr, :stdin
|
30
|
-
|
31
|
-
INVALID_STATES = %w( terminated pending )
|
32
|
-
RUNNING_STATES = %w( running starting-up )
|
33
|
-
SHUTDOWN_STATES = %w( shutdown stopping stopped shutting-down )
|
34
|
-
VALID_STATES = RUNNING_STATES+SHUTDOWN_STATES
|
28
|
+
attr_accessor :provider, :stdout, :stderr, :stdin, :logger
|
35
29
|
|
36
30
|
################################################################################
|
37
31
|
|
38
|
-
def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN)
|
39
|
-
@stdout, @stderr, @stdin = stdout, stderr, stdin
|
32
|
+
def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN, logger=$logger)
|
33
|
+
@stdout, @stderr, @stdin, @logger = stdout, stderr, stdin, logger
|
40
34
|
@stdout.sync = true if @stdout.respond_to?(:sync=)
|
41
35
|
|
42
|
-
@
|
43
|
-
:provider => 'AWS',
|
44
|
-
:aws_access_key_id => Cucumber::Chef::Config[:aws][:aws_access_key_id],
|
45
|
-
:aws_secret_access_key => Cucumber::Chef::Config[:aws][:aws_secret_access_key],
|
46
|
-
:region => Cucumber::Chef::Config[:aws][:region]
|
47
|
-
)
|
48
|
-
ensure_security_group
|
36
|
+
@provider = Cucumber::Chef::Provider.new(@stdout, @stderr, @stdin, @logger)
|
49
37
|
end
|
50
38
|
|
51
39
|
################################################################################
|
52
40
|
|
53
41
|
def ssh
|
54
42
|
if (!defined?(@ssh) || @ssh.nil?)
|
55
|
-
ssh_private_key_file = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{Cucumber::Chef::Config[:lab_user]}")
|
56
|
-
File.chmod(0400, ssh_private_key_file)
|
57
43
|
@ssh ||= ZTK::SSH.new
|
58
44
|
|
59
|
-
@ssh.config.host_name = self.
|
60
|
-
@ssh.config.
|
61
|
-
@ssh.config.
|
45
|
+
@ssh.config.host_name = self.ip
|
46
|
+
@ssh.config.port = self.port
|
47
|
+
@ssh.config.user = Cucumber::Chef.lab_user
|
48
|
+
@ssh.config.keys = Cucumber::Chef.lab_identity
|
62
49
|
end
|
63
50
|
@ssh
|
64
51
|
end
|
@@ -69,17 +56,16 @@ module Cucumber
|
|
69
56
|
container = container.to_sym
|
70
57
|
@proxy_ssh ||= Hash.new
|
71
58
|
if (!defined?(@proxy_ssh[container]) || @proxy_ssh[container].nil?)
|
72
|
-
ssh_private_key_file = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{Cucumber::Chef::Config[:lab_user]}")
|
73
|
-
File.chmod(0400, ssh_private_key_file)
|
74
59
|
@proxy_ssh[container] ||= ZTK::SSH.new
|
75
60
|
|
76
|
-
@proxy_ssh[container].config.proxy_host_name = self.
|
77
|
-
@proxy_ssh[container].config.
|
78
|
-
@proxy_ssh[container].config.
|
61
|
+
@proxy_ssh[container].config.proxy_host_name = self.ip
|
62
|
+
@proxy_ssh[container].config.proxy_port = self.port
|
63
|
+
@proxy_ssh[container].config.proxy_user = Cucumber::Chef.lab_user
|
64
|
+
@proxy_ssh[container].config.proxy_keys = Cucumber::Chef.lab_identity
|
79
65
|
|
80
66
|
@proxy_ssh[container].config.host_name = container
|
81
|
-
@proxy_ssh[container].config.user = Cucumber::Chef
|
82
|
-
@proxy_ssh[container].config.keys =
|
67
|
+
@proxy_ssh[container].config.user = Cucumber::Chef.lxc_user
|
68
|
+
@proxy_ssh[container].config.keys = Cucumber::Chef.lxc_identity
|
83
69
|
end
|
84
70
|
@proxy_ssh[container]
|
85
71
|
end
|
@@ -88,7 +74,7 @@ module Cucumber
|
|
88
74
|
|
89
75
|
def drb
|
90
76
|
if (!defined?(@drb) || @drb.nil?)
|
91
|
-
@drb ||= DRbObject.new_with_uri("druby://#{self.
|
77
|
+
@drb ||= DRbObject.new_with_uri("druby://#{self.ip}:8787")
|
92
78
|
@drb and DRb.start_service
|
93
79
|
@drb.servers = Hash.new(nil)
|
94
80
|
end
|
@@ -97,287 +83,12 @@ module Cucumber
|
|
97
83
|
|
98
84
|
################################################################################
|
99
85
|
|
100
|
-
def
|
101
|
-
if
|
102
|
-
|
103
|
-
|
104
|
-
server_definition = {
|
105
|
-
:image_id => Cucumber::Chef::Config.aws_image_id,
|
106
|
-
:groups => Cucumber::Chef::Config[:aws][:aws_security_group],
|
107
|
-
:flavor_id => Cucumber::Chef::Config[:aws][:aws_instance_type],
|
108
|
-
:key_name => Cucumber::Chef::Config[:aws][:aws_ssh_key_id],
|
109
|
-
:availability_zone => Cucumber::Chef::Config[:aws][:availability_zone],
|
110
|
-
:tags => { "purpose" => "cucumber-chef", "cucumber-chef-mode" => Cucumber::Chef::Config[:mode] },
|
111
|
-
:identity_file => Cucumber::Chef::Config[:aws][:identity_file]
|
112
|
-
}
|
113
|
-
if (@server = @connection.servers.create(server_definition))
|
114
|
-
@stdout.puts("Provisioning cucumber-chef test lab platform.")
|
115
|
-
|
116
|
-
@stdout.print("Waiting for instance...")
|
117
|
-
Cucumber::Chef.spinner do
|
118
|
-
@server.wait_for { ready? }
|
119
|
-
end
|
120
|
-
@stdout.puts("done.\n")
|
121
|
-
|
122
|
-
tag_server
|
123
|
-
|
124
|
-
@stdout.print("Waiting for 20 seconds...")
|
125
|
-
Cucumber::Chef.spinner do
|
126
|
-
sleep(20)
|
127
|
-
end
|
128
|
-
@stdout.print("done.\n")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
if @server
|
133
|
-
@stdout.print("Waiting for SSHD...")
|
134
|
-
Cucumber::Chef.spinner do
|
135
|
-
ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 22, :wait => 120).wait
|
136
|
-
end
|
137
|
-
@stdout.puts("done.\n")
|
138
|
-
end
|
139
|
-
|
140
|
-
@server
|
141
|
-
|
142
|
-
rescue Exception => e
|
143
|
-
Cucumber::Chef.logger.fatal { e.message }
|
144
|
-
Cucumber::Chef.logger.fatal { "Backtrace:\n#{e.backtrace.join("\n")}" }
|
145
|
-
raise TestLabError, e.message
|
146
|
-
end
|
147
|
-
|
148
|
-
################################################################################
|
149
|
-
|
150
|
-
def destroy
|
151
|
-
if ((l = labs).count > 0)
|
152
|
-
@stdout.puts("Destroying Servers:")
|
153
|
-
l.each do |server|
|
154
|
-
@stdout.puts(" * #{server.public_ip_address}")
|
155
|
-
server.destroy
|
156
|
-
end
|
157
|
-
else
|
158
|
-
@stdout.puts("There are no cucumber-chef test labs to destroy!")
|
159
|
-
end
|
160
|
-
|
161
|
-
rescue Exception => e
|
162
|
-
Cucumber::Chef.logger.fatal { e.message }
|
163
|
-
Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
|
164
|
-
raise TestLabError, e.message
|
165
|
-
end
|
166
|
-
|
167
|
-
################################################################################
|
168
|
-
|
169
|
-
def start
|
170
|
-
if (lab_exists? && (@server = labs_shutdown.first))
|
171
|
-
if @server.start
|
172
|
-
|
173
|
-
@stdout.print("Waiting for instance...")
|
174
|
-
Cucumber::Chef.spinner do
|
175
|
-
@server.wait_for { ready? }
|
176
|
-
end
|
177
|
-
@stdout.puts("done.\n")
|
178
|
-
|
179
|
-
@stdout.print("Waiting for SSHD...")
|
180
|
-
Cucumber::Chef.spinner do
|
181
|
-
ZTK::TCPSocketCheck.new(:host => @server.public_ip_address, :port => 22, :wait => 120).wait
|
182
|
-
end
|
183
|
-
@stdout.puts("done.\n")
|
184
|
-
|
185
|
-
@stdout.puts("Successfully started up cucumber-chef test lab!")
|
186
|
-
|
187
|
-
info
|
188
|
-
else
|
189
|
-
@stdout.puts("Failed to start up cucumber-chef test lab!")
|
190
|
-
end
|
191
|
-
else
|
192
|
-
@stdout.puts("There are no available cucumber-chef test labs to start up!")
|
193
|
-
end
|
194
|
-
|
195
|
-
rescue Exception => e
|
196
|
-
Cucumber::Chef.logger.fatal { e.message }
|
197
|
-
Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
|
198
|
-
raise TestLabError, e.message
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
def stop
|
203
|
-
if (lab_exists? && (@server = labs_running.first))
|
204
|
-
if @server.stop
|
205
|
-
@stdout.puts("Successfully shutdown cucumber-chef test lab!")
|
206
|
-
else
|
207
|
-
@stdout.puts("Failed to shutdown cucumber-chef test lab!")
|
208
|
-
end
|
209
|
-
else
|
210
|
-
@stdout.puts("There are no available cucumber-chef test labs top shutdown!")
|
211
|
-
end
|
212
|
-
|
213
|
-
rescue Exception => e
|
214
|
-
Cucumber::Chef.logger.fatal { e.message }
|
215
|
-
Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
|
216
|
-
raise TestLabError, e.message
|
217
|
-
end
|
218
|
-
|
219
|
-
################################################################################
|
220
|
-
|
221
|
-
def info
|
222
|
-
if lab_exists?
|
223
|
-
labs.each do |lab|
|
224
|
-
@stdout.puts("Instance ID: #{lab.id}")
|
225
|
-
@stdout.puts("State: #{lab.state}")
|
226
|
-
@stdout.puts("Username: #{lab.username}") if lab.username
|
227
|
-
if (lab.public_ip_address || lab.private_ip_address)
|
228
|
-
@stdout.puts
|
229
|
-
@stdout.puts("IP Address:")
|
230
|
-
@stdout.puts(" Public...: #{lab.public_ip_address}") if lab.public_ip_address
|
231
|
-
@stdout.puts(" Private..: #{lab.private_ip_address}") if lab.private_ip_address
|
232
|
-
end
|
233
|
-
if (lab.dns_name || lab.private_dns_name)
|
234
|
-
@stdout.puts
|
235
|
-
@stdout.puts("DNS:")
|
236
|
-
@stdout.puts(" Public...: #{lab.dns_name}") if lab.dns_name
|
237
|
-
@stdout.puts(" Private..: #{lab.private_dns_name}") if lab.private_dns_name
|
238
|
-
end
|
239
|
-
if (lab.tags.count > 0)
|
240
|
-
@stdout.puts
|
241
|
-
@stdout.puts("Tags:")
|
242
|
-
lab.tags.to_hash.each do |k,v|
|
243
|
-
@stdout.puts(" #{k}: #{v}")
|
244
|
-
end
|
245
|
-
end
|
246
|
-
if lab.public_ip_address
|
247
|
-
@stdout.puts
|
248
|
-
@stdout.puts("Chef-Server WebUI:")
|
249
|
-
@stdout.puts(" http://#{lab.public_ip_address}:4040/")
|
250
|
-
end
|
251
|
-
@stdout.puts
|
252
|
-
if (labs_running.include?(lab) && (n = nodes))
|
253
|
-
@stdout.puts
|
254
|
-
@stdout.puts("Nodes:")
|
255
|
-
n.each do |node|
|
256
|
-
@stdout.puts(" * #{node.name} (#{node.cloud.public_ipv4})")
|
257
|
-
end
|
258
|
-
end
|
259
|
-
if (labs_running.include?(lab) && (c = clients))
|
260
|
-
@stdout.puts
|
261
|
-
@stdout.puts("Clients:")
|
262
|
-
c.each do |client|
|
263
|
-
@stdout.puts(" * #{client.name}")
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
else
|
268
|
-
@stdout.puts("There are no cucumber-chef test labs to display information for!")
|
269
|
-
end
|
270
|
-
|
271
|
-
rescue Exception => e
|
272
|
-
Cucumber::Chef.logger.fatal { e.message }
|
273
|
-
Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
|
274
|
-
raise TestLabError, e.message
|
275
|
-
end
|
276
|
-
|
277
|
-
################################################################################
|
278
|
-
|
279
|
-
def lab_exists?
|
280
|
-
(labs.size > 0)
|
281
|
-
end
|
282
|
-
|
283
|
-
################################################################################
|
284
|
-
|
285
|
-
def labs
|
286
|
-
results = @connection.servers.select do |server|
|
287
|
-
Cucumber::Chef.logger.debug("candidate") { "ID=#{server.id}, state='#{server.state}'" }
|
288
|
-
( server.tags['cucumber-chef-mode'] == Cucumber::Chef::Config[:mode].to_s &&
|
289
|
-
server.tags['cucumber-chef-user'] == Cucumber::Chef::Config[:user].to_s &&
|
290
|
-
VALID_STATES.any?{ |state| state == server.state } )
|
291
|
-
end
|
292
|
-
results.each do |server|
|
293
|
-
Cucumber::Chef.logger.debug("results") { "ID=#{server.id}, state='#{server.state}'" }
|
294
|
-
end
|
295
|
-
results
|
296
|
-
end
|
297
|
-
|
298
|
-
################################################################################
|
299
|
-
|
300
|
-
def labs_running
|
301
|
-
results = @connection.servers.select do |server|
|
302
|
-
Cucumber::Chef.logger.debug("candidate") { "ID=#{server.id}, state='#{server.state}'" }
|
303
|
-
( server.tags['cucumber-chef-mode'] == Cucumber::Chef::Config[:mode].to_s &&
|
304
|
-
server.tags['cucumber-chef-user'] == Cucumber::Chef::Config[:user].to_s &&
|
305
|
-
RUNNING_STATES.any?{ |state| state == server.state } )
|
306
|
-
end
|
307
|
-
results.each do |server|
|
308
|
-
Cucumber::Chef.logger.debug("results") { "ID=#{server.id}, state='#{server.state}'" }
|
309
|
-
end
|
310
|
-
results
|
311
|
-
end
|
312
|
-
|
313
|
-
################################################################################
|
314
|
-
|
315
|
-
def labs_shutdown
|
316
|
-
results = @connection.servers.select do |server|
|
317
|
-
Cucumber::Chef.logger.debug("candidate") { "ID=#{server.id}, state='#{server.state}'" }
|
318
|
-
( server.tags['cucumber-chef-mode'] == Cucumber::Chef::Config[:mode].to_s &&
|
319
|
-
server.tags['cucumber-chef-user'] == Cucumber::Chef::Config[:user].to_s &&
|
320
|
-
SHUTDOWN_STATES.any?{ |state| state == server.state } )
|
321
|
-
end
|
322
|
-
results.each do |server|
|
323
|
-
Cucumber::Chef.logger.debug("results") { "ID=#{server.id}, state='#{server.state}'" }
|
324
|
-
end
|
325
|
-
results
|
326
|
-
end
|
327
|
-
|
328
|
-
################################################################################
|
329
|
-
|
330
|
-
def nodes
|
331
|
-
Cucumber::Chef.load_knife
|
332
|
-
query = "tags:#{Cucumber::Chef::Config[:mode]} AND tags:#{Cucumber::Chef::Config[:user]}"
|
333
|
-
Cucumber::Chef.logger.debug { "query(#{query})" }
|
334
|
-
nodes, offset, total = ::Chef::Search::Query.new.search("node", URI.escape(query))
|
335
|
-
nodes.compact
|
336
|
-
end
|
337
|
-
|
338
|
-
def clients
|
339
|
-
Cucumber::Chef.load_knife
|
340
|
-
query = "tags:#{Cucumber::Chef::Config[:mode]} AND tags:#{Cucumber::Chef::Config[:user]}"
|
341
|
-
Cucumber::Chef.logger.debug { "query(#{query})" }
|
342
|
-
clients, offset, total = ::Chef::Search::Query.new.search("client", URI.escape(query))
|
343
|
-
clients.compact
|
344
|
-
end
|
345
|
-
|
346
|
-
|
347
|
-
################################################################################
|
348
|
-
private
|
349
|
-
################################################################################
|
350
|
-
|
351
|
-
def tag_server
|
352
|
-
{
|
353
|
-
"cucumber-chef-mode" => Cucumber::Chef::Config[:mode],
|
354
|
-
"cucumber-chef-user" => Cucumber::Chef::Config[:user],
|
355
|
-
"purpose" => "cucumber-chef"
|
356
|
-
}.each do |k, v|
|
357
|
-
tag = @connection.tags.new
|
358
|
-
tag.resource_id = @server.id
|
359
|
-
tag.key, tag.value = k, v
|
360
|
-
tag.save
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
################################################################################
|
365
|
-
|
366
|
-
def ensure_security_group
|
367
|
-
security_group_name = Cucumber::Chef::Config[:aws][:aws_security_group]
|
368
|
-
if (security_group = @connection.security_groups.get(security_group_name))
|
369
|
-
port_ranges = security_group.ip_permissions.collect{ |entry| entry["fromPort"]..entry["toPort"] }
|
370
|
-
security_group.authorize_port_range(22..22) if port_ranges.none?{ |port_range| port_range === 22 }
|
371
|
-
security_group.authorize_port_range(4000..4000) if port_ranges.none?{ |port_range| port_range === 4000 }
|
372
|
-
security_group.authorize_port_range(4040..4040) if port_ranges.none?{ |port_range| port_range === 4040 }
|
373
|
-
security_group.authorize_port_range(8787..8787) if port_ranges.none?{ |port_range| port_range === 8787 }
|
374
|
-
elsif (security_group = @connection.security_groups.new(:name => security_group_name, :description => "cucumber-chef test lab")).save
|
375
|
-
security_group.authorize_port_range(22..22)
|
376
|
-
security_group.authorize_port_range(4000..4000)
|
377
|
-
security_group.authorize_port_range(4040..4040)
|
378
|
-
security_group.authorize_port_range(8787..8787)
|
86
|
+
def method_missing(method_name, *method_args)
|
87
|
+
if Cucumber::Chef::Provider::PROXY_METHODS.include?(method_name.to_s)
|
88
|
+
Cucumber::Chef.logger.debug { "test_lab: #{method_name} #{method_args.inspect}" }
|
89
|
+
@provider.send(method_name.to_sym, *method_args)
|
379
90
|
else
|
380
|
-
|
91
|
+
super(method_name, *method_args)
|
381
92
|
end
|
382
93
|
end
|
383
94
|
|