Skip to content
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

handle TypeError when get_mount_info function get None #4322

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cloudinit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2782,7 +2782,14 @@ def get_mount_info(path, log=LOG, get_mnt_opts=False):


def has_mount_opt(path, opt: str) -> bool:
*_, mnt_opts = get_mount_info(path, get_mnt_opts=True)
try:
*_, mnt_opts = get_mount_info(path, get_mnt_opts=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this function return None to begin with?

Copy link
Contributor Author

@xiaoge1001 xiaoge1001 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would this function return None to begin with?

The reason still needs to be further identified. However, when we look at the implementation code of this function, there is some cases of returning None.

https://github.com/canonical/cloud-init/blob/main/cloudinit/util.py#L2530
https://github.com/canonical/cloud-init/blob/main/cloudinit/util.py#L2560
https://github.com/canonical/cloud-init/blob/main/cloudinit/util.py#L2570
https://github.com/canonical/cloud-init/blob/main/cloudinit/util.py#L2583

Copy link
Collaborator

@igalic igalic Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of all of those, only the first and the last would leave no trace in the log

the first one would mean your mountinfo file is in the wrong, or a new unknown, different, format. Hopefully, that's an easy fix.

the last one would mean no match was found, including no match for /! I'm not sure there are scenarios where that makes sense (at least as a system to run cloud-init on)

except TypeError:
LOG.warning(
"Found no mount info for %s",
path,
)
return False
return opt in mnt_opts.split(",")


Expand Down
Loading