Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FM-8494) fix provision progress in travis and rubocop #182

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
require: rubocop-rspec
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: '2.3'
TargetRubyVersion: '2.5'
Include:
- "**/*.rb"
Exclude:
43 changes: 26 additions & 17 deletions lib/puppet_litmus/rake_tasks.rb
Original file line number Diff line number Diff line change
@@ -141,19 +141,27 @@ def run_local_command(command)
end

params = { 'action' => 'provision', 'platform' => args[:platform], 'inventory' => Dir.pwd }
spinner = if (ENV['CI'] == 'true') || !ENV['DISTELLI_BUILDNUM'].nil?
TTY::Spinner.new(':spinner', frames: ['.'], interval: 0.1)
else
TTY::Spinner.new("Provisioning #{args[:platform]} using #{args[:provisioner]} provisioner.[:spinner]")
end
spinner.auto_spin
if (ENV['CI'] == 'true') || !ENV['DISTELLI_BUILDNUM'].nil?
progress = Thread.new do
loop do
printf '.'
sleep(10)
end
end
else
spinner = TTY::Spinner.new("Provisioning #{args[:platform]} using #{args[:provisioner]} provisioner.[:spinner]")
spinner.auto_spin
end
results = run_task("provision::#{args[:provisioner]}", 'localhost', params, config: config_data, inventory: nil)
if results.first['status'] != 'success'
spinner.error
raise "Failed provisioning #{args[:platform]} using #{args[:provisioner]}\n#{results.first}"
end

spinner.success
if (ENV['CI'] == 'true') || !ENV['DISTELLI_BUILDNUM'].nil?
Thread.kill(progress)
else
spinner.success
end
puts "#{results.first['result']['node_name']}, #{args[:platform]}"
end

@@ -189,7 +197,10 @@ def run_local_command(command)
end

# fix the path on ssh_nodes
results = run_command('echo PATH="$PATH:/opt/puppetlabs/puppet/bin" > /etc/environment', 'ssh_nodes', config: nil, inventory: inventory_hash) unless inventory_hash['groups'].select { |group| group['name'] == 'ssh_nodes' }.size.zero? # rubocop:disable Metrics/LineLength
unless inventory_hash['groups'].select { |group| group['name'] == 'ssh_nodes' }.size.zero?
results = run_command('echo PATH="$PATH:/opt/puppetlabs/puppet/bin" > /etc/environment',
'ssh_nodes', config: nil, inventory: inventory_hash)
end
results.each do |result|
if result['status'] != 'success'
puts "Failed on #{result['node']}\n#{result}"
@@ -283,15 +294,13 @@ def run_local_command(command)
run_local_command("bundle exec bolt file upload \"#{module_tar}\" /tmp/#{File.basename(module_tar)} --nodes #{target_string} --inventoryfile inventory.yaml")
install_module_command = "puppet module install /tmp/#{File.basename(module_tar)}"
result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
# rubocop:disable Style/GuardClause
if result.is_a?(Array)
result.each do |node|
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
end
else
raise "Failed trying to run '#{install_module_command}' against inventory."

raise "Failed trying to run '#{install_module_command}' against inventory." unless result.is_a?(Array)

result.each do |node|
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
end
# rubocop:enable Style/GuardClause

puts 'Installed'
end

28 changes: 20 additions & 8 deletions lib/puppet_litmus/serverspec.rb
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ def apply_manifest(manifest, opts = {})

result = run_command(command_to_run, target_node_name, config: nil, inventory: inventory_hash)
status = result.first['result']['exit_code']
report_puppet_error(command_to_run, result) unless puppet_successful?(status) && opts[:expect_failures] != true
report_puppet_change(command_to_run, result) if puppet_changes?(status) && opts[:catch_changes] == true
report_puppet_apply_error(command_to_run, result) unless puppet_successful?(status) && opts[:expect_failures] != true
report_puppet_apply_change(command_to_run, result) if puppet_changes?(status) && opts[:catch_changes] == true

result = OpenStruct.new(exit_code: result.first['result']['exit_code'],
stdout: result.first['result']['stdout'],
@@ -235,19 +235,31 @@ def bolt_run_script(script, opts = {}, arguments: [])
#
# @param command [String] The puppet command causing the error.
# @param result [Array] The result struct containing the result
def report_puppet_error(command, result)
raise "apply manifest failed\n`#{command}`\n======Start output of failed Puppet run======\n#{puppet_output(result)}\n======End output of failed Puppet run======"
def report_puppet_apply_error(command, result)
puppet_apply_error = <<-ERROR
apply manifest failed
`#{command}`
======Start output of failed Puppet run======
#{puppet_output(result)}
======End output of failed Puppet run======
ERROR
raise puppet_apply_error
end

# Report an unexpected change in the puppet run
#
# @param command [String] The puppet command causing the error.
# @param result [Array] The result struct containing the result
# rubocop: disable Metrics/LineLength
def report_puppet_change(command, result)
raise "apply manifest expected no changes\n`#{command}`\n======Start output of Puppet run with unexpected changes======\n#{puppet_output(result)}\n======End output of Puppet run with unexpected changes======"
def report_puppet_apply_change(command, result)
puppet_apply_changes = <<-ERROR
apply manifest expected no changes
`#{command}`
======Start output of Puppet run with unexpected changes======
#{puppet_output(result)}
======End output of Puppet run with unexpected changes======
ERROR
raise puppet_apply_changes
end
# rubocop: enable Metrics/LineLength

# Return the stdout of the puppet run
def puppet_output(result)