Replace Shotgun with Timmy
With adding some glue code. Change-Id: Iebe3b05cac93f3cc00a611a84bb8f3764dba6ad3 implements: bp/shotgun-retirement
This commit is contained in:
parent
fa254cf7ca
commit
0a87735a1c
|
@ -26,17 +26,20 @@ module Astute
|
|||
enable_result_logging=false
|
||||
)
|
||||
|
||||
upload_file = MClient.new(ctx, 'uploadfile', ['master'])
|
||||
begin
|
||||
config_path = '/tmp/dump_config'
|
||||
upload_file.upload(
|
||||
:path => config_path,
|
||||
:content => settings.to_json,
|
||||
:user_owner => 'root',
|
||||
:group_owner => 'root',
|
||||
:overwrite => true)
|
||||
|
||||
dump_cmd = "shotgun -c #{config_path} > /dev/null 2>&1 && cat #{settings['lastdump']}"
|
||||
log_file = "/var/log/timmy.log"
|
||||
snapshot = File.basename(settings['target'])
|
||||
if settings['timestamp']
|
||||
snapshot = DateTime.now.strftime("#{snapshot}-%Y-%m-%d_%H-%M-%S")
|
||||
end
|
||||
base_dir = File.dirname(settings['target'])
|
||||
dest_dir = File.join(base_dir, snapshot)
|
||||
dest_file = File.join(dest_dir, "config.tar.gz")
|
||||
dump_cmd = "mkdir -p #{dest_dir} && "\
|
||||
"timmy --logs --days 3 --dest-file #{dest_file} --log-file #{log_file} && "\
|
||||
"tar --directory=#{base_dir} -cf #{dest_dir}.tar #{snapshot} && "\
|
||||
"echo #{dest_dir}.tar > #{settings['lastdump']} && "\
|
||||
"rm -rf #{dest_dir}"
|
||||
Astute.logger.debug("Try to execute command: #{dump_cmd}")
|
||||
result = shell.execute(:cmd => dump_cmd).first.results
|
||||
|
||||
|
@ -44,13 +47,13 @@ module Astute
|
|||
|
||||
if result[:data][:exit_code] == 0
|
||||
Astute.logger.info("#{ctx.task_id}: Snapshot is done.")
|
||||
report_success(ctx, result[:data][:stdout].force_encoding(Encoding.default_external).rstrip)
|
||||
report_success(ctx, "#{dest_dir}.tar")
|
||||
elsif result[:data][:exit_code] == 28
|
||||
Astute.logger.error("#{ctx.task_id}: Disk space for creating snapshot exceeded.")
|
||||
report_error(ctx, "Shotgun exit code: #{result[:data][:exit_code]}. Disk space for creating snapshot exceeded.")
|
||||
report_error(ctx, "Timmy exit code: #{result[:data][:exit_code]}. Disk space for creating snapshot exceeded.")
|
||||
else
|
||||
Astute.logger.error("#{ctx.task_id}: Dump command returned non zero exit code. For details see /var/log/shotgun.log")
|
||||
report_error(ctx, "Shotgun exit code: #{result[:data][:exit_code]}")
|
||||
Astute.logger.error("#{ctx.task_id}: Dump command returned non zero exit code. For details see #{log_file}")
|
||||
report_error(ctx, "Timmy exit code: #{result[:data][:exit_code]}")
|
||||
end
|
||||
rescue Timeout::Error
|
||||
msg = "Dump is timed out"
|
||||
|
|
|
@ -22,6 +22,7 @@ describe 'dump_environment' do
|
|||
let(:settings) do
|
||||
{
|
||||
'lastdump' => '/last/dump/path',
|
||||
'target' => '/var/dump/path',
|
||||
'timeout' => 300,
|
||||
}
|
||||
end
|
||||
|
@ -37,43 +38,36 @@ describe 'dump_environment' do
|
|||
end
|
||||
|
||||
it "should upload the config and call execute method with shotgun as cmd" do
|
||||
config_path = '/tmp/dump_config'
|
||||
dump_cmd = "shotgun -c #{config_path} > /dev/null 2>&1 && cat #{settings['lastdump']}"
|
||||
rpc_mock.expects(:upload).with({
|
||||
path: config_path,
|
||||
content: settings.to_json,
|
||||
user_owner: 'root',
|
||||
group_owner: 'root',
|
||||
overwrite: true}).returns([mock_mc_result])
|
||||
|
||||
target = settings['target']
|
||||
dump_cmd = "mkdir -p #{target} && "\
|
||||
"timmy --logs --days 3 --dest-file #{target}/config.tar.gz "\
|
||||
"--log-file /var/log/timmy.log && "\
|
||||
"tar --directory=/var/dump -cf #{target}.tar path && "\
|
||||
"echo #{target}.tar > #{settings['lastdump']} && "\
|
||||
"rm -rf #{target}"
|
||||
rpc_mock.expects(:execute).with({:cmd => dump_cmd}).returns(exec_result)
|
||||
|
||||
Astute::Dump.dump_environment(ctx, settings)
|
||||
end
|
||||
|
||||
it "should report success if shell agent returns 0" do
|
||||
rpc_mock.expects(:upload).returns([mock_mc_result])
|
||||
rpc_mock.expects(:execute).returns(exec_result)
|
||||
Astute::Dump.expects(:report_success)
|
||||
Astute::Dump.dump_environment(ctx, settings)
|
||||
end
|
||||
|
||||
it "should report error if shell agent returns not 0" do
|
||||
rpc_mock.expects(:upload).returns([mock_mc_result])
|
||||
rpc_mock.expects(:execute).returns(exec_result(1, '', ''))
|
||||
Astute::Dump.expects(:report_error).with(ctx, "Shotgun exit code: 1")
|
||||
Astute::Dump.expects(:report_error).with(ctx, "Timmy exit code: 1")
|
||||
Astute::Dump.dump_environment(ctx, settings)
|
||||
end
|
||||
|
||||
it "should report disk space error if shell agent returns 28" do
|
||||
rpc_mock.expects(:upload).returns([mock_mc_result])
|
||||
rpc_mock.expects(:execute).returns(exec_result(28, '', ''))
|
||||
Astute::Dump.expects(:report_error).with(ctx, "Shotgun exit code: 28. Disk space for creating snapshot exceeded.")
|
||||
Astute::Dump.expects(:report_error).with(ctx, "Timmy exit code: 28. Disk space for creating snapshot exceeded.")
|
||||
Astute::Dump.dump_environment(ctx, settings)
|
||||
end
|
||||
|
||||
it "non default timeout should be used" do
|
||||
Astute::MClient.stubs(:new).with(ctx, 'uploadfile', ['master'])
|
||||
Astute::MClient.stubs(:new).with(ctx, 'execute_shell_command', ['master'], true, 300, 0, false)
|
||||
Astute::Dump.dump_environment(ctx, settings)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue