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'])
|
Astute.logger.warn(ret['error'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
update_node_status(already_rebooted.select { |node, rebooted| rebooted }.keys)
|
||||||
|
|
||||||
ret
|
ret
|
||||||
end # reboot_hook
|
end # reboot_hook
|
||||||
|
|
||||||
|
@ -443,6 +445,17 @@ module Astute
|
||||||
)
|
)
|
||||||
end
|
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
|
end # class
|
||||||
|
|
||||||
class HookReporter
|
class HookReporter
|
||||||
|
|
|
@ -50,7 +50,10 @@ module Astute
|
||||||
end
|
end
|
||||||
|
|
||||||
current_bt = boot_time
|
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
|
end
|
||||||
|
|
||||||
def validation
|
def validation
|
||||||
|
@ -85,5 +88,15 @@ module Astute
|
||||||
0
|
0
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -934,7 +934,7 @@ describe Astute::NailgunHooks do
|
||||||
{'uid' => '1', 'role' => 'hook'},
|
{'uid' => '1', 'role' => 'hook'},
|
||||||
{'uid' => '3', '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_manifest'],
|
||||||
puppet_hook['parameters']['puppet_modules'],
|
puppet_hook['parameters']['puppet_modules'],
|
||||||
puppet_hook['parameters']['cwd']
|
puppet_hook['parameters']['cwd']
|
||||||
|
@ -1112,6 +1112,14 @@ describe Astute::NailgunHooks do
|
||||||
)
|
)
|
||||||
.returns('2' => '', '3' => '')
|
.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.stubs(:sleep)
|
||||||
|
|
||||||
hooks.process
|
hooks.process
|
||||||
|
@ -1138,6 +1146,7 @@ describe Astute::NailgunHooks do
|
||||||
)
|
)
|
||||||
.returns('2' => '', '3' => '')
|
.returns('2' => '', '3' => '')
|
||||||
|
|
||||||
|
hooks.stubs(:update_node_status).once
|
||||||
hooks.stubs(:sleep)
|
hooks.stubs(:sleep)
|
||||||
|
|
||||||
hooks.process
|
hooks.process
|
||||||
|
@ -1164,6 +1173,8 @@ describe Astute::NailgunHooks do
|
||||||
)
|
)
|
||||||
.returns('2' => '', '3' => '')
|
.returns('2' => '', '3' => '')
|
||||||
|
|
||||||
|
hooks.stubs(:update_node_status).once
|
||||||
|
|
||||||
hooks.expects(:sleep).with(reboot_hook['parameters']['timeout']/10)
|
hooks.expects(:sleep).with(reboot_hook['parameters']['timeout']/10)
|
||||||
|
|
||||||
hooks.process
|
hooks.process
|
||||||
|
@ -1190,6 +1201,7 @@ describe Astute::NailgunHooks do
|
||||||
60,
|
60,
|
||||||
)
|
)
|
||||||
.returns('2' => '', '3' => '')
|
.returns('2' => '', '3' => '')
|
||||||
|
hooks.stubs(:update_node_status).once
|
||||||
|
|
||||||
hooks.expects(:sleep).with(300/10)
|
hooks.expects(:sleep).with(300/10)
|
||||||
|
|
||||||
|
@ -1235,6 +1247,7 @@ describe Astute::NailgunHooks do
|
||||||
.returns('3' => '')
|
.returns('3' => '')
|
||||||
|
|
||||||
hooks.stubs(:sleep)
|
hooks.stubs(:sleep)
|
||||||
|
hooks.stubs(:update_node_status).once
|
||||||
|
|
||||||
time = Time.now.to_i + 100
|
time = Time.now.to_i + 100
|
||||||
hooks.stubs(:run_shell_without_check).once.with(
|
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 - 5).to_s, '3' => (time - 5).to_s).then
|
||||||
.returns('2' => time.to_s, '3' => time.to_s)
|
.returns('2' => time.to_s, '3' => time.to_s)
|
||||||
|
hooks.stubs(:update_node_status).once
|
||||||
expect {hooks.process}.to_not raise_error
|
expect {hooks.process}.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1304,6 +1318,7 @@ describe Astute::NailgunHooks do
|
||||||
10,
|
10,
|
||||||
)
|
)
|
||||||
.returns('2' => (time - 5).to_s, '3' => time.to_s)
|
.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/)
|
expect {hooks.process}.to raise_error(Astute::DeploymentEngineError, /Failed to execute hook/)
|
||||||
end
|
end
|
||||||
|
@ -1318,6 +1333,7 @@ describe Astute::NailgunHooks do
|
||||||
)
|
)
|
||||||
.returns('2' => time.to_s, '3' => time.to_s).then
|
.returns('2' => time.to_s, '3' => time.to_s).then
|
||||||
.returns('2' => (time - 1).to_s, '3' => (time - 2).to_s)
|
.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
|
expect {hooks.process}.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1338,6 +1354,7 @@ describe Astute::NailgunHooks do
|
||||||
regexp_matches(/stat/),
|
regexp_matches(/stat/),
|
||||||
10,
|
10,
|
||||||
).returns({})
|
).returns({})
|
||||||
|
hooks.stubs(:update_node_status)
|
||||||
|
|
||||||
expect {hooks.process}.to raise_error(Astute::DeploymentEngineError, /Failed to execute hook/)
|
expect {hooks.process}.to raise_error(Astute::DeploymentEngineError, /Failed to execute hook/)
|
||||||
end
|
end
|
||||||
|
|
|
@ -167,6 +167,7 @@ describe Astute::Reboot do
|
||||||
|
|
||||||
it 'it should succeed if boot time before and after is different' do
|
it 'it should succeed if boot time before and after is different' do
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
|
subject.stubs(:update_online_node_status)
|
||||||
subject.expects(:boot_time).twice.returns(12).then.returns(13)
|
subject.expects(:boot_time).twice.returns(12).then.returns(13)
|
||||||
|
|
||||||
subject.run
|
subject.run
|
||||||
|
@ -175,6 +176,7 @@ describe Astute::Reboot do
|
||||||
|
|
||||||
it 'it should succeed if boot time before and after are different' do
|
it 'it should succeed if boot time before and after are different' do
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
|
subject.stubs(:update_online_node_status)
|
||||||
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
||||||
|
|
||||||
subject.run
|
subject.run
|
||||||
|
@ -183,12 +185,22 @@ describe Astute::Reboot do
|
||||||
|
|
||||||
it 'it should succeed if boot time before and after is different' do
|
it 'it should succeed if boot time before and after is different' do
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
|
subject.stubs(:update_online_node_status)
|
||||||
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
subject.expects(:boot_time).twice.returns(12).then.returns(11)
|
||||||
|
|
||||||
subject.run
|
subject.run
|
||||||
expect(subject.status).to eql(:successful)
|
expect(subject.status).to eql(:successful)
|
||||||
end
|
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
|
it 'it should fail if timeout is reached' do
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
subject.expects(:boot_time).once.returns(12)
|
subject.expects(:boot_time).once.returns(12)
|
||||||
|
@ -198,8 +210,19 @@ describe Astute::Reboot do
|
||||||
expect(subject.status).to eql(:failed)
|
expect(subject.status).to eql(:failed)
|
||||||
end
|
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
|
it 'it should succeed after several tries' do
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
|
subject.stubs(:update_online_node_status)
|
||||||
subject.expects(:boot_time).times(4).returns(12)
|
subject.expects(:boot_time).times(4).returns(12)
|
||||||
.then.returns(12)
|
.then.returns(12)
|
||||||
.then.returns(0)
|
.then.returns(0)
|
||||||
|
@ -219,6 +242,7 @@ describe Astute::Reboot do
|
||||||
.then.raises(Astute::MClientTimeout)
|
.then.raises(Astute::MClientTimeout)
|
||||||
.then.returns({:stdout => "13"})
|
.then.returns({:stdout => "13"})
|
||||||
subject.stubs(:reboot)
|
subject.stubs(:reboot)
|
||||||
|
subject.stubs(:update_online_node_status)
|
||||||
|
|
||||||
subject.run
|
subject.run
|
||||||
expect(subject.status).to eql(:running)
|
expect(subject.status).to eql(:running)
|
||||||
|
|
Loading…
Reference in New Issue