diff --git a/acceptance/config/el6/Rakefile b/acceptance/config/el6/Rakefile index 0e1f68ae6..4f82325f8 100644 --- a/acceptance/config/el6/Rakefile +++ b/acceptance/config/el6/Rakefile @@ -1,39 +1,99 @@ require 'rake/clean' +require 'pp' REPO_CONFIGS_DIR = "repo-configs" -CLEAN.include('*.tar', REPO_CONFIGS_DIR) +CLEAN.include('*.tar', REPO_CONFIGS_DIR, 'preserved_config.yaml') namespace :ci do - desc "Run the acceptance tests through the Jenkins CI system. (Requires commit SHA to be put under test as environment variable: SHA='')" - task :test do - ENV['OPTIONS'] = (ENV['OPTIONS'] || "") + " --xml" + def test(option_hash = {}) + passed_options = option_hash[:options] || '' ENV['TESTING_MODE'] = 'jenkins' - sh "beaker -o config/options.rb #{ENV['OPTIONS'] || ''} -t #{ENV['TEST'] || '../../tests'}" + options = (ENV['OPTIONS'] || '') + " --xml " + options << passed_options + tests = ENV['TEST'] || option_hash[:test] || '../../tests' + begin + sh "beaker -o config/options.rb #{options} -t #{tests}" + rescue RuntimeError => e + puts "Beaker Failed: #{e}" + end + end + + task :_test do + test + end + + task :_test_and_preserve do + test(:options => '--preserve-hosts') + end + + desc "Run the acceptance tests through the Jenkins CI system. (Requires commit SHA to be put under test as environment variable: SHA='')" + task :test => 'ci:_test' + + desc "Capture the master and agent hostname from the latest log and construct a preserved_config.yaml for re-running against preserved hosts without provisioning." + task :extract_preserved_config do + nodes = { :master => {}, :agent => {} } + File.open('log/latest/config.yml', 'r') do |file| + config = file.read + config =~ /master:.*?platform: ([\w-]+)\s*$/m + nodes[:master][:platform] = $1 + config =~ /agent:.*?platform: ([\w-]+)\s*$/m + nodes[:agent][:platform] = $1 + end + File.open('log/latest/pre-suite-run.log', 'r') do |log_file| + while nodes.values.detect { |h| h[:hostname].nil? } + if log_file.readline =~ /^(\w+) \((master|agent)\)/ + nodes[$2.to_sym][:hostname] = $1 + end + end + end + pp nodes + File.open('preserved_config.yaml', 'w') do |config_file| + config_file.puts <<-EOF +HOSTS: + #{nodes[:master][:hostname]}.delivery.puppetlabs.net: + roles: + - master + - agent + platform: #{nodes[:master][:platform]} + #{nodes[:agent][:hostname]}.delivery.puppetlabs.net: + roles: + - agent + platform: #{nodes[:agent][:platform]} + EOF + end + end + + desc "Run an acceptance test for a given node configuration and preserve the hosts. Writes a local preserved_config.yaml with the hostnames so that we can rerun." + task :test_and_preserve_hosts => ['ci:_test_and_preserve', 'ci:extract_preserved_config'] + + desc "Rerun an acceptance test using the last captured preserved_config.yaml to skip provisioning. Uses the setup/rsync/pre-suite to rsync the local puppet source onto master and agent." + task :test_against_preserved_hosts do + test(:options => '--config=preserved_config.yaml --no-provision --preserve-hosts --pre-suite=setup/rsync/pre-suite') end end namespace :standalone do desc "Bring up the vagrant environment. Includes pre-puppet environment packages installation and cross node networking support (/etc/hosts munging)" task :up do sh "vagrant up" end desc "Completely destroy the vagrant instances." task :clean do sh "vagrant destroy -f" end task :ensure_good_private_key do sh "chmod 600 acceptance.priv" end desc "Bring up vagrant boxes and run the tests through the puppet-acceptance beaker harness. Specify TEST='../../tests/foo' to customize which tests are to be run, and/or OPTIONS='bar' to pass options to beaker." task :test => [:up, :ensure_good_private_key] do ENV['TESTING_MODE'] = 'local' sh "beaker -o config/options.rb #{ENV['OPTIONS'] || ''} -t #{ENV['TEST'] || '../../tests'}" end end task :default do sh('rake -T') end diff --git a/acceptance/config/el6/setup/rsync/pre-suite/00_PurgeAndReinstall.rb b/acceptance/config/el6/setup/rsync/pre-suite/00_PurgeAndReinstall.rb new file mode 100644 index 000000000..489f234c2 --- /dev/null +++ b/acceptance/config/el6/setup/rsync/pre-suite/00_PurgeAndReinstall.rb @@ -0,0 +1,8 @@ +test_name "Purge and Reinstall Packages" do + hosts.each do |host| + host.uninstall_package('puppet') + host.uninstall_package('puppet-common') + additional_switches = '--allow-unauthenticated' if host['platform'] =~ /debian|ubuntu/ + host.install_package('puppet', additional_switches) + end +end diff --git a/acceptance/config/el6/setup/rsync/pre-suite/01_RsyncSource.rb b/acceptance/config/el6/setup/rsync/pre-suite/01_RsyncSource.rb new file mode 100644 index 000000000..62ffd927e --- /dev/null +++ b/acceptance/config/el6/setup/rsync/pre-suite/01_RsyncSource.rb @@ -0,0 +1,19 @@ +test_name "Rsync Source" do + + hosts.each do |host| + step "rsyncing local puppet source to #{host}" do + filter_opt = "--filter='merge #{ENV['RSYNC_FILTER_FILE']}'" if ENV['RSYNC_FILTER_FILE'] + destination_dir = case host['platform'] + when /debian|ubuntu/ + then '/usr/lib/ruby/vendor_ruby' + else + raise "We should actually do some #{host['platform']} platform specific rsyncing here..." + end + cmd = "rsync -r --exclude '.*.swp' #{filter_opt} --size-only -i -e'ssh -i id_rsa-acceptance' ../../../lib/* root@#{host}:#{destination_dir}" + puts "RSYNC: #{cmd}" + result = `#{cmd}` + raise("Failed rsync execution:\n#{result}") if $? != 0 + puts result + end + end +end