summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 9e5db405a2bc9895aa08d5a57eefee1dfbd620e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet-catalog-test'

# return list of modules, either
# submodules, custom or all modules
# so we can check each array seperately
def modules_pattern (type)
  submodules = Array.new
  custom_modules = Array.new
  all_modules = Array.new

  Dir['puppet/modules/*'].sort.each do |m|
    system("grep -q #{m} .gitmodules")
    if $?.exitstatus == 0
      submodules << m + '/**/*.pp'
    else
      custom_modules << m + '/**/*.pp'
    end
    all_modules << m + '/**/*.pp'
  end

  case type
    when 'submodule'
      submodules
    when 'custom'
      custom_modules
    when 'all'
      all_modules
  end
end

exclude_paths = ["**/vendor/**/*", "spec/fixtures/**/*", "pkg/**/*" ]

# redefine lint task so we don't lint submoudules for now
Rake::Task[:lint].clear
PuppetLint::RakeTask.new :lint do |config|
  # only check for custom manifests, not submodules for now
  config.pattern          = modules_pattern('custom')
  config.ignore_paths     = exclude_paths
  config.disable_checks   = ['documentation', '80chars']
  config.fail_on_warnings = false
end

# rake syntax::* tasks
PuppetSyntax.exclude_paths = exclude_paths
PuppetSyntax.future_parser = true

desc "Validate erb templates"
task :templates do
  Dir['**/templates/**/*.erb'].each do |template|
    sh "erb -P -x -T '-' #{template} | ruby -c" unless template =~ /.*vendor.*/
  end
end

desc "Compile hiera config for test_provider"
task :test_provider_compile do
  sh "cd tests/puppet/provider; bundle exec leap compile"
end

namespace :catalog do
  PuppetCatalogTest::RakeTask.new(:all) do |t|
    Rake::Task["test_provider_compile"].invoke
    t.module_paths = ["puppet/modules"]
    t.manifest_path = File.join("puppet","manifests", "site.pp")
    t.facts = {
      "operatingsystem"           => "Debian",
      "osfamily"                  => "Debian",
      "operatingsystemmajrelease" => "8",
      "debian_release"            => "stable",
      "debian_codename"           => "jessie",
      "lsbdistcodename"           => "jessie",
      "concat_basedir"            => "/var/lib/puppet/concat",
      "interfaces"                => "eth0"
    }

    # crucial option for hiera integration
    t.config_dir = File.join("tests/puppet") # expects hiera.yaml to be included in directory

    # t.parser = "future"
    t.verbose = true
  end
end

desc "Run all puppet checks required for CI (syntax , validate, spec, lint)"
task :test => [:syntax , :validate, :templates, :spec, :lint]