ostree: show commit metadata
This new API call allows one to check (among other things) if a commit exists in a repo. It'll throw a RuntimeException if the commit is missing.
This commit is contained in:
parent
1de74ce2c9
commit
441e67a6f6
3 changed files with 27 additions and 1 deletions
|
|
@ -129,6 +129,24 @@ def rev_parse(repo: PathLike, ref: str) -> str:
|
|||
return msg
|
||||
|
||||
|
||||
def show(repo: PathLike, checksum: str) -> str:
|
||||
"""Show the metada of an OSTree object pointed by `checksum` in the repository at `repo`"""
|
||||
|
||||
repo = os.fspath(repo)
|
||||
|
||||
r = subprocess.run(["ostree", "show", f"--repo={repo}", checksum],
|
||||
encoding="utf-8",
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False)
|
||||
|
||||
msg = r.stdout.strip()
|
||||
if r.returncode != 0:
|
||||
raise RuntimeError(msg)
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
def deployment_path(root: PathLike, osname: str, ref: str, serial: int):
|
||||
"""Return the path to a deployment given the parameters"""
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import os
|
|||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from osbuild.util import ostree
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ def run(*args, check=True, encoding="utf-8", **kwargs):
|
|||
return res
|
||||
|
||||
|
||||
class TestObjectStore(unittest.TestCase):
|
||||
class TestObjectStore(test.TestBase):
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@unittest.skipUnless(test.TestBase.have_rpm_ostree(), "rpm-ostree missing")
|
||||
|
|
@ -88,6 +89,13 @@ class TestObjectStore(unittest.TestCase):
|
|||
for p, v in params.items():
|
||||
self.assertEqual(v, js[p])
|
||||
|
||||
@unittest.skipUnless(test.TestBase.have_test_data(), "no test-data access")
|
||||
def test_show_commit(self):
|
||||
repo_path = os.path.join(self.locate_test_data(), "sources/org.osbuild.ostree/data/repo")
|
||||
ostree.show(repo_path, "d6243b0d0ca3dc2aaef2e0eb3e9f1f4836512c2921007f124b285f7c466464d8")
|
||||
with pytest.raises(RuntimeError):
|
||||
ostree.show(repo_path, "f000000000000000000000000DEADBEEF000000000000000000000000000000f")
|
||||
|
||||
|
||||
class TestPasswdLike(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue