Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Add os.release facts on FreeBSD #485

Merged
merged 4 commits into from
May 6, 2020

Conversation

smortex
Copy link
Contributor

@smortex smortex commented Apr 30, 2020

This PR provide support for Facter 3.x os.release facts on FreeBSD to Facter 4:

Before:

romain@zappy ~/Projects/facter-ng % bundle exec bin/facter os        
cat: /etc/release: No such file or directory
[2020-04-29 18:51:23.841325 ] ERROR Facter::Resolvers::SolarisRelease - Could not build release fact because of missing or empty file /etc/release 
cat: /etc/release: No such file or directory
[2020-04-29 18:51:23.842256 ] ERROR Facter::Resolvers::SolarisRelease - Could not build release fact because of missing or empty file /etc/release 
cat: /etc/release: No such file or directory
[2020-04-29 18:51:23.843051 ] ERROR Facter::Resolvers::SolarisRelease - Could not build release fact because of missing or empty file /etc/release 
{
  architecture => "amd64",
  family => "FreeBSD",
  hardware => "amd64",
  name => "FreeBSD",
  release => {
    full => null,
    major => null,
    minor => null
  }
}

After:

romain@zappy ~/Projects/facter-ng % bundle exec bin/facter os      
{
  architecture => "amd64",
  family => "FreeBSD",
  hardware => "amd64",
  name => "FreeBSD",
  release => {
    branch => "RELEASE-p4",
    full => "12.1-RELEASE-p4",
    major => "12",
    minor => "1",
    patchlevel => "4"
  }
}

Compare to:

romain@zappy ~/Projects/facter-ng % facter os
{
  architecture => "amd64",
  family => "FreeBSD",
  hardware => "amd64",
  name => "FreeBSD",
  release => {
    branch => "RELEASE-p4",
    full => "12.1-RELEASE-p4",
    major => "12",
    minor => "1",
    patchlevel => "4"
  }
}

@smortex smortex requested review from a team April 30, 2020 04:55
@puppetlabs-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

@smortex smortex force-pushed the freebsd-os-release branch from 385226c to 010a16f Compare April 30, 2020 05:24
@smortex smortex force-pushed the freebsd-os-release branch from 010a16f to 5723eec Compare April 30, 2020 05:48
"Bsd": [
"Freebsd"
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FreeBSD is definitively a descendant of BSD, yet BSD is not a decedent of Solaris (amusingly, early version of Sun OS (which became Solaris at some point) was based on BSD).

For now, this is convenient because Solaris facts and resolvers provide ZFS related facts which are working on FreeBSD, however, ZFS on Linux is a thing and some refactoring will be necessary at some point. Don't know how / where to log this so that it can be tracked…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe it is as simple as renaming the Solaris ZFS resolver to make it obvious it is not Solaris specific and use similar facts for FreeBSD, Solaris and maybe Linux to gather these facts… So basically the same code facts multiple times, but maybe it's not a problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smortex I talked with @oanatmaria and maybe we can have something like

...
  {
    "Unix": [
      "Solaris",
      {
        "Bsd": [
          "Freebsd"
        ]
      }

    ]
  },
...

Both Solaris and Bsd will inherit from Unix. This is based on the diagram from https://upload.wikimedia.org/wikipedia/commons/7/77/Unix_history-simple.svg

@oanatmaria oanatmaria added feature bugfix Something isn't working community and removed bugfix Something isn't working labels Apr 30, 2020
Comment on lines +28 to +30
@fact_list[:installed_kernel] = freebsd_version_results[0].strip
@fact_list[:running_kernel] = freebsd_version_results[1].strip
@fact_list[:installed_userland] = freebsd_version_results[2].strip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.strip will raise NoMethodError if output is empty string or if freebsd_version_results[0/1/2] is nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

freebsd-version -kru is expected to return exactly 3 lines (each flag produce a line), so I do not thing this is a problem for us here. Yet, some FreeBSD forks might be detected as "FreeBSD" while not providing freebsd-update, so it's worth being sure that the command succeeded.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HardenedBSD doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igalic did you have the opportunity to try it on HardenedBSD? I need to allocate some time to dig in this project…

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, my current priority
canonical/cloud-init#363 is a few yak stacks away from testing HardenedBSD

@smortex smortex changed the title Add os.release facts on FreeBSD WIP: Add os.release facts on FreeBSD Apr 30, 2020
This program is always supposed to be found and return the expected
output on FreeBSD but make sure it runs successfully, catpure stderr in
case it becomes used at some point, and do not raise exceptions if the
resolver fails.
@smortex smortex force-pushed the freebsd-os-release branch from 5edea77 to ca9c35e Compare May 1, 2020 07:11
@smortex smortex changed the title WIP: Add os.release facts on FreeBSD Add os.release facts on FreeBSD May 1, 2020
@smortex smortex requested a review from oanatmaria May 1, 2020 07:24
smortex added 2 commits May 5, 2020 04:37
If the resolver fails to gather the fact, return an empty resolved fact
instead of an empty array.
spec/facter/resolvers/utils/windows/network_utils_spec.rb:37:7: C: RSpec/EmptyHook: Empty hook detected.
      before do
      ^^^^^^
@BogdanIrimie
Copy link
Contributor

Great job with this PR @smortex and @oanatmaria !

@BogdanIrimie BogdanIrimie merged commit b0de928 into puppetlabs:master May 6, 2020
@smortex smortex deleted the freebsd-os-release branch May 7, 2020 05:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants