Commit b1eef313 authored by Lucas Nussbaum's avatar Lucas Nussbaum
Browse files

[dev] migrate input/duplicates

parent ab0ccb17
......@@ -39,22 +39,25 @@ namespace :valid do
task "homogeneity" do
require 'refrepo/valid/homogeneity'
options = {}
if ENV['SITE']
options[:sites] = ENV['SITE'].split(',')
else
options[:sites] = G5K_SITES
end
if ENV['CLUSTER']
options[:clusters] = ENV['CLUSTER'].split(',')
else
options[:clusters] = []
end
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 = check_cluster_homogeneity(options)
exit(ret)
end
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
desc "Check input data schema validity"
task "schema" do
invoke_script "#{VALIDATORS_DIR}/yaml-input-schema-validator.rb"
......@@ -64,17 +67,9 @@ namespace :valid do
task "oar-properties" do
require 'refrepo/valid/oar-properties'
options = {}
options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
options[:clusters] = ( ENV['CLUSTER'] ? ENV['CLUSTER'].split(',') : [] )
options[:verbose] = true if ENV['VERBOSE']
if ENV['SITE']
options[:sites] = ENV['SITE'].split(',')
else
options[:sites] = G5K_SITES
end
if ENV['CLUSTER']
options[:clusters] = ENV['CLUSTER'].split(',')
else
options[:clusters] = []
end
ret = RefRepo::Valid::OarProperties::check(options)
exit(ret)
end
......@@ -86,11 +81,7 @@ namespace :gen do
task "wiki" do
require 'refrepo/gen/wiki'
options = {}
if ENV['SITE']
options[:sites] = ENV['SITE'].split(',')
else
options[:sites] = ['global'] + G5K_SITES
end
options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
if ENV['NAME']
options[:generators] = ENV['NAME'].split(',')
else
......@@ -118,11 +109,7 @@ namespace :gen do
task "oar-properties" do
require 'refrepo/gen/oar-properties'
options = {}
if ENV['SITE']
options[:sites] = ENV['SITE'].split(',')
else
options[:sites] = G5K_SITES
end
options[:sites] = ( ENV['SITE'] ? ENV['SITE'].split(',') : G5K_SITES )
if ENV['CLUSTER']
options[:clusters] = ENV['CLUSTER'].split(',')
end
......
#!/usr/bin/ruby
if RUBY_VERSION < "2.1"
puts "This script requires ruby >= 2.1"
exit
end
require 'pp'
require '../lib/input_loader'
require 'refrepo/input_loader'
# replace default deep_merge before calling load_yaml_file_hierarchy
class ::Hash
......@@ -38,7 +33,8 @@ class ::Hash
end
end
def yaml_input_find_duplicates(refapi_hash, options)
def yaml_input_find_duplicates(options)
refapi_hash = load_yaml_file_hierarchy
refapi_hash["sites"].sort.each do |site_uid, site|
if options.key?(:sites) && !options[:sites].include?(site_uid)
......@@ -69,57 +65,9 @@ def yaml_input_find_duplicates(refapi_hash, options)
if refapi_hash.empty?
puts "OK: no duplicate entries."
exit(0)
return true
else
puts refapi_hash.to_yaml
exit(1)
return false
end
end
if __FILE__ == $0
require 'optparse'
options = {}
options[:sites] = %w{grenoble lille luxembourg lyon nancy nantes rennes sophia}
options[:api] = {}
OptionParser.new do |opts|
opts.banner = "Usage: yaml-input-find-duplicates.rb [options]"
opts.separator ""
opts.separator "Example: ruby yaml-input-find-duplicates.rb -v"
###
opts.separator ""
opts.separator "Filters:"
opts.on('-s', '--sites a,b,c', Array, 'Select site(s)',
"Default: "+options[:sites].join(", ")) do |s|
raise "Wrong argument for -s option." unless (s - options[:sites]).empty?
options[:sites] = s
end
opts.on('-c', '--clusters a,b,c', Array, 'Select clusters(s). Default: all') do |s|
options[:clusters] = s
end
opts.separator ""
opts.separator "Common options:"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] ||= 0
options[:verbose] = options[:verbose] + 1
end
# Print an options summary.
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!
refapi_hash = load_yaml_file_hierarchy("../../input/grid5000/")
yaml_input_find_duplicates(refapi_hash, options)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment