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
}
if manifest.metadata:
description["metadata"] = manifest.metadata
if sources:
description["sources"] = sources
@ -355,10 +358,15 @@ def load(description: Dict, index: Index) -> Manifest:
sources = description.get("sources", {})
pipelines = description.get("pipelines", [])
metadata = description.get("metadata", {})
manifest = Manifest()
source_refs = set()
# metadata
for key, value in metadata.items():
manifest.add_metadata(key, value)
# load the sources
for name, desc in sources.items():
info = index.get_module_info("Source", name)

View file

@ -4,7 +4,7 @@ import hashlib
import json
import os
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 .api import API
@ -388,9 +388,13 @@ class Manifest:
"""Representation of a pipeline and its sources"""
def __init__(self):
self.metadata = {}
self.pipelines = collections.OrderedDict()
self.sources = []
def add_metadata(self, name: str, data: Dict[str, Any]) -> None:
self.metadata[name] = data
def add_pipeline(
self,
name: str,

View file

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