Rakefile 6.02 KB
Newer Older
1
2
3
4
5
if ENV['COV']
  require 'simplecov'
  SimpleCov.start
end

6
7
8
9
10
if RUBY_VERSION < "2.1"
  puts "This script requires ruby >= 2.1"
  exit
end

11
12
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'refrepo'
13

Lucas Nussbaum's avatar
Lucas Nussbaum committed
14
15
16
17
18
19
if Dir::exists?(ENV['HOME'] + '/.gpuppet/repo')
  PUPPET_ODIR = ENV['HOME'] + '/.gpuppet/repo'
else
  PUPPET_ODIR = '/tmp/puppet'
end

20
G5K_SITES = RefRepo::Utils::get_sites
21

22
namespace :valid do
23

24
  desc "Check homogeneity of clusters -- parameters: SITE={grenoble,..} CLUSTER={yeti,..} VERBOSE=1"
25
  task "homogeneity" do
26
27
    require 'refrepo/valid/homogeneity'
    options = {}
28
29
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
    options[:clusters] = ( ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [] )
30
31
32
33
    options[:verbose] = ENV['VERBOSE'].to_i if ENV['VERBOSE']

    ret = check_cluster_homogeneity(options)
    exit(ret)
34
35
  end

36
37
38
39
40
41
42
43
44
45
46
  desc "Check for duplicates fields in input -- parameters: SITE={grenoble..} CLUSTER={yeti,...} VERBOSE=1"
  task "duplicates" do
    require 'refrepo/valid/input/duplicates'
    options = {}
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
    options[:clusters] = ( ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [] )
    options[:verbose] = ENV['VERBOSE'].to_i if ENV['VERBOSE']
    ret = yaml_input_find_duplicates(options)
    exit(ret)
  end

Lucas Nussbaum's avatar
Lucas Nussbaum committed
47
  desc "Check input data schema validity -- parameters: SITE={grenoble,..} CLUSTER={yeti,..}"
48
  task "schema" do
Lucas Nussbaum's avatar
Lucas Nussbaum committed
49
50
51
52
53
54
    require 'refrepo/valid/input/schema'
    options = {}
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
    options[:clusters] = ( ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [] )
    ret = yaml_input_schema_validator(options)
    exit(ret)
55
  end
56

57
  desc "Check OAR properties -- parameters: [SITE={grenoble,...}] [CLUSTER={yeti,...}] [VERBOSE=1]"
58
  task "oar-properties" do
59
    require 'refrepo/valid/oar-properties'
60
    options = {}
61
62
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
    options[:clusters] = ( ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [] )
63
64
65
66
67
    options[:verbose] = true if ENV['VERBOSE']
    ret = RefRepo::Valid::OarProperties::check(options)
    exit(ret)
  end

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  desc "Check network description -- parameters: [SITE={grenoble,...}] [VERBOSE=1] GENERATE_DOT=1"
  task "network" do
    require 'refrepo/valid/network'
    options = {}
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
    options[:verbose] = true if ENV['VERBOSE']
    options[:dot] = true if ENV['GENERATE_DOT']
    ret = 2
    begin
      ret = check_network_description(options)
    rescue StandardError => e
      puts e
      ret = 3
    ensure
      exit(ret)
    end
  end
85
86
end

87
namespace :gen do
88
  desc "Run wiki generator -- parameters: NAME={hardware,site_hardware,...} SITE={global,grenoble,...} DO={diff,print,update}"
89
  task "wiki" do
90
    require 'refrepo/gen/wiki'
91
    options = {}
92
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : ['global'] + G5K_SITES )
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    if ENV['NAME']
      options[:generators] = ENV['NAME'].split(',')
    else
      puts "You must specify a generator name using NAME="
      exit(1)
    end
    options[:diff] = false
    options[:print] = false
    options[:update] = false
    if ENV['DO']
      ENV['DO'].split(',').each do |t|
        options[:diff] = true if t == 'diff'
        options[:print] = true if t == 'print'
        options[:update] = true if t == 'update'
      end
    else
      puts "You must specify something to do using DO="
      exit(1)
    end
112
113
    ret = RefRepo::Gen::Wiki::wikigen(options)
    exit(ret)
114
  end
115
116
117
118
119

  desc "Generate OAR properties -- parameters: SITE={grenoble,...} CLUSTER={yeti,...} NODE={dahu-1,...} DO={print,exec,diff,check} VERBOSE={0,1,2,3}"
  task "oar-properties" do
    require 'refrepo/gen/oar-properties'
    options = {}
120
    options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    if ENV['CLUSTER']
      options[:clusters] = ENV['CLUSTER'].split(',')
    end
    if ENV['NODE']
      options[:nodes] = ENV['NODE'].split(',')
    end
    options[:output] = false
    options[:diff] = false
    options[:exec] = false
    options[:check] = false
    if ENV['DO']
      ENV['DO'].split(',').each do |t|
        options[:diff] = true if t == 'diff'
        options[:output] = true if t == 'output'
        options[:exec] = true if t == 'update'
        if t == 'check'
          options[:diff] = true # check requires diff
          options[:check] = true
        end
      end
    else
      puts "You must specify something to do using DO="
      exit(1)
    end

    if ENV['VERBOSE']
      options[:verbose] = ENV['VERBOSE'].to_i
    else
      options[:verbose] = 0
    end

    ret = generate_oar_properties(options)
    exit(ret)
  end

156
157
158
159
160
namespace :puppet do

  all_puppet_tasks = [:bindg5k, :conmang5k, :dhcpg5k, :kadeployg5k, :lanpowerg5k, :kavlang5k]

  all_puppet_tasks.each { |t|
Lucas Nussbaum's avatar
Lucas Nussbaum committed
161
    desc "Generate #{t} configuration -- parameters: SITE={grenoble,...} OUTPUTDIR=[default: #{PUPPET_ODIR}] [CONFDIR=...] VERBOSE=1"
162
    task t do
Lucas Nussbaum's avatar
Lucas Nussbaum committed
163
164
165
166
167
168
169
170
      require "refrepo/gen/puppet/#{t}"
      options = {}
      options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
      options[:output_dir] = ENV['OUTPUTDIR'] || PUPPET_ODIR
      options[:verbose] = (ENV['VERBOSE'] != nil)
      options[:conf_dir] = ENV['CONFDIR'] if ENV['CONFDIR']
      send("generate_puppet_#{t}", options)

171
172
173
174
175
176
177
178
179
    end
  }

  desc "Launch all puppet generators"
  task :all => all_puppet_tasks

end


180
181
end

Lucas Nussbaum's avatar
Lucas Nussbaum committed
182
desc "Creates JSON data from inputs"
183
task "reference-api" do
Lucas Nussbaum's avatar
Lucas Nussbaum committed
184
185
  require 'refrepo/gen/reference-api'
  generate_reference_api
186
187
end

188
189
190
191
192
193
194
195
196
197
#Hack rake: call only the first task and consider the rest as arguments to this task
currentTask = Rake.application.top_level_tasks.first
taskNames = Rake.application.tasks().map { |task| task.name() }
if (taskNames.include?(currentTask))
  Rake.application.instance_variable_set(:@top_level_tasks, [currentTask])
  ARGV.shift(ARGV.index(currentTask) + 1)
  $CMD_ARGS = ARGV.map{|arg| "'#{arg}'"}.join(' ')
else
  #Not running any task, maybe rake options, invalid, etc...
end