From fce69ead5e2c7e5357de839ac5908f942c6d6b82 Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Sat, 18 Nov 2023 21:41:47 +0100 Subject: [PATCH 1/2] (FACT-3163) Add support for OpenBSD fix order dependency of tests when run: $ rspec -fd './spec/facter/resolvers/openbsd/virtual_spec.rb[1:2:1]' \ './spec/facter/util/facts/posix/virtual_detector_spec.rb[1:1:12:1]' \ --order random:17181 additionally recognized, the 'virtual' fact didn't return 'physical' when on a physical machine. --- lib/facter/resolvers/openbsd/virtual.rb | 45 +++++++++++++++++++ spec/facter/resolvers/openbsd/virtual_spec.rb | 34 ++++++++++++++ .../util/facts/posix/virtual_detector_spec.rb | 28 ++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 lib/facter/resolvers/openbsd/virtual.rb create mode 100644 spec/facter/resolvers/openbsd/virtual_spec.rb diff --git a/lib/facter/resolvers/openbsd/virtual.rb b/lib/facter/resolvers/openbsd/virtual.rb new file mode 100644 index 0000000000..50e8cd93cb --- /dev/null +++ b/lib/facter/resolvers/openbsd/virtual.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module Facter + module Resolvers + module Openbsd + class Virtual < BaseResolver + init_resolver + + class << self + #:model + + VM_GUEST_SYSCTL_NAMES = { + 'VMM' => 'vmm', + 'vServer' => 'vserver', + 'oracle' => 'virtualbox', + 'xen' => 'xenu', + 'none' => nil + }.freeze + + private + + def post_resolve(fact_name, _options) + @fact_list.fetch(fact_name) { read_facts(fact_name) } + end + + CTL_HW = 6 + HW_PRODUCT = 15 + + def read_facts(fact_name) + require 'facter/resolvers/bsd/ffi/ffi_helper' + + vm = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_PRODUCT]) + if VM_GUEST_SYSCTL_NAMES.key?(vm) + vm = VM_GUEST_SYSCTL_NAMES[vm] + else + vm = "physical" + end + @fact_list[:vm] = vm + @fact_list[fact_name] + end + end + end + end + end +end diff --git a/spec/facter/resolvers/openbsd/virtual_spec.rb b/spec/facter/resolvers/openbsd/virtual_spec.rb new file mode 100644 index 0000000000..eeed19746b --- /dev/null +++ b/spec/facter/resolvers/openbsd/virtual_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facter::Resolvers::Openbsd::Virtual do + subject(:resolver) { Facter::Resolvers::Openbsd::Virtual } + + after do + resolver.invalidate_cache + end + + before do + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 15]) + .and_return(vm) + end + + let(:vm) { nil } + + context 'when running on bare metal' do + let(:vm) { 'physical' } + + it 'returns physical' do + expect(resolver.resolve(:vm)).to eq('physical') + end + end + + context 'when running in a vm' do + let(:vm) { 'VMM' } + + it 'returns VMM' do + expect(resolver.resolve(:vm)).to eq('vmm') + end + end +end diff --git a/spec/facter/util/facts/posix/virtual_detector_spec.rb b/spec/facter/util/facts/posix/virtual_detector_spec.rb index bea687bf61..d9058b6a0b 100644 --- a/spec/facter/util/facts/posix/virtual_detector_spec.rb +++ b/spec/facter/util/facts/posix/virtual_detector_spec.rb @@ -47,6 +47,25 @@ end end + context 'when OpenBSD' do + let(:value) { 'vmm' } + + before do + allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return('vmm') + end + + it 'calls Facter::Resolvers::Openbsd::Virtual' do + detector.platform + + expect(Facter::Resolvers::Openbsd::Virtual).to have_received(:resolve).with(:vm) + end + + it 'returns vmm' do + expect(detector.platform).to eq(value) + end + end + context 'when gce' do let(:value) { 'gce' } @@ -73,6 +92,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(value) @@ -95,6 +115,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelversion).and_return(nil) @@ -118,6 +139,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) @@ -142,6 +164,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) @@ -167,6 +190,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) @@ -193,6 +217,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) @@ -226,6 +251,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) @@ -271,6 +297,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) @@ -293,6 +320,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) From fff8397f9f99b9b61d37038ff6fb6d9a33ae5aac Mon Sep 17 00:00:00 2001 From: Sebastian Reitenbach Date: Sat, 18 Nov 2023 22:16:31 +0100 Subject: [PATCH 2/2] (FACT-3163) Add support for OpenBSD Most inspiration taken from FreeBSD, rest from other OS, and some own creations. Not all core facts supported, but makes puppet facts works well, as well as puppet agent --test Developed/Tested on OpenBSD 7.2, AMD64, Puppet 7.20.0, Ruby 3.1.2 also disable RuboCop Metrics/PerceivedComplexity and Metrics/CyclomaticComplexity as suggested by @joshcooper Additionally: Case insensitive OS detection ran into trouble when facter installed via puppetserver gem install, there the OS returned seems to be OpenBSD instead of all lowercase. --- lib/facter/config.rb | 5 +- lib/facter/facts/openbsd/augeas/version.rb | 19 +++ lib/facter/facts/openbsd/dmi/bios/vendor.rb | 19 +++ lib/facter/facts/openbsd/dmi/bios/version.rb | 19 +++ lib/facter/facts/openbsd/dmi/manufacturer.rb | 17 +++ lib/facter/facts/openbsd/dmi/product/name.rb | 19 +++ .../openbsd/dmi/product/serial_number.rb | 19 +++ lib/facter/facts/openbsd/dmi/product/uuid.rb | 19 +++ lib/facter/facts/openbsd/ec2_metadata.rb | 23 ++++ lib/facter/facts/openbsd/ec2_userdata.rb | 23 ++++ lib/facter/facts/openbsd/facterversion.rb | 14 ++ lib/facter/facts/openbsd/identity/gid.rb | 16 +++ lib/facter/facts/openbsd/identity/group.rb | 18 +++ .../facts/openbsd/identity/privileged.rb | 16 +++ lib/facter/facts/openbsd/identity/uid.rb | 16 +++ lib/facter/facts/openbsd/identity/user.rb | 17 +++ .../facts/openbsd/ipaddress6_interfaces.rb | 20 +++ .../facts/openbsd/ipaddress_interfaces.rb | 20 +++ lib/facter/facts/openbsd/is_virtual.rb | 21 +++ lib/facter/facts/openbsd/kernel.rb | 14 ++ lib/facter/facts/openbsd/kernelrelease.rb | 14 ++ lib/facter/facts/openbsd/mountpoints.rb | 21 +++ .../facts/openbsd/netmask6_interfaces.rb | 20 +++ .../facts/openbsd/netmask_interfaces.rb | 20 +++ .../facts/openbsd/network6_interfaces.rb | 20 +++ .../facts/openbsd/network_interfaces.rb | 20 +++ lib/facter/facts/openbsd/networking/dhcp.rb | 17 +++ lib/facter/facts/openbsd/networking/domain.rb | 18 +++ lib/facter/facts/openbsd/networking/fqdn.rb | 18 +++ .../facts/openbsd/networking/hostname.rb | 18 +++ .../facts/openbsd/networking/interfaces.rb | 17 +++ lib/facter/facts/openbsd/networking/ip.rb | 18 +++ lib/facter/facts/openbsd/networking/ip6.rb | 18 +++ lib/facter/facts/openbsd/networking/mac.rb | 18 +++ lib/facter/facts/openbsd/networking/mtu.rb | 17 +++ .../facts/openbsd/networking/netmask.rb | 18 +++ .../facts/openbsd/networking/netmask6.rb | 18 +++ .../facts/openbsd/networking/network.rb | 18 +++ .../facts/openbsd/networking/network6.rb | 18 +++ .../facts/openbsd/networking/primary.rb | 17 +++ lib/facter/facts/openbsd/networking/scope6.rb | 17 +++ lib/facter/facts/openbsd/os/architecture.rb | 18 +++ lib/facter/facts/openbsd/os/hardware.rb | 18 +++ lib/facter/facts/openbsd/os/name.rb | 18 +++ lib/facter/facts/openbsd/os/release.rb | 23 ++++ lib/facter/facts/openbsd/path.rb | 15 ++ lib/facter/facts/openbsd/processors/isa.rb | 17 +++ lib/facter/facts/openbsd/ruby/platform.rb | 18 +++ lib/facter/facts/openbsd/ruby/sitedir.rb | 18 +++ lib/facter/facts/openbsd/ruby/version.rb | 18 +++ lib/facter/facts/openbsd/ssh.rb | 26 ++++ lib/facter/facts/openbsd/sshalgorithmkey.rb | 17 +++ lib/facter/facts/openbsd/sshfp_algorithm.rb | 20 +++ .../facts/openbsd/system_uptime/days.rb | 18 +++ .../facts/openbsd/system_uptime/hours.rb | 18 +++ .../facts/openbsd/system_uptime/seconds.rb | 18 +++ .../facts/openbsd/system_uptime/uptime.rb | 18 +++ lib/facter/facts/openbsd/timezone.rb | 15 ++ lib/facter/facts/openbsd/virtual.rb | 15 ++ lib/facter/framework/core/file_loader.rb | 59 ++++++++ lib/facter/framework/detector/os_detector.rb | 2 + lib/facter/resolvers/openbsd/dhcp.rb | 21 +++ lib/facter/resolvers/openbsd/dmi.rb | 41 ++++++ lib/facter/resolvers/openbsd/mountpoints.rb | 72 ++++++++++ lib/facter/resolvers/openbsd/virtual.rb | 12 +- .../util/facts/posix/virtual_detector.rb | 8 +- .../facts/openbsd/augeas/version_spec.rb | 25 ++++ .../facts/openbsd/dmi/bios/vendor_spec.rb | 25 ++++ .../facts/openbsd/dmi/bios/version_spec.rb | 25 ++++ .../facts/openbsd/dmi/manufacturer_spec.rb | 25 ++++ .../facts/openbsd/dmi/product/name_spec.rb | 25 ++++ .../openbsd/dmi/product/serial_number_spec.rb | 40 ++++++ .../facts/openbsd/dmi/product/uuid_spec.rb | 25 ++++ .../facter/facts/openbsd/ec2_metadata_spec.rb | 79 +++++++++++ .../facter/facts/openbsd/ec2_userdata_spec.rb | 79 +++++++++++ .../facts/openbsd/facterversion_spec.rb | 23 ++++ .../facter/facts/openbsd/identity/gid_spec.rb | 23 ++++ .../facts/openbsd/identity/group_spec.rb | 24 ++++ .../facts/openbsd/identity/privileged_spec.rb | 23 ++++ .../facter/facts/openbsd/identity/uid_spec.rb | 23 ++++ .../facts/openbsd/identity/user_spec.rb | 24 ++++ .../openbsd/ipaddress6_interfaces_spec.rb | 34 +++++ .../openbsd/ipaddress_interfaces_spec.rb | 34 +++++ spec/facter/facts/openbsd/is_virtual_spec.rb | 33 +++++ spec/facter/facts/openbsd/kernel_spec.rb | 23 ++++ .../facts/openbsd/kernelrelease_spec.rb | 23 ++++ spec/facter/facts/openbsd/mountpoints_spec.rb | 62 +++++++++ .../facts/openbsd/netmask6_interfaces_spec.rb | 37 +++++ .../facts/openbsd/netmask_interfaces_spec.rb | 34 +++++ .../facts/openbsd/network6_interfaces_spec.rb | 34 +++++ .../facts/openbsd/network_interfaces_spec.rb | 34 +++++ .../facts/openbsd/networking/dhcp_spec.rb | 32 +++++ .../facts/openbsd/networking/domain_spec.rb | 34 +++++ .../facts/openbsd/networking/fqdn_spec.rb | 34 +++++ .../facts/openbsd/networking/hostname_spec.rb | 34 +++++ .../openbsd/networking/interfaces_spec.rb | 130 ++++++++++++++++++ .../facts/openbsd/networking/ip6_spec.rb | 34 +++++ .../facts/openbsd/networking/ip_spec.rb | 34 +++++ .../facts/openbsd/networking/mac_spec.rb | 34 +++++ .../facts/openbsd/networking/mtu_spec.rb | 32 +++++ .../facts/openbsd/networking/netmask6_spec.rb | 34 +++++ .../facts/openbsd/networking/netmask_spec.rb | 34 +++++ .../facts/openbsd/networking/network6_spec.rb | 34 +++++ .../facts/openbsd/networking/network_spec.rb | 34 +++++ .../facts/openbsd/networking/primary_spec.rb | 32 +++++ .../facts/openbsd/networking/scope6_spec.rb | 34 +++++ .../facts/openbsd/os/architecture_spec.rb | 24 ++++ spec/facter/facts/openbsd/os/hardware_spec.rb | 24 ++++ spec/facter/facts/openbsd/os/name_spec.rb | 24 ++++ spec/facter/facts/openbsd/os/release_spec.rb | 30 ++++ spec/facter/facts/openbsd/path_spec.rb | 24 ++++ .../facts/openbsd/processors/isa_spec.rb | 25 ++++ .../facts/openbsd/ruby/platform_spec.rb | 24 ++++ .../facter/facts/openbsd/ruby/sitedir_spec.rb | 24 ++++ .../facter/facts/openbsd/ruby/version_spec.rb | 25 ++++ spec/facter/facts/openbsd/ssh_spec.rb | 33 +++++ .../facts/openbsd/sshalgorithmkey_spec.rb | 32 +++++ .../facts/openbsd/sshfp_algorithm_spec.rb | 32 +++++ .../facts/openbsd/system_uptime/days_spec.rb | 24 ++++ .../facts/openbsd/system_uptime/hours_spec.rb | 24 ++++ .../openbsd/system_uptime/seconds_spec.rb | 24 ++++ .../openbsd/system_uptime/uptime_spec.rb | 24 ++++ spec/facter/facts/openbsd/timezone_spec.rb | 24 ++++ spec/facter/facts/openbsd/virtual_spec.rb | 35 +++++ .../facter/facts/openbsd/virtual_spec.rb.save | 35 +++++ .../facter/resolvers/openbsd/dmi_bios_spec.rb | 81 +++++++++++ .../resolvers/openbsd/mountpoints_spec.rb | 33 +++++ spec/facter/resolvers/openbsd/virtual_spec.rb | 34 ----- .../util/facts/posix/virtual_detector_spec.rb | 4 +- spec/fixtures/openbsd_df | 4 + spec/fixtures/openbsd_filesystems | 3 + 131 files changed, 3339 insertions(+), 44 deletions(-) create mode 100644 lib/facter/facts/openbsd/augeas/version.rb create mode 100644 lib/facter/facts/openbsd/dmi/bios/vendor.rb create mode 100644 lib/facter/facts/openbsd/dmi/bios/version.rb create mode 100644 lib/facter/facts/openbsd/dmi/manufacturer.rb create mode 100644 lib/facter/facts/openbsd/dmi/product/name.rb create mode 100644 lib/facter/facts/openbsd/dmi/product/serial_number.rb create mode 100644 lib/facter/facts/openbsd/dmi/product/uuid.rb create mode 100644 lib/facter/facts/openbsd/ec2_metadata.rb create mode 100644 lib/facter/facts/openbsd/ec2_userdata.rb create mode 100644 lib/facter/facts/openbsd/facterversion.rb create mode 100644 lib/facter/facts/openbsd/identity/gid.rb create mode 100644 lib/facter/facts/openbsd/identity/group.rb create mode 100644 lib/facter/facts/openbsd/identity/privileged.rb create mode 100644 lib/facter/facts/openbsd/identity/uid.rb create mode 100644 lib/facter/facts/openbsd/identity/user.rb create mode 100644 lib/facter/facts/openbsd/ipaddress6_interfaces.rb create mode 100644 lib/facter/facts/openbsd/ipaddress_interfaces.rb create mode 100644 lib/facter/facts/openbsd/is_virtual.rb create mode 100644 lib/facter/facts/openbsd/kernel.rb create mode 100644 lib/facter/facts/openbsd/kernelrelease.rb create mode 100644 lib/facter/facts/openbsd/mountpoints.rb create mode 100644 lib/facter/facts/openbsd/netmask6_interfaces.rb create mode 100644 lib/facter/facts/openbsd/netmask_interfaces.rb create mode 100644 lib/facter/facts/openbsd/network6_interfaces.rb create mode 100644 lib/facter/facts/openbsd/network_interfaces.rb create mode 100644 lib/facter/facts/openbsd/networking/dhcp.rb create mode 100644 lib/facter/facts/openbsd/networking/domain.rb create mode 100644 lib/facter/facts/openbsd/networking/fqdn.rb create mode 100644 lib/facter/facts/openbsd/networking/hostname.rb create mode 100644 lib/facter/facts/openbsd/networking/interfaces.rb create mode 100644 lib/facter/facts/openbsd/networking/ip.rb create mode 100644 lib/facter/facts/openbsd/networking/ip6.rb create mode 100644 lib/facter/facts/openbsd/networking/mac.rb create mode 100644 lib/facter/facts/openbsd/networking/mtu.rb create mode 100644 lib/facter/facts/openbsd/networking/netmask.rb create mode 100644 lib/facter/facts/openbsd/networking/netmask6.rb create mode 100644 lib/facter/facts/openbsd/networking/network.rb create mode 100644 lib/facter/facts/openbsd/networking/network6.rb create mode 100644 lib/facter/facts/openbsd/networking/primary.rb create mode 100644 lib/facter/facts/openbsd/networking/scope6.rb create mode 100644 lib/facter/facts/openbsd/os/architecture.rb create mode 100644 lib/facter/facts/openbsd/os/hardware.rb create mode 100644 lib/facter/facts/openbsd/os/name.rb create mode 100644 lib/facter/facts/openbsd/os/release.rb create mode 100644 lib/facter/facts/openbsd/path.rb create mode 100644 lib/facter/facts/openbsd/processors/isa.rb create mode 100644 lib/facter/facts/openbsd/ruby/platform.rb create mode 100644 lib/facter/facts/openbsd/ruby/sitedir.rb create mode 100644 lib/facter/facts/openbsd/ruby/version.rb create mode 100644 lib/facter/facts/openbsd/ssh.rb create mode 100644 lib/facter/facts/openbsd/sshalgorithmkey.rb create mode 100644 lib/facter/facts/openbsd/sshfp_algorithm.rb create mode 100644 lib/facter/facts/openbsd/system_uptime/days.rb create mode 100644 lib/facter/facts/openbsd/system_uptime/hours.rb create mode 100644 lib/facter/facts/openbsd/system_uptime/seconds.rb create mode 100644 lib/facter/facts/openbsd/system_uptime/uptime.rb create mode 100644 lib/facter/facts/openbsd/timezone.rb create mode 100644 lib/facter/facts/openbsd/virtual.rb create mode 100644 lib/facter/resolvers/openbsd/dhcp.rb create mode 100644 lib/facter/resolvers/openbsd/dmi.rb create mode 100644 lib/facter/resolvers/openbsd/mountpoints.rb create mode 100644 spec/facter/facts/openbsd/augeas/version_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/bios/vendor_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/bios/version_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/manufacturer_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/product/name_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/product/serial_number_spec.rb create mode 100644 spec/facter/facts/openbsd/dmi/product/uuid_spec.rb create mode 100644 spec/facter/facts/openbsd/ec2_metadata_spec.rb create mode 100644 spec/facter/facts/openbsd/ec2_userdata_spec.rb create mode 100644 spec/facter/facts/openbsd/facterversion_spec.rb create mode 100644 spec/facter/facts/openbsd/identity/gid_spec.rb create mode 100644 spec/facter/facts/openbsd/identity/group_spec.rb create mode 100644 spec/facter/facts/openbsd/identity/privileged_spec.rb create mode 100644 spec/facter/facts/openbsd/identity/uid_spec.rb create mode 100644 spec/facter/facts/openbsd/identity/user_spec.rb create mode 100644 spec/facter/facts/openbsd/ipaddress6_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/ipaddress_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/is_virtual_spec.rb create mode 100644 spec/facter/facts/openbsd/kernel_spec.rb create mode 100644 spec/facter/facts/openbsd/kernelrelease_spec.rb create mode 100644 spec/facter/facts/openbsd/mountpoints_spec.rb create mode 100644 spec/facter/facts/openbsd/netmask6_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/netmask_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/network6_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/network_interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/dhcp_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/domain_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/fqdn_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/hostname_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/interfaces_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/ip6_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/ip_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/mac_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/mtu_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/netmask6_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/netmask_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/network6_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/network_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/primary_spec.rb create mode 100644 spec/facter/facts/openbsd/networking/scope6_spec.rb create mode 100644 spec/facter/facts/openbsd/os/architecture_spec.rb create mode 100644 spec/facter/facts/openbsd/os/hardware_spec.rb create mode 100644 spec/facter/facts/openbsd/os/name_spec.rb create mode 100644 spec/facter/facts/openbsd/os/release_spec.rb create mode 100644 spec/facter/facts/openbsd/path_spec.rb create mode 100644 spec/facter/facts/openbsd/processors/isa_spec.rb create mode 100644 spec/facter/facts/openbsd/ruby/platform_spec.rb create mode 100644 spec/facter/facts/openbsd/ruby/sitedir_spec.rb create mode 100644 spec/facter/facts/openbsd/ruby/version_spec.rb create mode 100644 spec/facter/facts/openbsd/ssh_spec.rb create mode 100644 spec/facter/facts/openbsd/sshalgorithmkey_spec.rb create mode 100644 spec/facter/facts/openbsd/sshfp_algorithm_spec.rb create mode 100644 spec/facter/facts/openbsd/system_uptime/days_spec.rb create mode 100644 spec/facter/facts/openbsd/system_uptime/hours_spec.rb create mode 100644 spec/facter/facts/openbsd/system_uptime/seconds_spec.rb create mode 100644 spec/facter/facts/openbsd/system_uptime/uptime_spec.rb create mode 100644 spec/facter/facts/openbsd/timezone_spec.rb create mode 100644 spec/facter/facts/openbsd/virtual_spec.rb create mode 100644 spec/facter/facts/openbsd/virtual_spec.rb.save create mode 100644 spec/facter/resolvers/openbsd/dmi_bios_spec.rb create mode 100644 spec/facter/resolvers/openbsd/mountpoints_spec.rb delete mode 100644 spec/facter/resolvers/openbsd/virtual_spec.rb create mode 100644 spec/fixtures/openbsd_df create mode 100644 spec/fixtures/openbsd_filesystems diff --git a/lib/facter/config.rb b/lib/facter/config.rb index 2f236cb8c2..4ae2dc5d79 100644 --- a/lib/facter/config.rb +++ b/lib/facter/config.rb @@ -44,8 +44,9 @@ module Config ] }, { - 'Bsd' => [ - 'Freebsd' + 'Bsd' => %w[ + Freebsd + Openbsd ] }, 'Solaris', diff --git a/lib/facter/facts/openbsd/augeas/version.rb b/lib/facter/facts/openbsd/augeas/version.rb new file mode 100644 index 0000000000..50c31da1d1 --- /dev/null +++ b/lib/facter/facts/openbsd/augeas/version.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Augeas + class Version + FACT_NAME = 'augeas.version' + ALIASES = 'augeasversion' + + def call_the_resolver + fact_value = Facter::Resolvers::Augeas.resolve(:augeas_version) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), + Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/bios/vendor.rb b/lib/facter/facts/openbsd/dmi/bios/vendor.rb new file mode 100644 index 0000000000..46f084d9d0 --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/bios/vendor.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + module Bios + class Vendor + FACT_NAME = 'dmi.bios.vendor' + ALIASES = 'bios_vendor' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_vendor) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/bios/version.rb b/lib/facter/facts/openbsd/dmi/bios/version.rb new file mode 100644 index 0000000000..ed4d5a8ea2 --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/bios/version.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + module Bios + class Version + FACT_NAME = 'dmi.bios.version' + ALIASES = 'bios_version' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:bios_version) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/manufacturer.rb b/lib/facter/facts/openbsd/dmi/manufacturer.rb new file mode 100644 index 0000000000..b0b27499ee --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/manufacturer.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + class Manufacturer + FACT_NAME = 'dmi.manufacturer' + ALIASES = 'manufacturer' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:sys_vendor) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/product/name.rb b/lib/facter/facts/openbsd/dmi/product/name.rb new file mode 100644 index 0000000000..74f5759327 --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/product/name.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + module Product + class Name + FACT_NAME = 'dmi.product.name' + ALIASES = 'productname' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_name) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/product/serial_number.rb b/lib/facter/facts/openbsd/dmi/product/serial_number.rb new file mode 100644 index 0000000000..6927564f65 --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/product/serial_number.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + module Product + class SerialNumber + FACT_NAME = 'dmi.product.serial_number' + ALIASES = 'serialnumber' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_serial) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/dmi/product/uuid.rb b/lib/facter/facts/openbsd/dmi/product/uuid.rb new file mode 100644 index 0000000000..d990504d5a --- /dev/null +++ b/lib/facter/facts/openbsd/dmi/product/uuid.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Dmi + module Product + class Uuid + FACT_NAME = 'dmi.product.uuid' + ALIASES = 'uuid' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::DmiBios.resolve(:product_uuid) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ec2_metadata.rb b/lib/facter/facts/openbsd/ec2_metadata.rb new file mode 100644 index 0000000000..eadec9d1d7 --- /dev/null +++ b/lib/facter/facts/openbsd/ec2_metadata.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Ec2Metadata + FACT_NAME = 'ec2_metadata' + + def call_the_resolver + return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors? + + fact_value = Facter::Resolvers::Ec2.resolve(:metadata) + + Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value) + end + + private + + def aws_hypervisors? + Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/ + end + end + end +end diff --git a/lib/facter/facts/openbsd/ec2_userdata.rb b/lib/facter/facts/openbsd/ec2_userdata.rb new file mode 100644 index 0000000000..223eed91c4 --- /dev/null +++ b/lib/facter/facts/openbsd/ec2_userdata.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Ec2Userdata + FACT_NAME = 'ec2_userdata' + + def call_the_resolver + return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors? + + fact_value = Facter::Resolvers::Ec2.resolve(:userdata) + + Facter::ResolvedFact.new(FACT_NAME, fact_value&.empty? ? nil : fact_value) + end + + private + + def aws_hypervisors? + Facter::Util::Facts::Posix::VirtualDetector.platform =~ /kvm|xen|aws/ + end + end + end +end diff --git a/lib/facter/facts/openbsd/facterversion.rb b/lib/facter/facts/openbsd/facterversion.rb new file mode 100644 index 0000000000..1cf7baeb1d --- /dev/null +++ b/lib/facter/facts/openbsd/facterversion.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Facterversion + FACT_NAME = 'facterversion' + + def call_the_resolver + fact_value = Facter::Resolvers::Facterversion.resolve(:facterversion) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/facts/openbsd/identity/gid.rb b/lib/facter/facts/openbsd/identity/gid.rb new file mode 100644 index 0000000000..cdb2e604ac --- /dev/null +++ b/lib/facter/facts/openbsd/identity/gid.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Identity + class Gid + FACT_NAME = 'identity.gid' + + def call_the_resolver + fact_value = Facter::Resolvers::PosxIdentity.resolve(:gid) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/identity/group.rb b/lib/facter/facts/openbsd/identity/group.rb new file mode 100644 index 0000000000..6b6b67dad9 --- /dev/null +++ b/lib/facter/facts/openbsd/identity/group.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Identity + class Group + FACT_NAME = 'identity.group' + ALIASES = 'gid' + + def call_the_resolver + fact_value = Facter::Resolvers::PosxIdentity.resolve(:group) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/identity/privileged.rb b/lib/facter/facts/openbsd/identity/privileged.rb new file mode 100644 index 0000000000..bf1d47fc5d --- /dev/null +++ b/lib/facter/facts/openbsd/identity/privileged.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Identity + class Privileged + FACT_NAME = 'identity.privileged' + + def call_the_resolver + fact_value = Facter::Resolvers::PosxIdentity.resolve(:privileged) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/identity/uid.rb b/lib/facter/facts/openbsd/identity/uid.rb new file mode 100644 index 0000000000..b19fdb3ad8 --- /dev/null +++ b/lib/facter/facts/openbsd/identity/uid.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Identity + class Uid + FACT_NAME = 'identity.uid' + + def call_the_resolver + fact_value = Facter::Resolvers::PosxIdentity.resolve(:uid) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/identity/user.rb b/lib/facter/facts/openbsd/identity/user.rb new file mode 100644 index 0000000000..21181ccddc --- /dev/null +++ b/lib/facter/facts/openbsd/identity/user.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Identity + class User + FACT_NAME = 'identity.user' + ALIASES = 'id' + + def call_the_resolver + fact_value = Facter::Resolvers::PosxIdentity.resolve(:user) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ipaddress6_interfaces.rb b/lib/facter/facts/openbsd/ipaddress6_interfaces.rb new file mode 100644 index 0000000000..fad08d2466 --- /dev/null +++ b/lib/facter/facts/openbsd/ipaddress6_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Ipaddress6Interfaces + FACT_NAME = 'ipaddress6_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("ipaddress6_#{interface_name}", info[:ip6], :legacy) if info[:ip6] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/ipaddress_interfaces.rb b/lib/facter/facts/openbsd/ipaddress_interfaces.rb new file mode 100644 index 0000000000..c2f8e947b0 --- /dev/null +++ b/lib/facter/facts/openbsd/ipaddress_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class IpaddressInterfaces + FACT_NAME = 'ipaddress_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("ipaddress_#{interface_name}", info[:ip], :legacy) if info[:ip] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/is_virtual.rb b/lib/facter/facts/openbsd/is_virtual.rb new file mode 100644 index 0000000000..0ee5f01007 --- /dev/null +++ b/lib/facter/facts/openbsd/is_virtual.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class IsVirtual + FACT_NAME = 'is_virtual' + + def call_the_resolver + fact_value = Facter::Util::Facts::Posix::VirtualDetector.platform + + Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value)) + end + + private + + def check_if_virtual(found_vm) + Facter::Util::Facts::PHYSICAL_HYPERVISORS.count(found_vm).zero? + end + end + end +end diff --git a/lib/facter/facts/openbsd/kernel.rb b/lib/facter/facts/openbsd/kernel.rb new file mode 100644 index 0000000000..cb5a9e8ada --- /dev/null +++ b/lib/facter/facts/openbsd/kernel.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Kernel + FACT_NAME = 'kernel' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:kernelname) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/facts/openbsd/kernelrelease.rb b/lib/facter/facts/openbsd/kernelrelease.rb new file mode 100644 index 0000000000..eaee8fbdc6 --- /dev/null +++ b/lib/facter/facts/openbsd/kernelrelease.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Kernelrelease + FACT_NAME = 'kernelrelease' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:kernelrelease) + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/facts/openbsd/mountpoints.rb b/lib/facter/facts/openbsd/mountpoints.rb new file mode 100644 index 0000000000..57b5577cf3 --- /dev/null +++ b/lib/facter/facts/openbsd/mountpoints.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Mountpoints + FACT_NAME = 'mountpoints' + + def call_the_resolver + mountpoints = Facter::Resolvers::Openbsd::Mountpoints.resolve(FACT_NAME.to_sym) + return Facter::ResolvedFact.new(FACT_NAME, nil) unless mountpoints + + fact = {} + mountpoints.each do |path, mnt| + fact[path.to_sym] = mnt.reject { |k| k == :path } + end + + Facter::ResolvedFact.new(FACT_NAME, fact) + end + end + end +end diff --git a/lib/facter/facts/openbsd/netmask6_interfaces.rb b/lib/facter/facts/openbsd/netmask6_interfaces.rb new file mode 100644 index 0000000000..5c39957fca --- /dev/null +++ b/lib/facter/facts/openbsd/netmask6_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Netmask6Interfaces + FACT_NAME = 'netmask6_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("netmask6_#{interface_name}", info[:netmask6], :legacy) if info[:netmask6] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/netmask_interfaces.rb b/lib/facter/facts/openbsd/netmask_interfaces.rb new file mode 100644 index 0000000000..bdfe39168a --- /dev/null +++ b/lib/facter/facts/openbsd/netmask_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class NetmaskInterfaces + FACT_NAME = 'netmask_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("netmask_#{interface_name}", info[:netmask], :legacy) if info[:netmask] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/network6_interfaces.rb b/lib/facter/facts/openbsd/network6_interfaces.rb new file mode 100644 index 0000000000..9756905f72 --- /dev/null +++ b/lib/facter/facts/openbsd/network6_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Network6Interfaces + FACT_NAME = 'network6_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("network6_#{interface_name}", info[:network6], :legacy) if info[:network6] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/network_interfaces.rb b/lib/facter/facts/openbsd/network_interfaces.rb new file mode 100644 index 0000000000..28c099f6ce --- /dev/null +++ b/lib/facter/facts/openbsd/network_interfaces.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class NetworkInterfaces + FACT_NAME = 'network_.*' + TYPE = :legacy + + def call_the_resolver + arr = [] + interfaces = Facter::Resolvers::Networking.resolve(:interfaces) + interfaces&.each do |interface_name, info| + arr << Facter::ResolvedFact.new("network_#{interface_name}", info[:network], :legacy) if info[:network] + end + + arr + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/dhcp.rb b/lib/facter/facts/openbsd/networking/dhcp.rb new file mode 100644 index 0000000000..84c073f470 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/dhcp.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Dhcp + FACT_NAME = 'networking.dhcp' + + def call_the_resolver + fact_value = Facter::Resolvers::Openbsd::Dhcp.resolve(:dhcp) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/domain.rb b/lib/facter/facts/openbsd/networking/domain.rb new file mode 100644 index 0000000000..02304e3f15 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/domain.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Domain + FACT_NAME = 'networking.domain' + ALIASES = 'domain' + + def call_the_resolver + fact_value = Facter::Resolvers::Hostname.resolve(:domain) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/fqdn.rb b/lib/facter/facts/openbsd/networking/fqdn.rb new file mode 100644 index 0000000000..fbf2810fe5 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/fqdn.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Fqdn + FACT_NAME = 'networking.fqdn' + ALIASES = 'fqdn' + + def call_the_resolver + fact_value = Facter::Resolvers::Hostname.resolve(:fqdn) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/hostname.rb b/lib/facter/facts/openbsd/networking/hostname.rb new file mode 100644 index 0000000000..ec7592a7e0 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/hostname.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Hostname + FACT_NAME = 'networking.hostname' + ALIASES = 'hostname' + + def call_the_resolver + fact_value = Facter::Resolvers::Hostname.resolve(:hostname) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/interfaces.rb b/lib/facter/facts/openbsd/networking/interfaces.rb new file mode 100644 index 0000000000..bfc80d0e2b --- /dev/null +++ b/lib/facter/facts/openbsd/networking/interfaces.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Interfaces + FACT_NAME = 'networking.interfaces' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:interfaces) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/ip.rb b/lib/facter/facts/openbsd/networking/ip.rb new file mode 100644 index 0000000000..67fdbc04a8 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/ip.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Ip + FACT_NAME = 'networking.ip' + ALIASES = 'ipaddress' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:ip) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/ip6.rb b/lib/facter/facts/openbsd/networking/ip6.rb new file mode 100644 index 0000000000..9a01fd9e3f --- /dev/null +++ b/lib/facter/facts/openbsd/networking/ip6.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Ip6 + FACT_NAME = 'networking.ip6' + ALIASES = 'ipaddress6' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:ip6) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/mac.rb b/lib/facter/facts/openbsd/networking/mac.rb new file mode 100644 index 0000000000..7e5ada8673 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/mac.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Mac + FACT_NAME = 'networking.mac' + ALIASES = 'macaddress' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:mac) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/mtu.rb b/lib/facter/facts/openbsd/networking/mtu.rb new file mode 100644 index 0000000000..0403f663e8 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/mtu.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Mtu + FACT_NAME = 'networking.mtu' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:mtu) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/netmask.rb b/lib/facter/facts/openbsd/networking/netmask.rb new file mode 100644 index 0000000000..cac415d80a --- /dev/null +++ b/lib/facter/facts/openbsd/networking/netmask.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Netmask + FACT_NAME = 'networking.netmask' + ALIASES = 'netmask' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:netmask) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/netmask6.rb b/lib/facter/facts/openbsd/networking/netmask6.rb new file mode 100644 index 0000000000..f14884831c --- /dev/null +++ b/lib/facter/facts/openbsd/networking/netmask6.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Netmask6 + FACT_NAME = 'networking.netmask6' + ALIASES = 'netmask6' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:netmask6) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/network.rb b/lib/facter/facts/openbsd/networking/network.rb new file mode 100644 index 0000000000..eba2a57e1d --- /dev/null +++ b/lib/facter/facts/openbsd/networking/network.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Network + FACT_NAME = 'networking.network' + ALIASES = 'network' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:network) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/network6.rb b/lib/facter/facts/openbsd/networking/network6.rb new file mode 100644 index 0000000000..4de2b96e2a --- /dev/null +++ b/lib/facter/facts/openbsd/networking/network6.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Network6 + FACT_NAME = 'networking.network6' + ALIASES = 'network6' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:network6) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/primary.rb b/lib/facter/facts/openbsd/networking/primary.rb new file mode 100644 index 0000000000..4c59b07bb7 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/primary.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Primary + FACT_NAME = 'networking.primary' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:primary_interface) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/networking/scope6.rb b/lib/facter/facts/openbsd/networking/scope6.rb new file mode 100644 index 0000000000..08ad8f43c2 --- /dev/null +++ b/lib/facter/facts/openbsd/networking/scope6.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Networking + class Scope6 + FACT_NAME = 'networking.scope6' + + def call_the_resolver + fact_value = Facter::Resolvers::Networking.resolve(:scope6) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/os/architecture.rb b/lib/facter/facts/openbsd/os/architecture.rb new file mode 100644 index 0000000000..cba807dfa9 --- /dev/null +++ b/lib/facter/facts/openbsd/os/architecture.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Os + class Architecture + FACT_NAME = 'os.architecture' + ALIASES = 'architecture' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:machine) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/os/hardware.rb b/lib/facter/facts/openbsd/os/hardware.rb new file mode 100644 index 0000000000..f44046709e --- /dev/null +++ b/lib/facter/facts/openbsd/os/hardware.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Os + class Hardware + FACT_NAME = 'os.hardware' + ALIASES = 'hardwaremodel' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:machine) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/os/name.rb b/lib/facter/facts/openbsd/os/name.rb new file mode 100644 index 0000000000..dd877e59bf --- /dev/null +++ b/lib/facter/facts/openbsd/os/name.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Os + class Name + FACT_NAME = 'os.name' + ALIASES = 'operatingsystem' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:kernelname) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/os/release.rb b/lib/facter/facts/openbsd/os/release.rb new file mode 100644 index 0000000000..618b1b4bc3 --- /dev/null +++ b/lib/facter/facts/openbsd/os/release.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Os + class Release + FACT_NAME = 'os.release' + ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze + + def call_the_resolver + # From Freebsd + # Facter::ResolvedFact.new(ALIASES.last, installed_userland, :legacy)] + + version = Facter::Resolvers::Uname.resolve(:kernelrelease) + major, minor = version.split('.') + [Facter::ResolvedFact.new(FACT_NAME, full: version, major: major, minor: minor), + Facter::ResolvedFact.new(ALIASES.first, major, :legacy), + Facter::ResolvedFact.new(ALIASES.last, version, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/path.rb b/lib/facter/facts/openbsd/path.rb new file mode 100644 index 0000000000..9fae66bbe0 --- /dev/null +++ b/lib/facter/facts/openbsd/path.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Path + FACT_NAME = 'path' + + def call_the_resolver + fact_value = Facter::Resolvers::Path.resolve(:path) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/facts/openbsd/processors/isa.rb b/lib/facter/facts/openbsd/processors/isa.rb new file mode 100644 index 0000000000..fa1f4da68f --- /dev/null +++ b/lib/facter/facts/openbsd/processors/isa.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Processors + class Isa + FACT_NAME = 'processors.isa' + ALIASES = 'hardwareisa' + + def call_the_resolver + fact_value = Facter::Resolvers::Uname.resolve(:processor) + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ruby/platform.rb b/lib/facter/facts/openbsd/ruby/platform.rb new file mode 100644 index 0000000000..2ccce2908d --- /dev/null +++ b/lib/facter/facts/openbsd/ruby/platform.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Ruby + class Platform + FACT_NAME = 'ruby.platform' + ALIASES = 'rubyplatform' + + def call_the_resolver + fact_value = Facter::Resolvers::Ruby.resolve(:platform) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ruby/sitedir.rb b/lib/facter/facts/openbsd/ruby/sitedir.rb new file mode 100644 index 0000000000..ac1cce45bc --- /dev/null +++ b/lib/facter/facts/openbsd/ruby/sitedir.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Ruby + class Sitedir + FACT_NAME = 'ruby.sitedir' + ALIASES = 'rubysitedir' + + def call_the_resolver + fact_value = Facter::Resolvers::Ruby.resolve(:sitedir) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ruby/version.rb b/lib/facter/facts/openbsd/ruby/version.rb new file mode 100644 index 0000000000..c5f74ece8d --- /dev/null +++ b/lib/facter/facts/openbsd/ruby/version.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module Ruby + class Version + FACT_NAME = 'ruby.version' + ALIASES = 'rubyversion' + + def call_the_resolver + fact_value = Facter::Resolvers::Ruby.resolve(:version) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/ssh.rb b/lib/facter/facts/openbsd/ssh.rb new file mode 100644 index 0000000000..74b93c09f2 --- /dev/null +++ b/lib/facter/facts/openbsd/ssh.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Ssh + FACT_NAME = 'ssh' + + def call_the_resolver + result = Facter::Resolvers::Ssh.resolve(:ssh) + ssh_facts = {} + result.each { |ssh| ssh_facts.merge!(create_ssh_fact(ssh)) } + Facter::ResolvedFact.new(FACT_NAME, ssh_facts) + end + + private + + def create_ssh_fact(ssh) + { ssh.name.to_sym => + { fingerprints: { sha1: ssh.fingerprint.sha1, + sha256: ssh.fingerprint.sha256 }, + key: ssh.key, + type: ssh.type } } + end + end + end +end diff --git a/lib/facter/facts/openbsd/sshalgorithmkey.rb b/lib/facter/facts/openbsd/sshalgorithmkey.rb new file mode 100644 index 0000000000..3fda0c5653 --- /dev/null +++ b/lib/facter/facts/openbsd/sshalgorithmkey.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Sshalgorithmkey + FACT_NAME = 'ssh.*key' + TYPE = :legacy + + def call_the_resolver + facts = [] + result = Facter::Resolvers::Ssh.resolve(:ssh) + result.each { |ssh| facts << Facter::ResolvedFact.new("ssh#{ssh.name.to_sym}key", ssh.key, :legacy) } + facts + end + end + end +end diff --git a/lib/facter/facts/openbsd/sshfp_algorithm.rb b/lib/facter/facts/openbsd/sshfp_algorithm.rb new file mode 100644 index 0000000000..d9da6cc990 --- /dev/null +++ b/lib/facter/facts/openbsd/sshfp_algorithm.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class SshfpAlgorithm + FACT_NAME = 'sshfp_.*' + TYPE = :legacy + + def call_the_resolver + facts = [] + result = Facter::Resolvers::Ssh.resolve(:ssh) + result.each do |ssh| + facts << Facter::ResolvedFact.new("sshfp_#{ssh.name.to_sym}", + "#{ssh.fingerprint.sha1}\n#{ssh.fingerprint.sha256}", :legacy) + end + facts + end + end + end +end diff --git a/lib/facter/facts/openbsd/system_uptime/days.rb b/lib/facter/facts/openbsd/system_uptime/days.rb new file mode 100644 index 0000000000..e76608b1bb --- /dev/null +++ b/lib/facter/facts/openbsd/system_uptime/days.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module SystemUptime + class Days + FACT_NAME = 'system_uptime.days' + ALIASES = 'uptime_days' + + def call_the_resolver + fact_value = Facter::Resolvers::Uptime.resolve(:days) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/system_uptime/hours.rb b/lib/facter/facts/openbsd/system_uptime/hours.rb new file mode 100644 index 0000000000..cc5c3485cb --- /dev/null +++ b/lib/facter/facts/openbsd/system_uptime/hours.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module SystemUptime + class Hours + FACT_NAME = 'system_uptime.hours' + ALIASES = 'uptime_hours' + + def call_the_resolver + fact_value = Facter::Resolvers::Uptime.resolve(:hours) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/system_uptime/seconds.rb b/lib/facter/facts/openbsd/system_uptime/seconds.rb new file mode 100644 index 0000000000..3795c1419d --- /dev/null +++ b/lib/facter/facts/openbsd/system_uptime/seconds.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module SystemUptime + class Seconds + FACT_NAME = 'system_uptime.seconds' + ALIASES = 'uptime_seconds' + + def call_the_resolver + fact_value = Facter::Resolvers::Uptime.resolve(:seconds) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/system_uptime/uptime.rb b/lib/facter/facts/openbsd/system_uptime/uptime.rb new file mode 100644 index 0000000000..5e640b9ee4 --- /dev/null +++ b/lib/facter/facts/openbsd/system_uptime/uptime.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + module SystemUptime + class Uptime + FACT_NAME = 'system_uptime.uptime' + ALIASES = 'uptime' + + def call_the_resolver + fact_value = Facter::Resolvers::Uptime.resolve(:uptime) + + [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] + end + end + end + end +end diff --git a/lib/facter/facts/openbsd/timezone.rb b/lib/facter/facts/openbsd/timezone.rb new file mode 100644 index 0000000000..bb2c8f191c --- /dev/null +++ b/lib/facter/facts/openbsd/timezone.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Timezone + FACT_NAME = 'timezone' + + def call_the_resolver + fact_value = Facter::Resolvers::Timezone.resolve(:timezone) + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/facts/openbsd/virtual.rb b/lib/facter/facts/openbsd/virtual.rb new file mode 100644 index 0000000000..2649d64978 --- /dev/null +++ b/lib/facter/facts/openbsd/virtual.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Facts + module Openbsd + class Virtual + FACT_NAME = 'virtual' + + def call_the_resolver + fact_value = Facter::Util::Facts::Posix::VirtualDetector.platform + + Facter::ResolvedFact.new(FACT_NAME, fact_value) + end + end + end +end diff --git a/lib/facter/framework/core/file_loader.rb b/lib/facter/framework/core/file_loader.rb index 8aa07a1fec..22e3d17a88 100644 --- a/lib/facter/framework/core/file_loader.rb +++ b/lib/facter/framework/core/file_loader.rb @@ -650,6 +650,65 @@ require_relative '../../facts/ol/os/distro/description' require_relative '../../facts/ol/os/distro/id' + when 'openbsd' + require_relative '../../facts/openbsd/augeas/version' + require_relative '../../facts/openbsd/ec2_metadata' + require_relative '../../facts/openbsd/ec2_userdata' + require_relative '../../facts/openbsd/facterversion' + require_relative '../../facts/openbsd/is_virtual' + require_relative '../../facts/openbsd/kernel' + require_relative '../../facts/openbsd/kernelrelease' + require_relative '../../facts/openbsd/mountpoints' + require_relative '../../facts/openbsd/path' + require_relative '../../facts/openbsd/ssh' + require_relative '../../facts/openbsd/sshalgorithmkey' + require_relative '../../facts/openbsd/sshfp_algorithm' + require_relative '../../facts/openbsd/timezone' + require_relative '../../facts/openbsd/virtual' + require_relative '../../facts/openbsd/dmi/bios/vendor' + require_relative '../../facts/openbsd/dmi/bios/version' + require_relative '../../facts/openbsd/dmi/manufacturer' + require_relative '../../facts/openbsd/dmi/product/name' + require_relative '../../facts/openbsd/dmi/product/serial_number' + require_relative '../../facts/openbsd/dmi/product/uuid' + require_relative '../../facts/openbsd/identity/group' + require_relative '../../facts/openbsd/identity/gid' + require_relative '../../facts/openbsd/identity/privileged' + require_relative '../../facts/openbsd/identity/uid' + require_relative '../../facts/openbsd/identity/user' + require_relative '../../facts/openbsd/networking/dhcp' + require_relative '../../facts/openbsd/networking/domain' + require_relative '../../facts/openbsd/networking/fqdn' + require_relative '../../facts/openbsd/networking/hostname' + require_relative '../../facts/openbsd/networking/interfaces' + require_relative '../../facts/openbsd/networking/ip' + require_relative '../../facts/openbsd/networking/ip6' + require_relative '../../facts/openbsd/networking/mac' + require_relative '../../facts/openbsd/networking/mtu' + require_relative '../../facts/openbsd/networking/netmask' + require_relative '../../facts/openbsd/networking/netmask6' + require_relative '../../facts/openbsd/networking/network' + require_relative '../../facts/openbsd/networking/network6' + require_relative '../../facts/openbsd/networking/primary' + require_relative '../../facts/openbsd/networking/scope6' + require_relative '../../facts/openbsd/os/architecture' + require_relative '../../facts/openbsd/os/hardware' + require_relative '../../facts/openbsd/os/name' + require_relative '../../facts/openbsd/os/release' + require_relative '../../facts/openbsd/processors/isa' + require_relative '../../facts/openbsd/ruby/platform' + require_relative '../../facts/openbsd/ruby/sitedir' + require_relative '../../facts/openbsd/ruby/version' + require_relative '../../facts/openbsd/system_uptime/days' + require_relative '../../facts/openbsd/system_uptime/hours' + require_relative '../../facts/openbsd/system_uptime/seconds' + require_relative '../../facts/openbsd/system_uptime/uptime' + + require_relative '../../resolvers/openbsd/dhcp' + require_relative '../../resolvers/openbsd/dmi' + require_relative '../../resolvers/openbsd/mountpoints' + require_relative '../../resolvers/openbsd/virtual' + when 'openwrt' require_relative '../../facts/openwrt/os/release' diff --git a/lib/facter/framework/detector/os_detector.rb b/lib/facter/framework/detector/os_detector.rb index 95e54346b2..4b0e9f5640 100644 --- a/lib/facter/framework/detector/os_detector.rb +++ b/lib/facter/framework/detector/os_detector.rb @@ -26,6 +26,8 @@ def detect detect_distro when /freebsd/ :freebsd + when /openbsd/i + :openbsd when /bsd/ :bsd when /solaris/ diff --git a/lib/facter/resolvers/openbsd/dhcp.rb b/lib/facter/resolvers/openbsd/dhcp.rb new file mode 100644 index 0000000000..3a311bb91d --- /dev/null +++ b/lib/facter/resolvers/openbsd/dhcp.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../networking' + +module Facter + module Resolvers + module Openbsd + class Dhcp < Facter::Resolvers::Networking + init_resolver + class << self + def extract_dhcp(interface_name, raw_data, parsed_interface_data) + return unless raw_data.match?(/status:\s+active/) + + result = Facter::Core::Execution.execute("dhcpleasectl -l #{interface_name}", logger: log) + parsed_interface_data[:dhcp] = extract_values(result, /\sdhcp server (\S+)/).first unless result.empty? + end + end + end + end + end +end diff --git a/lib/facter/resolvers/openbsd/dmi.rb b/lib/facter/resolvers/openbsd/dmi.rb new file mode 100644 index 0000000000..d17fab47ed --- /dev/null +++ b/lib/facter/resolvers/openbsd/dmi.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Facter + module Resolvers + module Openbsd + class DmiBios < BaseResolver + init_resolver + + class << self + private + + def post_resolve(fact_name, _options) + @fact_list.fetch(fact_name) { read_facts(fact_name) } + end + + CTL_HW = 6 + HW_VENDOR = 14 + HW_PRODUCT = 15 + HW_VERSION = 16 + HW_SERIALNO = 17 + HW_UUID = 18 + + def read_facts(fact_name) + require 'facter/resolvers/bsd/ffi/ffi_helper' + + @fact_list[:bios_vendor] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_VENDOR]) + @fact_list[:bios_version] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_VERSION]) + + @fact_list[:product_name] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_PRODUCT]) + @fact_list[:product_serial] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_SERIALNO]) + @fact_list[:product_uuid] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_UUID]) + + @fact_list[:sys_vendor] = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_VENDOR]) + + @fact_list[fact_name] + end + end + end + end + end +end diff --git a/lib/facter/resolvers/openbsd/mountpoints.rb b/lib/facter/resolvers/openbsd/mountpoints.rb new file mode 100644 index 0000000000..379472176b --- /dev/null +++ b/lib/facter/resolvers/openbsd/mountpoints.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module Facter + module Resolvers + module Openbsd + class Mountpoints < BaseResolver + init_resolver + + BLOCK_SIZE = 512 + + class << self + private + + def post_resolve(fact_name, _options) + @fact_list.fetch(fact_name) { read_mount(fact_name) } + end + + def read_mount(fact_name) + @fact_list[:mountpoints] = {} + output = Facter::Core::Execution.execute('mount', logger: log) + output.split("\n").map do |line| + add_mount_points_fact(line) + end + + retrieve_sizes_for_mounts + @fact_list[fact_name] + end + + def add_mount_points_fact(line) + elem = line.split("\s") + options = elem.drop(5) + options.each { |option| option.tr!('(),', '') } + @fact_list[:mountpoints][elem[2]] = { device: elem[0], filesystem: elem[4], + options: options } + end + + def retrieve_sizes_for_mounts + output = Facter::Core::Execution.execute('df -P', logger: log) + output.split("\n").drop(1).map do |line| + next if line.match?(/-\s+-\s+-/) + + mount_info = line.split("\s") + mount_info[3] = translate_to_bytes(mount_info[3]) + mount_info[2] = translate_to_bytes(mount_info[2]) + mount_info[1] = translate_to_bytes(mount_info[1]) + compute_sizes(mount_info) + end + end + + def translate_to_bytes(strin_size) + strin_size.to_i * BLOCK_SIZE + end + + def compute_sizes(info) + available_bytes = info[3] + used_bytes = info[2] + size_bytes = info[1] + @fact_list[:mountpoints][info.last].merge!( + capacity: Facter::Util::Resolvers::FilesystemHelper.compute_capacity(used_bytes, size_bytes), + available_bytes: available_bytes, + used_bytes: used_bytes, + size_bytes: size_bytes, + available: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes), + used: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes), + size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes) + ) + end + end + end + end + end +end diff --git a/lib/facter/resolvers/openbsd/virtual.rb b/lib/facter/resolvers/openbsd/virtual.rb index 50e8cd93cb..5b1cc32dce 100644 --- a/lib/facter/resolvers/openbsd/virtual.rb +++ b/lib/facter/resolvers/openbsd/virtual.rb @@ -7,7 +7,7 @@ class Virtual < BaseResolver init_resolver class << self - #:model + # :model VM_GUEST_SYSCTL_NAMES = { 'VMM' => 'vmm', @@ -30,11 +30,11 @@ def read_facts(fact_name) require 'facter/resolvers/bsd/ffi/ffi_helper' vm = Facter::Bsd::FfiHelper.sysctl(:string, [CTL_HW, HW_PRODUCT]) - if VM_GUEST_SYSCTL_NAMES.key?(vm) - vm = VM_GUEST_SYSCTL_NAMES[vm] - else - vm = "physical" - end + vm = if VM_GUEST_SYSCTL_NAMES.key?(vm) + VM_GUEST_SYSCTL_NAMES[vm] + else + 'physical' + end @fact_list[:vm] = vm @fact_list[fact_name] end diff --git a/lib/facter/util/facts/posix/virtual_detector.rb b/lib/facter/util/facts/posix/virtual_detector.rb index ff2c56a6f7..cc4ba11b70 100644 --- a/lib/facter/util/facts/posix/virtual_detector.rb +++ b/lib/facter/util/facts/posix/virtual_detector.rb @@ -8,7 +8,7 @@ module VirtualDetector class << self def platform @fact_value ||= # rubocop:disable Naming/MemoizedInstanceVariableName - check_docker_lxc || check_freebsd || check_gce || check_illumos_lx || \ + check_docker_lxc || check_freebsd || check_openbsd || check_gce || check_illumos_lx || \ retrieve_from_virt_what || check_vmware || check_open_vz || check_vserver || \ check_xen || check_other_facts || check_lspci || 'physical' end @@ -54,6 +54,12 @@ def check_freebsd Facter::Resolvers::Freebsd::Virtual.resolve(:vm) end + def check_openbsd + return unless Object.const_defined?('Facter::Resolvers::Openbsd::Virtual') + + Facter::Resolvers::Openbsd::Virtual.resolve(:vm) + end + def check_other_facts bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor) return 'kvm' if bios_vendor&.include?('Amazon EC2') diff --git a/spec/facter/facts/openbsd/augeas/version_spec.rb b/spec/facter/facts/openbsd/augeas/version_spec.rb new file mode 100644 index 0000000000..405c746e6e --- /dev/null +++ b/spec/facter/facts/openbsd/augeas/version_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Augeas::Version do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Augeas::Version.new } + + let(:version) { '1.12.0' } + + before do + allow(Facter::Resolvers::Augeas).to \ + receive(:resolve).with(:augeas_version).and_return(version) + end + + it 'calls Facter::Resolvers::Augeas' do + fact.call_the_resolver + expect(Facter::Resolvers::Augeas).to have_received(:resolve).with(:augeas_version) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'augeas.version', value: version), + an_object_having_attributes(name: 'augeasversion', value: version, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/bios/vendor_spec.rb b/spec/facter/facts/openbsd/dmi/bios/vendor_spec.rb new file mode 100644 index 0000000000..23d0d77d43 --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/bios/vendor_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Bios::Vendor do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Bios::Vendor.new } + + let(:vendor) { 'Phoenix Technologies LTD' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:bios_vendor).and_return(vendor) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:bios_vendor) + end + + it 'returns bios vendor fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.bios.vendor', value: vendor), + an_object_having_attributes(name: 'bios_vendor', value: vendor, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/bios/version_spec.rb b/spec/facter/facts/openbsd/dmi/bios/version_spec.rb new file mode 100644 index 0000000000..2fd4e162e7 --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/bios/version_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Bios::Version do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Bios::Version.new } + + let(:version) { '6.00' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:bios_version).and_return(version) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:bios_version) + end + + it 'returns bios version fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.bios.version', value: version), + an_object_having_attributes(name: 'bios_version', value: version, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/manufacturer_spec.rb b/spec/facter/facts/openbsd/dmi/manufacturer_spec.rb new file mode 100644 index 0000000000..874fa54196 --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/manufacturer_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Manufacturer do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Manufacturer.new } + + let(:sys_vendor) { 'OpenBSD' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:sys_vendor).and_return(sys_vendor) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:sys_vendor) + end + + it 'returns manufacturer fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.manufacturer', value: sys_vendor), + an_object_having_attributes(name: 'manufacturer', value: sys_vendor, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/product/name_spec.rb b/spec/facter/facts/openbsd/dmi/product/name_spec.rb new file mode 100644 index 0000000000..cbf6a668fb --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/product/name_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Product::Name do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Product::Name.new } + + let(:product_name) { 'VMM' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:product_name).and_return(product_name) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:product_name) + end + + it 'returns product name fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.product.name', value: product_name), + an_object_having_attributes(name: 'productname', value: product_name, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/product/serial_number_spec.rb b/spec/facter/facts/openbsd/dmi/product/serial_number_spec.rb new file mode 100644 index 0000000000..444cb102be --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/product/serial_number_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Product::SerialNumber do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Product::SerialNumber.new } + + context 'when resolver returns serial number' do + let(:serial_number) { '17425315' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:product_serial).and_return(serial_number) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:product_serial) + end + + it 'returns resolved facts' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.product.serial_number', value: serial_number), + an_object_having_attributes(name: 'serialnumber', value: serial_number, type: :legacy)) + end + end + + context 'when resolver returns nil' do + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:product_serial).and_return(nil) + end + + it 'returns serial information' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.product.serial_number', value: nil), + an_object_having_attributes(name: 'serialnumber', value: nil, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/dmi/product/uuid_spec.rb b/spec/facter/facts/openbsd/dmi/product/uuid_spec.rb new file mode 100644 index 0000000000..d558e9809f --- /dev/null +++ b/spec/facter/facts/openbsd/dmi/product/uuid_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Dmi::Product::Uuid do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Dmi::Product::Uuid.new } + + let(:product_uuid) { '421aa929-318f-fae9-7d69-2e2321b00c45' } + + before do + allow(Facter::Resolvers::Openbsd::DmiBios).to \ + receive(:resolve).with(:product_uuid).and_return(product_uuid) + end + + it 'calls Facter::Resolvers::Openbsd::DmiBios' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::DmiBios).to have_received(:resolve).with(:product_uuid) + end + + it 'returns resolved facts' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'dmi.product.uuid', value: product_uuid), + an_object_having_attributes(name: 'uuid', value: product_uuid, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ec2_metadata_spec.rb b/spec/facter/facts/openbsd/ec2_metadata_spec.rb new file mode 100644 index 0000000000..9907424c5f --- /dev/null +++ b/spec/facter/facts/openbsd/ec2_metadata_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ec2Metadata do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ec2Metadata.new } + + let(:virtual_detector_double) { class_spy(Facter::Util::Facts::Posix::VirtualDetector) } + + before do + allow(Facter::Resolvers::Ec2).to receive(:resolve).with(:metadata).and_return(value) + end + + context 'when physical machine with no hypervisor' do + let(:value) { nil } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return(nil) + end + + it 'returns ec2 metadata fact as nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'ec2_metadata', value: value) + end + + it "doesn't call Ec2 resolver" do + fact.call_the_resolver + expect(Facter::Resolvers::Ec2).not_to have_received(:resolve).with(:metadata) + end + end + + shared_examples 'check ec2 resolver called with metadata' do + it 'calls ec2 resolver' do + fact.call_the_resolver + + expect(Facter::Resolvers::Ec2).to have_received(:resolve).with(:metadata) + end + end + + shared_examples 'check resolved fact value' do + it 'returns ec2 metadata fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'ec2_metadata', value: value) + end + end + + context 'when platform is kvm' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('kvm') + end + + it_behaves_like 'check ec2 resolver called with metadata' + it_behaves_like 'check resolved fact value' + end + + context 'when platform is xen' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('xen') + end + + it_behaves_like 'check ec2 resolver called with metadata' + it_behaves_like 'check resolved fact value' + end + + context 'when platform is aws' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('aws') + end + + it_behaves_like 'check ec2 resolver called with metadata' + it_behaves_like 'check resolved fact value' + end + end +end diff --git a/spec/facter/facts/openbsd/ec2_userdata_spec.rb b/spec/facter/facts/openbsd/ec2_userdata_spec.rb new file mode 100644 index 0000000000..2db4273ebc --- /dev/null +++ b/spec/facter/facts/openbsd/ec2_userdata_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ec2Userdata do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ec2Userdata.new } + + let(:virtual_detector_double) { class_spy(Facter::Util::Facts::Posix::VirtualDetector) } + + before do + allow(Facter::Resolvers::Ec2).to receive(:resolve).with(:userdata).and_return(value) + end + + context 'when physical machine with no hypervisor' do + let(:value) { nil } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('nil') + end + + it 'returns ec2 userdata fact as nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'ec2_userdata', value: value) + end + + it "doesn't call Ec2 resolver" do + fact.call_the_resolver + expect(Facter::Resolvers::Ec2).not_to have_received(:resolve).with(:userdata) + end + end + + shared_examples 'check ec2 resolver called with userdata' do + it 'calls ec2 resolver' do + fact.call_the_resolver + + expect(Facter::Resolvers::Ec2).to have_received(:resolve).with(:userdata) + end + end + + shared_examples 'check resolved fact value' do + it 'returns ec2 userdata fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'ec2_userdata', value: value) + end + end + + context 'when platform is kvm' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('kvm') + end + + it_behaves_like 'check ec2 resolver called with userdata' + it_behaves_like 'check resolved fact value' + end + + context 'when platform is xen' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('xen') + end + + it_behaves_like 'check ec2 resolver called with userdata' + it_behaves_like 'check resolved fact value' + end + + context 'when platform is aws' do + let(:value) { { 'info' => 'value' } } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('aws') + end + + it_behaves_like 'check ec2 resolver called with userdata' + it_behaves_like 'check resolved fact value' + end + end +end diff --git a/spec/facter/facts/openbsd/facterversion_spec.rb b/spec/facter/facts/openbsd/facterversion_spec.rb new file mode 100644 index 0000000000..d904c080f7 --- /dev/null +++ b/spec/facter/facts/openbsd/facterversion_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Facterversion do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Facterversion.new } + + let(:value) { '4.0.3' } + + before do + allow(Facter::Resolvers::Facterversion).to receive(:resolve).with(:facterversion).and_return(value) + end + + it 'calls Facter::Resolvers::Facterversion' do + fact.call_the_resolver + expect(Facter::Resolvers::Facterversion).to have_received(:resolve).with(:facterversion) + end + + it 'returns facterversion fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'facterversion', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/identity/gid_spec.rb b/spec/facter/facts/openbsd/identity/gid_spec.rb new file mode 100644 index 0000000000..ab18b1d3cc --- /dev/null +++ b/spec/facter/facts/openbsd/identity/gid_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Identity::Gid do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Identity::Gid.new } + + let(:value) { '20' } + + before do + allow(Facter::Resolvers::PosxIdentity).to receive(:resolve).with(:gid).and_return(value) + end + + it 'calls Facter::Resolvers::PosxIdentity' do + fact.call_the_resolver + expect(Facter::Resolvers::PosxIdentity).to have_received(:resolve).with(:gid) + end + + it 'returns identity gid fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'identity.gid', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/identity/group_spec.rb b/spec/facter/facts/openbsd/identity/group_spec.rb new file mode 100644 index 0000000000..7716b25b19 --- /dev/null +++ b/spec/facter/facts/openbsd/identity/group_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Identity::Group do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Identity::Group.new } + + let(:value) { 'staff' } + + before do + allow(Facter::Resolvers::PosxIdentity).to receive(:resolve).with(:group).and_return(value) + end + + it 'calls Facter::Resolvers::PosxIdentity' do + fact.call_the_resolver + expect(Facter::Resolvers::PosxIdentity).to have_received(:resolve).with(:group) + end + + it 'returns identity group fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'identity.group', value: value), + an_object_having_attributes(name: 'gid', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/identity/privileged_spec.rb b/spec/facter/facts/openbsd/identity/privileged_spec.rb new file mode 100644 index 0000000000..b533538e51 --- /dev/null +++ b/spec/facter/facts/openbsd/identity/privileged_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Identity::Privileged do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Identity::Privileged.new } + + let(:value) { 'false' } + + before do + allow(Facter::Resolvers::PosxIdentity).to receive(:resolve).with(:privileged).and_return(value) + end + + it 'calls Facter::Resolvers::PosxIdentity' do + fact.call_the_resolver + expect(Facter::Resolvers::PosxIdentity).to have_received(:resolve).with(:privileged) + end + + it 'returns identity privileged fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'identity.privileged', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/identity/uid_spec.rb b/spec/facter/facts/openbsd/identity/uid_spec.rb new file mode 100644 index 0000000000..86ef507f60 --- /dev/null +++ b/spec/facter/facts/openbsd/identity/uid_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Identity::Uid do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Identity::Uid.new } + + let(:value) { '501' } + + before do + allow(Facter::Resolvers::PosxIdentity).to receive(:resolve).with(:uid).and_return(value) + end + + it 'calls Facter::Resolvers::PosxIdentity' do + fact.call_the_resolver + expect(Facter::Resolvers::PosxIdentity).to have_received(:resolve).with(:uid) + end + + it 'returns identity uid fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'identity.uid', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/identity/user_spec.rb b/spec/facter/facts/openbsd/identity/user_spec.rb new file mode 100644 index 0000000000..8eede4a2a0 --- /dev/null +++ b/spec/facter/facts/openbsd/identity/user_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Identity::User do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Identity::User.new } + + let(:value) { 'root' } + + before do + allow(Facter::Resolvers::PosxIdentity).to receive(:resolve).with(:user).and_return(value) + end + + it 'calls Facter::Resolvers::PosxIdentity' do + fact.call_the_resolver + expect(Facter::Resolvers::PosxIdentity).to have_received(:resolve).with(:user) + end + + it 'returns id and identity user name' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'identity.user', value: value), + an_object_having_attributes(name: 'id', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ipaddress6_interfaces_spec.rb b/spec/facter/facts/openbsd/ipaddress6_interfaces_spec.rb new file mode 100644 index 0000000000..ff062c8735 --- /dev/null +++ b/spec/facter/facts/openbsd/ipaddress6_interfaces_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ipaddress6Interfaces do + subject(:fact) { Facts::Openbsd::Ipaddress6Interfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) { { 'em0' => { ip6: 'fe80::99bf:da20:ad3:9bfe' }, 'vio0' => { ip6: 'fe80::99bf:da20:ad3:9bfe' } } } + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names ipaddress6_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'ipaddress6_em0', + value: interfaces['em0'][:ip6], type: :legacy), + an_object_having_attributes(name: 'ipaddress6_vio0', + value: interfaces['vio0'][:ip6], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver returns nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/ipaddress_interfaces_spec.rb b/spec/facter/facts/openbsd/ipaddress_interfaces_spec.rb new file mode 100644 index 0000000000..54696290b7 --- /dev/null +++ b/spec/facter/facts/openbsd/ipaddress_interfaces_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::IpaddressInterfaces do + subject(:fact) { Facts::Openbsd::IpaddressInterfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) { { 'em0' => { ip: '10.16.117.100' }, 'vio0' => { ip: '10.16.117.255' } } } + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names ipaddress_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'ipaddress_em0', + value: interfaces['em0'][:ip], type: :legacy), + an_object_having_attributes(name: 'ipaddress_vio0', + value: interfaces['vio0'][:ip], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver returns nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/is_virtual_spec.rb b/spec/facter/facts/openbsd/is_virtual_spec.rb new file mode 100644 index 0000000000..1cf8bb8ee2 --- /dev/null +++ b/spec/facter/facts/openbsd/is_virtual_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::IsVirtual do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::IsVirtual.new } + + let(:virtual_detector_double) { class_spy(Facter::Util::Facts::Posix::VirtualDetector) } + + before do + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return(virtual_value) + end + + context 'when not in a virtual environment' do + let(:virtual_value) { 'physical' } + + it 'return resolved fact with nil value' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'is_virtual', value: false) + end + end + + context 'when in a virtual environment' do + let(:virtual_value) { 'vmm' } + + it 'return resolved fact with nil value' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'is_virtual', value: true) + end + end + end +end diff --git a/spec/facter/facts/openbsd/kernel_spec.rb b/spec/facter/facts/openbsd/kernel_spec.rb new file mode 100644 index 0000000000..b2a5d2ae4e --- /dev/null +++ b/spec/facter/facts/openbsd/kernel_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Kernel do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Kernel.new } + + let(:value) { 'OpenBSD' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelname).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:kernelname) + end + + it 'returns kernel fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'kernel', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/kernelrelease_spec.rb b/spec/facter/facts/openbsd/kernelrelease_spec.rb new file mode 100644 index 0000000000..ad1b9a877c --- /dev/null +++ b/spec/facter/facts/openbsd/kernelrelease_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Kernelrelease do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Kernelrelease.new } + + let(:value) { '7.2' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelrelease).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:kernelrelease) + end + + it 'returns kernelrelease fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'kernelrelease', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/mountpoints_spec.rb b/spec/facter/facts/openbsd/mountpoints_spec.rb new file mode 100644 index 0000000000..ec7c15f833 --- /dev/null +++ b/spec/facter/facts/openbsd/mountpoints_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Mountpoints do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Mountpoints.new } + + context 'when resolver returns hash' do + let(:resolver_output) do + { '/var': { available: '15.18 GiB', + available_bytes: 16_299_800_576, + capacity: '12.49%', + device: '/dev/sd0j', + filesystem: 'ffs', + options: %w[local nodev nosuid], + size: '18.40 GiB', + size_bytes: 19_754_121_216, + used: '2.30 GiB', + used_bytes: 2_466_615_296 } } + end + let(:parsed_fact) do + { '/var' => { 'available' => '15.18 GiB', + 'available_bytes' => 16_299_800_576, + 'capacity' => '12.49%', + 'device' => '/dev/sd0j', + 'filesystem' => 'ffs', + 'options' => %w[local nodev nosuid], + 'size' => '18.40 GiB', + 'size_bytes' => 19_754_121_216, + 'used' => '2.30 GiB', + 'used_bytes' => 2_466_615_296 } } + end + + before do + allow(Facter::Resolvers::Openbsd::Mountpoints).to \ + receive(:resolve).with(:mountpoints).and_return(resolver_output) + end + + it 'calls Facter::Resolvers::Openbsd::Mountpoints' do + fact.call_the_resolver + expect(Facter::Resolvers::Openbsd::Mountpoints).to \ + have_received(:resolve).with(:mountpoints) + end + + it 'returns mountpoints information' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'mountpoints', value: parsed_fact) + end + end + + context 'when resolver returns nil' do + before do + allow(Facter::Resolvers::Openbsd::Mountpoints).to \ + receive(:resolve).with(:mountpoints).and_return(nil) + end + + it 'returns mountpoints information' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'mountpoints', value: nil) + end + end + end +end diff --git a/spec/facter/facts/openbsd/netmask6_interfaces_spec.rb b/spec/facter/facts/openbsd/netmask6_interfaces_spec.rb new file mode 100644 index 0000000000..dad59941f7 --- /dev/null +++ b/spec/facter/facts/openbsd/netmask6_interfaces_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Netmask6Interfaces do + subject(:fact) { Facts::Openbsd::Netmask6Interfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) do + { 'em0' => { netmask6: 'fe80::99bf:da20:ad3:9bfe' }, + 'vio0' => { netmask6: 'fe80::99bf:da20:ad3:9bfe' } } + end + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names netmask6_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'netmask6_em0', + value: interfaces['em0'][:netmask6], type: :legacy), + an_object_having_attributes(name: 'netmask6_vio0', + value: interfaces['vio0'][:netmask6], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver return nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/netmask_interfaces_spec.rb b/spec/facter/facts/openbsd/netmask_interfaces_spec.rb new file mode 100644 index 0000000000..e34d2641e7 --- /dev/null +++ b/spec/facter/facts/openbsd/netmask_interfaces_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::NetmaskInterfaces do + subject(:fact) { Facts::Openbsd::NetmaskInterfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) { { 'em0' => { netmask: '10.255.255.255' }, 'vio0' => { netmask: '10.17.255.255' } } } + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names netmask_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'netmask_em0', + value: interfaces['em0'][:netmask], type: :legacy), + an_object_having_attributes(name: 'netmask_vio0', + value: interfaces['vio0'][:netmask], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver returns nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/network6_interfaces_spec.rb b/spec/facter/facts/openbsd/network6_interfaces_spec.rb new file mode 100644 index 0000000000..67423aba2f --- /dev/null +++ b/spec/facter/facts/openbsd/network6_interfaces_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Network6Interfaces do + subject(:fact) { Facts::Openbsd::Network6Interfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) { { 'em0' => { network6: '::1' }, 'vio0' => { network6: 'fe80::' } } } + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names network6_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'network6_em0', + value: interfaces['em0'][:network6], type: :legacy), + an_object_having_attributes(name: 'network6_vio0', + value: interfaces['vio0'][:network6], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver returns nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/network_interfaces_spec.rb b/spec/facter/facts/openbsd/network_interfaces_spec.rb new file mode 100644 index 0000000000..321128f3dc --- /dev/null +++ b/spec/facter/facts/openbsd/network_interfaces_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::NetworkInterfaces do + subject(:fact) { Facts::Openbsd::NetworkInterfaces.new } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + describe '#call_the_resolver' do + let(:interfaces) { { 'em0' => { network: '10.255.255.255' }, 'vio0' => { network: '10.17.255.255' } } } + + it 'calls Facter::Resolvers::NetworkingOpenBSD' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns legacy facts with names network_' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'network_em0', + value: interfaces['em0'][:network], type: :legacy), + an_object_having_attributes(name: 'network_vio0', + value: interfaces['vio0'][:network], type: :legacy)) + end + end + + describe '#call_the_resolver when resolver returns nil' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and contain_exactly + end + end +end diff --git a/spec/facter/facts/openbsd/networking/dhcp_spec.rb b/spec/facter/facts/openbsd/networking/dhcp_spec.rb new file mode 100644 index 0000000000..8e3ac19e9f --- /dev/null +++ b/spec/facter/facts/openbsd/networking/dhcp_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Dhcp do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Dhcp.new } + + let(:value) { '192.168.158.6' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:dhcp).and_return(value) + end + + it 'calls Facter::Resolvers::Networking' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:dhcp) + end + + it 'returns networking.dhcp fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.dhcp', value: value) + end + + context 'when dhcp can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.dhcp', value: value) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/domain_spec.rb b/spec/facter/facts/openbsd/networking/domain_spec.rb new file mode 100644 index 0000000000..854a97c81a --- /dev/null +++ b/spec/facter/facts/openbsd/networking/domain_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Domain do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Domain.new } + + let(:value) { 'domain' } + + before do + allow(Facter::Resolvers::Hostname).to receive(:resolve).with(:domain).and_return(value) + end + + it 'calls Facter::Resolvers::Hostname' do + fact.call_the_resolver + expect(Facter::Resolvers::Hostname).to have_received(:resolve).with(:domain) + end + + it 'returns domain fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.domain', value: value), + an_object_having_attributes(name: 'domain', value: value, type: :legacy)) + end + + context 'when domain can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.domain', value: value), + an_object_having_attributes(name: 'domain', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/fqdn_spec.rb b/spec/facter/facts/openbsd/networking/fqdn_spec.rb new file mode 100644 index 0000000000..9fd6e419b7 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/fqdn_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Fqdn do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Fqdn.new } + + let(:value) { 'host.domain' } + + before do + allow(Facter::Resolvers::Hostname).to receive(:resolve).with(:fqdn).and_return(value) + end + + it 'calls Facter::Resolvers::Hostname' do + fact.call_the_resolver + expect(Facter::Resolvers::Hostname).to have_received(:resolve).with(:fqdn) + end + + it 'returns fqdn fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.fqdn', value: value), + an_object_having_attributes(name: 'fqdn', value: value, type: :legacy)) + end + + context 'when fqdn can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.fqdn', value: value), + an_object_having_attributes(name: 'fqdn', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/hostname_spec.rb b/spec/facter/facts/openbsd/networking/hostname_spec.rb new file mode 100644 index 0000000000..6d5a79a662 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/hostname_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Hostname do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Hostname.new } + + let(:value) { 'host' } + + before do + allow(Facter::Resolvers::Hostname).to receive(:resolve).with(:hostname).and_return(value) + end + + it 'calls Facter::Resolvers::Hostname' do + fact.call_the_resolver + expect(Facter::Resolvers::Hostname).to have_received(:resolve).with(:hostname) + end + + it 'returns hostname fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.hostname', value: value), + an_object_having_attributes(name: 'hostname', value: value, type: :legacy)) + end + + context 'when hostname can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.hostname', value: value), + an_object_having_attributes(name: 'hostname', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/interfaces_spec.rb b/spec/facter/facts/openbsd/networking/interfaces_spec.rb new file mode 100644 index 0000000000..437f21080f --- /dev/null +++ b/spec/facter/facts/openbsd/networking/interfaces_spec.rb @@ -0,0 +1,130 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Interfaces do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Interfaces.new } + + let(:interfaces) do + { + 'awdl0' => + { mtu: 1484, + mac: '2e:ba:e4:83:4b:b7', + bindings6: + [{ address: 'fe80::2cba:e4ff:fe83:4bb7', + netmask: 'ffff:ffff:ffff:ffff::', + network: 'fe80::' }], + ip6: 'fe80::2cba:e4ff:fe83:4bb7', + netmask6: 'ffff:ffff:ffff:ffff::', + network6: 'fe80::' }, + 'bridge0' => { mtu: 1500, mac: '82:17:0e:93:9d:00' }, + 'en0' => + { dhcp: '192.587.6.9', + mtu: 1500, + mac: '64:5a:ed:ea:5c:81', + bindings: + [{ address: '192.168.1.2', + netmask: '255.255.255.0', + network: '192.168.1.0' }], + ip: '192.168.1.2', + netmask: '255.255.255.0', + network: '192.168.1.0' }, + 'gif0' => { mtu: 1280 }, + 'lo0' => + { mtu: 16_384, + bindings: + [{ address: '127.0.0.1', netmask: '255.0.0.0', network: '127.0.0.0' }], + bindings6: + [{ address: '::1', + netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + network: '::1' }, + { address: 'fe80::1', + netmask: 'ffff:ffff:ffff:ffff::', + network: 'fe80::' }], + ip: '127.0.0.1', + netmask: '255.0.0.0', + network: '127.0.0.0', + ip6: '::1', + netmask6: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + network6: '::1' } + } + end + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:interfaces).and_return(interfaces) + end + + it 'calls Facter::Resolvers::Networking with interfaces' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:interfaces) + end + + it 'returns networking.interfaces fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'networking.interfaces', value: anything) + end + + it 'returns all interfaces' do + interfaces = %w[awdl0 bridge0 en0 gif0 lo0] + + result = fact.call_the_resolver + + expect(result.value).to include(*interfaces) + end + + it 'returns the interface awdl0 correctly' do + expected = { 'mtu' => 1484, + 'mac' => '2e:ba:e4:83:4b:b7', + 'bindings6' => + [{ 'address' => 'fe80::2cba:e4ff:fe83:4bb7', + 'netmask' => 'ffff:ffff:ffff:ffff::', + 'network' => 'fe80::' }], + 'ip6' => 'fe80::2cba:e4ff:fe83:4bb7', + 'netmask6' => 'ffff:ffff:ffff:ffff::', + 'network6' => 'fe80::' } + + result = fact.call_the_resolver + + expect(result.value['awdl0']).to match(expected) + end + + it 'returns the interface bridge0 correctly' do + result = fact.call_the_resolver + + expect(result.value['bridge0']).to match({ 'mtu' => 1500, 'mac' => '82:17:0e:93:9d:00' }) + end + + it 'returns the interface en0 correctly' do + expected = { 'mtu' => 1500, + 'mac' => '64:5a:ed:ea:5c:81', + 'bindings' => + [{ 'address' => '192.168.1.2', + 'netmask' => '255.255.255.0', + 'network' => '192.168.1.0' }], + 'ip' => '192.168.1.2', + 'netmask' => '255.255.255.0', + 'network' => '192.168.1.0', + 'dhcp' => '192.587.6.9' } + + result = fact.call_the_resolver + + expect(result.value['en0']).to match(expected) + end + + it 'returns the interface gif0 correctly' do + result = fact.call_the_resolver + + expect(result.value['gif0']).to match({ 'mtu' => 1280 }) + end + + context 'when interfaces can not be retrieved' do + let(:interfaces) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'networking.interfaces', value: interfaces) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/ip6_spec.rb b/spec/facter/facts/openbsd/networking/ip6_spec.rb new file mode 100644 index 0000000000..091c2447bd --- /dev/null +++ b/spec/facter/facts/openbsd/networking/ip6_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Ip6 do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Ip6.new } + + let(:value) { 'fe80::2cba:e4ff:fe83:4bb7' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:ip6).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :ip6' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:ip6) + end + + it 'returns the ip6 fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.ip6', value: value), + an_object_having_attributes(name: 'ipaddress6', value: value, type: :legacy)) + end + + context 'when ip6 can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.ip6', value: value), + an_object_having_attributes(name: 'ipaddress6', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/ip_spec.rb b/spec/facter/facts/openbsd/networking/ip_spec.rb new file mode 100644 index 0000000000..a4bffb5197 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/ip_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Ip do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Ip.new } + + let(:value) { '10.0.0.1' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:ip).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :ip' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:ip) + end + + it 'returns the ip6 fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.ip', value: value), + an_object_having_attributes(name: 'ipaddress', value: value, type: :legacy)) + end + + context 'when ip can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.ip', value: value), + an_object_having_attributes(name: 'ipaddress', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/mac_spec.rb b/spec/facter/facts/openbsd/networking/mac_spec.rb new file mode 100644 index 0000000000..f4e1339715 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/mac_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Mac do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Mac.new } + + let(:value) { '64:5a:ed:ea:c3:25' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:mac).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :mac' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:mac) + end + + it 'returns macaddress fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.mac', value: value), + an_object_having_attributes(name: 'macaddress', value: value, type: :legacy)) + end + + context 'when mac can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.mac', value: value), + an_object_having_attributes(name: 'macaddress', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/mtu_spec.rb b/spec/facter/facts/openbsd/networking/mtu_spec.rb new file mode 100644 index 0000000000..20447af686 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/mtu_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Mtu do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Mtu.new } + + let(:value) { 1500 } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:mtu).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :mtu' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:mtu) + end + + it 'returns mtu fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.mtu', value: value) + end + + context 'when mtu can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.mtu', value: value) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/netmask6_spec.rb b/spec/facter/facts/openbsd/networking/netmask6_spec.rb new file mode 100644 index 0000000000..db293180cf --- /dev/null +++ b/spec/facter/facts/openbsd/networking/netmask6_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Netmask6 do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Netmask6.new } + + let(:value) { 'ffff:ffff:ffff:ffff::' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:netmask6).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :netmask6' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:netmask6) + end + + it 'returns the netmask6 fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.netmask6', value: value), + an_object_having_attributes(name: 'netmask6', value: value, type: :legacy)) + end + + context 'when netmask6 can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.netmask6', value: value), + an_object_having_attributes(name: 'netmask6', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/netmask_spec.rb b/spec/facter/facts/openbsd/networking/netmask_spec.rb new file mode 100644 index 0000000000..acd23fd2c9 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/netmask_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Netmask do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Netmask.new } + + let(:value) { '255.255.255.0' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:netmask).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :netmask' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:netmask) + end + + it 'returns the netmask fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.netmask', value: value), + an_object_having_attributes(name: 'netmask', value: value, type: :legacy)) + end + + context 'when netmask can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.netmask', value: value), + an_object_having_attributes(name: 'netmask', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/network6_spec.rb b/spec/facter/facts/openbsd/networking/network6_spec.rb new file mode 100644 index 0000000000..4484eaea41 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/network6_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Network6 do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Network6.new } + + let(:value) { 'ff80:3454::' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:network6).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :network6' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:network6) + end + + it 'returns the network6 fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.network6', value: value), + an_object_having_attributes(name: 'network6', value: value, type: :legacy)) + end + + context 'when network6 can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.network6', value: value), + an_object_having_attributes(name: 'network6', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/network_spec.rb b/spec/facter/facts/openbsd/networking/network_spec.rb new file mode 100644 index 0000000000..7abf5faefd --- /dev/null +++ b/spec/facter/facts/openbsd/networking/network_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Network do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Network.new } + + let(:value) { '192.168.143.0' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:network).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :network' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:network) + end + + it 'returns the network fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.network', value: value), + an_object_having_attributes(name: 'network', value: value, type: :legacy)) + end + + context 'when network can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'networking.network', value: value), + an_object_having_attributes(name: 'network', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/primary_spec.rb b/spec/facter/facts/openbsd/networking/primary_spec.rb new file mode 100644 index 0000000000..1f19391673 --- /dev/null +++ b/spec/facter/facts/openbsd/networking/primary_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Primary do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Primary.new } + + let(:value) { 'em0' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:primary_interface).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with :primary_interface' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:primary_interface) + end + + it 'returns networking.primary fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.primary', value: value) + end + + context 'when primary interface can not be retrieved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact).and have_attributes(name: 'networking.primary', value: value) + end + end + end +end diff --git a/spec/facter/facts/openbsd/networking/scope6_spec.rb b/spec/facter/facts/openbsd/networking/scope6_spec.rb new file mode 100644 index 0000000000..a1621a1c4f --- /dev/null +++ b/spec/facter/facts/openbsd/networking/scope6_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Networking::Scope6 do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Networking::Scope6.new } + + let(:value) { 'link' } + + before do + allow(Facter::Resolvers::Networking).to receive(:resolve).with(:scope6).and_return(value) + end + + it 'calls Facter::Resolvers::Networking with scope6' do + fact.call_the_resolver + expect(Facter::Resolvers::Networking).to have_received(:resolve).with(:scope6) + end + + it 'returns scope6 fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'networking.scope6', value: value) + end + + context 'when scope6 can not be resolved' do + let(:value) { nil } + + it 'returns nil' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'networking.scope6', value: value) + end + end + end +end diff --git a/spec/facter/facts/openbsd/os/architecture_spec.rb b/spec/facter/facts/openbsd/os/architecture_spec.rb new file mode 100644 index 0000000000..ff6d8f328a --- /dev/null +++ b/spec/facter/facts/openbsd/os/architecture_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Os::Architecture do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Os::Architecture.new } + + let(:value) { 'amd64' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine) + end + + it 'returns architecture fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.architecture', value: value), + an_object_having_attributes(name: 'architecture', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/os/hardware_spec.rb b/spec/facter/facts/openbsd/os/hardware_spec.rb new file mode 100644 index 0000000000..c86b97397f --- /dev/null +++ b/spec/facter/facts/openbsd/os/hardware_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Os::Hardware do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Os::Hardware.new } + + let(:value) { 'amd64' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value) + end + + it 'calls Facter::Resolvers::HardwareArchitecture' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine) + end + + it 'returns hardware model fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.hardware', value: value), + an_object_having_attributes(name: 'hardwaremodel', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/os/name_spec.rb b/spec/facter/facts/openbsd/os/name_spec.rb new file mode 100644 index 0000000000..23f544befb --- /dev/null +++ b/spec/facter/facts/openbsd/os/name_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Os::Name do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Os::Name.new } + + let(:value) { 'OpenBSD' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelname).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:kernelname) + end + + it 'returns operating system name fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.name', value: value), + an_object_having_attributes(name: 'operatingsystem', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/os/release_spec.rb b/spec/facter/facts/openbsd/os/release_spec.rb new file mode 100644 index 0000000000..a0d75bcd29 --- /dev/null +++ b/spec/facter/facts/openbsd/os/release_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Os::Release do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Os::Release.new } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:kernelrelease).and_return(value) + end + + context 'when OpenBSD RELEASE' do + let(:value) { '7.2' } + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:kernelrelease) + end + + it 'returns release fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.release', value: { 'full' => value, + 'major' => '7', + 'minor' => '2' }), + an_object_having_attributes(name: 'operatingsystemmajrelease', value: '7', + type: :legacy), + an_object_having_attributes(name: 'operatingsystemrelease', value: value, type: :legacy)) + end + end + end +end diff --git a/spec/facter/facts/openbsd/path_spec.rb b/spec/facter/facts/openbsd/path_spec.rb new file mode 100644 index 0000000000..53084a5cca --- /dev/null +++ b/spec/facter/facts/openbsd/path_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Path do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Path.new } + + let(:value) { '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin' } + + before do + allow(Facter::Resolvers::Path).to \ + receive(:resolve).with(:path).and_return(value) + end + + it 'calls Facter::Resolvers::Path' do + fact.call_the_resolver + expect(Facter::Resolvers::Path).to have_received(:resolve).with(:path) + end + + it 'returns path fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'path', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/processors/isa_spec.rb b/spec/facter/facts/openbsd/processors/isa_spec.rb new file mode 100644 index 0000000000..ceac928df2 --- /dev/null +++ b/spec/facter/facts/openbsd/processors/isa_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Processors::Isa do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Processors::Isa.new } + + let(:isa) { 'amd64' } + + before do + allow(Facter::Resolvers::Uname).to \ + receive(:resolve).with(:processor).and_return(isa) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:processor) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'processors.isa', value: isa), + an_object_having_attributes(name: 'hardwareisa', value: isa, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ruby/platform_spec.rb b/spec/facter/facts/openbsd/ruby/platform_spec.rb new file mode 100644 index 0000000000..49dcd2ae09 --- /dev/null +++ b/spec/facter/facts/openbsd/ruby/platform_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ruby::Platform do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ruby::Platform.new } + + let(:value) { 'x86_64-openbsd' } + + before do + allow(Facter::Resolvers::Ruby).to receive(:resolve).with(:platform).and_return(value) + end + + it 'calls Facter::Resolvers::Ruby' do + fact.call_the_resolver + expect(Facter::Resolvers::Ruby).to have_received(:resolve).with(:platform) + end + + it 'return ruby.platform fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'ruby.platform', value: value), + an_object_having_attributes(name: 'rubyplatform', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ruby/sitedir_spec.rb b/spec/facter/facts/openbsd/ruby/sitedir_spec.rb new file mode 100644 index 0000000000..6907a58196 --- /dev/null +++ b/spec/facter/facts/openbsd/ruby/sitedir_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ruby::Sitedir do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ruby::Sitedir.new } + + let(:value) { '/usr/local/lib/ruby/site_ruby/3.1' } + + before do + allow(Facter::Resolvers::Ruby).to receive(:resolve).with(:sitedir).and_return(value) + end + + it 'calls Facter::Resolvers::Ruby' do + fact.call_the_resolver + expect(Facter::Resolvers::Ruby).to have_received(:resolve).with(:sitedir) + end + + it 'return ruby sitedir fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'ruby.sitedir', value: value), + an_object_having_attributes(name: 'rubysitedir', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ruby/version_spec.rb b/spec/facter/facts/openbsd/ruby/version_spec.rb new file mode 100644 index 0000000000..2243fdcc4b --- /dev/null +++ b/spec/facter/facts/openbsd/ruby/version_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ruby::Version do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ruby::Version.new } + + let(:value) { '3.1.2' } + + before do + allow(Facter::Resolvers::Ruby).to receive(:resolve).with(:version).and_return(value) + end + + it 'calls Facter::Resolvers::Ruby' do + fact.call_the_resolver + expect(Facter::Resolvers::Ruby).to have_received(:resolve).with(:version) + end + + it 'returns ruby version fact' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Array) + .and contain_exactly(an_object_having_attributes(name: 'ruby.version', value: value), + an_object_having_attributes(name: 'rubyversion', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/ssh_spec.rb b/spec/facter/facts/openbsd/ssh_spec.rb new file mode 100644 index 0000000000..ab2958a12e --- /dev/null +++ b/spec/facter/facts/openbsd/ssh_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Ssh do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Ssh.new } + + let(:ssh) do + [Facter::Util::Resolvers::Ssh.new(Facter::Util::Resolvers::FingerPrint + .new('test', 'test'), 'ecdsa', 'test', 'ecdsa')] + end + let(:value) do + { 'ecdsa' => { 'fingerprints' => + { 'sha1' => 'test', 'sha256' => 'test' }, + 'key' => 'test', + 'type' => 'ecdsa' } } + end + + before do + allow(Facter::Resolvers::Ssh).to \ + receive(:resolve).with(:ssh).and_return(ssh) + end + + it 'calls Facter::Resolvers::Ssh' do + fact.call_the_resolver + expect(Facter::Resolvers::Ssh).to have_received(:resolve).with(:ssh) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'ssh', value: value) + end + end +end diff --git a/spec/facter/facts/openbsd/sshalgorithmkey_spec.rb b/spec/facter/facts/openbsd/sshalgorithmkey_spec.rb new file mode 100644 index 0000000000..fabb0223fb --- /dev/null +++ b/spec/facter/facts/openbsd/sshalgorithmkey_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Sshalgorithmkey do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Sshalgorithmkey.new } + + let(:ssh) do + [Facter::Util::Resolvers::Ssh.new(Facter::Util::Resolvers::FingerPrint + .new('test', 'test'), 'ecdsa', 'test', 'ecdsa'), + Facter::Util::Resolvers::Ssh.new(Facter::Util::Resolvers::FingerPrint + .new('test', 'test'), 'rsa', 'test', 'rsa')] + end + let(:legacy_fact1) { { name: 'ecdsa', value: 'test' } } + let(:legacy_fact2) { { name: 'rsa', value: 'test' } } + + before do + allow(Facter::Resolvers::Ssh).to \ + receive(:resolve).with(:ssh).and_return(ssh) + end + + it 'calls Facter::Resolvers::Ssh' do + fact.call_the_resolver + expect(Facter::Resolvers::Ssh).to have_received(:resolve).with(:ssh) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: "ssh#{legacy_fact1[:name]}key", value: legacy_fact1[:value]), + an_object_having_attributes(name: "ssh#{legacy_fact2[:name]}key", value: legacy_fact2[:value])) + end + end +end diff --git a/spec/facter/facts/openbsd/sshfp_algorithm_spec.rb b/spec/facter/facts/openbsd/sshfp_algorithm_spec.rb new file mode 100644 index 0000000000..1bc5c8e6ed --- /dev/null +++ b/spec/facter/facts/openbsd/sshfp_algorithm_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::SshfpAlgorithm do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::SshfpAlgorithm.new } + + let(:ssh) do + [Facter::Util::Resolvers::Ssh.new(Facter::Util::Resolvers::FingerPrint + .new('sha11', 'sha2561'), 'ecdsa', 'test', 'ecdsa'), + Facter::Util::Resolvers::Ssh.new(Facter::Util::Resolvers::FingerPrint + .new('sha12', 'sha2562'), 'rsa', 'test', 'rsa')] + end + let(:legacy_fact1) { { name: 'ecdsa', value: "sha11\nsha2561" } } + let(:legacy_fact2) { { name: 'rsa', value: "sha12\nsha2562" } } + + before do + allow(Facter::Resolvers::Ssh).to \ + receive(:resolve).with(:ssh).and_return(ssh) + end + + it 'calls Facter::Resolvers::Ssh' do + fact.call_the_resolver + expect(Facter::Resolvers::Ssh).to have_received(:resolve).with(:ssh) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: "sshfp_#{legacy_fact1[:name]}", value: legacy_fact1[:value]), + an_object_having_attributes(name: "sshfp_#{legacy_fact2[:name]}", value: legacy_fact2[:value])) + end + end +end diff --git a/spec/facter/facts/openbsd/system_uptime/days_spec.rb b/spec/facter/facts/openbsd/system_uptime/days_spec.rb new file mode 100644 index 0000000000..170ad51e6d --- /dev/null +++ b/spec/facter/facts/openbsd/system_uptime/days_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::SystemUptime::Days do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::SystemUptime::Days.new } + + let(:value) { '2' } + + before do + allow(Facter::Resolvers::Uptime).to receive(:resolve).with(:days).and_return(value) + end + + it 'calls Facter::Resolvers::Uptime' do + fact.call_the_resolver + expect(Facter::Resolvers::Uptime).to have_received(:resolve).with(:days) + end + + it 'returns days since last boot' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'system_uptime.days', value: value), + an_object_having_attributes(name: 'uptime_days', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/system_uptime/hours_spec.rb b/spec/facter/facts/openbsd/system_uptime/hours_spec.rb new file mode 100644 index 0000000000..bf456e3135 --- /dev/null +++ b/spec/facter/facts/openbsd/system_uptime/hours_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::SystemUptime::Hours do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::SystemUptime::Hours.new } + + let(:value) { '2' } + + before do + allow(Facter::Resolvers::Uptime).to receive(:resolve).with(:hours).and_return(value) + end + + it 'calls Facter::Resolvers::Uptime' do + fact.call_the_resolver + expect(Facter::Resolvers::Uptime).to have_received(:resolve).with(:hours) + end + + it 'returns hours since last boot' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'system_uptime.hours', value: value), + an_object_having_attributes(name: 'uptime_hours', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/system_uptime/seconds_spec.rb b/spec/facter/facts/openbsd/system_uptime/seconds_spec.rb new file mode 100644 index 0000000000..87fb8df05b --- /dev/null +++ b/spec/facter/facts/openbsd/system_uptime/seconds_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::SystemUptime::Seconds do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::SystemUptime::Seconds.new } + + let(:value) { 3600 } + + before do + allow(Facter::Resolvers::Uptime).to receive(:resolve).with(:seconds).and_return(value) + end + + it 'calls Facter::Resolvers::Uptime' do + fact.call_the_resolver + expect(Facter::Resolvers::Uptime).to have_received(:resolve).with(:seconds) + end + + it 'returns minutes since last boot' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'system_uptime.seconds', value: value), + an_object_having_attributes(name: 'uptime_seconds', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/system_uptime/uptime_spec.rb b/spec/facter/facts/openbsd/system_uptime/uptime_spec.rb new file mode 100644 index 0000000000..65dd96eb8d --- /dev/null +++ b/spec/facter/facts/openbsd/system_uptime/uptime_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::SystemUptime::Uptime do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::SystemUptime::Uptime.new } + + let(:value) { '6 days' } + + before do + allow(Facter::Resolvers::Uptime).to receive(:resolve).with(:uptime).and_return(value) + end + + it 'calls Facter::Resolvers::Uptime' do + fact.call_the_resolver + expect(Facter::Resolvers::Uptime).to have_received(:resolve).with(:uptime) + end + + it 'returns total uptime since last boot' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'system_uptime.uptime', value: value), + an_object_having_attributes(name: 'uptime', value: value, type: :legacy)) + end + end +end diff --git a/spec/facter/facts/openbsd/timezone_spec.rb b/spec/facter/facts/openbsd/timezone_spec.rb new file mode 100644 index 0000000000..e272ac8672 --- /dev/null +++ b/spec/facter/facts/openbsd/timezone_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Timezone do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Timezone.new } + + let(:timezone) { 'UTC' } + + before do + allow(Facter::Resolvers::Timezone).to \ + receive(:resolve).with(:timezone).and_return(timezone) + end + + it 'calls Facter::Resolvers::Timezone' do + fact.call_the_resolver + expect(Facter::Resolvers::Timezone).to have_received(:resolve).with(:timezone) + end + + it 'returns a resolved fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'timezone', value: timezone) + end + end +end diff --git a/spec/facter/facts/openbsd/virtual_spec.rb b/spec/facter/facts/openbsd/virtual_spec.rb new file mode 100644 index 0000000000..70dd50f93f --- /dev/null +++ b/spec/facter/facts/openbsd/virtual_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Virtual do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Virtual.new } + + let(:virtual_detector_double) { class_spy(Facter::Util::Facts::Posix::VirtualDetector) } + let(:log_spy) { instance_spy(Facter::Log) } + + before do + allow(Facter::Log).to receive(:new).and_return(log_spy) + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return(value) + end + + shared_examples 'check resolved fact value' do + it 'return resolved fact with nil value' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'virtual', value: value) + end + end + + context 'when not in a virtual environment' do + let(:value) { 'physical' } + + it_behaves_like 'check resolved fact value' + end + + context 'when in a virtual environment' do + let(:value) { 'vmm' } + + it_behaves_like 'check resolved fact value' + end + end +end diff --git a/spec/facter/facts/openbsd/virtual_spec.rb.save b/spec/facter/facts/openbsd/virtual_spec.rb.save new file mode 100644 index 0000000000..70dd50f93f --- /dev/null +++ b/spec/facter/facts/openbsd/virtual_spec.rb.save @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +describe Facts::Openbsd::Virtual do + describe '#call_the_resolver' do + subject(:fact) { Facts::Openbsd::Virtual.new } + + let(:virtual_detector_double) { class_spy(Facter::Util::Facts::Posix::VirtualDetector) } + let(:log_spy) { instance_spy(Facter::Log) } + + before do + allow(Facter::Log).to receive(:new).and_return(log_spy) + allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return(value) + end + + shared_examples 'check resolved fact value' do + it 'return resolved fact with nil value' do + expect(fact.call_the_resolver) + .to be_an_instance_of(Facter::ResolvedFact) + .and have_attributes(name: 'virtual', value: value) + end + end + + context 'when not in a virtual environment' do + let(:value) { 'physical' } + + it_behaves_like 'check resolved fact value' + end + + context 'when in a virtual environment' do + let(:value) { 'vmm' } + + it_behaves_like 'check resolved fact value' + end + end +end diff --git a/spec/facter/resolvers/openbsd/dmi_bios_spec.rb b/spec/facter/resolvers/openbsd/dmi_bios_spec.rb new file mode 100644 index 0000000000..1fbc2f219f --- /dev/null +++ b/spec/facter/resolvers/openbsd/dmi_bios_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +describe Facter::Resolvers::Openbsd::DmiBios do + describe '#resolve' do + subject(:resolver) { Facter::Resolvers::Openbsd::DmiBios } + + let(:bios_vendor) { 'Phoenix Technologies LTD' } + let(:bios_version) { '6.00' } + let(:product_name) { 'VMware Virtual Platform' } + let(:product_serial) { 'VMware-42 1a 02 ea e6 27 76 b8-a1 23 a7 8a d3 12 ee cf' } + let(:product_uuid) { 'ea021a42-27e6-b876-a123-a78ad312eecf' } + let(:sys_vendor) { 'Phoenix Technologies LTD' } + + before do + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 14]) + .and_return(bios_vendor) + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 16]) + .and_return(bios_version) + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 15]) + .and_return(product_name) + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 17]) + .and_return(product_serial) + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 18]) + .and_return(product_uuid) + allow(Facter::Bsd::FfiHelper) + .to receive(:sysctl) + .with(:string, [6, 14]) + .and_return(sys_vendor) + end + + after do + Facter::Resolvers::Openbsd::DmiBios.invalidate_cache + end + + context 'when bios_vendor is available' do + it 'returns bios_release_date' do + expect(resolver.resolve(:bios_vendor)).to eq(bios_vendor) + end + end + + context 'when bios_version is available' do + it 'returns bios_version' do + expect(resolver.resolve(:bios_version)).to eq(bios_version) + end + end + + context 'when sys_vendor is available' do + it ' returns sys_vendor' do + expect(resolver.resolve(:sys_vendor)).to eq(sys_vendor) + end + end + + context 'when product_name is available' do + it 'returns product_name' do + expect(resolver.resolve(:product_name)).to eq(product_name) + end + end + + context 'when product_serial is available' do + it 'returns product_serial_number' do + expect(resolver.resolve(:product_serial)).to eq(product_serial) + end + end + + context 'when product_uuid is available' do + it 'returns product_uuid' do + expect(resolver.resolve(:product_uuid)).to eq(product_uuid) + end + end + end +end diff --git a/spec/facter/resolvers/openbsd/mountpoints_spec.rb b/spec/facter/resolvers/openbsd/mountpoints_spec.rb new file mode 100644 index 0000000000..387c815e1d --- /dev/null +++ b/spec/facter/resolvers/openbsd/mountpoints_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +describe Facter::Resolvers::Openbsd::Mountpoints do + let(:mountpoints) do + { '/' => { available: '738.97 MiB', available_bytes: 774_868_992, capacity: '20.04%', device: '/dev/sd0a', + filesystem: 'ffs', options: ['local'], size: '985.76 MiB', size_bytes: 1_033_648_128, + used: '197.50 MiB', used_bytes: 207_097_856 }, + '/usr' => { available: '157.56 MiB', available_bytes: 165_216_256, capacity: '79.02%', device: '/dev/sd0d', + filesystem: 'ffs', options: %w[local nodev], size: '985.76 MiB', size_bytes: 1_033_648_128, + used: '778.91 MiB', used_bytes: 816_750_592 }, + '/usr/local' => { available: '1.10 GiB', available_bytes: 1_178_118_144, capacity: '57.17%', + device: '/dev/sd0e', filesystem: 'ffs', options: %w[local nodev wxallowed], + size: '2.90 GiB', size_bytes: 3_114_448_896, used: '1.66 GiB', + used_bytes: 1_780_609_024 } } + end + let(:log_spy) { instance_spy(Facter::Log) } + + before do + Facter::Resolvers::Openbsd::Mountpoints.instance_variable_set(:@log, log_spy) + allow(Facter::Core::Execution).to receive(:execute) + .with('mount', { logger: log_spy }) + .and_return(load_fixture('openbsd_filesystems').read) + allow(Facter::Core::Execution).to receive(:execute) + .with('df -P', { logger: log_spy }) + .and_return(load_fixture('openbsd_df').read) + end + + it 'returns mountpoints' do + result = Facter::Resolvers::Openbsd::Mountpoints.resolve(:mountpoints) + + expect(result).to eq(mountpoints) + end +end diff --git a/spec/facter/resolvers/openbsd/virtual_spec.rb b/spec/facter/resolvers/openbsd/virtual_spec.rb deleted file mode 100644 index eeed19746b..0000000000 --- a/spec/facter/resolvers/openbsd/virtual_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -describe Facter::Resolvers::Openbsd::Virtual do - subject(:resolver) { Facter::Resolvers::Openbsd::Virtual } - - after do - resolver.invalidate_cache - end - - before do - allow(Facter::Bsd::FfiHelper) - .to receive(:sysctl) - .with(:string, [6, 15]) - .and_return(vm) - end - - let(:vm) { nil } - - context 'when running on bare metal' do - let(:vm) { 'physical' } - - it 'returns physical' do - expect(resolver.resolve(:vm)).to eq('physical') - end - end - - context 'when running in a vm' do - let(:vm) { 'VMM' } - - it 'returns VMM' do - expect(resolver.resolve(:vm)).to eq('vmm') - end - end -end diff --git a/spec/facter/util/facts/posix/virtual_detector_spec.rb b/spec/facter/util/facts/posix/virtual_detector_spec.rb index d9058b6a0b..72dfa39366 100644 --- a/spec/facter/util/facts/posix/virtual_detector_spec.rb +++ b/spec/facter/util/facts/posix/virtual_detector_spec.rb @@ -47,11 +47,12 @@ end end - context 'when OpenBSD' do + context 'when in OpenBSD' do let(:value) { 'vmm' } before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return('vmm') end @@ -72,6 +73,7 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Freebsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) + allow(Facter::Resolvers::Openbsd::Virtual).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return('Google Engine') end diff --git a/spec/fixtures/openbsd_df b/spec/fixtures/openbsd_df new file mode 100644 index 0000000000..e94c930d2d --- /dev/null +++ b/spec/fixtures/openbsd_df @@ -0,0 +1,4 @@ +Filesystem 512-blocks Used Available Capacity Mounted on +/dev/sd0a 2018844 404488 1513416 21% / +/dev/sd0d 2018844 1595216 322688 83% /usr +/dev/sd0e 6082908 3477752 2301012 60% /usr/local diff --git a/spec/fixtures/openbsd_filesystems b/spec/fixtures/openbsd_filesystems new file mode 100644 index 0000000000..1b97e80847 --- /dev/null +++ b/spec/fixtures/openbsd_filesystems @@ -0,0 +1,3 @@ +/dev/sd0a on / type ffs (local) +/dev/sd0d on /usr type ffs (local, nodev) +/dev/sd0e on /usr/local type ffs (local, nodev, wxallowed)