cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

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

Open ubuntu-server-builder opened this issue 2 years ago • 2 comments

This bug was originally filed in Launchpad as LP: #1885598

Launchpad details
affected_projects = []
assignee = None
assignee_name = None
date_closed = None
date_created = 2020-06-29T16:18:15.900486+00:00
date_fix_committed = None
date_fix_released = None
id = 1885598
importance = medium
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/1885598
milestone = None
owner = chad.smith
owner_name = Chad Smith
private = False
status = triaged
submitter = chad.smith
submitter_name = Chad Smith
tags = ['bitsize']
duplicates = []

Launchpad user Chad Smith(chad.smith) wrote on 2020-06-29T16:18:15.900486+00:00

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 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'

ubuntu-server-builder avatar May 12 '23 08:05 ubuntu-server-builder

Launchpad user Alberto Contreras(aciba) wrote on 2022-07-11T07:43:47.776913+00:00

Another example:

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

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

ubuntu-server-builder avatar May 12 '23 08:05 ubuntu-server-builder

Launchpad user Chad Smith(chad.smith) wrote on 2022-07-13T03:52:13.930724+00:00

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

ubuntu-server-builder avatar May 12 '23 08:05 ubuntu-server-builder