diff --git a/.fixtures.yml b/.fixtures.yml index ca905cbf6..0a9cdf914 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,5 +3,8 @@ fixtures: "stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib" "translate": "https://github.com/puppetlabs/puppetlabs-translate" "cron_core": "https://github.com/puppetlabs/puppetlabs-cron_core.git" + "facts": "git://github.com/puppetlabs/puppetlabs-facts.git" + "puppet_agent": "git://github.com/puppetlabs/puppetlabs-puppet_agent.git" + "provision": "git://github.com/puppetlabs/provision.git" symlinks: "mysql": "#{source_dir}" diff --git a/.sync.yml b/.sync.yml index ab7b9aa29..bc075b4ad 100644 --- a/.sync.yml +++ b/.sync.yml @@ -4,16 +4,16 @@ - ---.project .travis.yml: - docker_sets: - - set: docker/centos-7 - - set: docker/ubuntu-14.04 - docker_defaults: - bundler_args: "" - secure: "" - branches: - - release - + unmanaged: true + Gemfile: + optional: + ':development': + - gem: puppet-lint-i18n + - gem: 'github_changelog_generator' + git: 'https://github.com/skywinder/github-changelog-generator' + ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' + condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" required: ':system_tests': - gem: 'puppet-module-posix-system-r#{minor_version}' @@ -23,15 +23,13 @@ Gemfile: - mswin - mingw - x64_mingw - - gem: beaker-testmode_switcher - ':development': - - gem: puppet-lint-i18n - optional: - ':development': - - gem: 'github_changelog_generator' - git: 'https://github.com/skywinder/github-changelog-generator' - ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' - condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" + - gem: 'puppet_litmus' + platforms: + - ruby + - mswin + - mingw + - x64_mingw + condition: "ENV['PUPPET_GEM_VERSION'].nil? or ENV['PUPPET_GEM_VERSION'] !~ %r{ 5}" appveyor.yml: unmanaged: true @@ -39,6 +37,7 @@ appveyor.yml: Rakefile: requires: - puppet_pot_generator/rake_tasks + use_litmus_tasks: true   changelog_user: 'puppetlabs' spec/spec_helper.rb: diff --git a/.travis.yml b/.travis.yml index 9472d0381..f95a6a43d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,49 +11,127 @@ script: - 'bundle exec rake $CHECK' bundler_args: --without system_tests rvm: - - 2.5.3 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy + - 2.5.1 +env: + global: + - PUPPET_GEM_VERSION="~> 6.0" matrix: fast_finish: true include: - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply - rvm: 2.5.3 - script: bundle exec rake beaker + env: PLATFORMS=deb_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='localhost*' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply - rvm: 2.5.3 - script: bundle exec rake beaker + env: PLATFORM=deb_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='localhost*' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORMS=el7_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el7]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORM=el7_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el7]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORM=centos6_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision[docker, waffleimage/centos6]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - TARGET_HOST=localhost:2222 bundle exec rspec ./spec/acceptance/ + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORM=centos6_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision[docker, waffleimage/centos6]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - TARGET_HOST=localhost:2222 bundle exec rspec ./spec/acceptance/ + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORM=scientificlinux6_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision[docker, waffleimage/scientificlinux6]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - TARGET_HOST=localhost:2222 bundle exec rspec ./spec/acceptance/ + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORM=scientificlinux6_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision[docker, waffleimage/scientificlinux6]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - TARGET_HOST=localhost:2222 bundle exec rspec ./spec/acceptance/ services: docker - stage: acceptance sudo: required - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" - stage: static - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec rvm: 2.4.5 - stage: spec - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec rvm: 2.5.3 - stage: spec - - - env: DEPLOY_TO_FORGE=yes - stage: deploy branches: only: - master diff --git a/Gemfile b/Gemfile index b12115ce4..6aa9ccfe6 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ end group :system_tests do gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "beaker-testmode_switcher", require: false + gem "puppet_litmus", require: false, platforms: [:ruby, :mswin, :mingw, :x64_mingw] if ENV['PUPPET_GEM_VERSION'].nil? or ENV['PUPPET_GEM_VERSION'] !~ %r{ 5} end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/README.md b/README.md index aeb1399d5..dac6accd8 100644 --- a/README.md +++ b/README.md @@ -518,6 +518,8 @@ For an extensive list of supported operating systems, see [metadata.json](https: ## Development +We are experimenting with a new tool for running acceptance tests. Its name is [puppet_litmus](https://github.com/puppetlabs/puppet_litmus) this replaces beaker as the test runner. To run the acceptance tests follow the instructions from this point [here](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#install-the-necessary-gems-for-the-module). + Puppet modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. diff --git a/Rakefile b/Rakefile index 98157db67..bc24a1842 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? diff --git a/distelli-manifest.yml b/distelli-manifest.yml new file mode 100644 index 000000000..ac086b4ef --- /dev/null +++ b/distelli-manifest.yml @@ -0,0 +1,25 @@ +team-modules/puppetlabs-mysql: + PreBuild: + - source /opt/rh/rh-ruby25/enable + - echo "--- LETS update BUNDLER ---" + - bundle install --path vendor/bundle --jobs 3 + Build: + - echo "--- PROVISIONING ---" + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:provision_list[release_checks] + - cat inventory.yaml + - echo "--- AGENT INSTALLATION ---" + - bundle exec rake litmus:install_agent + - echo "--- MODULE INSTALLATION ---" + - bundle exec rake litmus:install_module + - echo "--- TESTS RUNNING ---" + - bundle exec rake litmus:acceptance:parallel + AfterBuildSuccess: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + AfterBuildFailure: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + CommitData: + - RepoType: Git + - RepoPath: . diff --git a/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index 38b855b3e..5696a90c3 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -63,6 +63,16 @@ require => Mysql_user["${backupuser}@localhost"], } + if $::osfamily == 'RedHat' { + package {'cronie': + ensure => present, + } + } else { + package {'cron': + ensure => present, + } + } + cron { 'mysqlbackup-weekly': ensure => $ensure, command => 'mysqlbackup backup', diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index 4f0895cbc..2771820dc 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -52,6 +52,20 @@ require => Mysql_user["${backupuser}@localhost"], } + if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '5' { + package {'crontabs': + ensure => present, + } + } elsif $::osfamily == 'RedHat' { + package {'cronie': + ensure => present, + } + } else { + package {'cron': + ensure => present, + } + } + cron { 'mysql-backup': ensure => $ensure, command => '/usr/local/sbin/mysqlbackup.sh', diff --git a/manifests/params.pp b/manifests/params.pp index 274463d68..33adb874a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -185,7 +185,6 @@ } else { $provider = 'mysql' } - if $provider == 'mariadb' { $client_package_name = 'mariadb-client' $server_package_name = 'mariadb-server' @@ -222,13 +221,13 @@ } else { $php_package_name = 'php5-mysql' } + $python_package_name = 'python-mysqldb' - $ruby_package_name = $::lsbdistcodename ? { - 'jessie' => 'ruby-mysql', - 'stretch' => 'ruby-mysql2', - 'trusty' => 'ruby-mysql', - 'xenial' => 'ruby-mysql', - 'bionic' => 'ruby-mysql2', + $ruby_package_name = $::operatingsystemrelease ? { + '8' => 'ruby-mysql', + '9' => 'ruby-mysql2', + '14' => 'ruby-mysql', + '16' => 'ruby-mysql', default => 'libmysql-ruby', } } diff --git a/metadata.json b/metadata.json index 788f0e8bd..be79bdddd 100644 --- a/metadata.json +++ b/metadata.json @@ -81,7 +81,7 @@ } ], "description": "MySQL module", - "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-gf778803", + "template-url": "https://github.com/puppetlabs/pdk-templates/#1.10.0", + "template-ref": "1.10.0-0-gbba9ac3", "pdk-version": "1.10.0" } diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 000000000..adb965170 --- /dev/null +++ b/provision.yaml @@ -0,0 +1,13 @@ +--- +default: + provisioner: docker + images: ['waffleimage/centos7'] +travis_deb: + provisioner: docker + images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] +travis_el7: + provisioner: docker + images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7'] +release_checks: + provisioner: vmpooler + images: ['redhat-5-x86_64', 'redhat-6-x86_64', 'redhat-7-x86_64', 'centos-5-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'oracle-5-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'sles-11-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64'] diff --git a/spec/acceptance/mysql_backup_spec.rb b/spec/acceptance/mysql_backup_spec.rb index 5454eb2f6..057a34072 100644 --- a/spec/acceptance/mysql_backup_spec.rb +++ b/spec/acceptance/mysql_backup_spec.rb @@ -1,6 +1,4 @@ require 'spec_helper_acceptance' -require 'puppet/util/package' -require_relative './mysql_helper.rb' describe 'mysql::server::backup class' do context 'should work with no errors' do @@ -29,55 +27,48 @@ class { 'mysql::server::backup': } MANIFEST it 'when configuring mysql backups' do - idempotent_apply(default, pp, {}) + idempotent_apply(pp) end end - describe 'mysqlbackup.sh' do + describe 'mysqlbackup.sh', if: Gem::Version.new(mysql_version) < Gem::Version.new('5.7.0') do before(:all) do pre_run end it 'runs mysqlbackup.sh with no errors' do - unless version_is_greater_than('5.7.0') - shell('/usr/local/sbin/mysqlbackup.sh') do |r| - expect(r.stderr).to eq('') - end + run_shell('/usr/local/sbin/mysqlbackup.sh') do |r| + expect(r.stderr).to eq('') end end it 'dumps all databases to single file' do - unless version_is_greater_than('5.7.0') - shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| - expect(r.stdout).to match(%r{1}) - expect(r.exit_code).to be_zero - end + run_shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| + expect(r.stdout).to match(%r{1}) + expect(r.exit_code).to be_zero end end context 'should create one file per database per run' do it 'executes mysqlbackup.sh a second time' do - unless version_is_greater_than('5.7.0') - shell('sleep 1') - shell('/usr/local/sbin/mysqlbackup.sh') - end + run_shell('sleep 1') + run_shell('/usr/local/sbin/mysqlbackup.sh') end it 'creates at least one backup tarball' do - unless version_is_greater_than('5.7.0') - shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| - expect(r.stdout).to match(%r{2}) - expect(r.exit_code).to be_zero - end + run_shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| + expect(r.stdout).to match(%r{2}) + expect(r.exit_code).to be_zero end end end - # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength end + # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength +end - context 'with one file per database' do - context 'should work with no errors' do - pp = <<-MANIFEST +context 'with one file per database' do + context 'should work with no errors' do + pp = <<-MANIFEST class { 'mysql::server': root_password => 'password' } mysql::db { [ 'backup1', @@ -102,53 +93,44 @@ class { 'mysql::server::backup': execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', } MANIFEST - it 'when configuring mysql backups' do - idempotent_apply(default, pp, {}) - end + it 'when configuring mysql backups' do + idempotent_apply(pp) end + end - describe 'mysqlbackup.sh' do - before(:all) do - pre_run - end + describe 'mysqlbackup.sh', if: Gem::Version.new(mysql_version) < Gem::Version.new('5.7.0') do + before(:all) do + pre_run + end - it 'runs mysqlbackup.sh with no errors without root credentials' do - unless version_is_greater_than('5.7.0') - shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh') do |r| - expect(r.stderr).to eq('') - end - end + it 'runs mysqlbackup.sh with no errors without root credentials' do + run_shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh') do |r| + expect(r.stderr).to eq('') end + end - it 'creates one file per database' do - unless version_is_greater_than('5.7.0') - ['backup1', 'backup2'].each do |database| - shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| - expect(r.stdout).to match(%r{1}) - expect(r.exit_code).to be_zero - end - end + it 'creates one file per database' do + ['backup1', 'backup2'].each do |database| + run_shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| + expect(r.stdout).to match(%r{1}) + expect(r.exit_code).to be_zero end end + end - it 'executes mysqlbackup.sh a second time' do - unless version_is_greater_than('5.7.0') - shell('sleep 1') - shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh') - end - end + it 'executes mysqlbackup.sh a second time' do + run_shell('sleep 1') + run_shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh') + end - it 'has one file per database per run' do - unless version_is_greater_than('5.7.0') - ['backup1', 'backup2'].each do |database| - shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| - expect(r.stdout).to match(%r{2}) - expect(r.exit_code).to be_zero - end - end + it 'has one file per database per run' do + ['backup1', 'backup2'].each do |database| + run_shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| + expect(r.stdout).to match(%r{2}) + expect(r.exit_code).to be_zero end end - # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength end + # rubocop:enable RSpec/MultipleExpectations, RSpec/ExampleLength end end diff --git a/spec/acceptance/mysql_db_spec.rb b/spec/acceptance/mysql_db_spec.rb index cf28fb541..6fccaf7cb 100644 --- a/spec/acceptance/mysql_db_spec.rb +++ b/spec/acceptance/mysql_db_spec.rb @@ -1,6 +1,32 @@ require 'spec_helper_acceptance' describe 'mysql::db define' do + describe 'creating a database' do + let(:pp) do + <<-MANIFEST + class { 'mysql::server': + root_password => 'password', + service_enabled => 'true', + service_manage => 'true', + } + mysql::db { 'spec1': + user => 'root1', + password => 'password', + } + MANIFEST + end + + it 'behaves idempotently' do + idempotent_apply(pp) + end + + it 'Checking exit code and stdout' do + result = run_shell("mysql -e 'show databases;'") + expect(result.exit_code).to eq 0 + expect(result.stdout).to match %r{^spec1$} + end + end + describe 'creating a database with post-sql' do let(:pp) do <<-MANIFEST @@ -18,11 +44,38 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } } MANIFEST end - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end + + it 'Checking exit code and stdout' do + result = run_shell("mysql -e 'show tables;' spec2") + expect(result.exit_code).to eq 0 + expect(result.stdout).to match %r{^table1$} + end + end + + describe 'creating a database with dbname parameter' do + let(:check_command) { ' | grep realdb' } + let(:pp) do + <<-MANIFEST + class { 'mysql::server': override_options => { 'root_password' => 'password' } } + mysql::db { 'spec1': + user => 'root1', + password => 'password', + dbname => 'realdb', + } + MANIFEST + end + + it 'behaves idempotently' do + idempotent_apply(pp) + end - describe command("mysql -e 'show tables;' spec2") do - its(:exit_status) { is_expected.to eq 0 } - its(:stdout) { is_expected.to match %r{^table1$} } + it 'Checking exit code and stdout' do + result = run_shell("mysql -e 'show databases;'") + expect(result.exit_code).to eq 0 + expect(result.stdout).to match %r{^realdb$} end end end diff --git a/spec/acceptance/mysql_helper.rb b/spec/acceptance/mysql_helper.rb deleted file mode 100644 index 6da16ca5b..000000000 --- a/spec/acceptance/mysql_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -def pre_run - execute_manifest("class { 'mysql::server': root_password => 'password' }", catch_failures: true) - @mysql_version = (on default, 'mysql --version').output.chomp.match(%r{\d+\.\d+\.\d+})[0] -end - -def version_is_greater_than(version) - Puppet::Util::Package.versioncmp(@mysql_version, version) > 0 -end diff --git a/spec/acceptance/mysql_server_spec.rb b/spec/acceptance/mysql_server_spec.rb index 15770420b..e5360afc2 100644 --- a/spec/acceptance/mysql_server_spec.rb +++ b/spec/acceptance/mysql_server_spec.rb @@ -43,7 +43,9 @@ class { 'mysql::server': MANIFEST end - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end describe 'syslog configuration' do @@ -55,6 +57,8 @@ class { 'mysql::server': MANIFEST end - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end end diff --git a/spec/acceptance/sql_task_spec.rb b/spec/acceptance/mysql_task_spec.rb similarity index 51% rename from spec/acceptance/sql_task_spec.rb rename to spec/acceptance/mysql_task_spec.rb index e0f78cd72..7cc227f5d 100644 --- a/spec/acceptance/sql_task_spec.rb +++ b/spec/acceptance/mysql_task_spec.rb @@ -1,7 +1,7 @@ # run a test task require 'spec_helper_acceptance' -describe 'mysql tasks', if: puppet_version =~ %r{(5\.\d\.\d)} && os[:family] != 'sles' do +describe 'mysql tasks', if: os[:family] != 'sles' do describe 'execute some sql' do pp = <<-MANIFEST class { 'mysql::server': root_password => 'password' } @@ -12,12 +12,13 @@ class { 'mysql::server': root_password => 'password' } MANIFEST it 'sets up a mysql instance' do - execute_manifest_on(hosts, pp, catch_failures: true) + apply_manifest(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{#{task_summary_line}}]) + result = run_bolt_task('mysql::sql', 'sql' => 'show databases;', 'password' => 'password') + expect(result.stdout).to contain(%r{information_schema}) + expect(result.stdout).to contain(%r{spec1}) end end end diff --git a/spec/acceptance/types/mysql_database_spec.rb b/spec/acceptance/types/mysql_database_spec.rb index 67f77d86a..87490a88b 100644 --- a/spec/acceptance/types/mysql_database_spec.rb +++ b/spec/acceptance/types/mysql_database_spec.rb @@ -6,7 +6,7 @@ class { 'mysql::server': } MANIFEST it 'works with no errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end end @@ -17,16 +17,12 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the database #stdout' do - shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| + run_shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| expect(r.stdout).to match(%r{^spec_db$}) - end - end - it 'finds the database #stderr' do - shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| expect(r.stderr).to be_empty end end @@ -44,27 +40,19 @@ class { 'mysql::server': } } MANIFEST it 'creates two db of different types idempotently' do - idempotent_apply(default, pp, {}) + idempotent_apply(pp) end it 'finds latin1 db #stdout' do - shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| + run_shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| expect(r.stdout).to match(%r{^character_set_database\tlatin1\ncollation_database\tlatin1_swedish_ci$}) - end - end - it 'finds latin1 db #stderr' do - shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| expect(r.stderr).to be_empty end end it 'finds utf8 db #stdout' do - shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| + run_shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| expect(r.stdout).to match(%r{^character_set_database\tutf8\ncollation_database\tutf8_general_ci$}) - end - end - it 'finds utf8 db #stderr' do - shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| expect(r.stderr).to be_empty end end diff --git a/spec/acceptance/types/mysql_grant_spec.rb b/spec/acceptance/types/mysql_grant_spec.rb index 983757b18..073f0c87d 100644 --- a/spec/acceptance/types/mysql_grant_spec.rb +++ b/spec/acceptance/types/mysql_grant_spec.rb @@ -1,6 +1,4 @@ require 'spec_helper_acceptance' -require 'puppet/util/package' -require_relative '../mysql_helper.rb' describe 'mysql_grant' do before(:all) do @@ -8,9 +6,12 @@ class { 'mysql::server': root_password => 'password', } + package {'which': + ensure => present, + } MANIFEST - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end describe 'missing privileges for user' do @@ -26,11 +27,13 @@ class { 'mysql::server': } MANIFEST it 'fails' do - expect(execute_manifest(pp, expect_failures: true).stderr).to match(%r{`privileges` `parameter` is required}) + result = apply_manifest(pp, expect_failures: true) + expect(result.stderr).to contain(%r{`privileges` `parameter` is required}) end it 'does not find the user' do - expect(shell('mysql -NBe "SHOW GRANTS FOR test1@tester"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'test1' on host 'tester'}) + result = run_shell('mysql -NBe "SHOW GRANTS FOR test1@tester"', expect_failures: true) + expect(result.stderr).to contain(%r{There is no such grant defined for user 'test1' on host 'tester'}) end end @@ -47,11 +50,12 @@ class { 'mysql::server': } MANIFEST it 'fails' do - execute_manifest(pp, expect_failures: true) + apply_manifest(pp, expect_failures: true) end it 'does not find the user' do - expect(shell('mysql -NBe "SHOW GRANTS FOR atest@tester"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'atest' on host 'tester'}) + result = run_shell('mysql -NBe "SHOW GRANTS FOR atest@tester"', expect_failures: true) + expect(result.stderr).to contain(%r{There is no such grant defined for user 'atest' on host 'tester'}) end end @@ -69,18 +73,13 @@ class { 'mysql::server': } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') do |r| - expect(r.stdout).to match(%r{GRANT SELECT, UPDATE.*TO 'test2'@'tester'}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') do |r| - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') + expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE.*TO 'test2'@'tester'}) + expect(result.stderr).to be_empty end end @@ -98,18 +97,13 @@ class { 'mysql::server': } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") do |r| - expect(r.stdout).to match(%r{GRANT SELECT, UPDATE.*TO 'test-2'@'tester'}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") do |r| - expect(r.stderr).to be_empty - end + result = run_shell("mysql -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") + expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE.*TO 'test-2'@'tester'}) + expect(result.stderr).to be_empty end end @@ -128,18 +122,13 @@ class { 'mysql::server': } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r| - expect(r.stdout).to match(%r{GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r| - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') + expect(result.stdout).to contain(%r{GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$}) + expect(result.stderr).to be_empty end end @@ -157,7 +146,8 @@ class { 'mysql::server': } MANIFEST it 'fails' do - expect(execute_manifest(pp, expect_failures: true).stderr).to match(%r{`table` `parameter` is required.}) + result = apply_manifest(pp, expect_failures: true) + expect(result.stderr).to contain(%r{`table` `parameter` is required.}) end end @@ -176,18 +166,13 @@ class { 'mysql::server': } MANIFEST it 'onlies try to apply ALL' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR test4@tester"') do |r| - expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR test4@tester"') do |r| - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test4@tester"') + expect(result.stdout).to contain(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION}) + expect(result.stderr).to be_empty end end @@ -246,60 +231,39 @@ class { 'mysql::server': } MANIFEST it 'applies' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds short hostname #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR test@short"') do |r| - expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'}) - end - end - it 'finds short hostname #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR test@short"') do |r| - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test@short"') + expect(result.stdout).to contain(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'}) + expect(result.stderr).to be_empty end it 'finds long hostname #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| + run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'long.hostname.com'}) - end - end - it 'finds long hostname #stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| expect(r.stderr).to be_empty end end it 'finds ipv4 #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| + run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.6'}) - end - end - it 'finds ipv4 #stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| expect(r.stderr).to be_empty end end it 'finds ipv6 #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| + run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'}) - end - end - it 'finds ipv6 #stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| expect(r.stderr).to be_empty end end it 'finds short ipv6 #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| + run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'::1\/128'}) - end - end - it 'finds short ipv6 @stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| expect(r.stderr).to be_empty end end @@ -383,8 +347,7 @@ class { 'mysql::server': } MANIFEST it 'setup mysql::server' do - execute_manifest(pp, catch_failures: true) - execute_manifest(pp, catch_changes: true) + idempotent_apply(pp) end end @@ -401,7 +364,7 @@ class { 'mysql::server': } MANIFEST it 'create ALL privs' do - execute_manifest(pp_one, catch_failures: true) + apply_manifest(pp_one, catch_failures: true) end pp_two = <<-MANIFEST @@ -416,7 +379,8 @@ class { 'mysql::server': } MANIFEST it 'create lowercase all privs' do - expect(execute_manifest(pp_two, catch_failures: true).exit_code).to eq(0) + result = apply_manifest(pp_two, catch_failures: true) + expect(result.exit_code).to eq(0) end end @@ -439,18 +403,13 @@ class { 'mysql::server': } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') do |r| - expect(r.stdout).to match(%r{GRANT EXECUTE ON PROCEDURE `mysql`.`simpleproc` TO 'test2'@'tester'}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') do |r| - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test2@tester"') + expect(result.stdout).to match(%r{GRANT EXECUTE ON PROCEDURE `mysql`.`simpleproc` TO 'test2'@'tester'}) + expect(result.stderr).to be_empty end end @@ -475,14 +434,13 @@ class { 'mysql::server': } EOS - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end # rubocop:enable RSpec/ExampleLength it 'finds the user' do - shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r| - expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'}) - expect(r.stderr).to be_empty - end + result = run_shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') + expect(result.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'}) + expect(result.stderr).to be_empty end # rubocop:enable RSpec/MultipleExpectations end @@ -490,7 +448,7 @@ class { 'mysql::server': describe 'proxy privilieges' do pre_run - describe 'adding proxy privileges', if: version_is_greater_than('5.5.0') do + describe 'adding proxy privileges', if: Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') do pp = <<-MANIFEST mysql_user { 'proxy1@tester': ensure => present, @@ -504,22 +462,18 @@ class { 'mysql::server': } MANIFEST it 'works without errors when version greater than 5.5.0' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| + run_shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| expect(r.stdout).to match(%r{GRANT PROXY ON 'proxy_user'@'proxy_host' TO 'proxy1'@'tester'}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| expect(r.stderr).to be_empty end end end - describe 'removing proxy privileges', if: version_is_greater_than('5.5.0') do + describe 'removing proxy privileges', if: Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') do pp = <<-MANIFEST mysql_user { 'proxy1@tester': ensure => present, @@ -533,22 +487,18 @@ class { 'mysql::server': } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the user #stdout' do - shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| + run_shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| expect(r.stdout).not_to match(%r{GRANT PROXY ON 'proxy_user'@'proxy_host' TO 'proxy1'@'tester'}) - end - end - it 'finds the user #stderr' do - shell('mysql -NBe "SHOW GRANTS FOR proxy1@tester"') do |r| expect(r.stderr).to be_empty end end end - describe 'adding proxy privileges with other privileges', if: version_is_greater_than('5.5.0') do + describe 'adding proxy privileges with other privileges', if: Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') do pp = <<-MANIFEST mysql_user { 'proxy2@tester': ensure => present, @@ -562,15 +512,17 @@ class { 'mysql::server': } MANIFEST it 'fails' do - expect(execute_manifest(pp, expect_failures: true).stderr).to match(%r{`privileges` `parameter`: PROXY can only be specified by itself}) + result = apply_manifest(pp, expect_failures: true) + expect(result.stderr).to match(%r{`privileges` `parameter`: PROXY can only be specified by itself}) end it 'does not find the user' do - expect(shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) + result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', expect_failures: true) + expect(result.stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) end end - describe 'adding proxy privileges with mysql version less than 5.5.0', unless: version_is_greater_than('5.5.0') do + describe 'adding proxy privileges with mysql version less than 5.5.0', unless: Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') do pp = <<-MANIFEST mysql_user { 'proxy3@tester': ensure => present, @@ -584,15 +536,17 @@ class { 'mysql::server': } MANIFEST it 'fails' do - expect(execute_manifest(pp, expect_failures: true).stderr).to match(%r{PROXY user not supported on mysql versions < 5\.5\.0}i) + result = apply_manifest(pp, expect_failures: true) + expect(result.stderr).to match(%r{PROXY user not supported on mysql versions < 5\.5\.0}i) end it 'does not find the user' do - expect(shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) + result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy2@tester"', expect_failures: true) + expect(result.stderr).to match(%r{There is no such grant defined for user 'proxy2' on host 'tester'}) end end - describe 'adding proxy privileges with invalid proxy user', if: version_is_greater_than('5.5.0') do + describe 'adding proxy privileges with invalid proxy user', if: Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') do pp = <<-MANIFEST mysql_user { 'proxy3@tester': ensure => present, @@ -606,11 +560,13 @@ class { 'mysql::server': } MANIFEST it 'fails' do - expect(execute_manifest(pp, expect_failures: true).stderr).to match(%r{`table` `property` for PROXY should be specified as proxy_user@proxy_host.}) + result = apply_manifest(pp, expect_failures: true) + expect(result.stderr).to match(%r{`table` `property` for PROXY should be specified as proxy_user@proxy_host.}) end it 'does not find the user' do - expect(shell('mysql -NBe "SHOW GRANTS FOR proxy3@tester"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'proxy3' on host 'tester'}) + result = run_shell('mysql -NBe "SHOW GRANTS FOR proxy3@tester"', expect_failures: true) + expect(result.stderr).to contain(%r{There is no such grant defined for user 'proxy3' on host 'tester'}) end end end @@ -625,7 +581,7 @@ class { 'mysql::server': } MANIFEST it 'setup mysql::server' do - execute_manifest(pp_one, catch_failures: true) + apply_manifest(pp_one, catch_failures: true) end pp_two = <<-MANIFEST @@ -651,23 +607,20 @@ class { 'mysql::server': } MANIFEST it 'applies' do - execute_manifest(pp_two, catch_failures: true) + apply_manifest(pp_two, catch_failures: true) end it 'fails with fqdn' do pre_run - unless version_is_greater_than('5.7.0') - expect(shell('mysql -NBe "SHOW GRANTS FOR test@fqdn.com"', acceptable_exit_codes: 1).stderr).to match(%r{There is no such grant defined for user 'test' on host 'fqdn.com'}) + unless Gem::Version.new(mysql_version) > Gem::Version.new('5.7.0') + result = run_shell('mysql -NBe "SHOW GRANTS FOR test@fqdn.com"', expect_failures: true) + expect(result.stderr).to contain(%r{There is no such grant defined for user 'test' on host 'fqdn.com'}) end end it 'finds ipv4 #stdout' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| + run_shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| expect(r.stdout).to match(%r{GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.7'}) - end - end - it 'finds ipv4 #stderr' do - shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| expect(r.stderr).to be_empty end end @@ -685,10 +638,11 @@ class { 'mysql::server': } MANIFEST it 'fails to execute while applying' do - mysql_cmd = shell('which mysql').stdout.chomp - shell("mv #{mysql_cmd} #{mysql_cmd}.bak") - expect(execute_manifest(pp_three, expect_failures: true).stderr).to match(%r{Could not find a suitable provider for mysql_grant}) - shell("mv #{mysql_cmd}.bak #{mysql_cmd}") + mysql_cmd = run_shell('which mysql').stdout.chomp + run_shell("mv #{mysql_cmd} #{mysql_cmd}.bak") + result = apply_manifest(pp_three, expect_failures: true) + expect(result.stderr).to match(%r{Could not find a suitable provider for mysql_grant}) + run_shell("mv #{mysql_cmd}.bak #{mysql_cmd}") end pp_four = <<-MANIFEST @@ -697,7 +651,7 @@ class { 'mysql::server': } MANIFEST it 'reset mysql::server config' do - execute_manifest(pp_four, catch_failures: true) + apply_manifest(pp_four, catch_failures: true) end end @@ -707,22 +661,23 @@ class { 'mysql::server': class { 'mysql::server': override_options => { 'root_password' => 'password' } } MANIFEST it 'setup mysql server' do - execute_manifest(pp_one, catch_failures: true) + apply_manifest(pp_one, catch_failures: true) end pp_two = <<-MANIFEST mysql_user { 'test@localhost': ensure => present, } - mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table': + mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table_doesnt_exist': user => 'test@localhost', privileges => ['SELECT'], - table => 'grant_spec_db.grant_spec_table', + table => 'grant_spec_db.grant_spec_table_doesnt_exist', require => Mysql_user['test@localhost'], } MANIFEST it 'creates grant on missing table will fail' do - expect(execute_manifest(pp_two, expect_failures: true).stderr).to match(%r{Table 'grant_spec_db\.grant_spec_table' doesn't exist}) + result = apply_manifest(pp_two, expect_failures: true) + expect(result.stderr).to match(%r{Table 'grant_spec_db\.grant_spec_table_doesnt_exist' doesn't exist}) end pp_three = <<-MANIFEST @@ -738,11 +693,12 @@ class { 'mysql::server': override_options => { 'root_password' => 'password' } } } MANIFEST it 'creates table' do - execute_manifest(pp_three, catch_failures: true) + apply_manifest(pp_three, catch_failures: true) end it 'has the table' do - expect(shell("mysql -e 'show tables;' grant_spec_db|grep grant_spec_table").exit_code).to be_zero + result = run_shell("mysql -e 'show tables;' grant_spec_db|grep grant_spec_table") + expect(result.exit_code).to be_zero end end end diff --git a/spec/acceptance/types/mysql_plugin_spec.rb b/spec/acceptance/types/mysql_plugin_spec.rb index 2fab7df4c..d4766ec76 100644 --- a/spec/acceptance/types/mysql_plugin_spec.rb +++ b/spec/acceptance/types/mysql_plugin_spec.rb @@ -4,7 +4,7 @@ # of mysql) have varying levels of support for plugins and have # different plugins available. Choose a plugin that works or don't try # to test plugins if not available. -if fact('osfamily') == 'redhat' +if os[:family] == 'redhat' if os[:release].to_i == 5 plugin = nil # Plugins not supported on mysql on RHEL 5 elsif os[:release].to_i == 6 @@ -14,7 +14,7 @@ plugin = 'pam' plugin_lib = 'auth_pam.so' end -elsif fact('osfamily') == 'debian' +elsif os[:family] == 'debian' if os[:family] == 'ubuntu' if os[:release] =~ %r{^16\.04|^18\.04} # On Xenial running 5.7.12, the example plugin does not appear to be available. @@ -25,7 +25,7 @@ plugin_lib = 'ha_example.so' end end -elsif fact('osfamily') == 'suse' +elsif os[:family] == 'suse' plugin = nil # Plugin library path is broken on Suse http://lists.opensuse.org/opensuse-bugs/2013-08/msg01123.html end @@ -37,7 +37,7 @@ class { 'mysql::server': } MANIFEST - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end end @@ -49,16 +49,12 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_failures: true) end it 'finds the plugin #stdout' do - shell("mysql -NBe \"select plugin_name from information_schema.plugins where plugin_name='#{plugin}'\"") do |r| + run_shell("mysql -NBe \"select plugin_name from information_schema.plugins where plugin_name='#{plugin}'\"") do |r| expect(r.stdout).to match(%r{^#{plugin}$}i) - end - end - it 'finds the plugin #stderr' do - shell("mysql -NBe \"select plugin_name from information_schema.plugins where plugin_name='#{plugin}'\"") do |r| expect(r.stderr).to be_empty end end diff --git a/spec/acceptance/types/mysql_user_spec.rb b/spec/acceptance/types/mysql_user_spec.rb index ed941b8d5..cd87332d7 100644 --- a/spec/acceptance/types/mysql_user_spec.rb +++ b/spec/acceptance/types/mysql_user_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper_acceptance' -require_relative '../mysql_helper.rb' describe 'mysql_user' do describe 'setup' do @@ -7,7 +6,7 @@ class { 'mysql::server': } MANIFEST it 'works with no errors' do - execute_manifest(pp_one, catch_failures: true) + apply_manifest(pp_one, catch_failures: true) end end @@ -19,34 +18,25 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp_two, catch_failures: true) + apply_manifest(pp_two, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stderr).to be_empty end end it 'has no SSL options #stdout' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^\s*$}) - end - end - it 'has no SSL options #stderr' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stderr).to be_empty end end end - pre_run - describe 'changing authentication plugin', if: version_is_greater_than('5.5.0') do + describe 'changing authentication plugin', if: (Gem::Version.new(mysql_version) > Gem::Version.new('5.5.0') && os[:release] !~ %r{^16\.04}) do it 'works without errors' do pp = <<-EOS mysql_user { 'ashp@localhost': @@ -54,11 +44,11 @@ class { 'mysql::server': } } EOS - execute_manifest(pp, catch_failures: true) + idempotent_apply(pp) end it 'has the correct plugin' do - shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("mysql -NBe \"select plugin from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to eq('auth_socket') expect(r.stderr).to be_empty end @@ -66,12 +56,12 @@ class { 'mysql::server': } it 'does not have a password' do pre_run - table = if version_is_greater_than('5.7.0') + table = if Gem::Version.new(mysql_version) > Gem::Version.new('5.7.0') 'authentication_string' else 'password' end - shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("mysql -NBe \"select #{table} from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout.rstrip).to be_empty expect(r.stderr).to be_empty end @@ -88,40 +78,12 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp_three, catch_failures: true) - end - - it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| - expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| - expect(r.stderr).to be_empty - end - end - end - end - - context 'using foo@bar@localhost' do - describe 'adding user' do - pp_three = <<-MANIFEST - mysql_user { 'foo@bar@localhost': - password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', - } - MANIFEST - it 'works without errors' do - execute_manifest(pp_three, catch_failures: true) + apply_manifest(pp_three, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'foo@bar@localhost'\"") do |r| + run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'foo@bar@localhost'\"") do |r| expect(r.stderr).to be_empty end end @@ -136,16 +98,12 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp_four, catch_failures: true) + apply_manifest(pp_four, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stderr).to be_empty end end @@ -154,14 +112,9 @@ class { 'mysql::server': } context 'using resource should throw no errors' do describe 'find users' do it do - on default, puppet('resource mysql_user'), catch_failures: true do |r| - expect(r.stdout).not_to match(%r{Error:}) - end - end - it do - on default, puppet('resource mysql_user'), catch_failures: true do |r| - expect(r.stdout).not_to match(%r{must be properly quoted, invalid character:}) - end + result = run_shell('puppet resource mysql_user') + expect(result.stdout).not_to match(%r{Error:}) + expect(result.stdout).not_to match(%r{must be properly quoted, invalid character:}) end end end @@ -174,27 +127,19 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp_five, catch_failures: true) + apply_manifest(pp_five, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| + run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stderr).to be_empty end end it 'shows correct ssl_type #stdout' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| + run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(%r{^ANY$}) - end - end - it 'shows correct ssl_type #stderr' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stderr).to be_empty end end @@ -209,27 +154,19 @@ class { 'mysql::server': } } MANIFEST it 'works without errors' do - execute_manifest(pp_six, catch_failures: true) + apply_manifest(pp_six, catch_failures: true) end it 'finds the user #stdout' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| + run_shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(%r{^1$}) - end - end - it 'finds the user #stderr' do - shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stderr).to be_empty end end it 'shows correct ssl_type #stdout' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| + run_shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(%r{^X509$}) - end - end - it 'shows correct ssl_type #stderr' do - shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stderr).to be_empty end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 97b85bc9b..745d46e1b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,46 +1,59 @@ -require 'beaker-pe' -require 'beaker-puppet' -require 'puppet' -require 'beaker-rspec' -require 'beaker/puppet_install_helper' -require 'beaker/module_install_helper' -require 'beaker/i18n_helper' -require 'beaker-task_helper' -require 'beaker/testmode_switcher' -require 'beaker/testmode_switcher/dsl' +# frozen_string_literal: true -run_puppet_install_helper -configure_type_defaults_on(hosts) -install_ca_certs unless pe_install? -install_bolt_on(hosts) unless pe_install? -install_module_on(hosts) -install_module_dependencies_on(hosts) +require 'serverspec' +require 'puppet_litmus' +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) +include PuppetLitmus -def idempotent_apply(hosts, manifest, opts = {}, &block) - block_on hosts, opts do |host| - file_path = host.tmpfile('apply_manifest.pp') - create_remote_file(host, file_path, manifest + "\n") - - puppet_apply_opts = { :verbose => nil, 'detailed-exitcodes' => nil } - on_options = { acceptable_exit_codes: [0, 2] } - on host, puppet('apply', file_path, puppet_apply_opts), on_options, &block - puppet_apply_opts2 = { :verbose => nil, 'detailed-exitcodes' => nil } - on_options2 = { acceptable_exit_codes: [0] } - on host, puppet('apply', file_path, puppet_apply_opts2), on_options2, &block +if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' + puts 'Running tests against this machine !' + if Gem.win_platform? + set :backend, :cmd + else + set :backend, :exec end -end +else + # load inventory + inventory_hash = inventory_hash_from_inventory_file + node_config = config_from_node(inventory_hash, ENV['TARGET_HOST']) -RSpec.configure do |c| - # Readable test descriptions - c.formatter = :documentation -end + if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes') + host = ENV['TARGET_HOST'] + set :backend, :docker + set :docker_container, host + elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes') + set :backend, :ssh + options = Net::SSH::Config.for(host) + options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil? + options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil? + options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? + options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? + options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil? + host = if ENV['TARGET_HOST'].include?(':') + ENV['TARGET_HOST'].split(':').first + else + ENV['TARGET_HOST'] + end + set :host, options[:host_name] || host + set :ssh_options, options + set :request_pty, true + elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes') + require 'winrm' -shared_examples 'a idempotent resource' do - it 'applies with no errors' do - execute_manifest(pp, catch_failures: true) - end + set :backend, :winrm + set :os, family: 'windows' + user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? + pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? + endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" + + opts = { + user: user, + password: pass, + endpoint: endpoint, + operation_timeout: 300, + } - it 'applies a second time without changes', :skip_pup_5016 do - execute_manifest(pp, catch_changes: true) + winrm = WinRM::Connection.new opts + Specinfra.configuration.winrm = winrm end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb new file mode 100644 index 000000000..562140db5 --- /dev/null +++ b/spec/spec_helper_acceptance_local.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +def pre_run + apply_manifest("class { 'mysql::server': root_password => 'password' }", catch_failures: true) +end + +def mysql_version + shell_output = run_shell('mysql --version', expect_failures: true) + if shell_output.stdout.match(%r{\d+\.\d+\.\d+}).nil? + pre_run + shell_output = run_shell('mysql --version') + raise _('unable to get mysql version') if shell_output.stdout.match(%r{\d+\.\d+\.\d+}).nil? + end + mysql_version = shell_output.stdout.match(%r{\d+\.\d+\.\d+})[0] + mysql_version +end