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

mount resource: fix for Device-/Sharenames and Mountpoints including … #2257

Merged
merged 4 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion lib/utils/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# 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 ')
fs_path = type_split[0]
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+/))
else
# ... otherwise we just split the fields by whitespaces
mount = mount_line.scan(/\S+/)
end

# parse device and type
mount_options = { device: mount[0], type: mount[4] }
Expand All @@ -92,6 +104,12 @@ def parse_mount_options(mount_line, compatibility = false)

mount_options
end

# 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?(' ')
end
end

module BsdMountParser
Expand Down
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def md.directory?
# mount
"mount | grep -- ' on /'" => cmd.call("mount"),
"mount | grep -- ' on /mnt/iso-disk'" => cmd.call("mount-multiple"),
"mount | grep -- ' on /mnt/Research & Development'" => cmd.call("mount-whitespaces"),
# solaris 10 package manager
'pkginfo -l SUNWzfsr' => cmd.call('pkginfo-l-SUNWzfsr'),
# solaris 11 package manager
Expand Down
1 change: 1 addition & 0 deletions test/unit/mock/cmd/mount-whitespaces
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//fileserver.corp.internal/Research & Development on /mnt/Research & Development type cifs (rw,vers=1.0)
9 changes: 9 additions & 0 deletions test/unit/resources/mount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@
iso_resource.send(:options).must_equal(['ro'])
iso_resource.send(:count).must_equal(2)
end

let(:ws_resource) { load_resource('mount', '/mnt/Research & Development') }

it 'parses the mount data properly even if whitespaces are included' do
ws_resource.send(:device).must_equal('//fileserver.corp.internal/Research & Development')
ws_resource.send(:type).must_equal('cifs')
ws_resource.send(:options).must_equal(['rw','vers=1.0'])
ws_resource.send(:count).must_equal(1)
end
end