pipeline: detect_os() -> describe_os()
Rename the function to `describe_os()`. We do no actual detection, nor
verification here. That is, the return value of this function is in no
way guaranteed to be a valid runner. That is, error-handling needs to
be done in the caller. Make this clear by renaming the function.
Note: Currently, in case no runner exists for the OS, we end up with:
execv(...) failed: No such file or directory
This needs to be fixed in the future.
This commit is contained in:
parent
cd07d588fc
commit
53415a3cbc
2 changed files with 12 additions and 10 deletions
|
|
@ -302,14 +302,16 @@ class Pipeline:
|
|||
return results
|
||||
|
||||
|
||||
def detect_os(*paths):
|
||||
"""Detect the os from an os-release file.
|
||||
def describe_os(*paths):
|
||||
"""Read the Operating System Description from `os-release`
|
||||
|
||||
The first file in 'paths' is used and interpreted like a os-release(5)
|
||||
file.
|
||||
This creates a string describing the running operating-system name and
|
||||
version. It reads the information from the path array provided as `paths`.
|
||||
The first available file takes precedence. It must be formatted according
|
||||
to the rules in `os-release(5)`.
|
||||
|
||||
Returns ID + VERSION_ID (without dots), which is the same format that
|
||||
runners are named as.
|
||||
The returned string uses the format `${ID}${VERSION_ID}` with all dots
|
||||
stripped.
|
||||
"""
|
||||
osrelease = {}
|
||||
|
||||
|
|
@ -347,7 +349,7 @@ def load(description, sources_options):
|
|||
if build:
|
||||
build_pipeline, runner = load_build(build, sources_options)
|
||||
else:
|
||||
build_pipeline, runner = None, "org.osbuild." + detect_os("/etc/os-release", "/usr/lib/os-release")
|
||||
build_pipeline, runner = None, "org.osbuild." + describe_os("/etc/os-release", "/usr/lib/os-release")
|
||||
|
||||
pipeline = Pipeline(runner, build_pipeline)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ import osbuild
|
|||
class TestOSRelease(unittest.TestCase):
|
||||
def test_non_existant(self):
|
||||
"""Verify default os-release value, if no files are given."""
|
||||
self.assertEqual(osbuild.pipeline.detect_os(), "linux")
|
||||
self.assertEqual(osbuild.pipeline.describe_os(), "linux")
|
||||
|
||||
def test_detect_os(self):
|
||||
def test_describe_os(self):
|
||||
"""Test host os detection. test/os-release contains the os-release files
|
||||
for all supported runners.
|
||||
"""
|
||||
for entry in os.scandir("test/os-release"):
|
||||
with self.subTest(entry.name):
|
||||
self.assertEqual(osbuild.pipeline.detect_os(entry.path), entry.name)
|
||||
self.assertEqual(osbuild.pipeline.describe_os(entry.path), entry.name)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue