ostree: add convenience function for using default OSTree deployment

This adds a `default: true` option for all cases where OSTree
information is specified in schemas and allows for the information
to be picked up from the filesystem.

This is a safe operation because when building disk images there is
no known case where having two deployments makes sense. In the case
there ever were a case then the osname, ref, and serial options still
exist and can be used.

Co-authored-by: Luke Yang <luyang@redhat.com>
Co-authored-by: Michael Vogt <michael.vogt@gmail.com>
This commit is contained in:
Dusty Mabe 2024-01-25 13:57:51 -05:00
parent 2021b915f1
commit e1cbf92673
11 changed files with 264 additions and 49 deletions

View file

@ -518,8 +518,7 @@
"options": {
"coreos_compat": true,
"deployment": {
"ref": "ostree/1/1/0",
"osname": "fedora-coreos"
"default": true
}
}
},
@ -527,8 +526,7 @@
"type": "org.osbuild.ostree.selinux",
"options": {
"deployment": {
"ref": "ostree/1/1/0",
"osname": "fedora-coreos"
"default": true
}
}
}
@ -705,8 +703,7 @@
},
"static-configs": true,
"deployment": {
"ref": "ostree/1/1/0",
"osname": "fedora-coreos"
"default": true
}
},
"devices": {
@ -956,8 +953,7 @@
"options": {
"static-configs": true,
"deployment": {
"ref": "ostree/1/1/0",
"osname": "fedora-coreos"
"default": true
}
},
"devices": {

View file

@ -129,15 +129,11 @@ pipelines:
options:
coreos_compat: true
deployment:
ref: ostree/1/1/0
osname:
mpp-format-string: '{osname}'
default: true
- type: org.osbuild.ostree.selinux
options:
deployment:
ref: ostree/1/1/0
osname:
mpp-format-string: '{osname}'
default: true
- name: raw-image
build: name:build
stages:
@ -242,9 +238,7 @@ pipelines:
device: disk
static-configs: true
deployment:
ref: ostree/1/1/0
osname:
mpp-format-string: '{osname}'
default: true
devices:
disk:
type: org.osbuild.loopback
@ -408,9 +402,7 @@ pipelines:
options:
static-configs: true
deployment:
ref: ostree/1/1/0
osname:
mpp-format-string: '{osname}'
default: true
devices:
disk:
type: org.osbuild.loopback

View file

@ -11,6 +11,7 @@ import unittest
import pytest
from osbuild.testutil import make_fake_tree
from osbuild.util import ostree
from .. import test
@ -208,3 +209,41 @@ class TestPasswdLike(unittest.TestCase):
check.read_from(file)
assert subids.db == check.db
def test_parse_default_deployment_happy(tmp_path):
deployment = {
"default": True,
}
make_fake_tree(tmp_path, {
"ostree/deploy/fedora-coreos/deploy/72f807.0": "",
})
osname, ref, serial = ostree.parse_deployment_option(tmp_path, deployment)
assert osname == "fedora-coreos"
assert ref == "72f807"
assert serial == "0"
def test_parse_default_deployment_sad(tmp_path):
deployment = {
"default": True,
}
make_fake_tree(tmp_path, {
"ostree/deploy/fedora-coreos/deploy/72f807.0": "",
"ostree/deploy/fedora-coreos/deploy/123456.0": "",
})
with pytest.raises(ValueError) as exp:
ostree.parse_deployment_option(tmp_path, deployment)
assert "More than one deployment found: [" in str(exp.value)
def test_parse_deployment_happy(tmp_path):
deployment = {
"osname": "fedora-coreos",
"ref": "some-ref",
"serial": "0",
}
osname, ref, serial = ostree.parse_deployment_option(tmp_path, deployment)
assert osname == "fedora-coreos"
assert ref == "some-ref"
assert serial == "0"