Skip to content

Commit

Permalink
modify teardown command to allow teardown of containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Patten committed Oct 15, 2012
1 parent 9b63321 commit b9e49bc
Showing 1 changed file with 53 additions and 16 deletions.
69 changes: 53 additions & 16 deletions bin/cucumber-chef
Expand Up @@ -178,30 +178,67 @@ class CucumberChef < Thor


################################################################################ ################################################################################


desc "teardown", "Teardown cucumber-chef test lab in Amazon EC2" desc "teardown [container]", "Teardown the cucumber-chef test lab in Amazon EC2 or a test lab [container] if specified."
method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY" method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
def teardown def teardown(*args)
load_config load_config


puts puts
if (test_lab = Cucumber::Chef::TestLab.new) if (test_lab = Cucumber::Chef::TestLab.new)
if yes?(set_color("Are you sure you want to teardown your cucumber-chef test lab?", :red, true)) if args.count == 0
count_down_colors = { 5 => :green, 4 => :yellow, 3 => :yellow, 2 => :red, 1 => :red } if yes?(set_color("Are you sure you want to teardown your cucumber-chef test lab?", :red, true))
puts count_down_colors = { 5 => :green, 4 => :yellow, 3 => :yellow, 2 => :red, 1 => :red }
puts(set_color("You have 5 seconds to abort!", :green, true)) puts
puts puts(set_color("You have 5 seconds to abort!", :green, true))
print(set_color("Self-destructing in", :green, true)) puts
5.downto(1) do |x| print(set_color("Self-destructing in", :green, true))
print(set_color("...#{x}", count_down_colors[x], true)) 5.downto(1) do |x|
sleep(1) print(set_color("...#{x}", count_down_colors[x], true))
sleep(1)
end
puts(set_color("...BOOM!", :red, true))
puts
test_lab.destroy
else
puts
puts(set_color("Whew! That was close!", :green, true))
end end
puts(set_color("...BOOM!", :red, true))
puts
test_lab.destroy
else else
puts container = args[0]
puts(set_color("Whew! That was close!", :green, true)) if yes?(set_color("Are you sure you want to teardown the test lab containter '#{container}'?", :red, true))
count_down_colors = { 5 => :green, 4 => :yellow, 3 => :yellow, 2 => :red, 1 => :red }
puts
puts(set_color("You have 5 seconds to abort!", :green, true))
puts
print(set_color("Self-destructing in", :green, true))
5.downto(1) do |x|
print(set_color("...#{x}", count_down_colors[x], true))
sleep(1)
end
puts(set_color("...BOOM!", :red, true))
puts

ssh = ZTK::SSH.new
ssh.config.host_name = test_lab.labs_running.first.public_ip_address
ssh.config.user = "ubuntu"
ssh.config.keys = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{ssh.config.user}")
ssh.exec("nohup sudo pkill -9 -f cc-server")
ssh.exec("nohup sudo BACKGROUND=yes cc-server #{Cucumber::Chef.external_ip}")
Cucumber::Chef.spinner do
ZTK::TCPSocketCheck.new(:host => test_lab.labs_running.first.public_ip_address, :port => 8787, :data => "\n\n").wait
end

# initialize our drb object
test_lab_drb ||= DRbObject.new_with_uri("druby://#{test_lab.labs_running.first.public_ip_address}:8787")
test_lab_drb and DRb.start_service
test_lab_drb.servers = Hash.new(nil)
test_lab_drb.server_destroy(container)
else
puts
puts(set_color("Whew! That was close!", :green, true))
end
end end

else else
puts(set_color("Could not find a cucumber-chef test lab to teardown!", :red, true)) puts(set_color("Could not find a cucumber-chef test lab to teardown!", :red, true))
end end
Expand Down

0 comments on commit b9e49bc

Please sign in to comment.