-
Notifications
You must be signed in to change notification settings - Fork 679
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
mount resource: fix for Device-/Sharenames and Mountpoints including … #2257
Conversation
Please note, this PR do not address the case, when the Share-/Devicename and/or Mountpoint includes words like
Will most likely render wrong results / unexpected behavoir. |
…whitespaces Device-/Sharenames and Mountpoints on Linux may include whitespaces (\040), e.g. /etc/fstab entry like: ```//fileserver.corp.internal/Research\040&\040Development /mnt/Research\040&\040Development cifs OTHER_OPTS``` ... results in a mount line like: ```//fileserver.corp.internal/Research & Development on /mnt/Research & Development type cifs (OTHER_OPTS)``` The Linux mount command replaces \040 with whitspace automatically, so this should be tributed. I used a control like this: ``` describe mount('/mnt/Research & Development') do it { should be_mounted } its('device') { should eq '//fileserver.corp.internal/Research & Development' } end ``` Before: ``` × whitespaces-1: Mount with whitespace within sharename and mountpoint. (1 failed) ✔ Mount /mnt/Research & Development should be mounted × Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" expected: "//fileserver.corp.internal/Research & Development" got: "//fileserver.corp.internal/Research" (compared using ==) ``` After: ``` ✔ whitespaces-01: Mount with whitespace within sharename and mountpoint. ✔ Mount /mnt/Research & Development should be mounted ✔ Mount /mnt/Research & Development device should eq "//fileserver.corp.internal/Research & Development" ``` Signed-off-by: Markus Grobelin <[email protected]>
Signed-off-by: Markus Grobelin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good! Just a couple of code-cleanup items and a suggestion on a potential way around the "type" being in device/share names.
lib/utils/parser.rb
Outdated
other_opts = type_split[1] | ||
fs, path = fs_path.match(%r{^(.+?)\son\s(/.+?)$}).captures | ||
mount = [fs, 'on', path, 'type'] | ||
mount.concat other_opts.scan(/\S+/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to standardize on wrapping all method arguments in parentheses. Can you change this to:
mount.concat(other_opts.scan(/\S+/))
... so it's clearer? Thanks!
lib/utils/parser.rb
Outdated
# Device-/Sharename or Mountpoint includes whitespaces? | ||
def includes_whitespaces?(mount_line) | ||
ws = mount_line.match(/^(.+)\son\s(.+)\stype\s.*$/) | ||
ws.captures[0].include? ' ' or ws.captures[1].include? ' ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.. each of the include?
method calls should wrap their arguments with parentheses, please. :)
lib/utils/parser.rb
Outdated
@@ -67,7 +67,19 @@ module LinuxMountParser | |||
# this parses the output of mount command (only tested on linux) | |||
# this method expects only one line of the mount output | |||
def parse_mount_options(mount_line, compatibility = false) | |||
mount = mount_line.scan(/\S+/) | |||
if includes_whitespaces? mount_line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the other review comments, please wrap arguments with parentheses:
if includes_whitespaces?(mount_line)
lib/utils/parser.rb
Outdated
if includes_whitespaces? mount_line | ||
# Device-/Sharenames and Mountpoints including whitespaces require special treatment: | ||
# We use the keyword ' type ' to split up and rebuild the desired array of fields | ||
type_split = mount_line.split(' type ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to use rindex
to get the right-most type
to avoid picking up a share name with the word type
in it with spaces:
type_index = mount_line.rindex(' type ')
fs_path = mount_line[0...type_index]
other_opts_index = type_index + 6 # since ' type ' is 6 chars
other_opts = mount_line[other_opts_index..-1]
# ... etc ...
I think this might decently well, but would need to be tested. Worth playing around with a bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely worth, but I left it out for now due to high complexity. Maybe later, but I cannot promise due to endofyear-crunch.
If one would address this edge-case, it might be clever to do the same for BsdMountParser
, right? What would be your suggestion to keep it DRY?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK leaving it out for this PR and we can circle back to it if someone raises a bug or if you feel like coming back for a second iteration. :)
I would definitely DRY it up if possible as long as it doesn't make it too complicated. I'm happy to help as needed!
…chef/inspec/pull/2257/files Signed-off-by: Markus Grobelin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgrobelin just one more set of parentheses was missed in your last commit from my initial review, and then I think we can move forward with this. Thanks!
lib/utils/parser.rb
Outdated
@@ -67,7 +67,19 @@ module LinuxMountParser | |||
# this parses the output of mount command (only tested on linux) | |||
# this method expects only one line of the mount output | |||
def parse_mount_options(mount_line, compatibility = false) | |||
mount = mount_line.scan(/\S+/) | |||
if includes_whitespaces? mount_line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed one set of parentheses here and then I think we're good!
…whitespaces Signed-off-by: Markus Grobelin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this fix, @mgrobelin!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mgrobelin and @adamleff
…whitespaces
Device-/Sharenames and Mountpoints on Linux may include whitespaces (\040), e.g. /etc/fstab entry like:
... results in a mount line like:
The Linux mount command replaces \040 with whitspace automatically, so this should be tributed.
I used a control like this:
Before:
After:
Signed-off-by: Markus Grobelin [email protected]