schema: tracecback when using schema --annotate on single line dicts

Bug #1885598 reported by Chad Smith
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Medium
Unassigned

Bug Description

Annotate doesn't handle r-value dicts that begin on the same line as the l-value key.

Given the following example invalid cloudconfig (providing an int for a string value in chef), we get a traceback when trying to annotate the invalid user-data.

cat > invalid-chef-traceback.yaml <<EOF
#cloud-config
chef: {install_type: 1}
EOF

Annotate works on dicts that are not declared on the same line as the "chef" key

cat > invalid-chef.yaml <<EOF
#cloud-config
chef:
  install_type: 1
EOF

csmith@uptown:~/src/cloud-init$ python3 -m cloudinit.cmd.main devel schema -c invalid-chef.yaml --annotate
#cloud-config
chef:
   install_type: 1 # E1

# Errors: -------------
# E1: 1 is not of type 'string'

csmith@uptown:~/src/cloud-init$ python3 -m cloudinit.cmd.main devel schema -c invalid-chef-traceback.yaml --annotate
Traceback (most recent call last):
  File "/home/csmith/src/cloud-init/cloudinit/config/schema.py", line 215, in validate_cloudconfig_file
    validate_cloudconfig_schema(
  File "/home/csmith/src/cloud-init/cloudinit/config/schema.py", line 120, in validate_cloudconfig_schema
    raise SchemaValidationError(errors)
cloudinit.config.schema.SchemaValidationError: Cloud config schema errors: chef.install_type: 1 is not of type 'string'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/csmith/src/cloud-init/cloudinit/cmd/main.py", line 901, in <module>
    return_value = main(sys.argv)
  File "/home/csmith/src/cloud-init/cloudinit/cmd/main.py", line 891, in main
    retval = util.log_time(
  File "/home/csmith/src/cloud-init/cloudinit/util.py", line 2285, in log_time
    ret = func(*args, **kwargs)
  File "/home/csmith/src/cloud-init/cloudinit/config/schema.py", line 444, in handle_schema_args
    validate_cloudconfig_file(
  File "/home/csmith/src/cloud-init/cloudinit/config/schema.py", line 219, in validate_cloudconfig_file
    print(annotated_cloudconfig_file(
  File "/home/csmith/src/cloud-init/cloudinit/config/schema.py", line 151, in annotated_cloudconfig_file
    errors_by_line[schemapaths[path]].append(msg)
KeyError: 'chef.install_type'

Tags: bitsize
Chad Smith (chad.smith)
Changed in cloud-init:
status: New → Triaged
status: Triaged → Confirmed
Dan Watkins (oddbloke)
Changed in cloud-init:
status: Confirmed → Triaged
Revision history for this message
Alberto Contreras (aciba) wrote :

Another example:

```yaml
#cloud-config
users:
  - name: james
    hashed-passwd: somepassword
```

from https://github.com/canonical/cloud-init/pull/1549#pullrequestreview-1028680743

Revision history for this message
Chad Smith (chad.smith) wrote :

Let's address this, as there are a couple of failure paths in --annotate that really should be cleaned up for usability.

Changed in cloud-init:
importance: Undecided → Medium
tags: added: bitsize
Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Triaged → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.