Permalink
Browse files

Display some information about the problem when raising Gosen::Error

  • Loading branch information...
1 parent 184266e commit cb27391c777b8f67856e4e81ecc32e9ca3b074bd @priteau committed Oct 26, 2010
Showing with 19 additions and 7 deletions.
  1. +3 −3 lib/gosen/deployment.rb
  2. +1 −1 lib/gosen/deployment_run.rb
  3. +6 −1 test/gosen/test_deployment.rb
  4. +9 −2 test/gosen/test_deployment_run.rb
View
@@ -24,10 +24,10 @@ def initialize(site, environment, nodes, options = {})
@logger = options.delete(:logger) || NullLogger.new
@min_deployed_nodes = options.delete(:min_deployed_nodes) || 1
- raise Gosen::Error if @min_deployed_nodes > @nodes.length || @min_deployed_nodes < 0
+ raise Gosen::Error.new("Invalid minimal number of deployed nodes, should be between 0 and #{@nodes.length}") if @min_deployed_nodes > @nodes.length || @min_deployed_nodes < 0
@max_deploy_runs = options.delete(:max_deploy_runs) || 1
- raise Gosen::Error if @max_deploy_runs < 1
+ raise Gosen::Error.new("Invalid maximal number of deployments, should be greater than or equal to 1") if @max_deploy_runs < 1
if options[:ssh_public_key]
@ssh_public_key = options[:ssh_public_key]
@@ -62,7 +62,7 @@ def join
return
end
end
- raise Gosen::Error.new('Not enough nodes')
+ raise Gosen::Error.new("Not enough nodes deployed after #{@max_deploy_runs} deployment(s): needed #{@min_deployed_nodes} nodes, got only #{@good_nodes.length}")
end
def no_more_required?
@@ -57,7 +57,7 @@ def wait_for_completion
Kernel.sleep(Gosen::DeploymentRun::POLLING_TIME)
@deployment_resource.reload
end
- raise Gosen::Error if @deployment_resource['status'] == 'error'
+ raise Gosen::Error.new("Deployment error: #{@deployment_resource['output']}") if @deployment_resource['status'] == 'error'
end
def update_nodes
@@ -148,7 +148,12 @@ class TestDeployment < Test::Unit::TestCase
@deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :min_deployed_nodes => 2 })
assert_raise(Gosen::Error) {
- @deployment.join
+ begin
+ @deployment.join
+ rescue Gosen::Error => e
+ assert_equal("Not enough nodes deployed after 1 deployment(s): needed 2 nodes, got only 1", e.message)
+ raise e
+ end
}
end
@@ -95,6 +95,8 @@ class TestDeploymentRun < Test::Unit::TestCase
@ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
@resource = mock()
@resource.stubs(:[]).with('status').returns('processing', 'processing', 'error')
+ @output = 'Your key cannot be fetched.'
+ @resource.stubs(:[]).with('output').returns(@output)
@resource.expects(:reload).twice
Kernel.expects(:sleep).with(Gosen::DeploymentRun::POLLING_TIME).twice
@@ -106,9 +108,14 @@ class TestDeploymentRun < Test::Unit::TestCase
@deployment = Gosen::DeploymentRun.new(@site, @environment, @nodes, { :ssh_public_key => @ssh_public_key })
end
- should 'raise an exception' do
+ should 'raise an exception and print the deployment output' do
assert_raise(Gosen::Error) {
- @deployment.join
+ begin
+ @deployment.join
+ rescue Gosen::Error => e
+ assert_equal("Deployment error: #{@output}", e.message)
+ raise e
+ end
}
end
end

0 comments on commit cb27391

Please sign in to comment.