Skip to content

Commit

Permalink
fix(schema): allow networkv2 schema without top-level key (#5239)
Browse files Browse the repository at this point in the history
During validation process, the network schema is extracted without
the network key.  As such, the schema validation should work
either with or without the top level network key.  This change
updates the schema and adds a unit test to validate.
  • Loading branch information
catmsred committed May 1, 2024
1 parent efd37c0 commit 66a874b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cloudinit/config/schemas/schema-network-config-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,20 @@
}
}
},
"type": "object",
"required": [
"network"
],
"properties": {
"network": {
"oneOf": [
{
"$ref": "#/$defs/network_config_version2"
},
{
"required": [
"network"
],
"properties": {
"network": {
"$ref": "#/$defs/network_config_version2"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
]
}
10 changes: 10 additions & 0 deletions tests/unittests/config/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,16 @@ class TestNetworkSchema:
"",
id="net_v2_simple_example",
),
pytest.param(
{
"version": 2,
"ethernets": {"eno1": {"dhcp4": True}},
},
SchemaType.NETWORK_CONFIG_V2,
does_not_raise(),
"",
id="net_v2_no_top_level",
),
pytest.param(
{
"network": {
Expand Down

0 comments on commit 66a874b

Please sign in to comment.