Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail on Arch Linux #2752

Closed
bastelfreak opened this issue Sep 5, 2024 · 4 comments
Closed

Tests fail on Arch Linux #2752

bastelfreak opened this issue Sep 5, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@bastelfreak
Copy link
Contributor

Describe the Bug

Hi,
when running rspec on Arch Linux, a few tests fail:

rspec ./spec/framework/detector/os_detector_spec.rb:127 # OsDetector initialize when host_os is linux detects linux distro
rspec ./spec/framework/detector/os_detector_spec.rb:131 # OsDetector initialize when host_os is linux calls Facter::OsHierarchy with construct_hierarchy
rspec ./spec/framework/detector/os_detector_spec.rb:137 # OsDetector initialize when host_os is linux calls Facter::Resolvers::OsRelease with id
rspec ./spec/framework/detector/os_detector_spec.rb:143 # OsDetector initialize when host_os is linux calls Facter::Resolvers::RedHatRelease with id
rspec ./spec/framework/detector/os_detector_spec.rb:159 # OsDetector initialize when host_os is linux when distribution is not known falls back to linux
rspec ./spec/framework/detector/os_detector_spec.rb:164 # OsDetector initialize when host_os is linux when distribution is not known when no hierarchy for os identifier logs debug message
rspec ./spec/framework/detector/os_detector_spec.rb:198 # OsDetector initialize when host_os is linux when distribution is not known when family is known logs debug message

errors:

Failures:

  1) OsDetector initialize when host_os is linux detects linux distro
     Failure/Error: hierarchy = @os_hierarchy.construct_hierarchy(identifier)

       #<InstanceDouble(Facter::OsHierarchy) (anonymous)> received :construct_hierarchy with unexpected arguments
         expected: (:redhat)
              got: (:archlinux)
       Diff:
       @@ -1 +1 @@
       -[:redhat]
       +[:archlinux]

        Please stub a default value first if message might be received with other args as well.
     # ./lib/facter/framework/detector/os_detector.rb:46:in `detect_hierarchy'
     # ./lib/facter/framework/detector/os_detector.rb:41:in `detect'
     # ./lib/facter/framework/detector/os_detector.rb:13:in `initialize'
     # ./spec/framework/detector/os_detector_spec.rb:128:in `block (4 levels) in <top (required)>'

  2) OsDetector initialize when host_os is linux calls Facter::OsHierarchy with construct_hierarchy
     Failure/Error: hierarchy = @os_hierarchy.construct_hierarchy(identifier)

       #<InstanceDouble(Facter::OsHierarchy) (anonymous)> received :construct_hierarchy with unexpected arguments
         expected: (:redhat)
              got: (:archlinux)
       Diff:
       @@ -1 +1 @@
       -[:redhat]
       +[:archlinux]

        Please stub a default value first if message might be received with other args as well.
     # ./lib/facter/framework/detector/os_detector.rb:46:in `detect_hierarchy'
     # ./lib/facter/framework/detector/os_detector.rb:41:in `detect'
     # ./lib/facter/framework/detector/os_detector.rb:13:in `initialize'
     # ./spec/framework/detector/os_detector_spec.rb:132:in `block (4 levels) in <top (required)>'

  3) OsDetector initialize when host_os is linux calls Facter::Resolvers::OsRelease with id
     Failure/Error: hierarchy = @os_hierarchy.construct_hierarchy(identifier)

       #<InstanceDouble(Facter::OsHierarchy) (anonymous)> received :construct_hierarchy with unexpected arguments
         expected: (:redhat)
              got: (:archlinux)
       Diff:
       @@ -1 +1 @@
       -[:redhat]
       +[:archlinux]

        Please stub a default value first if message might be received with other args as well.
     # ./lib/facter/framework/detector/os_detector.rb:46:in `detect_hierarchy'
     # ./lib/facter/framework/detector/os_detector.rb:41:in `detect'
     # ./lib/facter/framework/detector/os_detector.rb:13:in `initialize'
     # ./spec/framework/detector/os_detector_spec.rb:138:in `block (4 levels) in <top (required)>'

  4) OsDetector initialize when host_os is linux calls Facter::Resolvers::RedHatRelease with id
     Failure/Error: hierarchy = @os_hierarchy.construct_hierarchy(identifier)

       #<InstanceDouble(Facter::OsHierarchy) (anonymous)> received :construct_hierarchy with unexpected arguments
         expected: (:redhat)
              got: (:archlinux)
       Diff:
       @@ -1 +1 @@
       -[:redhat]
       +[:archlinux]

        Please stub a default value first if message might be received with other args as well.
     # ./lib/facter/framework/detector/os_detector.rb:46:in `detect_hierarchy'
     # ./lib/facter/framework/detector/os_detector.rb:41:in `detect'
     # ./lib/facter/framework/detector/os_detector.rb:13:in `initialize'
     # ./spec/framework/detector/os_detector_spec.rb:144:in `block (4 levels) in <top (required)>'

  5) OsDetector initialize when host_os is linux when distribution is not known falls back to linux
     Failure/Error: expect(OsDetector.instance.identifier).to eq(:my_linux_distro)

       expected: :my_linux_distro
            got: :archlinux

       (compared using ==)

       Diff:
       @@ -1 +1 @@
       -:my_linux_distro
       +:archlinux
     # ./spec/framework/detector/os_detector_spec.rb:160:in `block (5 levels) in <top (required)>'

  6) OsDetector initialize when host_os is linux when distribution is not known when no hierarchy for os identifier logs debug message
     Failure/Error:
       expect(logger)
         .to have_received(:debug)
         .with('Could not detect hierarchy using os identifier: my_linux_distro , trying with family')

       #<InstanceDouble(Facter::Log) (anonymous)> received :debug with unexpected arguments
         expected: ("Could not detect hierarchy using os identifier: my_linux_distro , trying with family")
              got: ("Could not detect hierarchy using os identifier: archlinux , trying with family") (1 time)
                   ("Could not detect hierarchy using family , falling back to Linux") (1 time)
     # ./spec/framework/detector/os_detector_spec.rb:167:in `block (6 levels) in <top (required)>'

  7) OsDetector initialize when host_os is linux when distribution is not known when family is known logs debug message
     Failure/Error:
       expect(logger)
         .to have_received(:debug)
         .with('Could not detect hierarchy using os identifier: my_linux_distro , trying with family')

       #<InstanceDouble(Facter::Log) (anonymous)> received :debug with unexpected arguments
         expected: ("Could not detect hierarchy using os identifier: my_linux_distro , trying with family")
              got: ("Could not detect hierarchy using os identifier: archlinux , trying with family")
     # ./spec/framework/detector/os_detector_spec.rb:201:in `block (6 levels) in <top (required)>'

