Commit 745dbbc1 authored by Lucas Nussbaum's avatar Lucas Nussbaum

Many rubocop fixes

parent 7c040509
......@@ -11,7 +11,7 @@ end
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
require 'refrepo'
if Dir::exists?(ENV['HOME'] + '/.gpuppet/repo')
if Dir::exist?(ENV['HOME'] + '/.gpuppet/repo')
PUPPET_ODIR = ENV['HOME'] + '/.gpuppet/repo'
else
PUPPET_ODIR = '/tmp/puppet'
......
......@@ -60,12 +60,12 @@ def g5kchecks_importer(sourcedir)
write_yaml(new_filename, hash)
contents = File.read(new_filename)
File.open(new_filename, 'w') { |file|
file.write("# Generated by g5k-checks (g5k-checks -m api)\n")
file.write(contents)
}
File.open(new_filename, 'w') do |fd|
fd.write("# Generated by g5k-checks (g5k-checks -m api)\n")
fd.write(contents)
end
rescue Exception => e
rescue StandardError => e
puts "#{node_uid} - #{e.class}: #{e.message}\nError: #{e.backtrace}"
end
end
......
......@@ -25,7 +25,7 @@ def get_ref_default_properties(_site_uid, site)
properties[node_uid] = get_ref_node_properties_internal(cluster_uid, cluster, node_uid, node)
rescue MissingProperty => e
puts "Error (missing property) while processing node #{node_uid}: #{e}"
rescue Exception => e
rescue StandardError => e
puts "FATAL ERROR while processing node #{node_uid}: #{e}"
puts "Description of the node is:"
pp node
......@@ -477,7 +477,7 @@ end
def oarcmd_create_properties(properties_keys)
command = ''
properties_keys.each do |key, key_type|
if key_type == Fixnum
if key_type == Fixnum # rubocop:disable Lint/UnifiedInteger
command += "property_exist '#{key}' || oarproperty -a #{key}\n"
elsif key_type == String
command += "property_exist '#{key}' || oarproperty -a #{key} --varchar\n"
......@@ -532,18 +532,18 @@ def oarcmd_set_disk_properties(host, disk, disk_properties)
end
# sudo exec
def ssh_exec(site_uid, cmds, options)
def ssh_exec(site_uid, cmds, _options)
# The following is equivalent to : "cat cmds | bash"
#res = ""
c = Net::SSH.start("oar.#{site_uid}.g5kadmin", "g5kadmin")
c.open_channel { |channel|
channel.exec('sudo bash') { |ch, success|
# stdout
channel.on_data { |ch, data|
channel.on_data { |ch2, data|
puts data #if options[:verbose] # ssh cmd output
}
# stderr
channel.on_extended_data do |ch, type, data|
channel.on_extended_data do |ch2, type, data|
puts data
end
......
......@@ -197,7 +197,7 @@ def get_node_records(cluster_uid, node_uid, network_adapters)
return records
end
def get_node_kavlan_records(cluster_uid, node_uid, network_adapters, kavlan_adapters)
def get_node_kavlan_records(_cluster_uid, node_uid, network_adapters, kavlan_adapters)
records = []
kavlan_adapters.each { |net_uid, net_hash|
......@@ -290,7 +290,7 @@ end
def include_manual_file(zone)
manual_file_path = File.join(File.dirname(zone.file_path), File.basename(zone.file_path).sub('.db', '') + '-manual.db')
if (File.exists?(manual_file_path))
if (File.exist?(manual_file_path))
return "$INCLUDE /etc/bind/zones/#{zone.site_uid}/#{File.basename(zone.file_path).sub('.db', '') + '-manual.db'}\n"
end
return ''
......@@ -298,7 +298,7 @@ end
#
def load_zone(zone_file_path, site_uid, site, header)
if File.exists?(zone_file_path)
if File.exist?(zone_file_path)
zone = DNS::Zone.load(File.read(zone_file_path))
else
zone = DNS::Zone.new
......@@ -388,7 +388,7 @@ def get_orphan_reverse_manual_zones(zones_dir, site_uid, site)
zones = []
Dir.glob(File.join(zones_dir, "reverse-*-manual.db")).each { |reverse_manual_file|
output_file = reverse_manual_file.sub("-manual.db", ".db")
next if File.exists?(File.join(output_file))
next if File.exist?(File.join(output_file))
puts "Creating file for orphan reverse manual file: #{output_file}" if $options[:verbose]
#Creating the zone will include automatically the manual file
zone = load_zone(output_file, site_uid, site, true)
......
......@@ -17,8 +17,11 @@ def get_network_info(node_hash, network_interface)
node_network_interface = node_network_adapters.fetch(neti)
raise '"mac" is nil' unless node_mac = node_network_interface.fetch("mac")
raise '"ip" is nil' unless node_ip = node_network_interface.fetch("ip")
node_mac = node_network_interface.fetch("mac")
node_ip = node_network_interface.fetch("ip")
raise '"mac" is nil' unless node_mac
raise '"ip" is nil' unless node_ip
return [node_ip, node_mac]
end
......
......@@ -139,9 +139,9 @@ def generate_puppet_kadeployg5k(options)
overrides = conf[site_uid][cluster_uid]
dupes = (defaults.to_a & overrides.to_a)
if not dupes.empty?
puts "Warning: cluster-specific configuration for #{cluster_uid} overrides default values: #{dupes.to_s}"
puts "Warning: cluster-specific configuration for #{cluster_uid} overrides default values: #{dupes}"
end
data = data = defaults.merge(overrides)
data = defaults.merge(overrides)
if data.nil?
puts "Warning: configuration not found in #{options[:conf_dir]}/kadeployg5k#{suffix}.yaml for #{cluster_uid}. Skipped"
next
......
......@@ -238,6 +238,7 @@ class G5KHardwareGenerator < WikiGenerator
generated_content += "\n= Nodes models =\n"
table_columns = ['Nodes model'] + sites + ['Nodes total']
generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'node_models'))
return generated_content
end
def init(data, key1, key2)
......@@ -295,8 +296,8 @@ class G5KHardwareGenerator < WikiGenerator
'Skylake' => '2016',
'Zen' => '2017'
}
date = release_dates[microarchitecture.to_s]
raise "ERROR: microarchitecture not found: '#{microarchitecture.to_s}'. Add in hardware.rb" if date.nil?
date = release_dates[microarchitecture]
raise "ERROR: microarchitecture not found: '#{microarchitecture}'. Add in hardware.rb" if date.nil?
date
end
......
......@@ -149,7 +149,7 @@ class OarPropertiesGenerator < WikiGenerator
#Existing properties that won't be documented
@@ignored_properties = ["maintenance", "state", "ip_virtual"]
def get_nodes_properties(site_uid, site)
def get_nodes_properties(_site_uid, site)
properties = {}
site['clusters'].sort.to_h.each do |cluster_uid, cluster|
cluster['nodes'].sort.to_h.each do |node_uid, node|
......
......@@ -33,7 +33,7 @@ class SiteHardwareGenerator < WikiGenerator
# remove retired nodes
# FIXME this should probably move to a helper
h['clusters'].each_pair do |cl, v|
v['nodes'].delete_if { |n, v| v['status'] == 'retired' }
v['nodes'].delete_if { |n, v2| v2['status'] == 'retired' }
end
h['clusters'].delete_if { |k, v| v['nodes'].empty? }
......@@ -136,6 +136,7 @@ class SiteHardwareGenerator < WikiGenerator
generated_content = "\n= Cluster details =\n"
generated_content += text_data.join("\n")
return generated_content
end
end
......
......@@ -75,6 +75,7 @@ module G5K
i += 1
end
s += ']'
return s
end
def self.get_size(x, unit='IEC')
......
......@@ -12,7 +12,7 @@ class WikiGenerator
return G5K::get_global_hash
end
def login(options)
def login(_options)
tries = 3
begin
conf = RefRepo::Utils.get_api_config
......@@ -164,7 +164,7 @@ class WikiGenerator
end
opt_parse.parse!
if (!options[:diff] && !options[:print] && !options[:update])
puts "ERROR: At least one action must be given! (--diff, --print, --update)\n#{opt_parse.to_s}"
puts "ERROR: At least one action must be given! (--diff, --print, --update)\n#{opt_parse}"
exit(1)
end
return options
......
......@@ -26,7 +26,7 @@ def load_yaml_file_hierarchy(directory = File.expand_path("../../input/grid5000/
raise Exception.new("loaded hash is empty")
end
# YAML::Psych raises an exception if the file cannot be loaded.
rescue Exception => e
rescue StandardError => e
puts "Error loading '#{filename}', #{e.message}"
end
......
......@@ -122,7 +122,6 @@ end
def get_site_dead_nodes(site_uid, options)
oarnodes = ''
api_uri = URI.parse('https://api.grid5000.fr/stable/sites/' + site_uid + '/internal/oarapi/resources/details.json?limit=999999')
# Download the OAR properties from the OAR API (through G5K API)
......@@ -167,7 +166,6 @@ def cluster_homogeneity(refapi_hash, options = {:verbose => false})
ignore_keys = global_ignore_keys()
cignore_keys = cluster_ignore_keys(File.expand_path("data/homogeneity.yaml.erb", File.dirname(__FILE__)))
input_data_dir = "../../input/grid5000/"
count = {}
total_count = 0
......
......@@ -38,11 +38,11 @@ def yaml_input_find_duplicates(options)
site["clusters"].sort.each do |cluster_uid, cluster|
if options.key?(:clusters) && (not options[:clusters].empty?) && !options[:clusters].include?(cluster_uid)
site["clusters"].delete(cluster_uid)
site["clusters"].delete(cluster_uid)
end
cluster["nodes"].sort.each do |node_uid, node|
if node.key?("status") && node["status"] == "retired"
cluster["nodes"].delete(node_uid)
if node.key?("status") && node["status"] == "retired"
cluster["nodes"].delete(node_uid)
end
end
end
......
......@@ -8,7 +8,7 @@ class HashValidator::Validator::LinecardPortValidator < HashValidator::Validator
@port_properties = ["uid", "name", "port", "kind", "mtu", "rate", "site", "aggregation"]
end
def validate(key, values, validations, errors)
def validate(key, values, _validations, errors)
if values.is_a?(Hash)
values.each do |k, v|
if @port_properties.index(k) == nil
......@@ -32,7 +32,7 @@ class HashValidator::Validator::IpAddressValidator < HashValidator::Validator::B
super('ip_address')
end
def validate(key, values, validations, errors)
def validate(key, values, _validations, errors)
if values.is_a?(String)
unless (values =~ Resolv::IPv4::Regex || values =~ Resolv::IPv6::Regex)
errors[key] = "Invalid ip address format #{values}"
......
......@@ -66,7 +66,7 @@ end
# Monkey patching of the SimpleValidator to get more useful error messages
class HashValidator::Validator::SimpleValidator < HashValidator::Validator::Base
def validate(key, value, validations, errors)
def validate(key, value, _validations, errors)
unless lambda.call(value)
errors[key] = "#{self.name} required (current value: #{value.class}:#{value})"
end
......@@ -78,4 +78,5 @@ def load_yaml_schema(filename)
schema = YAML::load_file(filename)
schema = add_optional_validator(schema)
schema = replace_validators_keys(schema)
return schema
end
......@@ -55,7 +55,6 @@ def check_monitoring_properties(data)
data['sites'].each do |site_uid, site|
site_pdus = {}
site_pdu_outlets = {}
metric_nodes = {}
node_monitoring_wattmeter = {}
# if site['clusters'].nil?
# return
......
require_relative "./lib/schema_validator"
def run_validator(uid, data, schema)
validator = HashValidator.validate(data, schema, strict = true)
validator = HashValidator.validate(data, schema, true)
if ! validator.valid?
errors = {uid => validator.errors}
puts errors.to_yaml
......
......@@ -102,7 +102,7 @@ module RefRepo::Valid::OarProperties
end
if options[:verbose] and (host_cpusets_max - host_cpusets_min + 1 != nbcores or host_cores_max - host_cores_min + 1 != nbcores)
puts "id cpu core cpuset"
pp host_resources.map { |e| [e['id'], e['cpu'], e['core'], e['cpuset'] ] }
pp(host_resources.map { |e| [e['id'], e['cpu'], e['core'], e['cpuset'] ] })
end
end
end
......
......@@ -61,7 +61,7 @@ else
end
##Modify node yaml hash here
def modify_node_data(hash, node_uid, cluster_uid, site_uid)
def modify_node_data(hash, node_uid, cluster_uid, site_uid) #rubocop:disable Lint/UnusedMethodArgument
#example content:
hash["network_adapters"].each{ |na_id, na|
......@@ -103,12 +103,12 @@ list_of_yaml_files.each { |filename|
write_yaml(new_filename, hash)
contents = File.read(new_filename)
File.open(new_filename, 'w') { |file|
file.write("# Generated by g5k-checks (g5k-checks -m api)\n")
file.write(contents)
File.open(new_filename, 'w') { |fd|
fd.write("# Generated by g5k-checks (g5k-checks -m api)\n")
fd.write(contents)
}
rescue Exception => e
rescue StandardError => e
puts "#{node_uid} - #{e.class}: #{e.message}"
puts e.backtrace
end
......
......@@ -28,7 +28,7 @@ $g5k = Cute::G5K::API.new()
# puts 'Get site_uids'
begin
sites = $g5k.site_uids()
rescue Exception => e
rescue StandardError => e
puts "Error while getting the site list with ruby-cute: #{e.class}: #{e.message}"
puts "API unavailable ?"
refapi = load_yaml_file_hierarchy("../../input/grid5000/")
......@@ -154,7 +154,7 @@ def run_g5kcheck(site_uid, fnode_uid, options)
end
end
}
rescue Exception => e
rescue StandardError => e
puts "#{site_uid}: Error while processing #{fnode_uid} - #{e.class}: #{e.message}"
end
end
......@@ -165,7 +165,7 @@ def oarsub(site_uid, resources, queue)
begin
job = $g5k.reserve(:site => site_uid, :resources => resources, :walltime => '00:30:00', :wait => false, :queue => queue)
rescue Exception => e
rescue StandardError => e
puts "#{site_uid}: Error during the reservation '#{resources}' at #{site_uid} - #{e.class}: #{e.message}"
end
......@@ -205,7 +205,7 @@ if options[:force]
if nodes_status.nil?
begin
nodes_status = $g5k.nodes_status(site_uid)
rescue Exception => e
rescue StandardError => e
nodes_status = {} # do not retry
puts "Error while getting nodes status at #{site_uid}" #{e}
#next continue anyway as the --force option might be used for a new cluster that is not available yet in the reference-api
......@@ -252,7 +252,7 @@ else # ! options[:force]
begin
nodes_status = $g5k.nodes_status(site_uid)
rescue Exception => e
rescue StandardError => e
puts "Error while getting nodes status at #{site_uid}" #{e}
next
end
......@@ -311,9 +311,9 @@ else # ! options[:force]
#
loop do
waiting_jobs = $g5k.get_my_jobs(site_uid, state='waiting')
running_jobs = $g5k.get_my_jobs(site_uid, state='running')
launching_jobs = $g5k.get_my_jobs(site_uid, state='launching')
waiting_jobs = $g5k.get_my_jobs(site_uid, 'waiting')
running_jobs = $g5k.get_my_jobs(site_uid, 'running')
launching_jobs = $g5k.get_my_jobs(site_uid, 'launching')
puts "#{site_uid}: Running: #{running_jobs.size} - Waiting: #{waiting_jobs.size} - Launching: #{launching_jobs.size}"
......@@ -341,7 +341,7 @@ else # ! options[:force]
begin
$g5k.release(job)
released_jobs[site_uid][job_uid] = true
rescue Exception => e
rescue StandardError => e
puts "#{site_uid}: Error while releasing job #{job_uid} - #{e.class}: #{e.message}"
end
}
......@@ -358,26 +358,27 @@ else # ! options[:force]
} # options[:sites].peach
rescue Exception => e
rescue StandardError => e
puts "#{e.class}: #{e.message}"
ensure
jobs.each{|site_uid, jobs| jobs.compact.each { |job|
jobs.each do |site_uid, jobs2|
jobs2.compact.each do |job|
begin
job_uid = job['uid']
if released_jobs[site_uid][job_uid] != true
puts "Release job #{job['links'][0]['href']}"
$g5k.release(job)
end
rescue Exception => e
rescue StandardError => e
puts "Failed releasing job #{job['links'][0]['href']} - #{e.class}: #{e.message}"
end
}
}
end
end
exit
end
end # options[:force]
stdout_str, stderr_str, status = Open3.capture3('ruby postprocessing.rb')
stdout_str, stderr_str, _status = Open3.capture3('ruby postprocessing.rb')
puts stdout_str
puts stderr_str
......@@ -2,7 +2,8 @@
# FIXME adjust (probably broken)
require_relative "input_loader"
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../lib')))
require "refrepo"
require "test/unit"
require "hashdiff"
......@@ -40,16 +41,16 @@ class TestInputLoader < Test::Unit::TestCase
# Check recursivity
# At the last level
a = {"c-1": {"c-2": {"a-3": 0}}}
b = {"c-1": {"c-2": {"b-3": 0}}}
assert_equal_hash(deep_merge_entries(a, b), {"c-1": {"c-2": {"a-3": 0, "b-3": 0}}})
a = {"c-1" => {"c-2" => {"a-3" => 0}}}
b = {"c-1" => {"c-2" => {"b-3" => 0}}}
assert_equal_hash(deep_merge_entries(a, b), {"c-1" => {"c-2" => {"a-3" => 0, "b-3" => 0}}})
# At an intermediate level
a = {"c-1": {"a-2": {"a-3": 0}}}
b = {"c-1": {"b-2": {"b-3": 0}}}
assert_equal_hash(deep_merge_entries(a, b), {"c-1": {
"a-2": {"a-3": 0},
"b-2": {"b-3": 0}
a = {"c-1" => {"a-2" => {"a-3" => 0}}}
b = {"c-1" => {"b-2" => {"b-3" => 0}}}
assert_equal_hash(deep_merge_entries(a, b), {"c-1" => {
"a-2" => {"a-3" => 0},
"b-2" => {"b-3" => 0}
}
})
end
......@@ -57,16 +58,16 @@ class TestInputLoader < Test::Unit::TestCase
# Test the example given in documentation
def test__expand_square_brackets__doc_example
hash = {
"foo-1": {a: 0},
"foo-2": {a: 0},
"foo-3": {a: 0},
"foo-[2-]": {b: 1}
"foo-1" => {a => 0},
"foo-2" => {a => 0},
"foo-3" => {a => 0},
"foo-[2-]" => {b => 1}
}
expected_expanded_hash = {
"foo-1": {a: 0},
"foo-2": {a: 0, b: 1},
"foo-3": {a: 0, b: 1}
"foo-1" => {a => 0},
"foo-2" => {a => 0, b => 1},
"foo-3" => {a => 0, b => 1}
}
assert_equal_expanded_hash(hash, expected_expanded_hash)
......@@ -74,8 +75,8 @@ class TestInputLoader < Test::Unit::TestCase
# The 'a' parameter
def test__expand_square_brackets__a_values
assert_equal_expanded_hash({"foo-[-3]": 0}, {"foo-1": 0, "foo-2": 0, "foo-3": 0}) # Default 'a' value is 1
assert_equal_expanded_hash({"foo-[2-3]": 0}, {"foo-2": 0, "foo-3": 0}) # Simply check if the value of 'a' is taken into account
assert_equal_expanded_hash({"foo-[-3]" => 0}, {"foo-1" => 0, "foo-2" => 0, "foo-3" => 0}) # Default 'a' value is 1
assert_equal_expanded_hash({"foo-[2-3]" => 0}, {"foo-2" => 0, "foo-3" => 0}) # Simply check if the value of 'a' is taken into account
end
def test__expand_square_brackets__create_keys
......@@ -84,26 +85,26 @@ class TestInputLoader < Test::Unit::TestCase
#
# With symbol keys and numeric values
assert_equal_expanded_hash({"foo-[2-3]": 0}, {"foo-2": 0, "foo-3": 0})
assert_equal_expanded_hash({"foo-[-2]": 0}, {"foo-1": 0, "foo-2": 0})
assert_equal_expanded_hash({"foo-[2-3]" => 0}, {"foo-2" => 0, "foo-3" => 0})
assert_equal_expanded_hash({"foo-[-2]" => 0}, {"foo-1" => 0, "foo-2" => 0})
# With symbol keys and hash values
assert_equal_expanded_hash({"foo-[2-3]": {a: 0}}, {"foo-2": {a: 0}, "foo-3": {a: 0}})
assert_equal_expanded_hash({"foo-[-2]": {a: 0}}, {"foo-1": {a: 0}, "foo-2": {a: 0}})
assert_equal_expanded_hash({"foo-[2-3]" => {a => 0}}, {"foo-2" => {a => 0}, "foo-3" => {a => 0}})
assert_equal_expanded_hash({"foo-[-2]" => {a => 0}}, {"foo-1" => {a => 0}, "foo-2" => {a => 0}})
# With string keys and numeric values
assert_equal_expanded_hash({"foo-[2-3]" => 0}, {"foo-2" => 0, "foo-3" => 0})
assert_equal_expanded_hash({"foo-[-2]" => 0}, {"foo-1" => 0, "foo-2" => 0})
# With string keys and hash values
assert_equal_expanded_hash({"foo-[2-3]" => {a: 0}}, {"foo-2" => {a: 0}, "foo-3" => {a: 0}})
assert_equal_expanded_hash({"foo-[-2]" => {a: 0}}, {"foo-1" => {a: 0}, "foo-2" => {a: 0}})
assert_equal_expanded_hash({"foo-[2-3]" => {a => 0}}, {"foo-2" => {a => 0}, "foo-3" => {a => 0}})
assert_equal_expanded_hash({"foo-[-2]" => {a => 0}}, {"foo-1" => {a => 0}, "foo-2" => {a => 0}})
#
# If 'b' is not given, do not create any new key
#
assert_equal_expanded_hash({"foo-[-]": 0}, {}) # All
assert_equal_expanded_hash({"foo-[2-]": 0}, {})
assert_equal_expanded_hash({"foo-[-]" => 0}, {}) # All
assert_equal_expanded_hash({"foo-[2-]" => 0}, {})
end
......@@ -113,17 +114,17 @@ class TestInputLoader < Test::Unit::TestCase
#
[0, {h: 0}].each { |v|
assert_equal_expanded_hash({"foo-[1-3]": v, "foo-2": 1}, {"foo-1": v, "foo-2": 1, "foo-3": v}) # b given
assert_equal_expanded_hash({"foo-[2-]": v, "foo-2": 1}, {"foo-2": 1}) # b not given
assert_equal_expanded_hash({"foo-[1-3]" => v, "foo-2" => 1}, {"foo-1" => v, "foo-2" => 1, "foo-3" => v}) # b given
assert_equal_expanded_hash({"foo-[2-]" => v, "foo-2" => 1}, {"foo-2" => 1}) # b not given
}
end
# Some tests with nil values (=> nil values are created, existing nil values are overriden)
def test__expand_square_brackets__nil
assert_equal_expanded_hash({"foo-[2-3]": nil}, {"foo-2": nil, "foo-3": nil}) # PREFIX-[a-b] is nil
assert_equal_expanded_hash({"foo-[2-3]": 0, "foo-2": nil}, {"foo-2": 0, "foo-3": 0}) # PREFIX-x is nil
assert_equal_expanded_hash({"foo-[2-]": nil, "foo-3": 0}, {"foo-3": 0}) # PREFIX-[a-] is nil
assert_equal_expanded_hash({"foo-[2-]": 0, "foo-3": nil}, {"foo-3": 0}) # PREFIX-x is nil
assert_equal_expanded_hash({"foo-[2-3]" => nil}, {"foo-2" => nil, "foo-3" => nil}) # PREFIX-[a-b] is nil
assert_equal_expanded_hash({"foo-[2-3]" => 0, "foo-2" => nil}, {"foo-2" => 0, "foo-3" => 0}) # PREFIX-x is nil
assert_equal_expanded_hash({"foo-[2-]" => nil, "foo-3" => 0}, {"foo-3" => 0}) # PREFIX-[a-] is nil
assert_equal_expanded_hash({"foo-[2-]" => 0, "foo-3" => nil}, {"foo-3" => 0}) # PREFIX-x is nil
end
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