Skip to content

Commit

Permalink
Merge pull request #70 from yast/fix_crash
Browse files Browse the repository at this point in the history
Fix crash
  • Loading branch information
jreidinger committed Aug 23, 2018
2 parents 99ab4f1 + adcae72 commit d81c0fe
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package/yast2-nfs-client.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Aug 23 10:47:00 UTC 2018 - jreidinger@suse.com

- do not crash when nfs version is written as 4.0 instead of 4
(bsc#1105674)
- 4.1.0

-------------------------------------------------------------------
Wed Aug 22 16:07:12 CEST 2018 - schubi@suse.de

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-nfs-client.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-nfs-client
Version: 4.0.7
Version: 4.1.0
Release: 0
Url: https://github.com/yast/yast-nfs-client

Expand Down
4 changes: 3 additions & 1 deletion src/lib/y2nfs_client/nfs_version.rb
Expand Up @@ -63,9 +63,11 @@ def self.all
# @see #mntops_value
#
# @param value [String]
# @raise Argument error for parameter for which matching version is not found
# @return [NfsVersion]
def self.for_mntops_value(value)
all.find { |version| version.mntops_value == value }
value = "4" if value == "4.0"
all.find { |version| version.mntops_value == value } or raise ArgumentError, "Unknown value #{value.inspect}"
end

# Value used in the corresponding mount option (nfsvers or vers)
Expand Down
9 changes: 7 additions & 2 deletions src/modules/Nfs.rb
Expand Up @@ -197,8 +197,13 @@ def ImportAny(settings)

# vfstype can override a missing enable_nfs4
@nfs4_enabled = true if Builtins.find(entries) do |entry|
version = NfsOptions.nfs_version(entry["nfs_options"] || "")
version && version.requires_v4?
begin
version = NfsOptions.nfs_version(entry["nfs_options"] || "")
version.requires_v4?
rescue ArgumentError => e
log.error "Invalid version #{e.inspect} in entry #{entry.inspect}"
false
end
end

@nfs_entries = Builtins.maplist(entries) do |entry|
Expand Down
1 change: 1 addition & 0 deletions src/modules/NfsOptions.rb
Expand Up @@ -181,6 +181,7 @@ def validate(options)
#
# @param options [String] mount options in the comma-separated format used
# by mount and /etc/fstab
# @raise [ArgumentError] if no matching version is found
# @return [Y2NfsClient::NfsVersion]
def nfs_version(options)
option_list = from_string(options)
Expand Down
11 changes: 11 additions & 0 deletions test/nfs_options_test.rb
Expand Up @@ -107,6 +107,7 @@
{
"nfsvers=4" => "4",
"nfsvers=4,minorversion=1" => "4",
"nfsvers=4.0" => "4",
"defaults,nfsvers=3" => "3",
"nfsvers=4.1,nolock" => "4.1"
}.each_pair do |opts, version|
Expand Down Expand Up @@ -136,6 +137,16 @@
expect(returned.mntops_value).to eq version
end
end

it "raises ArgumentError if unknown version appears" do
[
"nfsvers=4.5",
"vers=5,rw"
].each do |opts|
expect { Yast::NfsOptions.nfs_version(opts) }.to raise_error(ArgumentError)
end

end
end

describe "#set_nfs_version" do
Expand Down

0 comments on commit d81c0fe

Please sign in to comment.