Permalink
Browse files

Allow a user to continue even when the deployment status is 'error'

For this, you need to pass :continue_if_error => true as an option to
Gosen::Deployment.new()
  • Loading branch information...
1 parent cb27391 commit 5148c704372f7de9b55871951be931133821c321 @priteau committed Oct 26, 2010
Showing with 51 additions and 8 deletions.
  1. +19 −7 lib/gosen/deployment.rb
  2. +1 −1 lib/gosen/deployment_run.rb
  3. +31 −0 test/gosen/test_deployment.rb
View
@@ -29,6 +29,8 @@ def initialize(site, environment, nodes, options = {})
@max_deploy_runs = options.delete(: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
+ @continue_if_error = options.delete(:continue_if_error) || false
+
if options[:ssh_public_key]
@ssh_public_key = options[:ssh_public_key]
end
@@ -48,14 +50,24 @@ def bad_nodes
def join
@max_deploy_runs.times do |i|
- @deployment_resource = Gosen::DeploymentRun.new(@site, @environment, @bad_nodes, @api_options)
+ @deployment_run = Gosen::DeploymentRun.new(@site, @environment, @bad_nodes, @api_options)
@logger.info("Kadeploy run #{i + 1} with #{@bad_nodes.length} nodes (#{@good_nodes.length} already deployed, need #{@min_deployed_nodes - @good_nodes.length} more)")
- @deployment_resource.wait_for_completion
- @deployment_resource.update_nodes
- @bad_nodes = @deployment_resource.bad_nodes
- @good_nodes |= @deployment_resource.good_nodes
- @logger.info("Nodes deployed: #{@deployment_resource.good_nodes.join(' ')}") unless @deployment_resource.good_nodes.empty?
- @logger.info("Nodes which failed: #{@deployment_resource.bad_nodes.join(' ')}") unless @deployment_resource.bad_nodes.empty?
+ begin
+ @deployment_run.wait_for_completion
+ rescue Gosen::Error => e
+ if e.message =~ /^Deployment error/ && @continue_if_error
+ @logger.warn("Deployment error: #{@deployment_run.deployment_resource['output']}")
+ @logger.warn("Continuing because continue_if_error is set")
+ next
+ else
+ raise e
+ end
+ end
+ @deployment_run.update_nodes
+ @bad_nodes = @deployment_run.bad_nodes
+ @good_nodes |= @deployment_run.good_nodes
+ @logger.info("Nodes deployed: #{@deployment_run.good_nodes.join(' ')}") unless @deployment_run.good_nodes.empty?
+ @logger.info("Nodes which failed: #{@deployment_run.bad_nodes.join(' ')}") unless @deployment_run.bad_nodes.empty?
if no_more_required?
@all_runs_done = true
@logger.info("Had to run #{i + 1} kadeploy runs, deployed #{@good_nodes.length} nodes")
@@ -3,7 +3,7 @@ class DeploymentRun
# Time between two checks of the deployment run status
POLLING_TIME = 10
- attr_reader :environment, :nodes, :site, :ssh_public_key
+ attr_reader :deployment_resource, :environment, :nodes, :site, :ssh_public_key
# Launch a new deployment run
# @param [Restfully:Resource] site the deployment site, as a restfully resource
@@ -201,6 +201,37 @@ class TestDeployment < Test::Unit::TestCase
assert_equal(@nodes, @deployment.good_nodes)
assert_equal([], @deployment.bad_nodes)
end
+
+ should 'continue deploying when an error happens and :continue_if_error was set' do
+ @ssh_public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvwM1XBJCIMtAyQlweE7BVRtvgyKdwGTeYCI4AFlsTtti4y0Ipe5Hsygx3p7S0BHFiJsVZWDANMRwZ4tcjp8YnjnMkG2yp1jB1qgUf34t/MmEQL0KkoOk8tIIb28o7nTFYKO15mXJm9yBVS1JY8ozEfnA7s5hkrdnvM6h9Jv6VScp8C1XTKmpEy3sWOeUlmCkYftYSr1fLM/7qk9S2TnljA/CGiK9dq2mhJMjnDtulVrdpc1hbh+0oCzL6m2BfXX3v4q1ORml8o04oFeEYDN5qzZneL+FzK+YfJIidvsjZ9ziVTv+7Oy5ms4wvoKiUGNapP0v/meXXBU1KvFRof3VZQ== priteau@parallelogram.local'
+ @deployment_resource1 = mock()
+ @deployment_resource2 = mock()
+ @deployment_resource1.stubs(:reload)
+ @deployment_resource2.stubs(:reload)
+
+ @output = 'Your key cannot be fetched.'
+ @deployment_result2 = {
+ 'paramount-1.rennes.grid5000.fr' => { 'state' => 'OK' },
+ 'paramount-2.rennes.grid5000.fr' => { 'state' => 'OK' }
+ }
+ @deployment_resource1.stubs(:[]).with('status').returns('processing', 'processing', 'error')
+ @deployment_resource1.stubs(:[]).with('output').returns(@output)
+ @deployment_resource2.stubs(:[]).with('status').returns('processing', 'processing', 'terminated')
+ @deployment_resource2.expects(:[]).with('result').returns(@deployment_result2)
+ @min_deployed_nodes = 2
+ @site_deployments.expects(:submit).twice.with({ :environment => @environment, :nodes => @nodes, :key => @ssh_public_key }).returns(@deployment_resource1, @deployment_resource2)
+ @logger.expects(:info).with("Kadeploy run 1 with 2 nodes (0 already deployed, need 2 more)")
+ @logger.expects(:warn).with("Deployment error: #{@output}")
+ @logger.expects(:warn).with("Continuing because continue_if_error is set")
+ @logger.expects(:info).with("Kadeploy run 2 with 2 nodes (0 already deployed, need 2 more)")
+ @logger.expects(:info).with("Nodes deployed: paramount-1.rennes.grid5000.fr paramount-2.rennes.grid5000.fr")
+ @logger.expects(:info).with("Had to run 2 kadeploy runs, deployed 2 nodes")
+
+ @deployment = Gosen::Deployment.new(@site, @environment, @nodes, { :logger => @logger, :min_deployed_nodes => @min_deployed_nodes, :max_deploy_runs => 2, :ssh_public_key => @ssh_public_key, :continue_if_error => true })
+ @deployment.join
+ assert_equal(@nodes, @deployment.good_nodes)
+ assert_equal([], @deployment.bad_nodes)
+ end
end
end
end

0 comments on commit 5148c70

Please sign in to comment.