schema validation not in line with specification
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Fix Released
|
High
|
Alberto Contreras |
Bug Description
Related to #1983303. My user-data begins with #include, as it's not a "Cloud Config Data" but an "Include File" as described in the official documentation. However, this causes the validator `cloud-init schema --system` to complain that
```
Error:
Cloud config schema errors: format-l1.c1: File None needs to begin with "#cloud-config"
```
Ok I thought, I just manually add "#cloud-config" at the top and re-test:
```
Error:
Cloud-config is not a YAML dict.
```
Well, it's not a YAML dict because it's not a cloud config data but an include file, which isn't in the YAML format.
See the specification: https:/
Also look at the implementation in `user_data.py`, function `_do_include`. As you can see, this file isn't processed as YAML but parsed line by line. So the specification and implementation agree, but the schema validator doesn't and thinks it should process it as YAML.
This wouldn't be a practical problem for me, but due to #1983303 I get mangled logs and can't work around it.
description: | updated |
Changed in cloud-init: | |
status: | Confirmed → Triaged |
importance: | Undecided → Medium |
Changed in cloud-init: | |
assignee: | nobody → Alberto Contreras (aciba) |
status: | Incomplete → In Progress |
Changed in cloud-init: | |
status: | In Progress → Fix Committed |
Reproduced with:
```bash www.canonical. com
cat > /tmp/lp1983306 <<EOF
#include
http://
EOF
lxc launch ubuntu- daily:kinetic lp1983306
lxc file push /tmp/lp1983306 lp1983306/root/
lxc exec lp1983306 -- cloud-init status --wait
$ lxc exec lp1983306 -- cloud-init --version g1fcd55d6- 0ubuntu1~ 22.10.1
/usr/bin/cloud-init 22.2-64-
$ lxc exec lp1983306 -- cloud-init schema -c /root/lp1983306
Error:
Cloud config schema errors: format-l1.c1: File /root/lp1983306 needs to begin with "#cloud-config"
$ lxc exec lp1983306 -- cloud-init schema -c /root/lp1983306 --annotate www.google. com
#include # E1
http://
# Errors: -------------
# E1: File /root/lp1983306 needs to begin with "#cloud-config"
```
Note that the query command does also not resolve include directives:
```bash cloud-init" , line 33, in <module> exit(load_ entry_point( 'cloud- init==22. 2', 'console_scripts', 'cloud-init')()) python3/ dist-packages/ cloudinit/ cmd/main. py", line 1063, in main python3/ dist-packages/ cloudinit/ util.py" , line 2621, in log_time python3/ dist-packages/ cloudinit/ cmd/query. py", line 291, in handle_args data_leaf_ by_varname_ path( python3/ dist-packages/ cloudinit/ cmd/query. py", line 230, in _find_instance_ data_leaf_ by_varname_ path vars_with_ aliases = jinja_vars_ with_aliases[ key_path_ part]
$ lxc exec lp1983306 -- cloud-init query -u /root/lp1983306 userdata.asdf
Traceback (most recent call last):
File "/usr/bin/
sys.
File "/usr/lib/
retval = util.log_time(
File "/usr/lib/
ret = func(*args, **kwargs)
File "/usr/lib/
response = _find_instance_
File "/usr/lib/
jinja_
TypeError: string indices must be integers
```