fix: prevent traceback in util.get_hostname_fqdn when hostname is numeric - #7014
fix: prevent traceback in util.get_hostname_fqdn when hostname is numeric#7014nabil-rady wants to merge 1 commit into
Conversation
5cfc3f4 to
e7ee608
Compare
| hostname = get_cfg_option_str(cfg, "hostname", fqdn.split(".")[0]) | ||
| else: | ||
| if "hostname" in cfg and cfg["hostname"].find(".") > 0: | ||
| hostname = str(cfg["hostname"]) if "hostname" in cfg else None |
There was a problem hiding this comment.
This seems like a weird place to address the error. The schema defines this key as a string - how did it get interpreted as an integer in the first place?
I'm concerned that by trying to fix it here it misses bugs in other parts of the code.
There was a problem hiding this comment.
I looked at this discussion, the fqdn fix makes sense and it has context to it, unlike this fix; as quoting the hostname fixes the issue. Would you suggest ignoring this issue or maybe moving the _maybe_set_hostname to the try/except block ?
There was a problem hiding this comment.
It would be better if cloud-init produced an error log rather than a traceback, but this is the expected behavior: if you pass an integer, cloud-init just doesn't know what to do with it. The cloud-init schema command shows that this configuration isn't valid.
There was a problem hiding this comment.
@holmanb returned empty hostname and fqdn when hostname is numeric. Running cloud-init status --long produced these warnings.
I am concerned whether we should fallback to cloud in case of a numeric hostname or not.
WARNING:
- cloud-config failed schema validation! You may run 'sudo cloud-init schema --system' to check the details.
- Invalid hostname type: expected string, got int
- Failed to non-persistently adjust the system hostname to
- Invalid hostname type: expected string, got int
- cloud-config failed schema validation! You may run 'sudo cloud-init schema --system' to check the details.
- Invalid hostname type: expected string, got int
- Failed to non-persistently adjust the system hostname to
- Invalid hostname type: expected string, got int
- cloud-config failed schema validation! You may run 'sudo cloud-init schema --system' to check the details.
- Invalid hostname type: expected string, got int
- Failed to non-persistently adjust the system hostname to
- Invalid hostname type: expected string, got int
- cloud-config failed schema validation! You may run 'sudo cloud-init schema --system' to check the details.
- Invalid hostname type: expected string, got int
- Failed to non-persistently adjust the system hostname to
- Invalid hostname type: expected string, got int
e7ee608 to
1fa2973
Compare
1fa2973 to
2c06c86
Compare
Catch the AttributeError thrown in util.get_hostname_fqdn and return empty hostname and fqdn to prevent cloud-init from crashing due to schema error and log a warning instead
2c06c86 to
334e13d
Compare
Proposed Commit Message
Additional Context
Reproduced the error using QEMU and the following user-data file
Fixes #7007
Test Steps
Merge type