Merge pull request #71 from Mirantis/dumptask

Dumptask
This commit is contained in:
Dmitry Pyzhov 2013-09-18 05:17:44 -07:00
commit eaa42df1b1
3 changed files with 64 additions and 0 deletions

View File

@ -31,6 +31,7 @@ require 'astute/puppetd'
require 'astute/rpuppet'
require 'astute/deployment_engine/nailyfact'
require 'astute/cobbler'
require 'astute/dump'
module Astute
autoload 'Context', 'astute/context'

59
lib/astute/dump.rb Normal file
View File

@ -0,0 +1,59 @@
# Copyright 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
module Astute
module Dump
def self.dump_environment(ctx, lastdump)
timeout = 500
shell = MClient.new(ctx, 'execute_shell_command', ['master'])
begin
Timeout.timeout(timeout) do
result = shell.execute(
:cmd => "/opt/nailgun/bin/nailgun_dump >>/var/log/dump.log 2>&1 && cat #{lastdump}").first
Astute.logger.debug("#{ctx.task_id}: \
stdout: #{result[:data][:stdout]} stderr: #{result[:data][:stderr]} \
exit code: #{result[:data][:exit_code]}")
if result[:data][:exit_code] == 0
Astute.logger.info("#{ctx.task_id}: Snapshot is done. Result: #{result[:data][:stdout]}")
report_success(ctx, result[:data][:stdout].rstrip)
else
Astute.logger.error("#{ctx.task_id}: Dump command returned non zero exit code")
report_error(ctx, "exit code: #{result[:data][:exit_code]} stderr: #{result[:data][:stderr]}")
end
end
rescue Timeout::Error
msg = "Dump is timed out"
Astute.logger.error("#{ctx.task_id}: #{msg}")
report_error(ctx, msg)
rescue Exception => e
msg = "Exception occured during dump task: message: #{e.message} \
trace: #{e.backtrace.inspect}"
Astute.logger.error("#{ctx.task_id}: #{msg}")
report_error(ctx, msg)
end
end
def self.report_success(ctx, msg=nil)
success_msg = {'status' => 'ready', 'progress' => 100}
success_msg.merge!({'msg' => msg}) if msg
ctx.reporter.report(success_msg)
end
def self.report_error(ctx, msg)
ctx.reporter.report({'status' => 'error', 'error' => msg, 'progress' => 100})
end
end
end

View File

@ -149,6 +149,10 @@ module Astute
NodesRemover.new(Context.new(task_id, reporter), nodes).remove
end
def dump_environment(reporter, task_id, lastdump)
Dump.dump_environment(Context.new(task_id, reporter), lastdump)
end
def verify_networks(reporter, task_id, nodes)
Network.check_network(Context.new(task_id, reporter), nodes)
end