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

handle TypeError when get_mount_info function get None #4322

wants to merge 2 commits into from

Conversation

xiaoge1001
Copy link
Contributor

Proposed Commit Message

handle TypeError when get_mount_info function get None

Fixes GH-4321

*_, mnt_opts = get_mount_info(path, get_mnt_opts=True)
except TypeError:
LOG.warning(
"Get Nothing mount info from %s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this message reads really confusing

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should say: "Found no mount info for %s",

@@ -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)

@xiaoge1001 xiaoge1001 requested a review from igalic August 14, 2023 01:02
@holmanb
Copy link
Member

holmanb commented Aug 15, 2023

Per @blackboxsw's comment, I don't think that the current approach is desired to resolve the issue.

@xiaoge1001
Copy link
Contributor Author

I don't think that the current approach is desired to resolve the issue.

Yes, we may need to fundamentally address why function get_mount_info() returns None.

@xiaoge1001 xiaoge1001 closed this Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: cannot unpack non-iterable NoneType object in has_mount_opt()
3 participants