From e283441078aa9d43901f21612ed72e8594e25efe Mon Sep 17 00:00:00 2001 From: "Vladimir Sharshov (warpc)" Date: Tue, 23 Aug 2016 14:06:06 +0300 Subject: [PATCH] Support Noop mode for every existing tasks Add support noop mode for tasks: - erase_node; - master_shell; - move_to_bootstrap; - noop; - stage; - skipped. Add summary for this tasks including noop mode: - erase_node; - move_to_bootstrap; - reboot. Also add progress report for nodes in case of dry run Change-Id: I39e5b7452bf6df28dc07f9d81d358ea5a8b9fd37 --- lib/astute/task_deployment.rb | 10 ++++++- lib/astute/task_node.rb | 6 ++++- lib/astute/tasks/erase_node.rb | 5 ++++ lib/astute/tasks/master_shell.rb | 1 - lib/astute/tasks/move_to_bootstrap.rb | 5 ++++ lib/astute/tasks/noop_erase_node.rb | 24 +++++++++++++++++ lib/astute/tasks/noop_master_shell.rb | 31 ++++++++++++++++++++++ lib/astute/tasks/noop_move_to_bootstrap.rb | 24 +++++++++++++++++ lib/astute/tasks/noop_reboot.rb | 5 ++++ lib/astute/tasks/reboot.rb | 5 ++++ 10 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 lib/astute/tasks/noop_erase_node.rb create mode 100644 lib/astute/tasks/noop_master_shell.rb create mode 100644 lib/astute/tasks/noop_move_to_bootstrap.rb diff --git a/lib/astute/task_deployment.rb b/lib/astute/task_deployment.rb index 968fa82f..439ba250 100644 --- a/lib/astute/task_deployment.rb +++ b/lib/astute/task_deployment.rb @@ -85,7 +85,8 @@ module Astute Deployment::Log.logger = Astute.logger if Astute.respond_to? :logger write_graph_to_file(cluster) result = if dry_run - {:success => true } + report_final_node_progress(cluster) + {:success => true} else run_result = cluster.run # imitate dry_run results for noop run after deployment @@ -275,5 +276,12 @@ module Astute uids end + def report_final_node_progress(cluster) + node_report = cluster.nodes.inject([]) do |node_progress, node| + node_progress += [{'uid' => node[0].to_s, 'progress' => 100}] + end + @ctx.report('nodes' => node_report) + end + end end diff --git a/lib/astute/task_node.rb b/lib/astute/task_node.rb index 5037c32c..615c766a 100644 --- a/lib/astute/task_node.rb +++ b/lib/astute/task_node.rb @@ -100,7 +100,7 @@ module Astute end def select_task_engine(data) - noop_prefix = noop_run? ? "Noop" : "" + noop_prefix = noop_run? && not_noop_type?(data) ? "Noop" : "" task_class_name = noop_prefix + data['type'].split('_').collect(&:capitalize).join Object.const_get('Astute::' + task_class_name).new(data, @ctx) rescue => e @@ -127,5 +127,9 @@ module Astute end end + def not_noop_type?(data) + !['noop', 'stage', 'skipped'].include?(data['type']) + end + end end diff --git a/lib/astute/tasks/erase_node.rb b/lib/astute/tasks/erase_node.rb index 3c123d2d..7ea8c086 100644 --- a/lib/astute/tasks/erase_node.rb +++ b/lib/astute/tasks/erase_node.rb @@ -15,6 +15,11 @@ module Astute class EraseNode < Task + def summary + {'task_summary' => "Node #{@task['node_id']} was erased without reboot"\ + " with result #{@status}"} + end + private def process diff --git a/lib/astute/tasks/master_shell.rb b/lib/astute/tasks/master_shell.rb index fc9eb239..ec920f9c 100644 --- a/lib/astute/tasks/master_shell.rb +++ b/lib/astute/tasks/master_shell.rb @@ -11,7 +11,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -require 'erb' module Astute class MasterShell < Task diff --git a/lib/astute/tasks/move_to_bootstrap.rb b/lib/astute/tasks/move_to_bootstrap.rb index 1cc53214..a6e6114b 100644 --- a/lib/astute/tasks/move_to_bootstrap.rb +++ b/lib/astute/tasks/move_to_bootstrap.rb @@ -20,6 +20,11 @@ module Astute @work_thread = nil end + def summary + {'task_summary' => "Node #{@task['node_id']} was move to bootstrap with"\ + " result #{@status}"} + end + private def process diff --git a/lib/astute/tasks/noop_erase_node.rb b/lib/astute/tasks/noop_erase_node.rb new file mode 100644 index 00000000..41569c50 --- /dev/null +++ b/lib/astute/tasks/noop_erase_node.rb @@ -0,0 +1,24 @@ +# Copyright 2016 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. +require 'astute/tasks/noop' + +module Astute + class NoopEraseNode < Noop + + def summary + {'task_summary' => "Node #{@task['node_id']} was erased without reboot (noop mode)"} + end + + end +end diff --git a/lib/astute/tasks/noop_master_shell.rb b/lib/astute/tasks/noop_master_shell.rb new file mode 100644 index 00000000..4a65892e --- /dev/null +++ b/lib/astute/tasks/noop_master_shell.rb @@ -0,0 +1,31 @@ +# Copyright 2016 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. +require 'astute/tasks/noop_shell' +require 'astute/tasks/master_shell' + +module Astute + class NoopMasterShell < MasterShell + + private + + def process + @shell_task = NoopShell.new( + generate_master_shell, + @ctx + ) + @shell_task.run + end + + end +end diff --git a/lib/astute/tasks/noop_move_to_bootstrap.rb b/lib/astute/tasks/noop_move_to_bootstrap.rb new file mode 100644 index 00000000..e19d9bc3 --- /dev/null +++ b/lib/astute/tasks/noop_move_to_bootstrap.rb @@ -0,0 +1,24 @@ +# Copyright 2016 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. +require 'astute/tasks/noop' + +module Astute + class NoopMoveToBootstrap < Noop + + def summary + {'task_summary' => "Node #{@task['node_id']} was move to bootstrap (noop mode)"} + end + + end +end diff --git a/lib/astute/tasks/noop_reboot.rb b/lib/astute/tasks/noop_reboot.rb index fe1f200e..27fea4e2 100644 --- a/lib/astute/tasks/noop_reboot.rb +++ b/lib/astute/tasks/noop_reboot.rb @@ -15,5 +15,10 @@ require 'astute/tasks/noop' module Astute class NoopReboot < Noop + + def summary + {'task_summary' => "Node #{@task['node_id']} was rebooted (noop mode)"} + end + end end diff --git a/lib/astute/tasks/reboot.rb b/lib/astute/tasks/reboot.rb index dc1c084c..2d511280 100644 --- a/lib/astute/tasks/reboot.rb +++ b/lib/astute/tasks/reboot.rb @@ -22,6 +22,11 @@ module Astute @already_rebooted = false end + def summary + {'task_summary' => "Node #{@task['node_id']} was rebooted with "\ + "result: #{@status}"} + end + private def process