From 439c1133e5d8b6848a0a00433f0aeb6ac9c7e78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Can=C3=A9vet?= Date: Wed, 29 Apr 2026 17:57:10 +0200 Subject: [PATCH] test(opennebula): validate gen_conf() output against network-config-v2 schema Add an autouse fixture to TestOpenNebulaNetwork that wraps gen_conf() and runs jsonschema validation against schema-network-config-v2.json on every call, so all existing tests implicitly assert schema conformance. --- tests/unittests/sources/test_opennebula.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/unittests/sources/test_opennebula.py b/tests/unittests/sources/test_opennebula.py index 10ccdea2ed3..7ef29707c27 100644 --- a/tests/unittests/sources/test_opennebula.py +++ b/tests/unittests/sources/test_opennebula.py @@ -5,9 +5,11 @@ import pwd from unittest import mock +import jsonschema import pytest from cloudinit import atomic_helper +from cloudinit.config.schema import SchemaType, get_schema from cloudinit.sources import DataSourceOpenNebula as ds from tests.unittests.helpers import populate_dir @@ -370,9 +372,24 @@ def my_devs_with(criteria): @mock.patch(DS_PATH + ".net.get_interfaces_by_mac", mock.Mock(return_value={})) class TestOpenNebulaNetwork: - system_nics = ("eth0", "ens3") + @pytest.fixture(autouse=True) + def _validate_gen_conf_schema(self, monkeypatch): + """Wrap gen_conf() to assert schema validity on every test.""" + schema = get_schema(SchemaType.NETWORK_CONFIG_V2) + assert schema, "network-config-v2 schema must not be empty" + validator_cls = jsonschema.validators.validator_for(schema) + validator = validator_cls(schema) + original = ds.OpenNebulaNetwork.gen_conf + + def validated(self_inner): + result = original(self_inner) + validator.validate(result) + return result + + monkeypatch.setattr(ds.OpenNebulaNetwork, "gen_conf", validated) + def test_context_devname(self): """Verify context_devname correctly returns mac and name.""" context = {