|
1 | | -require 'rubygems' |
2 | 1 | require 'puppetlabs_spec_helper/rake_tasks' |
3 | 2 | require 'puppet-lint/tasks/puppet-lint' |
| 3 | +require 'puppet-syntax/tasks/puppet-syntax' |
| 4 | +require 'json' |
4 | 5 |
|
5 | | -PuppetLint.configuration.fail_on_warnings = true |
6 | | -PuppetLint.configuration.send('disable_80chars') |
7 | | -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] |
| 6 | +modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1] |
| 7 | + |
| 8 | +PuppetSyntax.exclude_paths ||= [] |
| 9 | +PuppetSyntax.exclude_paths << "spec/fixtures/**/*" |
| 10 | +PuppetSyntax.exclude_paths << "pkg/**/*" |
| 11 | +PuppetSyntax.exclude_paths << "vendor/**/*" |
| 12 | + |
| 13 | +Rake::Task[:lint].clear |
| 14 | +PuppetLint::RakeTask.new :lint do |config| |
| 15 | + config.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"] |
| 16 | + config.fail_on_warnings = true |
| 17 | + config.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}' |
| 18 | + config.disable_checks = ["80chars", "class_inherits_from_params_class", "only_variable_string"] |
| 19 | +end |
| 20 | + |
| 21 | +desc "Run acceptance tests" |
| 22 | +RSpec::Core::RakeTask.new(:acceptance) do |t| |
| 23 | + t.pattern = 'spec/acceptance' |
| 24 | +end |
| 25 | + |
| 26 | +Rake::Task[:spec_prep].clear |
| 27 | +desc 'Create the fixtures directory' |
| 28 | +task :spec_prep do |
| 29 | + # Allow to test the module with custom dependencies |
| 30 | + # like you could do with .fixtures file |
| 31 | + if ENV['PUPPETFILE'] |
| 32 | + puppetfile = ENV['PUPPETFILE'] |
| 33 | + if ENV['GEM_HOME'] |
| 34 | + gem_home = ENV['GEM_HOME'] |
| 35 | + gem_bin_dir = "#{gem_home}" + '/bin/' |
| 36 | + else |
| 37 | + gem_bin_dir = '' |
| 38 | + end |
| 39 | + r10k = ['env'] |
| 40 | + r10k += ["PUPPETFILE=#{puppetfile}"] |
| 41 | + r10k += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"] |
| 42 | + r10k += ["#{gem_bin_dir}r10k"] |
| 43 | + r10k += ['puppetfile', 'install', '-v'] |
| 44 | + sh(*r10k) |
| 45 | + else |
| 46 | + # otherwise, use official OpenStack Puppetfile |
| 47 | + zuul_ref = ENV['ZUUL_REF'] |
| 48 | + zuul_branch = ENV['ZUUL_BRANCH'] |
| 49 | + zuul_url = ENV['ZUUL_URL'] |
| 50 | + repo = 'openstack/puppet-openstack-integration' |
| 51 | + rm_rf(repo) |
| 52 | + if File.exists?('/usr/zuul-env/bin/zuul-cloner') |
| 53 | + zuul_clone_cmd = ['/usr/zuul-env/bin/zuul-cloner'] |
| 54 | + zuul_clone_cmd += ['--cache-dir', '/opt/git'] |
| 55 | + zuul_clone_cmd += ['--zuul-ref', "#{zuul_ref}"] |
| 56 | + zuul_clone_cmd += ['--zuul-branch', "#{zuul_branch}"] |
| 57 | + zuul_clone_cmd += ['--zuul-url', "#{zuul_url}"] |
| 58 | + zuul_clone_cmd += ['git://git.openstack.org', "#{repo}"] |
| 59 | + sh(*zuul_clone_cmd) |
| 60 | + else |
| 61 | + sh("git clone https://git.openstack.org/#{repo} -b stable/liberty #{repo}") |
| 62 | + end |
| 63 | + script = ['env'] |
| 64 | + script += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"] |
| 65 | + script += ["ZUUL_REF=#{zuul_ref}"] |
| 66 | + script += ["ZUUL_BRANCH=#{zuul_branch}"] |
| 67 | + script += ["ZUUL_URL=#{zuul_url}"] |
| 68 | + script += ['bash', "#{repo}/install_modules_unit.sh"] |
| 69 | + sh(*script) |
| 70 | + end |
| 71 | + rm_rf("spec/fixtures/modules/#{modname}") |
| 72 | + ln_s(Dir.pwd, "spec/fixtures/modules/#{modname}") |
| 73 | + mkdir_p('spec/fixtures/manifests') |
| 74 | + touch('spec/fixtures/manifests/site.pp') |
| 75 | +end |
| 76 | + |
| 77 | +Rake::Task[:spec_clean].clear |
| 78 | +desc 'Clean up the fixtures directory' |
| 79 | +task :spec_clean do |
| 80 | + rm_rf('spec/fixtures/modules') |
| 81 | + rm_rf('openstack') |
| 82 | + if File.zero?('spec/fixtures/manifests/site.pp') |
| 83 | + rm_f('spec/fixtures/manifests/site.pp') |
| 84 | + end |
| 85 | +end |
0 commit comments