Commit 37626385 authored by Jérémie Gaidamour's avatar Jérémie Gaidamour
Browse files

[dev] Integration of yaml-input-schema-validator.rb into reference-api.rb

parent 959e6e8b
#
# All of the following is just to check the value of node['monitoring']['wattmeter']...
#
# Main method is check_monitoring_properties(data) where data is the input/ data after beeing processed by ../reference-api/reference-api.rb
def measurement_point_name(measure_point, site)
port = measure_point['port'] || measure_point['measure'] || 0
......@@ -50,8 +51,7 @@ def monitoring_wattmeter_annotation(pdu_info, site_pdus, site_pdu_outlets, site)
node_monitoring_wattmeter
end
# Attempts to add information to data to help users
def annotate(data)
def check_monitoring_properties(data)
data['sites'].each do |site_uid, site|
site_pdus = {}
site_pdu_outlets = {}
......@@ -139,21 +139,18 @@ def annotate(data)
node_monitoring_wattmeter[node['uid']] = "true" if node_monitoring_wattmeter[node['uid']] == true
node_monitoring_wattmeter[node['uid']] = "false" if node_monitoring_wattmeter[node['uid']] == false
if node.has_key?('monitoring')
if node['monitoring'].has_key?('wattmeter')
if node['monitoring']['wattmeter'] != node_monitoring_wattmeter[node['uid']]
puts "#{node['uid']}['monitoring']['wattmeter'] override calculated information with information found in input. Calculated it should be #{node_monitoring_wattmeter[node['uid']]}, keeping #{node['monitoring']['wattmeter']}"
end
else #create wattmeter entry
pp 'Missing'
node['monitoring']['wattmeter'] = node_monitoring_wattmeter[node['uid']]
if node.has_key?('monitoring') && node['monitoring'].has_key?('wattmeter')
if node['monitoring']['wattmeter'] != node_monitoring_wattmeter[node['uid']]
puts "Warning: it seems that #{node['uid']}['monitoring']['wattmeter'] should be #{node_monitoring_wattmeter[node['uid']]} instead of #{node['monitoring']['wattmeter']}."
end
else #create monitoring entry
pp 'Missing'
node['monitoring'] = {'wattmeter' => node_monitoring_wattmeter[node['uid']]}
else
puts "Warning: #{node['uid']}['monitoring']['wattmeter'] is missing. Should be #{node_monitoring_wattmeter[node['uid']]}."
end
#puts "#{node['uid']}['monitoring']['wattmeter'] = #{node['monitoring']['wattmeter']}"
end
end
end
end
if __FILE__ == $0
puts 'This ruby file cannot be executed by itself. Run ../reference-api/reference-api.rb instead.'
end
......@@ -6,9 +6,11 @@
# * http://rx.codesimply.com/
# * http://www.kuwata-lab.com/kwalify/ruby/users-guide.html
dir = Pathname(__FILE__).parent
require 'json'
require 'hash_validator' # https://github.com/jamesbrooks/hash_validator
require './lib/multihash_validator' # custom validator
require "#{dir}/multihash_validator" # custom validator
# Simple required_hash validator
HashValidator.append_validator(HashValidator::Validator::SimpleValidator.new('required_hash', lambda { |v| v.is_a?(Hash) }))
......
......@@ -25,4 +25,6 @@ kavlans:
<multi>:
network: string
gateway: string
pdu: optional_hash
pdus: optional_hash
renater_ip: string
frontend_ip: string
\ No newline at end of file
#!/usr/bin/ruby
require 'pp'
require 'fileutils'
require 'pathname'
require '../lib/input_loader'
require './lib/schema_validator'
dir = Pathname(__FILE__).parent
schema_global = load_yaml_schema('schema-global.yaml')
schema_site = load_yaml_schema('schema-site.yaml')
schema_cluster = load_yaml_schema('schema-cluster.yaml')
schema_node = load_yaml_schema('schema-node.yaml')
require "#{dir}/../lib/input_loader"
require "#{dir}/lib/schema_validator"
def run_validator(uid, data, schema)
validator = HashValidator.validate(data, schema, strict = true)
......@@ -20,22 +16,34 @@ def run_validator(uid, data, schema)
end
end
global_hash = load_yaml_file_hierarchy("../../input/grid5000/")
run_validator('global', global_hash, schema_global) #
global_hash["sites"].each do |site_uid, site|
run_validator(site_uid, site, schema_site) #
site["clusters"].each do |cluster_uid, cluster|
run_validator(cluster_uid, cluster, schema_cluster) #
cluster["nodes"].each do |node_uid, node|
run_validator(node_uid, node, schema_node) #
def yaml_input_schema_validator(global_hash)
dir = Pathname(__FILE__).parent
schema_global = load_yaml_schema("#{dir}/schema-global.yaml")
schema_site = load_yaml_schema("#{dir}/schema-site.yaml")
schema_cluster = load_yaml_schema("#{dir}/schema-cluster.yaml")
schema_node = load_yaml_schema("#{dir}/schema-node.yaml")
run_validator('global', global_hash, schema_global) #
global_hash["sites"].each do |site_uid, site|
run_validator(site_uid, site, schema_site) #
site["clusters"].each do |cluster_uid, cluster|
run_validator(cluster_uid, cluster, schema_cluster) #
cluster["nodes"].each do |node_uid, node|
run_validator(node_uid, node, schema_node) #
end
end
end
end
if __FILE__ == $0
global_hash = load_yaml_file_hierarchy("#{dir}/../../input/grid5000/")
yaml_input_schema_validator(global_hash)
end
......@@ -9,6 +9,7 @@ require 'json'
require 'time'
require '../lib/input_loader'
require '../input-validators/yaml-input-schema-validator'
require '../input-validators/check-monitoring-properties'
# Output directory
......@@ -19,6 +20,8 @@ refapi_path = "../../data/grid5000"
#global_hash = load_yaml_file_hierarchy("../../input/example/")
global_hash = load_yaml_file_hierarchy("../../input/grid5000/")
yaml_input_schema_validator(global_hash)
# Parse network equipment description and return switch name and port connected to given node
# In the network description, if the node interface is given (using "port" attribute),
# the interface parameter must be used.
......@@ -278,4 +281,4 @@ global_hash["sites"].each do |site_uid, site|
end
#annotate(global_hash)
check_monitoring_properties(global_hash)
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