From b0752c7a78ca2acbe85330adde22fb1d37eb73eb Mon Sep 17 00:00:00 2001 From: "Vladimir Sharshov (warpc)" Date: Fri, 30 Dec 2016 12:45:13 +0300 Subject: [PATCH] Fix fail detection for provisioning Add test to prevent such behavior in future Change-Id: If833723f0301f2008e6aabfc888d0bdf693f4f2e Partial-Bug: #1653210 --- lib/astute/image_provision.rb | 5 +++-- spec/unit/image_provision_spec.rb | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/astute/image_provision.rb b/lib/astute/image_provision.rb index 9fd82305..e3a0cc30 100644 --- a/lib/astute/image_provision.rb +++ b/lib/astute/image_provision.rb @@ -129,10 +129,11 @@ module Astute sleep Astute.config.task_poll_delay end - failed_uids = shell_tasks.select{ |t| t.failed? }.inject([]) do |task| + failed_uids = shell_tasks.select{ |t| t.failed? } + .inject([]) do |failed_nodes, task| Astute.logger.error("#{ctx.task_id}: Provision command returned " \ "non zero exit code on node: #{task.node_id}") - failed_uids << task.node_id + failed_nodes << task.node_id end failed_uids diff --git a/spec/unit/image_provision_spec.rb b/spec/unit/image_provision_spec.rb index 73baaf0d..484d7248 100644 --- a/spec/unit/image_provision_spec.rb +++ b/spec/unit/image_provision_spec.rb @@ -201,8 +201,14 @@ describe Astute::ImageProvision do end it 'should run return failed nodes' do - provisioner.stubs(:run_shell_task).once.returns([6]) - expect(provisioner.run_provision(ctx, nodes.map { |n| n['uid'] }, [])).to eql([6]) + Astute::Shell.any_instance.stubs(:process) + Astute::Shell.any_instance.expects(:run).twice + Astute::Shell.any_instance.stubs(:finished?).returns(true) + Astute::Shell.any_instance.expects(:failed?).times(2) + .returns(false) + .then.returns(true) + + expect(provisioner.run_provision(ctx, [5, 6], [])).to eql([6]) end it 'should not erase info about alread failed nodes' do