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

(FACT-2928) Better error for mountpoints stats #2371

Conversation

Dorin-Pleava
Copy link
Contributor

When Sys::Filesystem.stat(mountopint_path) fails, it will throw
statvfs() function failed: No such file or directory, but will not
show what file is missing.

Steps I used to reproduce a similar error as in FACT-2928:

$ yum install bind-chroot -y
...
$ systemctl start named-chroot

Place a binding to stop execution above https://github.com/puppetlabs/facter/blob/main/lib/facter/util/resolvers/filesystem_helper.rb#L20

$ puppet facts show

require 'sys/filesystem' => binding.pry Sys::Filesystem.stat(path)

When binding.pry is hit, run $ systemctl stop named-chroot, then
continue execution.

@Dorin-Pleava Dorin-Pleava requested review from a team April 26, 2021 14:46
@Dorin-Pleava Dorin-Pleava force-pushed the FACT-2928_better_error_reading_mountpoints_stats branch 4 times, most recently from 86ac611 to ffa514f Compare April 27, 2021 12:27
When Sys::Filesystem.stat(mountopint_path) fails, it will throw
`statvfs() function failed: No such file or directory`, but will not
show what file is missing.

Steps I used to reproduce the FACT-2928 error:

`$ yum install bind-chroot -y`
...
`$ systemctl start named-chroot`

Place a binding to stop execution above https://github.com/puppetlabs/facter/blob/main/lib/facter/util/resolvers/filesystem_helper.rb#L20
`$ puppet facts show`

  `require 'sys/filesystem'
=> binding.pry
   Sys::Filesystem.stat(path)`

When binding.pry is hit, run `$ systemctl stop named-chroot`, then
continue execution.
@Dorin-Pleava Dorin-Pleava force-pushed the FACT-2928_better_error_reading_mountpoints_stats branch from ffa514f to 29b668b Compare April 28, 2021 12:42
get_bytes_data(mount, stats)
rescue Sys::Filesystem::Error => e
@log.debug("Could not get stats for mountpoint #{mount[:path]}, got #{e}")
mount[:size_bytes] = mount[:available_bytes] = mount[:used_bytes] = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it help if we add this facts with value 0? since this is not the real information.
What happens if we do not set a value for this fields?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is for consistency, we have similar behavior in osx resolver:

size_bytes = used_bytes = available_bytes = 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will fail when trying to calculate total_bytes, https://github.com/puppetlabs/facter/blob/main/lib/facter/resolvers/mountpoints.rb#L74 and the fact will return nil.
I added the 0 values as the mountpoint fact already had some real data in it, like mount[:device], mount[:filesystem], mount[:path] and mount[:options]

@gimmyxd gimmyxd requested a review from a team April 29, 2021 06:41
@ciprianbadescu ciprianbadescu merged commit 0679e7f into puppetlabs:main May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants