def self.check_routing_table_has_entry(expected_attr)
return false if ! expected_attr[:destination]
cmd = Specinfra.command.get(:get_routing_table_entry, expected_attr[:destination])
ret = Specinfra.backend.run_command(cmd)
return false if ret.failure?
ret.stdout.gsub!(/\r\n/, "\n")
if os[:family] == 'openbsd'
match = ret.stdout.match(/^(\S+)\s+(\S+).*?(\S+[0-9]+)(\s*)$/)
actual_attr = {
:destination => $1,
:gateway => $2,
:interface => expected_attr[:interface] ? $3 : nil
}
else
matches = ret.stdout.scan(/^(\S+)(?: via (\S+))? dev (\S+).+\n|^(\S+).*\n|\s+nexthop via (\S+)\s+dev (\S+).+/)
if matches.length > 1
destination = nil
matches.each do |groups|
if groups[3]
destination = groups[3]
next
end
next if expected_attr[:gateway] && expected_attr[:gateway] != groups[4]
next if expected_attr[:interface] && expected_attr[:interface] != groups[5]
actual_attr = {
:destination => destination,
:gateway => groups[4],
:interface => groups[5]
}
end
elsif matches.length == 1
groups = matches[0]
actual_attr = {
:destination => groups[0],
:gateway => groups[1] ? groups[1] : groups[3],
:interface => expected_attr[:interface] ? groups[2] : nil
}
end
end
expected_attr.each do |key, val|
return false if actual_attr[key] != val
end
true
end