Skip to content

[FM-6584] Task test cleanup #1040

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

Merged
merged 1 commit into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ group :system_tests do
gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || '~> 0.1')
gem "puppet-blacksmith", '~> 3.4', :require => false
gem "beaker-task_helper"
end

gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/mysql_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class { 'mysql::server::backup':
end

it 'dumps all databases to single file #stdout' do
if version_is_greater_than('5.7.0')
unless version_is_greater_than('5.7.0')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentional? it's broken jenkins.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is to fix Jenkins - it was introduced in a recent rubocopificiation work, I added the fix to this PR.

You can view an adhoc run of this branch on Jenkins - https://jenkins-master-prod-1.delivery.puppetlabs.net/view/modules/view/linux/view/mysql/view/adhoc/ - all green :)

shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
expect(r.stdout).to match(%r{1})
end
Expand Down
8 changes: 4 additions & 4 deletions spec/acceptance/sql_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# run a test task
require 'spec_helper_acceptance'

describe 'mysql tasks' do
describe 'execute some sql', if: pe_install? && puppet_version =~ %r{(5\.\d\.\d)} do
describe 'mysql tasks', if: puppet_version =~ %r{(5\.\d\.\d)} && fact('operatingsystem') != 'SLES' do
describe 'execute some sql' do
pp = <<-MANIFEST
class { 'mysql::server': root_password => 'password' }
mysql::db { 'spec1':
Expand All @@ -12,12 +12,12 @@ class { 'mysql::server': root_password => 'password' }
MANIFEST

it 'sets up a mysql instance' do
apply_manifest(pp, catch_failures: true)
apply_manifest_on(hosts, pp, catch_failures: true)
end

it 'execute arbitary sql' do
result = run_task(task_name: 'mysql::sql', params: 'sql="show databases;" password=password')
expect_multiple_regexes(result: result, regexes: [%r{information_schema}, %r{performance_schema}, %r{Job completed. 1/1 nodes succeeded}])
expect_multiple_regexes(result: result, regexes: [%r{information_schema}, %r{#{task_summary_line}}])
end
end
end
49 changes: 2 additions & 47 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,14 @@
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'
require 'beaker/i18n_helper'

def install_bolt_on(hosts)
on(hosts, "/opt/puppetlabs/puppet/bin/gem install --source http://rubygems.delivery.puppetlabs.net bolt -v '> 0.0.1'", acceptable_exit_codes: [0, 1]).stdout
end

def pe_install?
ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i
end
require 'beaker/task_helper'

run_puppet_install_helper
install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i
install_ca_certs unless pe_install?
install_bolt_on(hosts) unless pe_install?
install_module_on(hosts)
install_module_dependencies_on(hosts)

UNSUPPORTED_PLATFORMS = %w[Windows Solaris AIX].freeze

def puppet_version
(on default, puppet('--version')).output.chomp
end

DEFAULT_PASSWORD = if default[:hypervisor] == 'vagrant'
'vagrant'
elsif default[:hypervisor] == 'vcloud'
'Qu@lity!'
end

def run_puppet_access_login(user:, password: '~!@#$%^*-/ aZ', lifetime: '5y')
on(master, puppet('access', 'login', '--username', user, '--lifetime', lifetime), stdin: password)
end

def run_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
if pe_install?
run_puppet_task(task_name: task_name, params: params)
else
run_bolt_task(task_name: task_name, params: params, password: password)
end
end

def run_bolt_task(task_name:, params: nil, password: DEFAULT_PASSWORD)
on(master, "/opt/puppetlabs/puppet/bin/bolt task run #{task_name} --modulepath /etc/puppetlabs/code/modules/service --nodes localhost --password #{password} #{params}", acceptable_exit_codes: [0, 1]).stdout # rubocop:disable Metrics/LineLength
end

def run_puppet_task(task_name:, params: nil)
on(master, puppet('task', 'run', task_name, '--nodes', fact_on(master, 'fqdn'), params.to_s), acceptable_exit_codes: [0, 1]).stdout
end

def expect_multiple_regexes(result:, regexes:)
regexes.each do |regex|
expect(result).to match(regex)
end
end

RSpec.configure do |c|
# Readable test descriptions
c.formatter = :documentation
Expand Down