Finished in 2.11 seconds (files took 1.13 seconds to load)
3150 examples, 7 failures

Expected Behavior

Passing tests with proper environment isolation

Steps to Reproduce

  • start Arch Linux
  • run bundle exec rspec

Environment

  • Arch Linux

Additional Context

  • I assume some mocking/stubbing isn't correct and OS information is leaking into the tests?
@bastelfreak bastelfreak added the bug Something isn't working label Sep 5, 2024
@bastelfreak
Copy link
Contributor Author

Some facts from facter 4.8.0 on Arch Linux, if that helps:

{
  "facterversion": "4.8.0",
  "os": {
    "architecture": "x86_64",
    "distro": {
      "codename": "n/a",
      "description": "Arch Linux",
      "id": "Arch",
      "release": {
        "full": "rolling",
        "major": "rolling",
        "minor": ""
      },
      "specification": "n/a"
    },
    "family": "Archlinux",
    "hardware": "x86_64",
    "name": "Archlinux",
    "release": {
      "full": "6.10.2-arch1-2",
      "major": "6",
      "minor": "10"
    },
    "selinux": {
      "enabled": false
    }
  },
  "puppetversion": "7.32.1"
}

@joshcooper
Copy link
Contributor

There's a bit of a catch-22 with facter's OS hierarchy. It needs to resolve the os family and distro to build the OS hierarchy, and then use the hierarchy to determine facts are applicable for that OS, which then resolves the OS family and distro facts. To break the deadlock, it uses RbConfig to detect the host

host_os = RbConfig::CONFIG['host_os']

And then resolves additional information in

def detect_family
Facter::Resolvers::OsRelease.resolve(:id_like)
end
def detect_based_on_release_file
@identifier = :devuan if File.readable?('/etc/devuan_version')
@identifier = :archlinux if File.readable?('/etc/arch-release')
end
def detect_distro
detect_based_on_release_file
return @identifier if @identifier
[Facter::Resolvers::OsRelease,
Facter::Resolvers::RedHatRelease,
Facter::Resolvers::SuseRelease].each do |resolver|
@identifier = resolver.resolve(:id)
break if @identifier
end
@identifier&.downcase&.to_sym
end
You might need ot modify the OsDetector or stub the tests to handle arch.

@bastelfreak
Copy link
Contributor Author

Ah the problem is File.readable?('/etc/arch-release') which isn't stubbed, so it's true when you run the tests on Arch Linux. I will raise a PR.

bastelfreak added a commit to bastelfreak/facter that referenced this issue Sep 6, 2024
This is required to run the test suite on Devuan/Arch Linux boxes.
@joshcooper
Copy link
Contributor

Fixed in #2753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants