-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(schema): use netplan python api for schema validation annotation #4767
feat(schema): use netplan python api for schema validation annotation #4767
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall nice add. I didn't really look at the tests since you're still working those though I'd suggest having a test that includes a deprecation warning, just to ensure we're handling it correctly.
I left some inline comments (mostly nits). Additionally, a few strings/comments mention python3-netplan
, but that is an ubuntu-specific package name. It's really just the netplan API doing the validation, so I think it'd be better to just refer to netplan
rather than python3-netplan
.
# network-config it generates, so create a <tmp_dir>/etc/netplan | ||
# to validate only our network-config. | ||
parse_dir = mkdtemp() | ||
netplan_file = os.path.join(parse_dir, "etc/netplan/network-config.yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Is the etc/netplan/
prefix necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, yes it is. netplan Parser.load_yaml_hierarchy only looks under the subdir path etc/netplan/ to process yaml parts. Otherwise it happily ignores files in the root subdir of a path
cloudinit/config/schema.py
Outdated
@@ -1002,7 +1098,14 @@ def validate_cloudconfig_file( | |||
if not netcfg: | |||
print("Skipping network-config schema validation on empty config.") | |||
return False | |||
elif netcfg.get("version") != 1: | |||
elif netcfg.get("version") == 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're validating userdata or network config v1 we call "validate_cloudconfig_schema", but for network config v2 call "netplan_validate_network_config". I think we could a little refactoring as this comes out a little confusing.
I think it's also a little odd that the caller has to check the version number and determine which thing to call. Ideally, we'd have something like "validate_schema" that we pass our configuration to along with some relevant options, and based on what it is, it calls the right validation function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I refactored netplan_validate_network_config to accept just the network_config dict instead of dealing with files. This simplified callsites sigificantly and allowed dealing with version 2 vs version 1 vs netplan API availability inside netplan_validate_network_schema
function. If unable to perform netplan_validate.... we fallthrough and use cloud-init's schema for validation if present. Since we don't have JSON schema version 2 yet, we will still emit Skipping schema validation messages when not netplan and not network schema version: 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I was avoiding the refactor to validate_cloudconfig_schema that would require adding a config path. But, I've since refactored this code to simplify call-sites and like cloudinit.stages
ffdadc3
to
6e23c4e
Compare
45757c5
to
d5ff050
Compare
) Validation of network-config version: 2 will be performed on systems with python3-netplan installed which delivers a python API netplan.Parser which allows cloud-init to parse and determine specific netplan schema errors. The netplan API is only present on Ubuntu Noble in the python3-netplan deb package. Add netplan_validate_network_config function to use netplan API when present. Wire this function into runtime schema validation at initial boot to warn about network-config invalid version: 2 schema. Also wire this function into cloud-init schema command to warn and annotate specific schema errors by line in datasource provided network-config.
) On Noble, python netplan bindings are available in python3-netplan deb package. The presence of they python bindings and netplan.Parser import allow cloud-int for parse and validate network-config version 2 schema. Add an integration tests asserting both schema validation and annotation of invalid network configuration on Ubuntu Noble. On non-Noble environments, expect Skipping of network-config version: 2 message.
d5ff050
to
8897c93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor issues left inline.
Did you miss this comment from my last review?
Additionally, a few strings/comments mention python3-netplan, but that is an ubuntu-specific package name. It's really just the netplan API doing the validation, so I think it'd be better to just refer to netplan rather than python3-netplan.
) Validation of network-config version: 2 will be performed on systems with python3-netplan installed which delivers a python API netplan.Parser which allows cloud-init to parse and determine specific netplan schema errors. The netplan API is only present on Ubuntu Noble in the python3-netplan deb package. Add netplan_validate_network_config function to use netplan API when present. Wire this function into runtime schema validation at initial boot to warn about network-config invalid version: 2 schema. Also wire this function into cloud-init schema command to warn and annotate specific schema errors by line in datasource provided network-config.
8897c93
to
28f23f3
Compare
) On Noble, python netplan bindings are available in python3-netplan deb package. The presence of they python bindings and netplan.Parser import allow cloud-int for parse and validate network-config version 2 schema. Add an integration tests asserting both schema validation and annotation of invalid network configuration on Ubuntu Noble. On non-Noble environments, expect Skipping of network-config version: 2 message.
) Validation of network-config version: 2 will be performed on systems with python3-netplan installed which delivers a python API netplan.Parser which allows cloud-init to parse and determine specific netplan schema errors. The netplan API is only present on Ubuntu Noble in the python3-netplan deb package. Add netplan_validate_network_config function to use netplan API when present. Wire this function into runtime schema validation at initial boot to warn about network-config invalid version: 2 schema. Also wire this function into cloud-init schema command to warn and annotate specific schema errors by line in datasource provided network-config.
) On Noble, python netplan bindings are available in python3-netplan deb package. The presence of they python bindings and netplan.Parser import allow cloud-int for parse and validate network-config version 2 schema. Add an integration tests asserting both schema validation and annotation of invalid network configuration on Ubuntu Noble. On non-Noble environments, expect Skipping of network-config version: 2 message.
28f23f3
to
8aa0ee0
Compare
) Validation of network-config version: 2 will be performed on systems with python3-netplan installed which delivers a python API netplan.Parser which allows cloud-init to parse and determine specific netplan schema errors. The netplan API is only present on Ubuntu Noble in the python3-netplan deb package. Add netplan_validate_network_config function to use netplan API when present. Wire this function into runtime schema validation at initial boot to warn about network-config invalid version: 2 schema. Also wire this function into cloud-init schema command to warn and annotate specific schema errors by line in datasource provided network-config.
) On Noble, python netplan bindings are available in python3-netplan deb package. The presence of they python bindings and netplan.Parser import allow cloud-int for parse and validate network-config version 2 schema. Add an integration tests asserting both schema validation and annotation of invalid network configuration on Ubuntu Noble. On non-Noble environments, expect Skipping of network-config version: 2 message.
8aa0ee0
to
30f05a0
Compare
) On Noble, python netplan bindings are available in python3-netplan deb package. The presence of they python bindings and netplan.Parser import allow cloud-int for parse and validate network-config version 2 schema. Add an integration tests asserting both schema validation and annotation of invalid network configuration on Ubuntu Noble. On non-Noble environments, expect Skipping of network-config version: 2 message.
30f05a0
to
ac1f870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I'll leave to you to merge
Validation of network-config version: 2 will be performed on systems with python3-netplan installed which delivers a python API netplan.Parser which allows cloud-init to parse and determine specific netplan schema errors. The netplan API is only present on Ubuntu Noble in the python3-netplan deb package. Add netplan_validate_network_config function to use netplan API when present. Wire this function into runtime schema validation at initial boot to warn about network-config invalid version: 2 schema. Also wire this function into cloud-init schema command to warn and annotate specific schema errors by line in datasource provided network-config.
Leverage netplan API to perform schema validation when on a system with python3-netplan package.
Context:
Checklist before ready for review:
Additional Context
Test Steps
Checklist
Merge type