test: metadata in describe

Michael Vogt pointed out that testcases start failing when we describe
the new format. Let's add a test case and fix the describe to include
the metadata.

Metadata is freeform in the `Manifest` instance but it is stored on it
during loading (at which time its properties are validated) and returned
as-is on describe.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2024-10-28 12:14:25 +01:00 committed by Michael Vogt
parent 12dcf3c6d9
commit 8429acf7e3
3 changed files with 21 additions and 1 deletions

View file

@ -166,6 +166,9 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict:
"pipelines": pipelines "pipelines": pipelines
} }
if manifest.metadata:
description["metadata"] = manifest.metadata
if sources: if sources:
description["sources"] = sources description["sources"] = sources
@ -355,10 +358,15 @@ def load(description: Dict, index: Index) -> Manifest:
sources = description.get("sources", {}) sources = description.get("sources", {})
pipelines = description.get("pipelines", []) pipelines = description.get("pipelines", [])
metadata = description.get("metadata", {})
manifest = Manifest() manifest = Manifest()
source_refs = set() source_refs = set()
# metadata
for key, value in metadata.items():
manifest.add_metadata(key, value)
# load the sources # load the sources
for name, desc in sources.items(): for name, desc in sources.items():
info = index.get_module_info("Source", name) info = index.get_module_info("Source", name)

View file

@ -4,7 +4,7 @@ import hashlib
import json import json
import os import os
from fnmatch import fnmatch from fnmatch import fnmatch
from typing import Dict, Generator, Iterable, Iterator, List, Optional from typing import Any, Dict, Generator, Iterable, Iterator, List, Optional
from . import buildroot, host, objectstore, remoteloop from . import buildroot, host, objectstore, remoteloop
from .api import API from .api import API
@ -388,9 +388,13 @@ class Manifest:
"""Representation of a pipeline and its sources""" """Representation of a pipeline and its sources"""
def __init__(self): def __init__(self):
self.metadata = {}
self.pipelines = collections.OrderedDict() self.pipelines = collections.OrderedDict()
self.sources = [] self.sources = []
def add_metadata(self, name: str, data: Dict[str, Any]) -> None:
self.metadata[name] = data
def add_pipeline( def add_pipeline(
self, self,
name: str, name: str,

View file

@ -12,6 +12,14 @@ import osbuild.meta
BASIC_PIPELINE = { BASIC_PIPELINE = {
"version": "2", "version": "2",
"metadata": {
"generators": [
{
"name": "handcrafted",
"version": "NaN",
},
],
},
"sources": { "sources": {
"org.osbuild.curl": { "org.osbuild.curl": {
"items": { "items": {