bin/cucumber-chef in cucumber-chef-2.1.0.rc.1 vs bin/cucumber-chef in cucumber-chef-2.1.0.rc.2
- old
+ new
@@ -33,12 +33,10 @@
def create_project(project)
@project = project
source_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cucumber", "chef", "templates", "cucumber"))
destination_dir = Cucumber::Chef.locate_parent(".chef")
- @is_rc = Cucumber::Chef.is_rc?
-
CucumberChef.source_root source_dir
templates = {
"readme.erb" => "features/#{project}/README",
"example_feature.erb" => "features/#{project}/#{project}.feature",
"example_steps.erb" => "features/#{project}/step_definitions/#{project}_steps.rb",
@@ -53,16 +51,18 @@
templates.each do |source, destination|
template(source, File.join(destination_dir, destination))
end
end
- def load_config
+ def boot
tag = Cucumber::Chef.tag("cucumber-chef")
puts(set_color(tag, :green, true))
- Cucumber::Chef.load_config(tag)
+ Cucumber::Chef.boot(tag)
$logger = Cucumber::Chef.logger
+ @is_rc = Cucumber::Chef.is_rc?
+
@options.test? and Cucumber::Chef::Config.test
end
def fatal(message)
puts(set_color(message, :red, :bold))
@@ -122,30 +122,32 @@
def init
initalize_config
end
################################################################################
+# SETUP
+################################################################################
desc "setup", "Setup cucumber-chef test lab in Amazon EC2"
method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
def setup
- load_config
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new)
- if (server = test_lab.create)
- if (provisioner = Cucumber::Chef::Provisioner.new(server))
+ if (provider = test_lab.create)
+ if (provisioner = Cucumber::Chef::Provisioner.new(test_lab))
provisioner.build
puts
puts("Your cucumber-chef test lab has now been provisioned!")
puts
puts("Be sure to log into the chef-server webui and change the default credentials.")
puts
puts(" Chef-Server WebUI:")
- puts(" http://#{server.public_ip_address}:4040/")
+ puts(" http://#{test_lab.ip}:4040/")
puts(" Username:")
puts(" admin")
puts(" Password:")
puts(" #{Cucumber::Chef::Provisioner::PASSWORD}")
@@ -164,15 +166,17 @@
$logger.fatal { e.backtrace.join("\n") }
fatal(e.message)
end
################################################################################
+# TEARDOWN
+################################################################################
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"
def teardown(*args)
- load_config
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new)
if args.count == 0
if yes?(set_color("Are you sure you want to teardown your cucumber-chef test lab?", :red, true))
@@ -208,11 +212,11 @@
puts
test_lab.ssh.exec("nohup sudo pkill -9 -f cc-server")
test_lab.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
+ ZTK::TCPSocketCheck.new(:host => test_lab.ip, :port => 8787, :data => "\n\n").wait
end
test_lab.drb.servers = Hash.new(nil)
test_lab.drb.server_destroy(container)
else
puts
@@ -229,66 +233,79 @@
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
+# UP
+################################################################################
- desc "test", "depreciated"
- def test
+ desc "up", "Startup the cucumber-chef test lab"
+ def up
+ boot
+
puts
- puts(set_color("The test task is depreciated! You should execute cucumber directly.", :red, true))
+ if (test_lab = Cucumber::Chef::TestLab.new)
+ test_lab.up
+ else
+ puts(set_color("Could not find a cucumber-chef test lab to startup!", :red, true))
+ end
puts
rescue Cucumber::Chef::Error => e
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
+# DOWN
+################################################################################
- desc "up", "Startup the cucumber-chef test lab"
- def up
- load_config
+ desc "down", "Shutdown the cucumber-chef test lab"
+ def down
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new)
- test_lab.start
+ test_lab.down
else
- puts(set_color("Could not find a cucumber-chef test lab to startup!", :red, true))
+ puts(set_color("Could not find a cucumber-chef test lab to shutdown!", :red, true))
end
puts
rescue Cucumber::Chef::Error => e
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
+# STATUS
+################################################################################
- desc "down", "Shutdown the cucumber-chef test lab"
- def down
- load_config
+ desc "status", "Displays the current status of the test lab."
+ method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
+ def status
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new)
- test_lab.stop
- else
- puts(set_color("Could not find a cucumber-chef test lab to shutdown!", :red, true))
+ test_lab.status
end
puts
rescue Cucumber::Chef::Error => e
$logger.fatal { e.backtrace.join("\n") }
- fatal(e)
+ fatal(e.message)
end
################################################################################
+# SSH
+################################################################################
desc "ssh [container]", "SSH to cucumber-chef test lab or [container] if specified."
method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
def ssh(*args)
- load_config
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new) && (test_lab.labs_running.count > 0)
if args.size == 0
puts([set_color("Attempting SSH connection to cucumber-chef '", :blue, true), set_color("test lab", :cyan, true), set_color("'...", :blue, true)].join)
@@ -308,14 +325,16 @@
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
+# LOG
+################################################################################
desc "log", "Streams the cucumber-chef local and test lab logs to the terminal."
def log
- load_config
+ boot
if ($test_lab = Cucumber::Chef::TestLab.new) && ($test_lab.labs_running.count > 0)
$tail_thread_remote = Thread.new do
$test_lab.ssh.exec("tail -n 0 -f /home/#{$test_lab.ssh.config.user}/.cucumber-chef/cucumber-chef.log")
@@ -341,17 +360,19 @@
$tail_thread_remote.kill
end
end
################################################################################
+# DIAGNOSE
+################################################################################
desc "diagnose <container>", "Provide diagnostics from the chef-client on the specified container."
method_option :strace, :type => :boolean, :desc => "output the chef-client 'chef-stacktrace.out'", :aliases => "-s", :default => true
method_option :log, :type => :boolean, :desc => "output the chef-client 'chef.log'", :aliases => "-l", :default => true
method_option :lines, :type => :numeric, :desc => "output the last N lines of the chef-client 'chef.log'", :aliases => "-n", :default => 1
def diagnose(container)
- load_config
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new) && (test_lab.labs_running.count > 0)
puts([set_color("Attempting to collect diagnostic information on cucumber-chef container '", :blue, true), set_color(container, :cyan, true), set_color("'...", :blue, true)].join)
if @options.strace?
@@ -374,30 +395,58 @@
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
+# DISPLAYCONFIG
+################################################################################
desc "displayconfig", "Display the current cucumber-chef config."
method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
def displayconfig
- load_config
+ boot
+ details = {
+ "root_dir" => Cucumber::Chef.root_dir,
+ "home_dir" => Cucumber::Chef.home_dir,
+ "log_file" => Cucumber::Chef.log_file,
+ "config_rb" => Cucumber::Chef.config_rb,
+ "servers_bin" => Cucumber::Chef.servers_bin,
+ "knife_rb" => Cucumber::Chef.knife_rb,
+ "chef_repo" => Cucumber::Chef.chef_repo,
+ "bootstrap_identity" => Cucumber::Chef.bootstrap_identity,
+ "lab_user" => Cucumber::Chef.lab_user,
+ "lab_user_home_dir" => Cucumber::Chef.lab_user_home_dir,
+ "lab_identity" => Cucumber::Chef.lab_identity,
+ "lxc_user" => Cucumber::Chef.lxc_user,
+ "lxc_user_home_dir" => Cucumber::Chef.lxc_user_home_dir,
+ "lxc_identity" => Cucumber::Chef.lxc_identity
+ }
+
puts
+
say(Cucumber::Chef::Config.configuration.to_yaml, :bold)
+
+ max_key_length = details.collect{ |k,v| k.to_s.length }.max
+ details.each do |key,value|
+ puts("%#{max_key_length}s = %s" % [key.downcase, value.inspect])
+ end
+
puts
rescue Cucumber::Chef::Error => e
$logger.fatal { e.backtrace.join("\n") }
fatal(e.message)
end
################################################################################
+# PS
+################################################################################
desc "ps [ps-options]", "Snapshot of the current cucumber-chef test lab container processes."
def ps(*args)
- load_config
+ boot
puts
if (test_lab = Cucumber::Chef::TestLab.new) && (test_lab.labs_running.count > 0)
puts(set_color("Getting container processes from cucumber-chef test lab...", :blue, true))
puts
@@ -411,27 +460,11 @@
$logger.fatal { e.backtrace.join("\n") }
fatal(e)
end
################################################################################
-
- desc "info", "Display information about the current test lab."
- method_option :test, :type => :boolean, :desc => "INTERNAL USE ONLY"
- def info
- load_config
-
- puts
- if (test_lab = Cucumber::Chef::TestLab.new)
- test_lab.info
- end
- puts
-
- rescue Cucumber::Chef::Error => e
- $logger.fatal { e.backtrace.join("\n") }
- fatal(e.message)
- end
-
+# CREATE
################################################################################
desc "create <project>" , "Create a project template for testing an infrastructure."
def create(project)
@@ -442,9 +475,40 @@
steps = File.join(features_dir, "step_definitions", "#{project}.steps")
puts
puts(set_color("Project created!", :green, true))
say("Please look at the README in '#{features_dir}/#{project}/', and the example features (#{File.basename(feature)}) and steps (#{File.basename(steps)}), which I have autogenerated for you.", :green)
+ puts
+
+ rescue Cucumber::Chef::Error => e
+ $logger.fatal { e.backtrace.join("\n") }
+ fatal(e)
+ end
+
+################################################################################
+# DEPRECIATED: INFO
+################################################################################
+
+ desc "info", "DEPRECIATED! - You should execute the 'status' task instead."
+ def info
+ puts
+ puts(set_color("The 'info' task is DEPRECIATED! You should execute the 'status' task instead.", :red, true))
+ puts
+ status
+
+ rescue Cucumber::Chef::Error => e
+ $logger.fatal { e.backtrace.join("\n") }
+ fatal(e)
+ end
+
+################################################################################
+# DEPRECIATED: TEST
+################################################################################
+
+ desc "test", "DEPRECIATED! - You should execute 'cucumber' or 'rspec' directly."
+ def test
+ puts
+ puts(set_color("The test task is DEPRECIATED! You should execute 'cucumber' or 'rspec' directly.", :red, true))
puts
rescue Cucumber::Chef::Error => e
$logger.fatal { e.backtrace.join("\n") }
fatal(e)