b1f2fff045
BinaryLane edge hosts have a public primary IP, so region/environment/country/zone resolve to unknown even though their VPC NIC sits in a known subnet. - match the primary IP first, unchanged for existing hosts - otherwise scan interface bindings in name order, skipping lo, dum* and wg* - add modules/libs/test/subnet_facts_check.rb (`ruby modules/libs/test/subnet_facts_check.rb`) Reviewed-on: #557 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
37 lines
1.4 KiB
Ruby
37 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# ruby modules/libs/test/subnet_facts_check.rb
|
|
module Facter
|
|
def self.value(_name)
|
|
{}
|
|
end
|
|
|
|
def self.add(*); end
|
|
end
|
|
load File.expand_path('../lib/facter/subnet_facts.rb', __dir__)
|
|
|
|
iface = ->(*addresses) { { 'bindings' => addresses.map { |address| { 'address' => address } } } }
|
|
|
|
checks = {
|
|
'primary ip wins over other interfaces' => [
|
|
{ 'ip' => '198.18.17.5', 'interfaces' => { 'eth1' => iface.call('198.18.13.5') } }, 'drw1'
|
|
],
|
|
'unmatched primary ip falls back to an interface' => [
|
|
{ 'ip' => '203.0.113.5', 'interfaces' => { 'eth0' => iface.call('203.0.113.5'), 'eth1' => iface.call('198.18.24.11') } }, 'syd1'
|
|
],
|
|
'lo, dum and wg interfaces are skipped' => [
|
|
{ 'ip' => '203.0.113.5',
|
|
'interfaces' => { 'dum0' => iface.call('198.18.2.161'), 'lo' => iface.call('198.18.19.1'),
|
|
'wg0' => iface.call('198.18.2.177') } }, 'unknown'
|
|
],
|
|
'interfaces are scanned in name order' => [
|
|
{ 'ip' => '203.0.113.5', 'interfaces' => { 'eth2' => iface.call('198.18.24.1'), 'eth1' => iface.call('198.18.17.1') } }, 'drw1'
|
|
],
|
|
'missing ip and interfaces resolve to unknown' => [{}, 'unknown']
|
|
}
|
|
|
|
failures = checks.reject { |_name, (networking, expected)| SubnetAttributes.from_networking(networking)[:region] == expected }
|
|
failures.each_key { |name| warn "FAIL: #{name}" }
|
|
abort if failures.any?
|
|
puts "ok (#{checks.size} checks)"
|