Merge "Run nailgun-agent on rebooted nodes"
This commit is contained in:
commit
5856dc1076
|
@ -310,6 +310,8 @@ module Astute
|
|||
Astute.logger.warn(ret['error'])
|
||||
end
|
||||
|
||||
update_node_status(already_rebooted.select { |node, rebooted| rebooted }.keys)
|
||||
|
||||
ret
|
||||
end # reboot_hook
|
||||
|
||||
|
@ -443,6 +445,17 @@ module Astute
|
|||
)
|
||||
end
|
||||
|
||||
def update_node_status(uids)
|
||||
run_shell_without_check(
|
||||
@ctx,
|
||||
uids,
|
||||
"flock -w 0 -o /var/lock/nailgun-agent.lock -c '/usr/bin/nailgun-agent"\
|
||||
" 2>&1 | tee -a /var/log/nailgun-agent.log | "\
|
||||
"/usr/bin/logger -t nailgun-agent'",
|
||||
_timeout=60 # nailgun-agent start with random (30) delay
|
||||
)
|
||||
end
|
||||
|
||||
end # class
|
||||
|
||||
class HookReporter
|
||||
|
|
|
@ -50,7 +50,10 @@ module Astute
|
|||
end
|
||||
|
||||
current_bt = boot_time
|
||||
succeed! if current_bt != @control_time && current_bt != 0
|
||||
if current_bt != @control_time && current_bt != 0
|
||||
update_online_node_status
|
||||
succeed!
|
||||
end
|
||||
end
|
||||
|
||||
def validation
|
||||
|
@ -85,5 +88,15 @@ module Astute
|
|||
0
|
||||
end
|
||||
|
||||
def update_online_node_status
|
||||
run_shell_without_check(
|
||||
@task['node_id'],
|
||||
"flock -w 0 -o /var/lock/nailgun-agent.lock -c '/usr/bin/nailgun-agent"\
|
||||
" 2>&1 | tee -a /var/log/nailgun-agent.log | "\
|
||||
"/usr/bin/logger -t nailgun-agent'",
|
||||
_timeout=60 # nailgun-agent start with random (30) delay
|
||||
)[:exit_code]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -934,7 +934,7 @@ describe Astute::NailgunHooks do
|
|||
{'uid' => '1', 'role' => 'hook'},
|
||||
{'uid' => '3', 'role' => 'hook'}
|
||||
],
|
||||
retries=puppet_hook['parameters']['retries'],
|
||||
_retries=puppet_hook['parameters']['retries'],
|
||||
puppet_hook['parameters']['puppet_manifest'],
|
||||
puppet_hook['parameters']['puppet_modules'],
|
||||
puppet_hook['parameters']['cwd']
|
||||
|
@ -1112,6 +1112,14 @@ describe Astute::NailgunHooks do
|
|||
)
|
||||
.returns('2' => '', '3' => '')
|
||||
|
||||
hooks.expects(:run_shell_without_check).once.with(
|
||||
ctx,
|
||||
['2','3'],
|
||||
regexp_matches(/nailgun-agent/),
|
||||
60,
|
||||
)
|
||||
.returns('2' => '', '3' => '')
|
||||
|
||||
hooks.stubs(:sleep)
|
||||
|
||||
hooks.process
|
||||
|
@ -1138,6 +1146,7 @@ describe Astute::NailgunHooks do
|
|||
)
|
||||
.returns('2' => '', '3' => '')
|
||||
|
||||
hooks.stubs(:update_node_status).once
|
||||
hooks.stubs(:sleep)
|
||||
|
||||
hooks.process
|
||||
|
@ -1164,6 +1173,8 @@ describe Astute::NailgunHooks do
|
|||
)
|
||||
.returns('2' => '', '3' => '')
|
||||
|
||||
hooks.stubs(:update_node_status).once
|
||||
|
||||
hooks.expects(:sleep).with(reboot_hook['parameters']['timeout']/10)
|
||||
|
||||
hooks.process
|
||||
|
@ -1190,6 +1201,7 @@ describe Astute::NailgunHooks do
|
|||
60,
|
||||
)
|
||||
.returns('2' => '', '3' => '')
|
||||
hooks.stubs(:update_node_status).once
|
||||
|
||||
hooks.expects(:sleep).with(300/10)
|
||||
|
||||
|
@ -1235,6 +1247,7 @@ describe Astute::NailgunHooks do
|
|||
.returns('3' => '')
|
||||
|
||||
hooks.stubs(:sleep)
|
||||
hooks.stubs(:update_node_status).once
|
||||
|
||||
time = Time.now.to_i + 100
|
||||
hooks.stubs(:run_shell_without_check).once.with(
|
||||
|
@ -1283,6 +1296,7 @@ describe Astute::NailgunHooks do
|
|||
)
|
||||
.returns('2' => (time - 5).to_s, '3' => (time - 5).to_s).then
|
||||
.returns('2' => time.to_s, '3' => time.to_s)
|
||||
hooks.stubs(:update_node_status).once
|
||||
expect {hooks.process}.to_not raise_error
|
||||
end
|
||||
|
||||
|
@ -1304,6 +1318,7 @@ describe Astute::NailgunHooks do
|
|||
10,
|
||||
)
|
||||
.returns('2' => (time - 5).to_s, '3' => time.to_s)
|
||||
hooks.expects(:update_node_status).with([])
|
||||
|
||||
expect {hooks.process}.to raise_error(Astute::DeploymentEngineError, /Failed to execute hook/)
|
||||
end
|
||||
|
@ -1318,6 +1333,7 @@ describe Astute::NailgunHooks do
|
|||
)
|
||||
.returns('2' => time.to_s, '3' => time.to_s).then
|
||||
.returns('2' => (time - 1).to_s, '3' => (time - 2).to_s)
|
||||
hooks.expects(:update_node_status).with(['2', '3'])
|
||||
expect {hooks.process}.to_not raise_error
|
||||
end
|
||||
|
||||
|
@ -1338,6 +1354,7 @@ describe Astute::NailgunHooks do
|
|||
regexp_matches(/stat/),
|
||||
10,
|
||||
).returns({})
|
||||
hooks.stubs(:update_node_status)
|
||||
|
||||
expect {hooks.process}.to raise_error(Astute::DeploymentEngineError, /Failed to execute hook/)
|
||||
end
|
||||
|
|
|
@ -167,6 +167,7 @@ describe Astute::Reboot do
|
|||
|
||||
it 'it should succeed if boot time before and after is different' do
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:update_online_node_status)
|
||||
subject.expects(:boot_time).twice.returns(12).then.returns(13)
|
||||
|
||||
subject.run
|
||||
|
@ -175,6 +176,7 @@ describe Astute::Reboot do
|
|||
|
||||
it 'it should succeed if boot time before and after are different' do
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:update_online_node_status)
|
||||
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
||||
|
||||
subject.run
|
||||
|
@ -183,12 +185,22 @@ describe Astute::Reboot do
|
|||
|
||||
it 'it should succeed if boot time before and after is different' do
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:update_online_node_status)
|
||||
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
||||
|
||||
subject.run
|
||||
expect(subject.status).to eql(:successful)
|
||||
end
|
||||
|
||||
it 'it should update node online status' do
|
||||
subject.stubs(:reboot)
|
||||
subject.expects(:update_online_node_status).once
|
||||
subject.stubs(:boot_time).twice.returns(12).then.returns(11)
|
||||
|
||||
subject.run
|
||||
expect(subject.status).to eql(:successful)
|
||||
end
|
||||
|
||||
it 'it should fail if timeout is reached' do
|
||||
subject.stubs(:reboot)
|
||||
subject.expects(:boot_time).once.returns(12)
|
||||
|
@ -198,8 +210,19 @@ describe Astute::Reboot do
|
|||
expect(subject.status).to eql(:failed)
|
||||
end
|
||||
|
||||
it 'it not update node online status if task failed' do
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:boot_time).once.returns(12)
|
||||
subject.expects(:update_online_node_status).never
|
||||
task['parameters']['timeout'] = -1
|
||||
|
||||
subject.run
|
||||
expect(subject.status).to eql(:failed)
|
||||
end
|
||||
|
||||
it 'it should succeed after several tries' do
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:update_online_node_status)
|
||||
subject.expects(:boot_time).times(4).returns(12)
|
||||
.then.returns(12)
|
||||
.then.returns(0)
|
||||
|
@ -219,6 +242,7 @@ describe Astute::Reboot do
|
|||
.then.raises(Astute::MClientTimeout)
|
||||
.then.returns({:stdout => "13"})
|
||||
subject.stubs(:reboot)
|
||||
subject.stubs(:update_online_node_status)
|
||||
|
||||
subject.run
|
||||
expect(subject.status).to eql(:running)
|
||||
|
|
Loading…
Reference in New Issue