FerretDB icon indicating copy to clipboard operation
FerretDB copied to clipboard

Improve how we identify Linux version in `hostInfo` command

Open rumyantseva opened this issue 2 years ago • 2 comments

What should be done?

In hostInfo we identify Linux' release by checking /etc/os-release file and parsing the version from it: https://github.com/FerretDB/FerretDB/blob/b1cc4e8b1138805a9d16fafb4ff880dc73d4e6eb/internal/handlers/common/msg_hostinfo.go#L47

However, not each Linux distro contains the version information in this file. As the result, this check https://github.com/FerretDB/FerretDB/blob/b1cc4e8b1138805a9d16fafb4ff880dc73d4e6eb/integration/commands_diagnostic_test.go#L227 will fail for such distros.

Let's investigate what's possible for such distros - is there a way to get the info about the version, should we set some "default value", or should we allow an empty version to be set (and then we need to fix the test).

Many thanks to @raeidish for reporting this problem with Arch Linux (see also https://gist.github.com/natefoo/814c5bf936922dad97ff).

rumyantseva avatar Apr 21 '23 13:04 rumyantseva

doing something like the following in parse_osrelease.go does fix the issue for me. however you might want to get the kernel version with uname utility instead

v, fv := configParams["VERSION"]
n, fn := configParams["NAME"]

if !fv {
    v = "undefined"
}

if !fn {
    n = "undefined"
}

raeidish avatar Apr 21 '23 18:04 raeidish

It is very strange that /etc/os-release does not exist on Arch Linux. It is the very common and standard file:

  • https://www.freedesktop.org/software/systemd/man/os-release.html
  • https://man.archlinux.org/man/os-release.5.en

Maybe the location is different and we should try a few more like /usr/lib/os-release?

We could also try to parse lsb-release file, but we definitely don't want to run lsb_release tool.

AlekSi avatar Apr 21 '23 19:04 AlekSi

I have checked several distros:

Distro /etc/os-release /usr/lib/os-release
Arch :x: :heavy_check_mark:
Red Hat :heavy_check_mark: :heavy_check_mark:
Ubuntu :heavy_check_mark: :heavy_check_mark:
Amazon Linux :heavy_check_mark: :heavy_check_mark:
CentOS :heavy_check_mark: :heavy_check_mark:
openSUSE :heavy_check_mark: :heavy_check_mark:
Debian :heavy_check_mark: :heavy_check_mark:
Scientific Linux(SL) :heavy_check_mark: :x:

However, Arch contains /etc/arch-release instead of /etc/os-release.

So we can:

  1. use the pattern /etc/*-release
  2. make a condition for Arch
  3. switch to file: /usr/lib/os-release EDIT: Scientific Linux misses it

What does seem to be a better option?

Can I work on this issue?

kropidlowsky avatar Apr 25 '23 20:04 kropidlowsky

@kropidlowsky, your proposal sounds good to me! Please feel free to take this issue.

rumyantseva avatar Apr 26 '23 08:04 rumyantseva

(As agreed, the option 2 should be enough)

rumyantseva avatar Apr 26 '23 08:04 rumyantseva

After reading http://0pointer.de/blog/projects/os-release, I think that instead of reading distribution-specific files, we should read two possible paths for distribution-independent files: /etc/os-release and /usr/lib/os-release.

@kropidlowsky could you contribute a new PR?

AlekSi avatar Apr 30 '23 10:04 AlekSi