From cb721e379c47cbf3f5c1d40b7244896e26ec9ff5 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Thu, 8 Oct 2015 14:12:18 -0700 Subject: [PATCH] Drop fixtures usage * install r10k gem * add openstack/ to .gitignore * Update Rakefile to not use fixtures anymore See https://review.openstack.org/#/c/226830/ for background. Change-Id: I4513491b4f53c74acd433c0045c5f3c956bc06ce --- config_defaults.yml | 1 + moduleroot/.gitignore | 1 + moduleroot/Rakefile | 64 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/config_defaults.yml b/config_defaults.yml index 749ee61..55c9b63 100644 --- a/config_defaults.yml +++ b/config_defaults.yml @@ -19,6 +19,7 @@ Gemfile: ':system_tests': - gem: beaker-rspec - gem: beaker-puppet_install_helper + - gem: r10k Rakefile: default_disabled_lint_checks: - '80chars' diff --git a/moduleroot/.gitignore b/moduleroot/.gitignore index d9f2fb2..2da77ae 100644 --- a/moduleroot/.gitignore +++ b/moduleroot/.gitignore @@ -8,6 +8,7 @@ coverage/ .idea/ *.swp *.iml +openstack/ <% if ! @configs['paths'].nil? -%> <% @configs['paths'].each do |path| -%> <%= path %> diff --git a/moduleroot/Rakefile b/moduleroot/Rakefile index c257964..04c5ab3 100644 --- a/moduleroot/Rakefile +++ b/moduleroot/Rakefile @@ -1,6 +1,9 @@ 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/**/*" @@ -19,3 +22,64 @@ 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