Astute do not respect debug option for puppet task

Run cluster with enable debug option do not affect
puppet task which always run with debug disable.

It is happened because Nailgun send debug option which
Astute setup for every task, but puppet task required
puppet_debug option to control it behavior. This code
will connect this parameters.

Change-Id: I8df68105aa699e83673c39a0f03bb22673171d6f
Closes-Bug: #1662512
This commit is contained in:
Vladimir Sharshov (warpc) 2017-02-07 17:13:35 +03:00
parent 64d62086e8
commit 003a0a0efd
3 changed files with 82 additions and 19 deletions

View File

@ -16,7 +16,7 @@ module Astute
class Task
ALLOWED_STATUSES = [:successful, :failed, :running, :pending, :skipped]
attr_reader :task
def initialize(task, context)
# WARNING: this code expect that only one node will be send
# on one hook.
@ -33,7 +33,7 @@ module Astute
running!
process
rescue => e
Astute.logger.warn("Fail to run task #{@task['type']} #{task_name}" \
Astute.logger.warn("Fail to run task #{task['type']} #{task_name}" \
" with error #{e.message} trace: #{e.format_backtrace}")
failed!
end
@ -43,7 +43,7 @@ module Astute
calculate_status unless finished?
@status
rescue => e
Astute.logger.warn("Fail to detect status of the task #{@task['type']}" \
Astute.logger.warn("Fail to detect status of the task #{task['type']}" \
" #{task_name} with error #{e.message} trace: #{e.format_backtrace}")
failed!
end
@ -169,14 +169,14 @@ module Astute
end
def task_name
@task['id'] || @task['diagnostic_name']
task['id'] || task['diagnostic_name']
end
def time_summary
amount_time = (Time.now.to_i - @time_start).to_i
wasted_time = Time.at(amount_time).utc.strftime("%H:%M:%S")
Astute.logger.debug("Task time summary: #{task_name} with status" \
" #{@status.to_s} on node #{@task['node_id']} took #{wasted_time}")
" #{@status.to_s} on node #{task['node_id']} took #{wasted_time}")
end
end

View File

@ -25,7 +25,7 @@ module Astute
def process
Astute.logger.debug "Puppet task options: "\
"#{@task['parameters'].pretty_inspect}"
"#{task['parameters'].pretty_inspect}"
puppet_task.run
end
@ -34,8 +34,8 @@ module Astute
end
def validation
validate_presence(@task, 'node_id')
validate_presence(@task['parameters'], 'puppet_manifest')
validate_presence(task, 'node_id')
validate_presence(task['parameters'], 'puppet_manifest')
end
def setup_default
@ -45,7 +45,7 @@ module Astute
'puppet_modules' => Astute.config.puppet_module_path,
'cwd' => Astute.config.shell_cwd,
'timeout' => Astute.config.puppet_timeout,
'puppet_debug' => false,
'debug' => false,
'succeed_retries' => Astute.config.puppet_succeed_retries,
'undefined_retries' => Astute.config.puppet_undefined_retries,
'raw_report' => Astute.config.puppet_raw_report,
@ -53,8 +53,9 @@ module Astute
'puppet_start_timeout' => Astute.config.puppet_start_timeout,
'puppet_start_interval' => Astute.config.puppet_start_interval
}
@task['parameters'].compact!
@task['parameters'].reverse_merge!(default_options)
task['parameters'].compact!
task['parameters'].reverse_merge!(default_options)
task['parameters']['puppet_debug'] = task['parameters']['debug']
end
def puppet_task
@ -62,17 +63,17 @@ module Astute
task_name,
PuppetMClient.new(
@ctx,
@task['node_id'],
@task['parameters'],
task['node_id'],
task['parameters'],
),
{
'retries' => @task['parameters']['retries'],
'succeed_retries' => @task['parameters']['succeed_retries'],
'undefined_retries' => @task['parameters']['undefined_retries'],
'timeout' => @task['parameters']['timeout'],
'puppet_start_timeout' => @task['parameters'][
'retries' => task['parameters']['retries'],
'succeed_retries' => task['parameters']['succeed_retries'],
'undefined_retries' => task['parameters']['undefined_retries'],
'timeout' => task['parameters']['timeout'],
'puppet_start_timeout' => task['parameters'][
'puppet_start_timeout'],
'puppet_start_interval' => @task['parameters'][
'puppet_start_interval' => task['parameters'][
'puppet_start_interval']
}
)

View File

@ -0,0 +1,62 @@
# Copyright 2017 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 File.join(File.dirname(__FILE__), '../../spec_helper')
describe Astute::Shell do
include SpecHelpers
let(:task) do
{
'parameters' => {
'debug' => false,
'retries' => 1,
'puppet_manifest' => 'puppet_manifest_example.pp',
'puppet_modules' => '/etc/puppet/modules',
'cwd' => '/',
'timeout' => nil,
'succeed_retries' => 1,
'timeout' => 180
},
'type' => 'puppet',
'id' => 'puppet_task_example',
'node_id' => 'node_id',
}
end
let(:ctx) { mock_ctx }
subject { Astute::Puppet.new(task, ctx) }
describe '#run' do
before { Astute::Puppet.any_instance.stubs(:process) }
context 'debug behavior' do
it 'puppet debug should disable if debug option disable or missing' do
subject.run
expect(subject.task['parameters']['puppet_debug']).to eq(false)
end
it 'puppet debug should enable if debug enable' do
task['parameters']['debug'] = true
subject.run
expect(subject.task['parameters']['debug']).to eq(true)
expect(subject.task['parameters']['puppet_debug']).to eq(true)
end
end # context
end # 'run'
end