From 1140ae26e3e713f4f7a9bb7677d74e9e3e772190 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 18 Jan 2016 09:11:27 -0500 Subject: [PATCH] Use puppet-openstack_spec_helper for Rakefile & spec_helper_acceptance Use common code in puppet-openstack_spec_helper in Rakefile and spec_helper_acceptance. Change-Id: Id95e433ef563cb2bc15e9cd2a0af85a0a2776a26 --- Rakefile | 86 +--------------------------------- spec/spec_helper_acceptance.rb | 57 +--------------------- 2 files changed, 2 insertions(+), 141 deletions(-) diff --git a/Rakefile b/Rakefile index ed79bead4..168d10814 100644 --- a/Rakefile +++ b/Rakefile @@ -1,85 +1 @@ -require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint/tasks/puppet-lint' -require 'puppet-syntax/tasks/puppet-syntax' -require 'json' - -modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1] - -PuppetSyntax.exclude_paths ||= [] -PuppetSyntax.exclude_paths << "spec/fixtures/**/*" -PuppetSyntax.exclude_paths << "pkg/**/*" -PuppetSyntax.exclude_paths << "vendor/**/*" - -Rake::Task[:lint].clear -PuppetLint::RakeTask.new :lint do |config| - config.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"] - config.fail_on_warnings = true - config.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}' - config.disable_checks = ["80chars", "class_inherits_from_params_class", "only_variable_string"] -end - -desc "Run acceptance tests" -RSpec::Core::RakeTask.new(:acceptance) do |t| - t.pattern = 'spec/acceptance' -end - -Rake::Task[:spec_prep].clear -desc 'Create the fixtures directory' -task :spec_prep do - # Allow to test the module with custom dependencies - # like you could do with .fixtures file - if ENV['PUPPETFILE'] - puppetfile = ENV['PUPPETFILE'] - if ENV['GEM_HOME'] - gem_home = ENV['GEM_HOME'] - gem_bin_dir = "#{gem_home}" + '/bin/' - else - gem_bin_dir = '' - end - r10k = ['env'] - r10k += ["PUPPETFILE=#{puppetfile}"] - r10k += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"] - r10k += ["#{gem_bin_dir}r10k"] - r10k += ['puppetfile', 'install', '-v'] - sh(*r10k) - else - # otherwise, use official OpenStack Puppetfile - zuul_ref = ENV['ZUUL_REF'] - zuul_branch = ENV['ZUUL_BRANCH'] - zuul_url = ENV['ZUUL_URL'] - repo = 'openstack/puppet-openstack-integration' - rm_rf(repo) - if File.exists?('/usr/zuul-env/bin/zuul-cloner') - zuul_clone_cmd = ['/usr/zuul-env/bin/zuul-cloner'] - zuul_clone_cmd += ['--cache-dir', '/opt/git'] - zuul_clone_cmd += ['--zuul-ref', "#{zuul_ref}"] - zuul_clone_cmd += ['--zuul-branch', "#{zuul_branch}"] - zuul_clone_cmd += ['--zuul-url', "#{zuul_url}"] - zuul_clone_cmd += ['git://git.openstack.org', "#{repo}"] - sh(*zuul_clone_cmd) - else - sh("git clone https://git.openstack.org/#{repo} #{repo}") - end - script = ['env'] - script += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"] - script += ["ZUUL_REF=#{zuul_ref}"] - script += ["ZUUL_BRANCH=#{zuul_branch}"] - script += ["ZUUL_URL=#{zuul_url}"] - script += ['bash', "#{repo}/install_modules_unit.sh"] - sh(*script) - end - rm_rf("spec/fixtures/modules/#{modname}") - ln_s(Dir.pwd, "spec/fixtures/modules/#{modname}") - mkdir_p('spec/fixtures/manifests') - touch('spec/fixtures/manifests/site.pp') -end - -Rake::Task[:spec_clean].clear -desc 'Clean up the fixtures directory' -task :spec_clean do - rm_rf('spec/fixtures/modules') - rm_rf('openstack') - if File.zero?('spec/fixtures/manifests/site.pp') - rm_f('spec/fixtures/manifests/site.pp') - end -end +require 'puppet-openstack_spec_helper/rake_tasks' diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 429e807c4..9196bc99b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,56 +1 @@ -require 'beaker-rspec' -require 'beaker/puppet_install_helper' - -run_puppet_install_helper - -RSpec.configure do |c| - # Project root - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1] - - # Readable test descriptions - c.formatter = :documentation - - # Configure all nodes in nodeset - c.before :suite do - # Install module and dependencies - hosts.each do |host| - - # install git - install_package host, 'git' - - zuul_ref = ENV['ZUUL_REF'] - zuul_branch = ENV['ZUUL_BRANCH'] - zuul_url = ENV['ZUUL_URL'] - - repo = 'openstack/puppet-openstack-integration' - - # Start out with clean moduledir, don't trust r10k to purge it - on host, "rm -rf /etc/puppet/modules/*" - # Install dependent modules via git or zuul - r = on host, "test -e /usr/zuul-env/bin/zuul-cloner", { :acceptable_exit_codes => [0,1] } - if r.exit_code == 0 - zuul_clone_cmd = '/usr/zuul-env/bin/zuul-cloner ' - zuul_clone_cmd += '--cache-dir /opt/git ' - zuul_clone_cmd += "--zuul-ref #{zuul_ref} " - zuul_clone_cmd += "--zuul-branch #{zuul_branch} " - zuul_clone_cmd += "--zuul-url #{zuul_url} " - zuul_clone_cmd += "git://git.openstack.org #{repo}" - on host, zuul_clone_cmd - else - on host, "git clone https://git.openstack.org/#{repo} #{repo}" - end - - on host, "ZUUL_REF=#{zuul_ref} ZUUL_BRANCH=#{zuul_branch} ZUUL_URL=#{zuul_url} bash #{repo}/install_modules.sh" - - # Install the module being tested - on host, "rm -fr /etc/puppet/modules/#{modname}" - puppet_module_install(:source => proj_root, :module_name => modname) - - on host, "rm -fr #{repo}" - - # List modules installed to help with debugging - on host, puppet('module','list'), { :acceptable_exit_codes => 0 } - end - end -end +require 'puppet-openstack_spec_helper/beaker_spec_helper'