lib/cucumber/chef/providers/aws.rb in cucumber-chef-2.1.0.rc.6 vs lib/cucumber/chef/providers/aws.rb in cucumber-chef-2.1.0.rc.7
- old
+ new
@@ -23,22 +23,21 @@
class Provider
class AWSError < Error; end
class AWS
- attr_accessor :connection, :server, :stdout, :stderr, :stdin, :logger
+ attr_accessor :connection, :server
INVALID_STATES = %w(terminated pending).map(&:to_sym)
RUNNING_STATES = %w(running starting-up).map(&:to_sym)
SHUTDOWN_STATES = %w(shutdown stopping stopped shutting-down).map(&:to_sym)
VALID_STATES = RUNNING_STATES+SHUTDOWN_STATES
################################################################################
- def initialize(stdout=STDOUT, stderr=STDERR, stdin=STDIN, logger=$logger)
- @stdout, @stderr, @stdin, @logger = stdout, stderr, stdin, logger
- @stdout.sync = true if @stdout.respond_to?(:sync=)
+ def initialize(ui=ZTK::UI.new)
+ @ui = ui
@connection = Fog::Compute.new(
:provider => 'AWS',
:aws_access_key_id => Cucumber::Chef::Config.aws[:aws_access_key_id],
:aws_secret_access_key => Cucumber::Chef::Config.aws[:aws_secret_access_key],
@@ -53,11 +52,11 @@
# CREATE
################################################################################
def create
if (exists? && alive?)
- @stdout.puts("A test lab already exists using the #{Cucumber::Chef::Config.provider.upcase} credentials you have supplied; attempting to reprovision it.")
+ @ui.stdout.puts("A test lab already exists using the #{Cucumber::Chef::Config.provider.upcase} credentials you have supplied; attempting to reprovision it.")
else
server_definition = {
:image_id => Cucumber::Chef::Config.aws_image_id,
:groups => Cucumber::Chef::Config.aws[:aws_security_group],
:flavor_id => Cucumber::Chef::Config.aws[:aws_instance_type],
@@ -66,23 +65,23 @@
:tags => { "purpose" => "cucumber-chef", "cucumber-chef-mode" => Cucumber::Chef::Config.mode },
:identity_file => Cucumber::Chef::Config.aws[:identity_file]
}
if (@server = @connection.servers.create(server_definition))
- ZTK::Benchmark.bench(:message => "Creating #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :stdout => @stdout) do
+ ZTK::Benchmark.bench(:message => "Creating #{Cucumber::Chef::Config.provider.upcase} instance", :mark => "completed in %0.4f seconds.", :ui => @ui) do
@server.wait_for { ready? }
tag_server
ZTK::TCPSocketCheck.new(:host => self.ip, :port => self.port, :wait => 120).wait
end
end
end
self
rescue Exception => e
- Cucumber::Chef.logger.fatal { e.message }
- Cucumber::Chef.logger.fatal { "Backtrace:\n#{e.backtrace.join("\n")}" }
+ @ui.logger.fatal { e.message }
+ @ui.logger.fatal { "Backtrace:\n#{e.backtrace.join("\n")}" }
raise AWSError, e.message
end
################################################################################
# DESTROY
@@ -94,12 +93,12 @@
else
raise AWSError, "We could not find a test lab!"
end
rescue Exception => e
- Cucumber::Chef.logger.fatal { e.message }
- Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
+ @ui.logger.fatal { e.message }
+ @ui.logger.fatal { e.backtrace.join("\n") }
raise AWSError, e.message
end
################################################################################
# UP
@@ -116,12 +115,12 @@
else
raise AWSError, "We could not find a powered off test lab."
end
rescue Exception => e
- Cucumber::Chef.logger.fatal { e.message }
- Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
+ @ui.logger.fatal { e.message }
+ @ui.logger.fatal { e.backtrace.join("\n") }
raise AWSError, e.message
end
################################################################################
# HALT
@@ -135,12 +134,12 @@
else
raise AWSError, "We could not find a running test lab."
end
rescue Exception => e
- Cucumber::Chef.logger.fatal { e.message }
- Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
+ @ui.logger.fatal { e.message }
+ @ui.logger.fatal { e.backtrace.join("\n") }
raise AWSError, e.message
end
################################################################################
# RELOAD
@@ -154,12 +153,12 @@
else
raise AWSError, "We could not find a running test lab."
end
rescue Exception => e
- Cucumber::Chef.logger.fatal { e.message }
- Cucumber::Chef.logger.fatal { e.backtrace.join("\n") }
+ @ui.logger.fatal { e.message }
+ @ui.logger.fatal { e.backtrace.join("\n") }
raise AWSError, e.message
end
################################################################################
@@ -201,19 +200,19 @@
################################################################################
private
################################################################################
def filter_servers(servers, states=VALID_STATES)
- Cucumber::Chef.logger.debug("states") { states.collect{ |s| s.inspect }.join(", ") }
+ @ui.logger.debug("states") { states.collect{ |s| s.inspect }.join(", ") }
results = servers.select do |server|
- Cucumber::Chef.logger.debug("candidate") { "id=#{server.id.inspect}, state=#{server.state.inspect}, tags=#{server.tags.inspect}" }
+ @ui.logger.debug("candidate") { "id=#{server.id.inspect}, state=#{server.state.inspect}, tags=#{server.tags.inspect}" }
( server.tags['cucumber-chef-mode'] == Cucumber::Chef::Config.mode.to_s &&
server.tags['cucumber-chef-user'] == Cucumber::Chef::Config.user.to_s &&
states.any?{ |state| state.to_s == server.state } )
end
results.each do |server|
- Cucumber::Chef.logger.debug("results") { "id=#{server.id.inspect}, state=#{server.state.inspect}" }
+ @ui.logger.debug("results") { "id=#{server.id.inspect}, state=#{server.state.inspect}" }
end
results.first
end
################################################################################